Skip to content

Commit 83b3b7f

Browse files
nickygerritsenmeisterT
authored andcommitted
Add support for toggles in macro tables and use it for contests and languages.
1 parent b793bec commit 83b3b7f

File tree

5 files changed

+73
-14
lines changed

5 files changed

+73
-14
lines changed

webapp/src/Controller/Jury/ContestController.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use Symfony\Component\HttpKernel\KernelInterface;
4545
use Symfony\Component\PropertyAccess\PropertyAccess;
4646
use Symfony\Component\Routing\Attribute\Route;
47+
use Symfony\Component\Routing\RouterInterface;
4748
use Symfony\Component\Security\Http\Attribute\IsGranted;
4849

4950
#[IsGranted('ROLE_JURY')]
@@ -186,12 +187,29 @@ public function indexAction(Request $request): Response
186187
}
187188

188189
$contestdata['process_balloons'] = [
189-
'value' => $contest->getProcessBalloons() ? 'yes' : 'no'
190+
'toggle_partial' => 'contest_toggle.html.twig',
191+
'partial_arguments' => [
192+
'type' => 'balloons',
193+
'contest' => $contest,
194+
'enabled' => $contest->getProcessBalloons(),
195+
],
190196
];
191197
$contestdata['medals_enabled'] = [
192-
'value' => $contest->getMedalsEnabled() ? 'yes' : 'no'
198+
'toggle_partial' => 'contest_toggle.html.twig',
199+
'partial_arguments' => [
200+
'type' => 'medals',
201+
'contest' => $contest,
202+
'enabled' => $contest->getMedalsEnabled(),
203+
],
204+
];
205+
$contestdata['public'] = [
206+
'toggle_partial' => 'contest_toggle.html.twig',
207+
'partial_arguments' => [
208+
'type' => 'public',
209+
'contest' => $contest,
210+
'enabled' => $contest->getPublic(),
211+
],
193212
];
194-
$contestdata['public'] = ['value' => $contest->getPublic() ? 'yes' : 'no'];
195213
if ($contest->isOpenToAllTeams()) {
196214
$contestdata['num_teams'] = ['value' => 'all'];
197215
} else {
@@ -343,8 +361,12 @@ public function viewAction(Request $request, int $contestId): Response
343361
}
344362

