Skip to content

Commit 43ab210

Browse files
Add toggles for booleans on contest page.
Fixes #2420
1 parent e391fd5 commit 43ab210

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

webapp/src/Controller/Jury/ContestController.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,43 @@ public function viewAction(Request $request, int $contestId): Response
342342
]);
343343
}
344344

345-
#[Route(path: '/{contestId}/toggle-submit', name: 'jury_contest_toggle_submit')]
346-
public function toggleSubmitAction(Request $request, string $contestId): Response
345+
#[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
347347
{
348348
$contest = $this->em->getRepository(Contest::class)->find($contestId);
349349
if (!$contest) {
350350
throw new NotFoundHttpException(sprintf('Contest with ID %s not found', $contestId));
351351
}
352352

353-
$contest->setAllowSubmit($request->request->getBoolean('allow_submit'));
353+
$value = $request->request->getBoolean('value');
354+
355+
switch ($type) {
356+
case 'submit':
357+
$contest->setAllowSubmit($value);
358+
$label = 'set allow submit';
359+
break;
360+
case 'balloons':
361+
$contest->setProcessBalloons($value);
362+
$label = 'set process balloons';
363+
break;
364+
case 'tiebreaker':
365+
$contest->setRuntimeAsScoreTiebreaker($value);
366+
$label = 'set runtime as tiebreaker';
367+
break;
368+
case 'medals':
369+
$contest->setMedalsEnabled($value);
370+
$label = 'set medal processing';
371+
break;
372+
case 'public':
373+
$contest->setPublic($value);
374+
$label = 'set publicly visible';
375+
break;
376+
default:
377+
throw new BadRequestHttpException('Unknown toggle type');
378+
}
354379
$this->em->flush();
355380

356-
$this->dj->auditlog('contest', $contestId, 'set allow submit',
357-
$request->request->getBoolean('allow_submit') ? 'yes' : 'no');
381+
$this->dj->auditlog('contest', $contestId, $label, $value ? 'yes' : 'no');
358382
return $this->redirectToRoute('jury_contest', ['contestId' => $contestId]);
359383
}
360384

webapp/templates/jury/contest.html.twig

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@
107107
<tr>
108108
<th>Allow submit</th>
109109
<td>
110-
<form action="{{ path('jury_contest_toggle_submit', {'contestId': contest.cid}) }}" method="post" class="d-inline">
110+
<form action="{{ path('jury_contest_toggle', {'contestId': contest.cid, 'type': 'submit'}) }}" method="post" class="d-inline">
111111
<input type="checkbox" data-toggle="toggle" data-size="mini" data-on="Yes" data-off="No"
112-
name="allow_submit" {% if contest.allowSubmit %}checked{% endif %}>
112+
name="value" {% if contest.allowSubmit %}checked{% endif %}>
113113
</form>
114114
</td>
115115
</tr>
@@ -126,15 +126,30 @@
126126
{% endif %}
127127
<tr>
128128
<th>Process balloons</th>
129-
<td>{{ contest.processBalloons | printYesNo }}</td>
129+
<td>
130+
<form action="{{ path('jury_contest_toggle', {'contestId': contest.cid, 'type': 'balloons'}) }}" method="post" class="d-inline">
131+
<input type="checkbox" data-toggle="toggle" data-size="mini" data-on="Yes" data-off="No"
132+
name="value" {% if contest.processBalloons %}checked{% endif %}>
133+
</form>
134+
</td>
130135
</tr>
131136
<tr>
132137
<th>Runtime as tiebreaker</th>
133-
<td>{{ contest.runtimeAsScoreTiebreaker | printYesNo }}</td>
138+
<td>
139+
<form action="{{ path('jury_contest_toggle', {'contestId': contest.cid, 'type': 'tiebreaker'}) }}" method="post" class="d-inline">
140+
<input type="checkbox" data-toggle="toggle" data-size="mini" data-on="Yes" data-off="No"
141+
name="value" {% if contest.runtimeAsScoreTiebreaker %}checked{% endif %}>
142+
</form>
143+
</td>
134144
</tr>
135145
<tr>
136146
<th>Process medals</th>
137-
<td>{{ contest.medalsEnabled | printYesNo }}</td>
147+
<td>
148+
<form action="{{ path('jury_contest_toggle', {'contestId': contest.cid, 'type': 'medals'}) }}" method="post" class="d-inline">
149+
<input type="checkbox" data-toggle="toggle" data-size="mini" data-on="Yes" data-off="No"
150+
name="value" {% if contest.medalsEnabled %}checked{% endif %}>
151+
</form>
152+
</td>
138153
</tr>
139154
<tr>
140155
<th>Medals</th>
@@ -175,7 +190,12 @@
175190
</tr>
176191
<tr>
177192
<th>Publicly visible</th>
178-
<td>{{ contest.public | printYesNo }}</td>
193+
<td>
194+
<form action="{{ path('jury_contest_toggle', {'contestId': contest.cid, 'type': 'public'}) }}" method="post" class="d-inline">
195+
<input type="checkbox" data-toggle="toggle" data-size="mini" data-on="Yes" data-off="No"
196+
name="value" {% if contest.public %}checked{% endif %}>
197+
</form>
198+
</td>
179199
</tr>
180200
<tr>
181201
<th>Open to all teams</th>

0 commit comments

Comments
 (0)