Skip to content

Commit 09dcacf

Browse files
committed
Add multi-delete options for teams.
Part of #229.
1 parent 962f109 commit 09dcacf

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

webapp/src/Controller/Jury/TeamController.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ public function indexAction(): Response
102102
'stats' => ['title' => 'stats', 'sort' => true,],
103103
];
104104

105+
if ($this->isGranted('ROLE_ADMIN')) {
106+
$table_fields = array_merge(
107+
['checkbox' => ['title' => '<input type="checkbox" class="select-all" title="Select all teams">', 'sort' => false, 'search' => false, 'raw' => true]],
108+
$table_fields
109+
);
110+
}
111+
105112
$userDataPerTeam = $this->em->createQueryBuilder()
106113
->from(Team::class, 't', 't.teamid')
107114
->leftJoin('t.users', 'u')
@@ -115,6 +122,36 @@ public function indexAction(): Response
115122
foreach ($teams as $t) {
116123
$teamdata = [];
117124
$teamactions = [];
125+
126+
if ($this->isGranted('ROLE_ADMIN')) {
127+
$isLocked = false;
128+
foreach ($t->getContests() as $contest) {
129+
if ($contest->isLocked()) {
130+
$isLocked = true;
131+
break;
132+
}
133+
}
134+
if (!$isLocked && $t->getCategory()) {
135+
foreach ($t->getCategory()->getContests() as $contest) {
136+
if ($contest->isLocked()) {
137+
$isLocked = true;
138+
break;
139+
}
140+
}
141+
}
142+
143+
if (!$isLocked) {
144+
$teamdata['checkbox'] = [
145+
'value' => sprintf(
146+
'<input type="checkbox" name="ids[]" value="%s" class="team-checkbox">',
147+
$t->getTeamid()
148+
)
149+
];
150+
} else {
151+
$teamdata['checkbox'] = ['value' => ''];
152+
}
153+
}
154+
118155
// Get whatever fields we can from the team object itself.
119156
foreach ($table_fields as $k => $v) {
120157
if ($propertyAccessor->isReadable($t, $k)) {
@@ -346,6 +383,47 @@ public function deleteAction(Request $request, int $teamId): Response
346383
return $this->deleteEntities($request, [$team], $this->generateUrl('jury_teams'));
347384
}
348385

386+
#[IsGranted('ROLE_ADMIN')]
387+
#[Route(path: '/delete-multiple', name: 'jury_team_delete_multiple', methods: ['GET', 'POST'])]
388+
public function deleteMultipleAction(Request $request): Response
389+
{
390+
$ids = $request->query->all('ids');
391+
if (empty($ids)) {
392+
throw new BadRequestHttpException('No IDs specified for deletion');
393+
}
394+
395+
$teams = $this->em->getRepository(Team::class)->findBy(['teamid' => $ids]);
396+
397+
$deletableTeams = [];
398+
foreach ($teams as $team) {
399+
$isLocked = false;
400+
foreach ($team->getContests() as $contest) {
401+
if ($contest->isLocked()) {
402+
$isLocked = true;
403+
break;
404+
}
405+
}
406+
if (!$isLocked && $team->getCategory()) {
407+
foreach ($team->getCategory()->getContests() as $contest) {
408+
if ($contest->isLocked()) {
409+
$isLocked = true;
410+
break;
411+
}
412+
}
413+
}
414+
if (!$isLocked) {
415+
$deletableTeams[] = $team;
416+
}
417+
}
418+
419+
if (empty($deletableTeams)) {
420+
$this->addFlash('warning', 'No teams could be deleted (they might be in a locked contest).');
421+
return $this->redirectToRoute('jury_teams');
422+
}
423+
424+
return $this->deleteEntities($request, $deletableTeams, $this->generateUrl('jury_teams'));
425+
}
426+
349427
#[IsGranted('ROLE_ADMIN')]
350428
#[Route(path: '/add', name: 'jury_team_add')]
351429
public function addAction(Request $request): Response

webapp/templates/jury/teams.html.twig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,24 @@
1515
{{ macros.table(teams, table_fields) }}
1616

1717
{%- if is_granted('ROLE_ADMIN') %}
18-
19-
<p>
18+
<p class="mt-4">
19+
{% include 'jury/partials/_delete_button.html.twig' with {'entities': teams} %}
2020
{{ button(path('jury_team_add'), 'Add new team', 'primary', 'plus') }}
2121
{{ button(path('jury_import_export', {'_fragment':'teams'}), 'Import teams', 'primary', 'upload') }}
2222
</p>
2323
{%- endif %}
2424
{% endblock %}
25+
26+
{% block extrafooter %}
27+
{{ parent() }}
28+
<script src="{{ asset('js/multi-delete.js') }}"></script>
29+
<script>
30+
$(function() {
31+
initializeMultiDelete({
32+
buttonSelector: '#delete-selected-button',
33+
checkboxClass: 'team-checkbox',
34+
deleteUrl: '{{ path('jury_team_delete_multiple') }}'
35+
});
36+
});
37+
</script>
38+
{% endblock %}

0 commit comments

Comments
 (0)