diff --git a/cms/server/admin/templates/activate_dataset.html b/cms/server/admin/templates/activate_dataset.html index 867ce0d082..a04e4c0827 100644 --- a/cms/server/admin/templates/activate_dataset.html +++ b/cms/server/admin/templates/activate_dataset.html @@ -1,3 +1,5 @@ +{% import "macro/reevaluation_buttons.html" as macro_reevaluation_buttons %} + {% extends "base.html" %} {% block js_init %} @@ -50,7 +52,8 @@

Preview dataset change for {{ task.title }} ( Reevaluate all submissions for the dataset "{{ dataset.description }}": - {{ ReevaluationButtons( + {{ macro_reevaluation_buttons.reevaluation_buttons( + admin.permission_all, url("dataset", dataset.id), dataset_id=dataset.id) }}

diff --git a/cms/server/admin/templates/base.html b/cms/server/admin/templates/base.html index 091d77cff9..6cb368890f 100644 --- a/cms/server/admin/templates/base.html +++ b/cms/server/admin/templates/base.html @@ -1,4 +1,3 @@ -{% from "fragments/reevaluation_buttons.html" import ReevaluationButtons with context %} diff --git a/cms/server/admin/templates/contest_submissions.html b/cms/server/admin/templates/contest_submissions.html index 691abbad66..6f49065031 100644 --- a/cms/server/admin/templates/contest_submissions.html +++ b/cms/server/admin/templates/contest_submissions.html @@ -1,4 +1,7 @@ +{% import "macro/reevaluation_buttons.html" as macro_reevaluation_buttons %} + {% extends "base.html" %} +{% import 'macro/submission.html' as macro_submission %} {% block core %}

All Submissions

@@ -7,13 +10,19 @@

All Submissions

Reevaluate all {{ submission_count }} submissions in this contest (for all datasets) - {{ ReevaluationButtons( + {{ macro_reevaluation_buttons.reevaluation_buttons( + admin.permission_all, url("contest", contest.id, "submissions"), contest_id=contest.id) }}

- {% set page_url = url["contest"][contest.id]["submissions"] %} - {% include "fragments/submission_rows.html" %} + {{ macro_submission.rows( + admin, + url, + url["contest"][contest.id]["submissions"], + submissions, + submission_page, + submission_pages) }} {% endblock core %} diff --git a/cms/server/admin/templates/dataset.html b/cms/server/admin/templates/dataset.html index 04b4c60df2..b7b7f16ac1 100644 --- a/cms/server/admin/templates/dataset.html +++ b/cms/server/admin/templates/dataset.html @@ -1,4 +1,7 @@ +{% import "macro/reevaluation_buttons.html" as macro_reevaluation_buttons %} + {% extends "base.html" %} +{% import 'macro/submission.html' as macro_submission %} {% block core %} @@ -13,13 +16,20 @@

Submissions

Reevaluate all {{ submission_count }} submissions for this dataset - {{ ReevaluationButtons( + {{ macro_reevaluation_buttons.reevaluation_buttons( + admin.permission_all, url("dataset", shown_dataset.id), dataset_id=shown_dataset.id) }}

- {% set page_url = url["dataset"][shown_dataset.id] %} - {% include "fragments/submission_rows.html" %} + {{ macro_submission.rows( + admin, + url, + url["dataset"][shown_dataset.id], + submissions, + submission_page, + submission_pages, + shown_dataset|default(none)) }}
diff --git a/cms/server/admin/templates/fragments/submission_rows.html b/cms/server/admin/templates/fragments/submission_rows.html deleted file mode 100644 index d650e419fb..0000000000 --- a/cms/server/admin/templates/fragments/submission_rows.html +++ /dev/null @@ -1,40 +0,0 @@ -{# This snippet shows a table using the list submissions as input #} -{% if submission_count == 0 %} -

No submissions found.

- -{% else %} - -{% if submission_count > submissions|length %} -
- Pages: - {% for i in range(submission_pages) %} - {% if i != submission_page %} - {{ i + 1 }} - {% else %} - {{ i + 1 }} - {% endif %} - {% endfor %} -
-{% endif %} - - - - - - - - - - - - - - - - - {% for s in submissions|sort(attribute="timestamp")|reverse %} - {% include "fragments/submission_row.html" %} - {% endfor %} - -
TimeUserTaskStatusFilesTokenOfficialCommentReevaluate
-{% endif %} diff --git a/cms/server/admin/templates/fragments/user_test_rows.html b/cms/server/admin/templates/fragments/user_test_rows.html index fe3d4e0905..79043eee0e 100644 --- a/cms/server/admin/templates/fragments/user_test_rows.html +++ b/cms/server/admin/templates/fragments/user_test_rows.html @@ -1,21 +1,12 @@ +{% import 'macro/pages.html' as macro_pages %} + {# This snippet shows a table using the list user_tests as input #} {% if user_test_count == 0 %}

No user tests found.

{% else %} -{% if user_test_count > user_tests|length %} -
- Pages: - {% for i in range(user_test_pages) %} - {% if i != user_test_page %} - {{ i + 1 }} - {% else %} - {{ i + 1 }} - {% endif %} - {% endfor %} -
-{% endif %} +{{ macro_pages.selector(page_url, user_test_page, user_test_pages) }} diff --git a/cms/server/admin/templates/macro/pages.html b/cms/server/admin/templates/macro/pages.html new file mode 100644 index 0000000000..fd6884cca7 --- /dev/null +++ b/cms/server/admin/templates/macro/pages.html @@ -0,0 +1,40 @@ +{% macro selector(page_url, page, pages) -%} +{# +Show a page selector for a paginated view. + +page_url (Url): the URL instance referring to the page displaying the table. +page (int): 0-based number of the current page. +pages (int): total number of pages. +#} + + {% if pages > 1 %} +
+ Pages: + {% if pages <= 20 %} + {{ range_selector(page_url, page, pages, 0, pages) }} + {% else %} + {% if page != 0 %} + First + {% endif %} + {{ range_selector(page_url, page, pages, page - 2, pages + 3) }} + {% if page != pages - 1 %} + Last + {% endif %} + {% endif %} +
+ {% endif %} +{%- endmacro %} + + +{% macro range_selector(page_url, page, pages, start, end) -%} +{# +Show a page range selector from start (included) to end (excluded). +#} + {% for i in range([0, start]|max, [pages, end]|min) %} + {% if i != page %} + {{ i + 1 }} + {% else %} + {{ i + 1 }} + {% endif %} + {% endfor %} +{%- endmacro %} diff --git a/cms/server/admin/templates/fragments/reevaluation_buttons.html b/cms/server/admin/templates/macro/reevaluation_buttons.html similarity index 87% rename from cms/server/admin/templates/fragments/reevaluation_buttons.html rename to cms/server/admin/templates/macro/reevaluation_buttons.html index 121d366230..7e769d0cd9 100644 --- a/cms/server/admin/templates/fragments/reevaluation_buttons.html +++ b/cms/server/admin/templates/macro/reevaluation_buttons.html @@ -1,8 +1,9 @@ -{% macro ReevaluationButtons(next_page, - submission_id=None, - dataset_id=None, - participation_id=None, - contest_id=None) %} +{% macro reevaluation_buttons(allowed, + next_page, + submission_id=None, + dataset_id=None, + participation_id=None, + contest_id=None) %} {# Render reevaluation buttons for the given filters. @@ -16,6 +17,7 @@ - contest_id: reevaluate all submission results of the contest (of all participations and tasks, for all datasets). +allowed (bool): whether the logged in admin is allowed to reevaluate. next_page (str): the URL to redirect to after the invalidation request has been sent. submission_id (int|None): id of the submission to invalidate. @@ -42,7 +44,7 @@ 'level': 'compilation'}, function(response) { utils.redirect_if_ok('{{ next_page }}', response); } );" -{% if not admin.permission_all %} +{% if not allowed %} disabled {% endif %} title="Compilation" >C @@ -55,7 +57,7 @@ 'level': 'evaluation'}, function(response) { utils.redirect_if_ok('{{ next_page }}', response); } );" -{% if not admin.permission_all %} +{% if not allowed %} disabled {% endif %} title="Evaluation" >E @@ -68,7 +70,7 @@ }, function(response) { utils.redirect_if_ok('{{ next_page }}', response); } );" -{% if not admin.permission_all %} +{% if not allowed %} disabled {% endif %} title="Score" >S diff --git a/cms/server/admin/templates/fragments/submission_row.html b/cms/server/admin/templates/macro/submission.html similarity index 69% rename from cms/server/admin/templates/fragments/submission_row.html rename to cms/server/admin/templates/macro/submission.html index e384d49b14..75a81f4620 100644 --- a/cms/server/admin/templates/fragments/submission_row.html +++ b/cms/server/admin/templates/macro/submission.html @@ -1,8 +1,64 @@ -{# This snippet shows a row of a submission table using the variable s as input #} +{% import "macro/reevaluation_buttons.html" as macro_reevaluation_buttons %} +{% import 'macro/pages.html' as macro_pages %} + + +{% macro rows(admin, url, page_url, submissions, page, pages, dataset=none) -%} +{# +Render a table of submission data. + +admin (Admin): the logged in admin. +url (Url): the URL instance referring to the root of AWS. +page_url (Url): the URL instance referring to the page displaying the table. +submissions ([Submissions]): the list of submissions to display in the table + (current page only). +page (int): 0-based number of the current page. +pages (int): total number of pages. +dataset (Dataset|None): the dataset to show results for, or if not defined use + the active one. +#} +{% if pages == 0 %} +

No submissions found.

-{% if shown_dataset is defined %} - {% set dataset = shown_dataset %} {% else %} + +{{ macro_pages.selector(page_url, page, pages) }} + +
+ + + + + + + + + + + + + + + {% for s in submissions|sort(attribute="timestamp")|reverse %} + {{ row(admin, url, s, dataset) }} + {% endfor %} + +
TimeUserTaskStatusFilesTokenOfficialCommentReevaluate
+{% endif %} +{%- endmacro %} + + +{% macro row(admin, url, s, dataset=None) -%} +{# +Render a table's row containing a submission data. + +admin (Admin): the logged in admin. +url (Url): the URL instance referring to the root of AWS. +s (Submission): the submission to render. +dataset (Dataset|None): the dataset to show results for, or if not defined use + the active one. +#} + +{% if dataset is none %} {% set dataset = s.task.active_dataset %} {% endif %} @@ -113,9 +169,12 @@

Compilation output

{# TODO: trim long outputs and add facility to see ra {{ s.short_comment }} - {{ ReevaluationButtons( + {{ macro_reevaluation_buttons.reevaluation_buttons( + admin.permission_all, url("submission", s.id, dataset.id), submission_id=s.id, dataset_id=dataset.id) }} + +{%- endmacro %} diff --git a/cms/server/admin/templates/participation.html b/cms/server/admin/templates/participation.html index f31b0576f5..f4e5e22eee 100644 --- a/cms/server/admin/templates/participation.html +++ b/cms/server/admin/templates/participation.html @@ -1,4 +1,7 @@ +{% import "macro/reevaluation_buttons.html" as macro_reevaluation_buttons %} + {% extends "base.html" %} +{% import 'macro/submission.html' as macro_submission %} {% block js %} function question_reply_toggle(element, invoker) @@ -36,13 +39,19 @@

Submissions

Reevaluate all {{ submission_count }} submissions for this user in this contest (for all datasets) - {{ ReevaluationButtons( + {{ macro_reevaluation_buttons.reevaluation_buttons( + admin.permission_all, url("contest", contest.id, "user", participation.user_id, "edit"), participation_id=participation.id) }}

- {% set page_url = url["contest"][contest.id]["user"][selected_user.id]["edit"] %} - {% include "fragments/submission_rows.html" %} + {{ macro_submission.rows( + admin, + url, + url["contest"][contest.id]["user"][selected_user.id]["edit"], + submissions, + submission_page, + submission_pages) }}
diff --git a/cms/server/admin/templates/submission.html b/cms/server/admin/templates/submission.html index 22806ee7b6..c052b91ff5 100644 --- a/cms/server/admin/templates/submission.html +++ b/cms/server/admin/templates/submission.html @@ -1,3 +1,5 @@ +{% import "macro/reevaluation_buttons.html" as macro_reevaluation_buttons %} + {% extends "base.html" %} {% block core %} @@ -164,7 +166,8 @@

Submission details

Reevaluate - {{ ReevaluationButtons( + {{ macro_reevaluation_buttons.reevaluation_buttons( + admin.permission_all, url("submission", s.id, shown_dataset.id), submission_id=s.id, dataset_id=shown_dataset.id) }}