From 957f6e93b89e49feb2e12529334f1cde9fcd7aac Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Sun, 7 May 2023 18:35:12 +0200 Subject: [PATCH] Auto calculate num actions for jury tables. (cherry picked from commit 1294b6e0306cc993bd950a56b5432fcc33d87237) # Conflicts: # webapp/src/Controller/Jury/ExecutableController.php # webapp/src/Twig/TwigExtension.php --- webapp/src/Controller/Jury/ContestController.php | 1 - webapp/src/Controller/Jury/ExecutableController.php | 1 - webapp/src/Controller/Jury/JudgehostController.php | 1 - webapp/src/Controller/Jury/LanguageController.php | 1 - webapp/src/Controller/Jury/ProblemController.php | 1 - .../src/Controller/Jury/TeamAffiliationController.php | 1 - webapp/src/Controller/Jury/TeamCategoryController.php | 1 - webapp/src/Controller/Jury/TeamController.php | 1 - webapp/src/Controller/Jury/UserController.php | 1 - webapp/src/Twig/TwigExtension.php | 10 ++++++++++ webapp/templates/jury/contests.html.twig | 2 +- webapp/templates/jury/executables.html.twig | 2 +- webapp/templates/jury/jury_macros.twig | 3 ++- webapp/templates/jury/languages.html.twig | 4 ++-- .../templates/jury/partials/judgehost_list.html.twig | 2 +- webapp/templates/jury/problems.html.twig | 2 +- webapp/templates/jury/team_affiliations.html.twig | 2 +- webapp/templates/jury/team_categories.html.twig | 2 +- webapp/templates/jury/teams.html.twig | 2 +- webapp/templates/jury/users.html.twig | 2 +- 20 files changed, 22 insertions(+), 20 deletions(-) diff --git a/webapp/src/Controller/Jury/ContestController.php b/webapp/src/Controller/Jury/ContestController.php index 0bfe46e49b..987d05e18e 100644 --- a/webapp/src/Controller/Jury/ContestController.php +++ b/webapp/src/Controller/Jury/ContestController.php @@ -379,7 +379,6 @@ public function indexAction(Request $request): Response 'upcoming_contest' => $upcomingContest, 'contests_table' => $contests_table, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') && !$contest->isLocked() ? 2 : 0, ]); } diff --git a/webapp/src/Controller/Jury/ExecutableController.php b/webapp/src/Controller/Jury/ExecutableController.php index f80f732a65..9cbb7afec1 100644 --- a/webapp/src/Controller/Jury/ExecutableController.php +++ b/webapp/src/Controller/Jury/ExecutableController.php @@ -116,7 +116,6 @@ public function indexAction(Request $request): Response return $this->render('jury/executables.html.twig', [ 'executables' => $executables_table, 'table_fields' => $table_fields, - 'num_actions' => count($execactions), 'form' => $form->createView(), ]); } diff --git a/webapp/src/Controller/Jury/JudgehostController.php b/webapp/src/Controller/Jury/JudgehostController.php index d4b0cdc807..afd7a024bc 100644 --- a/webapp/src/Controller/Jury/JudgehostController.php +++ b/webapp/src/Controller/Jury/JudgehostController.php @@ -184,7 +184,6 @@ public function indexAction(Request $request): Response $data = [ 'judgehosts' => $judgehosts_table, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') ? 2 : 0, 'all_checked_in_recently' => $all_checked_in_recently, 'refresh' => [ 'after' => 5, diff --git a/webapp/src/Controller/Jury/LanguageController.php b/webapp/src/Controller/Jury/LanguageController.php index f5f6c1683c..fb3c5e0020 100644 --- a/webapp/src/Controller/Jury/LanguageController.php +++ b/webapp/src/Controller/Jury/LanguageController.php @@ -146,7 +146,6 @@ public function indexAction(): Response 'enabled_languages' => $enabled_languages, 'disabled_languages' => $disabled_languages, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') ? 2 : 0, ]); } diff --git a/webapp/src/Controller/Jury/ProblemController.php b/webapp/src/Controller/Jury/ProblemController.php index 536c6fb928..62502bd74b 100644 --- a/webapp/src/Controller/Jury/ProblemController.php +++ b/webapp/src/Controller/Jury/ProblemController.php @@ -214,7 +214,6 @@ public function indexAction(): Response $data = [ 'problems' => $problems_table, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') ? 4 : 2, ]; return $this->render('jury/problems.html.twig', $data); diff --git a/webapp/src/Controller/Jury/TeamAffiliationController.php b/webapp/src/Controller/Jury/TeamAffiliationController.php index 62c12c5750..02436c76d5 100644 --- a/webapp/src/Controller/Jury/TeamAffiliationController.php +++ b/webapp/src/Controller/Jury/TeamAffiliationController.php @@ -143,7 +143,6 @@ public function indexAction(string $projectDir): Response return $this->render('jury/team_affiliations.html.twig', [ 'team_affiliations' => $team_affiliations_table, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') ? 2 : 0, ]); } diff --git a/webapp/src/Controller/Jury/TeamCategoryController.php b/webapp/src/Controller/Jury/TeamCategoryController.php index 9c0eecd9e6..789c12db82 100644 --- a/webapp/src/Controller/Jury/TeamCategoryController.php +++ b/webapp/src/Controller/Jury/TeamCategoryController.php @@ -127,7 +127,6 @@ public function indexAction(): Response return $this->render('jury/team_categories.html.twig', [ 'team_categories' => $team_categories_table, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') ? 2 : 0, ]); } diff --git a/webapp/src/Controller/Jury/TeamController.php b/webapp/src/Controller/Jury/TeamController.php index f4056c460d..500badb58e 100644 --- a/webapp/src/Controller/Jury/TeamController.php +++ b/webapp/src/Controller/Jury/TeamController.php @@ -239,7 +239,6 @@ public function indexAction(): Response return $this->render('jury/teams.html.twig', [ 'teams' => $teams_table, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') ? 3 : 1, ]); } diff --git a/webapp/src/Controller/Jury/UserController.php b/webapp/src/Controller/Jury/UserController.php index 7aed63c520..f69387ea69 100644 --- a/webapp/src/Controller/Jury/UserController.php +++ b/webapp/src/Controller/Jury/UserController.php @@ -184,7 +184,6 @@ public function indexAction(): Response return $this->render('jury/users.html.twig', [ 'users' => $users_table, 'table_fields' => $table_fields, - 'num_actions' => $this->isGranted('ROLE_ADMIN') ? 2 : 0, ]); } diff --git a/webapp/src/Twig/TwigExtension.php b/webapp/src/Twig/TwigExtension.php index 217b555ab4..4e1470b1b9 100644 --- a/webapp/src/Twig/TwigExtension.php +++ b/webapp/src/Twig/TwigExtension.php @@ -128,6 +128,7 @@ public function getFilters(): array new TwigFilter('printWarningContent', [$this, 'printWarningContent'], ['is_safe' => ['html']]), new TwigFilter('entityIdBadge', [$this, 'entityIdBadge'], ['is_safe' => ['html']]), new TwigFilter('medalType', [$this->awards, 'medalType']), + new TwigFilter('numTableActions', [$this, 'numTableActions']), ]; } @@ -1207,4 +1208,13 @@ public function entityIdBadge(BaseApiEntity $entity, string $idPrefix = ''): str 'externalId' => $externalIdField ? $propertyAccessor->getValue($entity, $externalIdField) : null, ]); } + + public function numTableActions(array $tableData): int + { + $maxNumActions = 0; + foreach ($tableData as $item) { + $maxNumActions = max($maxNumActions, count($item['actions'] ?? [])); + } + return $maxNumActions; + } } diff --git a/webapp/templates/jury/contests.html.twig b/webapp/templates/jury/contests.html.twig index a9af41e1a4..04cc260fc8 100644 --- a/webapp/templates/jury/contests.html.twig +++ b/webapp/templates/jury/contests.html.twig @@ -87,7 +87,7 @@

