Skip to content

Commit d9cca34

Browse files
committed
Update source diff title dynamically
1 parent 5fbfdd1 commit d9cca34

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

webapp/public/js/domjudge.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,10 @@ function initDiffEditor(editorId) {
13691369
}
13701370
})
13711371

1372+
const diffTitle = document.getElementById(`${editorId}-title-diff`);
1373+
const diffTag = diffTitle.querySelector('span.diff-tag');
1374+
const diffLink = diffTitle.querySelector('a.diff-link');
1375+
13721376
const editor = {
13731377
'getDiffMode': () => {
13741378
for (let radio of radios) {
@@ -1412,6 +1416,15 @@ function initDiffEditor(editorId) {
14121416
if (selected && selected.dataset.tag) {
14131417
setDiffTag(selected.dataset.tag);
14141418
}
1419+
1420+
if (noDiff) {
1421+
diffTitle.style.display = 'none';
1422+
} else {
1423+
diffTitle.style.display = 'inline';
1424+
diffTag.innerText = selected.dataset.tag;
1425+
diffLink.href = selected.dataset.url;
1426+
diffLink.innerText = `s${submitId}`;
1427+
}
14151428
};
14161429
updateSelect(parseInt(select[0].value), select[0].value === "");
14171430
editor.onDiffSelectChange(updateSelect);

webapp/public/style_jury.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,7 @@ table.table-full-clickable-cell tr .table-button-head-right-right{
248248
.timebutton {
249249
min-width: 9em;
250250
}
251+
252+
.diff-title {
253+
display: none;
254+
}

webapp/templates/jury/partials/submission_diff.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<select class="diff-select btn btn-secondary btn-sm form-select-sm text-start" aria-label="Submission to diff against">
3232
<option value="" data-tag="no-diff">No diff</option>
3333
{%- for other in otherSubmissions %}
34-
<option value="{{ other.submitid }}" {%- if other.tag %} data-tag="{{ other.tag }}" {%- endif %}>
34+
<option value="{{ other.submitid }}" data-url="{{ path('jury_submission', {submitId: other.submitid}) }}" {%- if other.tag %} data-tag="{{ other.tag }}" {%- endif %}>
3535
s{{ other.submitid }} {%- if other.tag %} ({{ other.tag }}) {%- endif %}
3636
</option>
3737
{%- endfor %}

webapp/templates/jury/submission_source.html.twig

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% endblock %}
99

1010
{% block content %}
11-
11+
{% set editor_id = "diffw" ~ submission.submitid %}
1212
<h1>
1313
Source code for submission
1414
<a href="{{ path('jury_submission', {submitId: submission.submitid}) }}">s{{ submission.submitid }}</a>
@@ -25,17 +25,15 @@
2525
)
2626
{% endif %}
2727

28-
{% if oldSubmission %}
29-
and diff to previous submission
30-
<a href="{{ path('jury_submission', {submitId: oldSubmission.submitid}) }}">
31-
s{{ oldSubmission.submitid }}
32-
</a>
33-
{% endif %}
28+
<span class="diff-title" id="{{editor_id}}-title-diff">
29+
and diff to <span class="diff-tag"></span> submission
30+
<a class="diff-link" href="#"></a>
31+
</span>
3432
</h1>
3533

3634
{%- if submission.entryPoint %}
3735
<p><b>Entry point</b>: {{ submission.entryPoint }}</p>
3836
{%- endif %}
3937

40-
{%- include 'jury/partials/submission_diff.html.twig' with {editor_id: "diffw" ~ submission.submitid} %}
38+
{%- include 'jury/partials/submission_diff.html.twig' with {editor_id: editor_id} %}
4139
{% endblock %}

0 commit comments

Comments
 (0)