Internal scoreboard: add category filter
This commit is contained in:
parent
502649620b
commit
657c5ac47b
@ -16,6 +16,13 @@ class ContestsController < ApplicationController
|
|||||||
@action_name = t("helpers.buttons.edit")
|
@action_name = t("helpers.buttons.edit")
|
||||||
@action_path = edit_contest_path(@contest)
|
@action_path = edit_contest_path(@contest)
|
||||||
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
|
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
|
||||||
|
if params.key?(:category) && params[:category] != "-1"
|
||||||
|
if params[:category] == "-2"
|
||||||
|
@contestants = @contestants.select { |contestant| contestant.categories.size == 0 }
|
||||||
|
else
|
||||||
|
@contestants = @contestants.select { |contestant| contestant.categories.where(id: params[:category]).any? }
|
||||||
|
end
|
||||||
|
end
|
||||||
@puzzles = @contest.puzzles.order(:id)
|
@puzzles = @contest.puzzles.order(:id)
|
||||||
@messages = @contest.messages.order(:time_seconds)
|
@messages = @contest.messages.order(:time_seconds)
|
||||||
set_badges
|
set_badges
|
||||||
|
@ -42,17 +42,38 @@ javascript:
|
|||||||
| + #{t("helpers.buttons.add")}
|
| + #{t("helpers.buttons.add")}
|
||||||
a.ms-2.btn-sm.btn.btn-primary href=contest_import_path(@contest) style="margin-top: -3px"
|
a.ms-2.btn-sm.btn.btn-primary href=contest_import_path(@contest) style="margin-top: -3px"
|
||||||
| #{t("helpers.buttons.import")}
|
| #{t("helpers.buttons.import")}
|
||||||
|
- if @contest.categories.size > 0
|
||||||
|
.row
|
||||||
|
.col
|
||||||
|
select.mt-2.mb-2 id="categories" style="padding: 5px"
|
||||||
|
option value=-1
|
||||||
|
| Tous.tes les participant.e.s
|
||||||
|
option value=-2
|
||||||
|
| Participant.e.s sans catégorie
|
||||||
|
- @contest.categories.each do |category|
|
||||||
|
option value=category.id
|
||||||
|
= category.name
|
||||||
|
javascript:
|
||||||
|
const select = document.getElementById('categories');
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const selectedCategory = urlParams.get('category');
|
||||||
|
Array.from(select.children).forEach((option) => {
|
||||||
|
if (option.value == selectedCategory) option.selected = true;
|
||||||
|
});
|
||||||
|
select.addEventListener('change', (e) => {
|
||||||
|
window.location.href = `#{contest_path(@contest)}?category=${e.target.value}`
|
||||||
|
})
|
||||||
.d-flex.flex-column style="overflow-y: auto"
|
.d-flex.flex-column style="overflow-y: auto"
|
||||||
table.table.table-striped.table-hover
|
table.table.table-striped.table-hover
|
||||||
thead
|
thead
|
||||||
tr
|
tr
|
||||||
th scope="col"
|
th
|
||||||
= t("helpers.rank")
|
= t("helpers.rank")
|
||||||
th scope="col"
|
th
|
||||||
= t("activerecord.attributes.contestant.name")
|
= t("activerecord.attributes.contestant.name")
|
||||||
th scope="col"
|
th
|
||||||
= t("activerecord.attributes.contestant.completions")
|
= t("activerecord.attributes.contestant.completions")
|
||||||
th scope="col"
|
th
|
||||||
= t("activerecord.attributes.contestant.display_time")
|
= t("activerecord.attributes.contestant.display_time")
|
||||||
tbody
|
tbody
|
||||||
- @contestants.each_with_index do |contestant, index|
|
- @contestants.each_with_index do |contestant, index|
|
||||||
@ -144,4 +165,4 @@ javascript:
|
|||||||
- else
|
- else
|
||||||
a.btn.btn-sm.btn-secondary.disabled href=contest_message_convert_path(@contest, message) style="white-space: nowrap;"
|
a.btn.btn-sm.btn-secondary.disabled href=contest_message_convert_path(@contest, message) style="white-space: nowrap;"
|
||||||
= t("helpers.buttons.add_completion")
|
= t("helpers.buttons.add_completion")
|
||||||
= link_to t("helpers.buttons.delete"), contest_message_path(@contest, message), data: { turbo_method: :delete }, class: "btn btn-sm btn-danger ms-2"
|
= link_to "x", contest_message_path(@contest, message), data: { turbo_method: :delete }, class: "btn btn-sm btn-danger ms-2"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user