All available contests

- {{ macros.table(contests_table, table_fields, num_actions) }} + {{ macros.table(contests_table, table_fields) }} {% if is_granted('ROLE_ADMIN') %}

diff --git a/webapp/templates/jury/executables.html.twig b/webapp/templates/jury/executables.html.twig index 94af4cae5b..cd5276371e 100644 --- a/webapp/templates/jury/executables.html.twig +++ b/webapp/templates/jury/executables.html.twig @@ -12,7 +12,7 @@

Executables

- {{ macros.table(executables, table_fields, num_actions, {'ordering': 'false'}) }} + {{ macros.table(executables, table_fields, {'ordering': 'false'}) }} {% if is_granted('ROLE_ADMIN') %}

diff --git a/webapp/templates/jury/jury_macros.twig b/webapp/templates/jury/jury_macros.twig index f86c3e08ac..ddb70eb30a 100644 --- a/webapp/templates/jury/jury_macros.twig +++ b/webapp/templates/jury/jury_macros.twig @@ -85,12 +85,13 @@ {% endmacro %} -{% macro table(data, fields, num_actions, options) %} +{% macro table(data, fields, options) %}

+ {%- set num_actions = data | numTableActions %} {%- set default_sort = 0 %} {%- set default_sort_order = 'asc' %} {%- for key,column in fields %} diff --git a/webapp/templates/jury/languages.html.twig b/webapp/templates/jury/languages.html.twig index 3a68e483b7..0df29e4c15 100644 --- a/webapp/templates/jury/languages.html.twig +++ b/webapp/templates/jury/languages.html.twig @@ -12,14 +12,14 @@

