Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto calculate num actions for jury tables. #2161

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/ExecutableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);
}
Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/ProblemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/TeamAffiliationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/TeamCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down
1 change: 0 additions & 1 deletion webapp/src/Controller/Jury/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down
10 changes: 10 additions & 0 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
];
}

Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion webapp/templates/jury/contests.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

<h3>All available contests</h3>

{{ macros.table(contests_table, table_fields, num_actions) }}
{{ macros.table(contests_table, table_fields) }}

{% if is_granted('ROLE_ADMIN') %}
<p>
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/executables.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<h1>Executables</h1>

{{ macros.table(executables, table_fields, num_actions, {'ordering': 'false'}) }}
{{ macros.table(executables, table_fields, {'ordering': 'false'}) }}

{% if is_granted('ROLE_ADMIN') %}
<p>
Expand Down
3 changes: 2 additions & 1 deletion webapp/templates/jury/jury_macros.twig
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@
</style>
{% endmacro %}

{% macro table(data, fields, num_actions, options) %}
{% macro table(data, fields, options) %}

<div class="table-wrapper">
<table class="data-table table table-sm table-striped" style="width:auto">
<thead class="">
<tr>
{%- set num_actions = data | numTableActions %}
{%- set default_sort = 0 %}
{%- set default_sort_order = 'asc' %}
{%- for key,column in fields %}
Expand Down
4 changes: 2 additions & 2 deletions webapp/templates/jury/languages.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

<h1>Enabled languages</h1>

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

<br/>
<br/>

<h1>Disabled languages</h1>

{{ macros.table(disabled_languages, table_fields, num_actions) }}
{{ macros.table(disabled_languages, table_fields) }}

{% if is_granted('ROLE_ADMIN') %}
<p>
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/partials/judgehost_list.html.twig
Original file line number Diff line number Diff line change
@@ -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'}) }}
2 changes: 1 addition & 1 deletion webapp/templates/jury/problems.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<h1>Problems</h1>

{{ macros.table(problems, table_fields, num_actions) }}
{{ macros.table(problems, table_fields) }}

{% if is_granted('ROLE_ADMIN') %}
<p>
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/team_affiliations.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<h1>Affiliations</h1>

{{ macros.table(team_affiliations, table_fields, num_actions) }}
{{ macros.table(team_affiliations, table_fields) }}

{%- if is_granted('ROLE_ADMIN') %}

Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/team_categories.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<h1>Categories</h1>

{{ macros.table(team_categories, table_fields, num_actions) }}
{{ macros.table(team_categories, table_fields) }}

{% if is_granted('ROLE_ADMIN') %}
<p>
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/teams.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<h1>Teams</h1>

{{ macros.table(teams, table_fields, num_actions) }}
{{ macros.table(teams, table_fields) }}

{%- if is_granted('ROLE_ADMIN') %}

Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/jury/users.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<h1>Users</h1>

{{ macros.table(users, table_fields, num_actions) }}
{{ macros.table(users, table_fields) }}

{% if is_granted('ROLE_ADMIN') %}
<p>
Expand Down
Loading