345363
#[Route(path: '/{contestId}/toggle/{type<submit|balloons|tiebreaker|medals|public>}', name: 'jury_contest_toggle')]
346-
public function toggleSubmitAction(Request $request, string $contestId, string $type): Response
347-
{
364+
public function toggleSubmitAction(
365+
RouterInterface $router,
366+
Request $request,
367+
string $contestId,
368+
string $type
369+
): Response {
348370
$contest = $this->em->getRepository(Contest::class)->find($contestId);
349371
if (!$contest) {
350372
throw new NotFoundHttpException(sprintf('Contest with ID %s not found', $contestId));
@@ -379,7 +401,11 @@ public function toggleSubmitAction(Request $request, string $contestId, string $
379401
$this->em->flush();
380402

381403
$this->dj->auditlog('contest', $contestId, $label, $value ? 'yes' : 'no');
382-
return $this->redirectToRoute('jury_contest', ['contestId' => $contestId]);
404+
return $this->redirectToLocalReferrer(
405+
$router,
406+
$request,
407+
$this->generateUrl('jury_contest', ['contestId' => $contestId])
408+
);
383409
}
384410

385411
#[Route(path: '/{contestId<\d+>}/remove-interval/{intervalId}', name: 'jury_contest_remove_interval', methods: ['POST'])]

webapp/src/Controller/Jury/LanguageController.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\HttpKernel\KernelInterface;
2323
use Symfony\Component\PropertyAccess\PropertyAccess;
2424
use Symfony\Component\Routing\Attribute\Route;
25+
use Symfony\Component\Routing\RouterInterface;
2526
use Symfony\Component\Security\Http\Attribute\IsGranted;
2627

2728
#[IsGranted('ROLE_JURY')]
@@ -98,12 +99,24 @@ public function indexAction(): Response
9899

99100
$executable = $lang->getCompileExecutable();
100101

102+
$allowJudgeOptions = [
103+
'toggle_partial' => 'language_toggle.html.twig',
104+
'partial_arguments' => [
105+
'path' => 'jury_language_toggle_judge',
106+
'language' => $lang,
107+
'value' => $lang->getAllowJudge(),
108+
],
109+
];
110+
111+
if (!$lang->getAllowJudge()) {
112+
$allowJudgeOptions['cssclass'] = 'text-danger font-weight-bold';
113+
}
114+
101115
// Merge in the rest of the data.
102116
$langdata = array_merge($langdata, [
103117
'entrypoint' => ['value' => $lang->getRequireEntryPoint() ? 'yes' : 'no'],
104118
'extensions' => ['value' => implode(', ', $lang->getExtensions())],
105-
'allowjudge' => $lang->getAllowJudge() ?
106-
['value' => 'yes'] : ['value' => 'no', 'cssclass'=>'text-danger font-weight-bold'],
119+
'allowjudge' => $allowJudgeOptions,
107120
'executable' => [
108121
'value' => $executable === null ? '-' : $executable->getShortDescription(),
109122
'link' => $executable === null ? null : $this->generateUrl('jury_executable', [
@@ -222,8 +235,11 @@ public function toggleSubmitAction(Request $request, string $langId): Response
222235
}
223236

224237
#[Route(path: '/{langId}/toggle-judge', name: 'jury_language_toggle_judge')]
225-
public function toggleJudgeAction(Request $request, string $langId): Response
226-
{
238+
public function toggleJudgeAction(
239+
RouterInterface $router,
240+
Request $request,
241+
string $langId
242+
): Response {
227243
$language = $this->em->getRepository(Language::class)->find($langId);
228244
if (!$language) {
229245
throw new NotFoundHttpException(sprintf('Language with ID %s not found', $langId));
@@ -239,7 +255,11 @@ public function toggleJudgeAction(Request $request, string $langId): Response
239255

240256
$this->dj->auditlog('language', $langId, 'set allow judge',
241257
$request->request->getBoolean('value') ? 'yes' : 'no');
242-
return $this->redirectToRoute('jury_language', ['langId' => $langId]);
258+
return $this->redirectToLocalReferrer(
259+
$router,
260+
$request,
261+
$this->generateUrl('jury_language', ['langId' => $langId])
262+
);
243263
}
244264

245265
#[Route(path: '/{langId}/toggle-filter-compiler-flags', name: 'jury_language_toggle_filter_compiler_files')]

webapp/templates/jury/contests.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{% block extrahead %}
77
{{ parent() }}
88
{{ macros.table_extrahead() }}
9+
{{ macros.toggle_extrahead() }}
910
{% endblock %}
1011

1112
{% block content %}
@@ -88,3 +89,8 @@
8889
{% endif %}
8990

9091
{% endblock %}
92+
93+
{% block extrafooter %}
94+
{{ macros.toggle_autosubmit_extrafooter() }}
95+
{% endblock %}
96+

webapp/templates/jury/jury_macros.twig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@
131131
{%- if item.sortvalue is defined %} data-sort="{{ item.sortvalue }}"{% endif %}
132132
{% if (column.render | default('')) == "entity_id_badge" %}style="text-align: right;" {% endif %}>
133133
{%- if item.link is defined %}<a href="{{ item.link }}" {%- if item.showlink is defined %} class="showlink"{% endif %}>
134-
{%- elseif row.link is defined %}<a href="{{ row.link }}">{% endif %}
135-
{% if key == "status" %}
134+
{%- elseif row.link is defined and not item.toggle_partial is defined %}<a href="{{ row.link }}">{% endif %}
135+
{% if item.toggle_partial is defined %}
136+
{% include 'jury/partials/' ~ item.toggle_partial with item.partial_arguments %}
137+
{% elseif key == "status" %}
136138
{{- (item.value|default(item.default|default('')))|statusIcon -}}
137139
{% elseif key == "country" %}
138140
{{- (item.value|default(item.default|default('')))|countryFlag -}}
@@ -150,7 +152,7 @@
150152
{{- (item.value|default(item.default|default(''))) -}}
151153
{% endif %}
152154
{% if item.icon is defined %}<i class="fas fa-{{ item.icon }}"></i>{%- endif %}
153-
{%- if item.link is defined or row.link is defined -%}</a>{% endif %}
155+
{%- if item.link is defined or (row.link is defined and not item.toggle_partial is defined) -%}</a>{% endif %}
154156
</td>
155157
{%- endfor %}
156158
{%- for action in row.actions %}

webapp/templates/jury/languages.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{% block extrahead %}
77
{{ parent() }}
88
{{ macros.table_extrahead() }}
9+
{{ macros.toggle_extrahead() }}
910
{% endblock %}
1011

1112
{% block content %}
@@ -28,3 +29,7 @@
2829
{% endif %}
2930

3031
{% endblock %}
32+
33+
{% block extrafooter %}
34+
{{ macros.toggle_autosubmit_extrafooter() }}
35+
{% endblock %}

0 commit comments

Comments
 (0)