Enabled languages

- {{ macros.table(enabled_languages, table_fields, num_actions) }} + {{ macros.table(enabled_languages, table_fields) }}

Disabled languages

- {{ macros.table(disabled_languages, table_fields, num_actions) }} + {{ macros.table(disabled_languages, table_fields) }} {% if is_granted('ROLE_ADMIN') %}

diff --git a/webapp/templates/jury/partials/judgehost_list.html.twig b/webapp/templates/jury/partials/judgehost_list.html.twig index aa31d1bb6d..a317734554 100644 --- a/webapp/templates/jury/partials/judgehost_list.html.twig +++ b/webapp/templates/jury/partials/judgehost_list.html.twig @@ -1,2 +1,2 @@ {% import "jury/jury_macros.twig" as macros %} -{{ macros.table(judgehosts, table_fields, num_actions, {ordering: 'false'}) }} +{{ macros.table(judgehosts, table_fields, {ordering: 'false'}) }} diff --git a/webapp/templates/jury/problems.html.twig b/webapp/templates/jury/problems.html.twig index 727b515ab2..511fcc5cbb 100644 --- a/webapp/templates/jury/problems.html.twig +++ b/webapp/templates/jury/problems.html.twig @@ -12,7 +12,7 @@

Problems

- {{ macros.table(problems, table_fields, num_actions) }} + {{ macros.table(problems, table_fields) }} {% if is_granted('ROLE_ADMIN') %}

diff --git a/webapp/templates/jury/team_affiliations.html.twig b/webapp/templates/jury/team_affiliations.html.twig index 4c5503003a..0241c263b0 100644 --- a/webapp/templates/jury/team_affiliations.html.twig +++ b/webapp/templates/jury/team_affiliations.html.twig @@ -12,7 +12,7 @@

Affiliations

- {{ macros.table(team_affiliations, table_fields, num_actions) }} + {{ macros.table(team_affiliations, table_fields) }} {%- if is_granted('ROLE_ADMIN') %} diff --git a/webapp/templates/jury/team_categories.html.twig b/webapp/templates/jury/team_categories.html.twig index 9024a8bc79..91e7a95b96 100644 --- a/webapp/templates/jury/team_categories.html.twig +++ b/webapp/templates/jury/team_categories.html.twig @@ -12,7 +12,7 @@

Categories

- {{ macros.table(team_categories, table_fields, num_actions) }} + {{ macros.table(team_categories, table_fields) }} {% if is_granted('ROLE_ADMIN') %}

diff --git a/webapp/templates/jury/teams.html.twig b/webapp/templates/jury/teams.html.twig index 4d1eeb11be..b2501cf750 100644 --- a/webapp/templates/jury/teams.html.twig +++ b/webapp/templates/jury/teams.html.twig @@ -12,7 +12,7 @@

Teams

- {{ macros.table(teams, table_fields, num_actions) }} + {{ macros.table(teams, table_fields) }} {%- if is_granted('ROLE_ADMIN') %} diff --git a/webapp/templates/jury/users.html.twig b/webapp/templates/jury/users.html.twig index e629db218f..e5e291843d 100644 --- a/webapp/templates/jury/users.html.twig +++ b/webapp/templates/jury/users.html.twig @@ -12,7 +12,7 @@

Users

- {{ macros.table(users, table_fields, num_actions) }} + {{ macros.table(users, table_fields) }} {% if is_granted('ROLE_ADMIN') %}