Skip to content

Commit b24ade1

Browse files
Show toggles for contest booleans at problems page.
1 parent b24d07c commit b24ade1

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

webapp/src/Controller/Jury/ProblemController.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
use Symfony\Component\HttpFoundation\Request;
3535
use Symfony\Component\HttpFoundation\Response;
3636
use Symfony\Component\HttpFoundation\StreamedResponse;
37+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
3738
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3839
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
3940
use Symfony\Component\HttpKernel\KernelInterface;
4041
use Symfony\Component\PropertyAccess\PropertyAccess;
4142
use Symfony\Component\Routing\Attribute\Route;
43+
use Symfony\Component\Routing\RouterInterface;
4244
use Symfony\Component\Security\Http\Attribute\IsGranted;
4345
use Symfony\Component\Yaml\Yaml;
4446
use ZipArchive;
@@ -1151,6 +1153,43 @@ public function requestRemainingRunsWholeProblemAction(string $probId): Redirect
11511153
return $this->redirectToRoute('jury_problem', ['probId' => $probId]);
11521154
}
11531155

1156+
#[Route(path: '/{contestId}/{probId}/toggle/{type<judge|submit>}', name: 'jury_problem_toggle')]
1157+
public function toggleSubmitAction(
1158+
RouterInterface $router,
1159+
Request $request,
1160+
string $contestId,
1161+
string $probId,
1162+
string $type
1163+
): Response {
1164+
$contestProblem = $this->em->getRepository(ContestProblem::class)->find([
1165+
'contest' => $contestId,
1166+
'problem' => $probId,
1167+
]);
1168+
if (!$contestProblem) {
1169+
throw new NotFoundHttpException(sprintf('Problem with ID %s not found for contest %s', $probId, $contestId));
1170+
}
1171+
1172+
$value = $request->request->getBoolean('value');
1173+
1174+
switch ($type) {
1175+
case 'judge':
1176+
$contestProblem->setAllowJudge($value);
1177+
$label = 'set allow judge';
1178+
break;
1179+
case 'submit':
1180+
$contestProblem->setAllowSubmit($value);
1181+
$label = 'set allow submit';
1182+
break;
1183+
default:
1184+
throw new BadRequestHttpException('Unknown toggle type');
1185+
}
1186+
$this->em->flush();
1187+
1188+
$id = [$contestProblem->getCid(), $contestProblem->getProbid()];
1189+
$this->dj->auditlog('contest_problem', implode(', ', $id), $label, $value ? 'yes' : 'no');
1190+
return $this->redirectToLocalReferrer($router, $request, $this->generateUrl('jury_problems'));
1191+
}
1192+
11541193
/**
11551194
* @param array<string, string[]> $allMessages
11561195
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<form action="{{ path('jury_problem_toggle', {contestId: contestProblem.cid, probId: contestProblem.probId, 'type': type}) }}" method="post" class="d-inline">
2+
<input type="checkbox" data-toggle="toggle" data-size="mini" data-on="Yes" data-off="No"
3+
name="value" {% if enabled %}checked{% endif %}>
4+
</form>

webapp/templates/jury/problem.html.twig

Lines changed: 11 additions & 2 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 %}
@@ -163,10 +164,14 @@
163164
<a href="{{ link }}">{{ contestProblem.shortname }}</a>
164165
</td>
165166
<td>
166-
<a href="{{ link }}">{{ contestProblem.allowSubmit | printYesNo }}</a>
167+
<a href="{{ link }}">
168+
{% include 'jury/partials/problem_toggle.html.twig' with {type: 'submit', enabled: contestProblem.allowSubmit} %}
169+
</a>
167170
</td>
168171
<td>
169-
<a href="{{ link }}">{{ contestProblem.allowJudge | printYesNo }}</a>
172+
<a href="{{ link }}">
173+
{% include 'jury/partials/problem_toggle.html.twig' with {type: 'judge', enabled: contestProblem.allowJudge} %}
174+
</a>
170175
</td>
171176
{% if contestProblem.color is empty %}
172177
<td><a href="{{ link }}">&nbsp;</a></td>
@@ -249,3 +254,7 @@
249254
</div>
250255

251256
{% endblock %}
257+
258+
{% block extrafooter %}
259+
{{ macros.toggle_autosubmit_extrafooter() }}
260+
{% endblock %}

0 commit comments

Comments
 (0)