Show offline participants on public scoreboard + filter
This commit is contained in:
@@ -92,6 +92,9 @@ class ContestsController < ApplicationController
|
||||
contestant.time_seconds
|
||||
] }
|
||||
filter_contestants_per_category
|
||||
if params.key?(:hide_offline) && params[:hide_offline] == "true"
|
||||
@contestants = @contestants.select { |contestant| !contestant.offline.present? }
|
||||
end
|
||||
@puzzles = @contest.puzzles.order(:id)
|
||||
@action_name = t("helpers.buttons.refresh")
|
||||
if params.key?(:category)
|
||||
@@ -99,6 +102,7 @@ class ContestsController < ApplicationController
|
||||
else
|
||||
@action_path = "/public/#{@contest.friendly_id}"
|
||||
end
|
||||
@space = " "
|
||||
render :scoreboard
|
||||
end
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
- if @contest.categories.size > 0
|
||||
.row
|
||||
.col
|
||||
select.mb-2 id="categories" style="padding: 5px"
|
||||
option value=-1
|
||||
| Tous.tes les participant.e.s
|
||||
- @contest.categories.each do |category|
|
||||
option value=category.id
|
||||
= category.name
|
||||
javascript:
|
||||
categorySelectEl = document.getElementById('categories');
|
||||
urlParams = new URLSearchParams(window.location.search);
|
||||
selectedCategory = urlParams.get('category');
|
||||
Array.from(categorySelectEl.children).forEach((option) => {
|
||||
if (option.value == selectedCategory) option.selected = true;
|
||||
});
|
||||
categorySelectEl.addEventListener('change', (e) => {
|
||||
window.location.replace(`/public/#{@contest.slug}?category=${e.target.value}`);
|
||||
})
|
||||
45
app/views/contests/_selectors.html.slim
Normal file
45
app/views/contests/_selectors.html.slim
Normal file
@@ -0,0 +1,45 @@
|
||||
javascript:
|
||||
function updateParams() {
|
||||
categorySelectEl = document.getElementById('categories');
|
||||
offlineInputEl = document.getElementById('offline');
|
||||
if (categorySelectEl && !offlineInputEl) {
|
||||
window.location.replace(`/public/#{@contest.slug}?category=${categorySelectEl.value}`);
|
||||
} else if (!categorySelectEl) {
|
||||
window.location.replace(`/public/#{@contest.slug}?hide_offline=${offlineInputEl.checked}`);
|
||||
} else {
|
||||
window.location.replace(`/public/#{@contest.slug}?category=${categorySelectEl.value}&hide_offline=${offlineInputEl.checked}`);
|
||||
}
|
||||
}
|
||||
- if @contest.categories.size > 0
|
||||
.row
|
||||
.col
|
||||
select.mb-2 id="categories" style="padding: 5px"
|
||||
option value=-1
|
||||
= t("contests.scoreboard.all_categories")
|
||||
- @contest.categories.each do |category|
|
||||
option value=category.id
|
||||
= category.name
|
||||
javascript:
|
||||
categorySelectEl = document.getElementById('categories');
|
||||
urlParams = new URLSearchParams(window.location.search);
|
||||
selectedCategory = urlParams.get('category');
|
||||
Array.from(categorySelectEl.children).forEach((option) => {
|
||||
if (option.value == selectedCategory) option.selected = true;
|
||||
});
|
||||
categorySelectEl.addEventListener('change', (e) => {
|
||||
updateParams();
|
||||
})
|
||||
- if @contest.offline_form
|
||||
.row
|
||||
.col
|
||||
input type="checkbox" id="offline" style="padding: 5px;"
|
||||
label for="offline"
|
||||
.ms-2
|
||||
= t("contests.scoreboard.hide_offline")
|
||||
javascript:
|
||||
offlineInputEl = document.getElementById('offline');
|
||||
urlParams = new URLSearchParams(window.location.search);
|
||||
offlineInputEl.checked = urlParams.get('hide_offline') == "true";
|
||||
offlineInputEl.addEventListener('change', (e) => {
|
||||
updateParams();
|
||||
})
|
||||
@@ -16,10 +16,10 @@ css:
|
||||
=> "#{puzzle.name} -"
|
||||
= "#{puzzle.brand} #{puzzle.pieces}p"
|
||||
|
||||
= render "category_selector"
|
||||
= render "selectors"
|
||||
|
||||
.row
|
||||
.col-6.d-flex.flex-column style="height: calc(100vh - 180px)"
|
||||
.mt-3.col-6.d-flex.flex-column style="height: calc(100vh - 250px)"
|
||||
.d-flex.flex-column style="overflow-y: auto"
|
||||
table.table.table-striped.table-hover
|
||||
thead
|
||||
@@ -38,6 +38,9 @@ css:
|
||||
tr scope="row"
|
||||
td
|
||||
= index + 1
|
||||
- if contestant.offline.present?
|
||||
= @space
|
||||
| (hors-ligne)
|
||||
td
|
||||
= contestant.name
|
||||
- if @contest.puzzles.size > 1
|
||||
|
||||
@@ -168,6 +168,8 @@ en:
|
||||
notice: Contest added
|
||||
title: New jigsaw puzzle contest
|
||||
scoreboard:
|
||||
all_categories: All categories
|
||||
hide_offline: Hide offline participants
|
||||
refresh: Activate auto-refresh (every 5s)
|
||||
title: "%{name}"
|
||||
show:
|
||||
|
||||
@@ -139,6 +139,8 @@ fr:
|
||||
notice: Concours ajouté
|
||||
title: Nouveau concours
|
||||
scoreboard:
|
||||
all_categories: Toutes les catégories
|
||||
hide_offline: Cacher les participant.e.s hors-ligne
|
||||
refresh: Activer le rafraichissement automatique de la page (toutes les 5s)
|
||||
title: "%{name}"
|
||||
show:
|
||||
|
||||
Reference in New Issue
Block a user