Skip to content

Commit 5fbfdd1

Browse files
committed
Add tag to submissions in the controller
In the controller we already have all information which we need for the tag, so we do not need a bunch of comparisons to figure out the correct tag. This also enables us to reuse the tag for the diff part of the title.
1 parent 6a13826 commit 5fbfdd1

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

webapp/src/Controller/Jury/SubmissionController.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,18 @@ public function sourceAction(
839839
return $response;
840840
}
841841

842+
/** @var array{
843+
* submitid: int,
844+
* tag?: string
845+
* } otherSubmissions
846+
*/
842847
$otherSubmissions = [];
843848
$originalSubmission = $submission->getOriginalSubmission();
844849
if ($originalSubmission) {
845-
$otherSubmissions[] = $originalSubmission;
850+
$otherSubmissions[] = [
851+
'submitid' => $originalSubmission->getSubmitid(),
852+
'tag' => 'original',
853+
];
846854
/** @var Submission $oldSubmission */
847855
$oldSubmission = $this->em->createQueryBuilder()
848856
->from(Submission::class, 's')
@@ -879,10 +887,13 @@ public function sourceAction(
879887
->getOneOrNullResult();
880888
}
881889
if ($oldSubmission !== null) {
882-
$otherSubmissions[] = $oldSubmission;
890+
$otherSubmissions[] = [
891+
'submitid' => $oldSubmission->getSubmitid(),
892+
'tag' => 'previous',
893+
];;
883894
}
884895

885-
$files_query = array_map(fn($s) => $s->getSubmitid(), $otherSubmissions);
896+
$files_query = array_map(fn($s) => $s['submitid'], $otherSubmissions);
886897
$files_query[] = $submission->getSubmitid();
887898
/** @var SubmissionFile[] $oldFiles */
888899
$oldFiles = $this->em->createQueryBuilder()

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@
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-
{%- set tag = "" %}
35-
{%- if originalSubmission and originalSubmission.submitid == other.submitid %}
36-
{%- set tag = "original" %}
37-
{%- elseif oldSubmission and oldSubmission.submitid == other.submitid %}
38-
{%- set tag = "previous" %}
39-
{%- endif %}
40-
<option value="{{ other.submitid }}" {%- if tag %} data-tag="{{ tag }}" {%- endif %}>
41-
s{{ other.submitid }} {%- if tag %} ({{ tag }}) {%- endif %}
34+
<option value="{{ other.submitid }}" {%- if other.tag %} data-tag="{{ other.tag }}" {%- endif %}>
35+
s{{ other.submitid }} {%- if other.tag %} ({{ other.tag }}) {%- endif %}
4236
</option>
4337
{%- endfor %}
4438
</select>

0 commit comments

Comments
 (0)