From 125fc90ec52259a63f04a1555bf7b9d71417b76f Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Fri, 28 Feb 2025 18:07:26 +0000 Subject: [PATCH] Improve hearts on scoreboard by using separate column --- webapp/public/js/domjudge.js | 55 ++++++++++--------- webapp/public/style_domjudge.css | 4 ++ .../Jury/TeamAffiliationController.php | 1 + webapp/src/Controller/Jury/TeamController.php | 1 + .../partials/scoreboard_summary.html.twig | 3 + .../partials/scoreboard_table.html.twig | 27 ++++++++- 6 files changed, 61 insertions(+), 30 deletions(-) diff --git a/webapp/public/js/domjudge.js b/webapp/public/js/domjudge.js index 3cc63a31f5..ab0165643a 100644 --- a/webapp/public/js/domjudge.js +++ b/webapp/public/js/domjudge.js @@ -301,30 +301,20 @@ function getScoreboards(mobile) function getRank(row) { - return row.getElementsByTagName("td")[0]; + return row.querySelector('.rank'); } function getHeartCol(row) { - var tds = row.getElementsByTagName("td"); - var td = null; - // search for td before the team name - for (var i = 1; i < 4; i++) { - if (tds[i].classList.contains("scoretn")) { - td = tds[i - 1]; + const tds = row.getElementsByTagName("td"); + let td = null; + // search for td to store the hearts + for (let i = 1; i < 5; i++) { + if (tds[i] && tds[i].classList.contains("heart")) { + td = tds[i]; break; } } - if (td === null) { - td = tds[1]; - } - if (td !== null) { - if (td.children.length) { - return td.children[0]; - } - return td; - } - - return null; + return td; } function getTeamname(row) @@ -397,11 +387,10 @@ function toggle(id, show, mobile) }); } -function addHeart(rank, row, id, isFav, mobile) +function getHeart(rank, row, id, isFav, mobile) { - var heartCol = getHeartCol(row); var iconClass = isFav ? "fas fa-heart" : "far fa-heart"; - return heartCol.innerHTML + ""; + return ""; } function initFavouriteTeams() @@ -426,20 +415,32 @@ function initFavouriteTeams() if (teamname === null) { continue; } - var firstCol = getRank(scoreboard[j]); + let rankElement; + if (mobile) { + rankElement = getRank(scoreboard[j + 1]); + } else { + rankElement = getRank(scoreboard[j]); + } var heartCol = getHeartCol(scoreboard[j]); - var rank = firstCol.innerHTML; + if (!heartCol) { + continue; + } + var rank = rankElement.innerHTML.trim(); for (var i = 0; i < favTeams.length; i++) { if (teamname === favTeams[i]) { found = true; - heartCol.innerHTML = addHeart(rank, scoreboard[j], teamIndex, found, mobile); + heartCol.innerHTML = getHeart(rank, scoreboard[j], teamIndex, found, mobile); toAdd[cntFound] = scoreboard[j].cloneNode(true); if (mobile) { toAddMobile[cntFound] = scoreboard[j + 1].cloneNode(true); } - if (rank.trim().length === 0) { + if (rank.length === 0) { // make rank explicit in case of tie - getRank(toAdd[cntFound]).innerHTML += lastRank; + if (mobile) { + getRank(toAddMobile[cntFound]).innerHTML += lastRank; + } else { + getRank(toAdd[cntFound]).innerHTML += lastRank; + } } scoreboard[j].style.background = "lightyellow"; const scoretn = scoreboard[j].querySelector('.scoretn'); @@ -455,7 +456,7 @@ function initFavouriteTeams() } } if (!found) { - heartCol.innerHTML = addHeart(rank, scoreboard[j], teamIndex, found, mobile); + heartCol.innerHTML = getHeart(rank, scoreboard[j], teamIndex, found, mobile); } if (rank !== "") { lastRank = rank; diff --git a/webapp/public/style_domjudge.css b/webapp/public/style_domjudge.css index daf7080a6a..48c794c925 100644 --- a/webapp/public/style_domjudge.css +++ b/webapp/public/style_domjudge.css @@ -198,6 +198,10 @@ del { .scoreboard td.no-border, .scoreboard th.no-border { border: none; } +.scoreboard td.heart { + padding-left: 0.5rem; + padding-right: 0.5rem; +} .scoreboard td.rank { padding-left: 0.3em; padding-right: 0.3em; diff --git a/webapp/src/Controller/Jury/TeamAffiliationController.php b/webapp/src/Controller/Jury/TeamAffiliationController.php index 32760f8d3c..2042f718cb 100644 --- a/webapp/src/Controller/Jury/TeamAffiliationController.php +++ b/webapp/src/Controller/Jury/TeamAffiliationController.php @@ -142,6 +142,7 @@ public function viewAction(Request $request, ScoreboardService $scoreboardServic 'ajax' => true, ], 'maxWidth' => $this->config->get('team_column_width'), + 'public' => false, ]; if ($currentContest = $this->dj->getCurrentContest()) { diff --git a/webapp/src/Controller/Jury/TeamController.php b/webapp/src/Controller/Jury/TeamController.php index bb1ad3aa31..87399655e9 100644 --- a/webapp/src/Controller/Jury/TeamController.php +++ b/webapp/src/Controller/Jury/TeamController.php @@ -247,6 +247,7 @@ public function viewAction( 'showFlags' => (bool)$this->config->get('show_flags'), 'showContest' => count($this->dj->getCurrentContests()) > 1, 'maxWidth' => $this->config->get("team_column_width"), + 'public' => false, ]; $currentContest = $this->dj->getCurrentContest(); diff --git a/webapp/templates/partials/scoreboard_summary.html.twig b/webapp/templates/partials/scoreboard_summary.html.twig index 65666ef567..2ba3c08ebf 100644 --- a/webapp/templates/partials/scoreboard_summary.html.twig +++ b/webapp/templates/partials/scoreboard_summary.html.twig @@ -11,6 +11,9 @@ {% set summaryColspan = summaryColspan + 1 %} {% endif %} {% endif %} + {% if public %} + {% set summaryColspan = summaryColspan + 1 %} + {% endif %} Summary {% if enable_ranking %} {% if scoreboard.showPoints %} diff --git a/webapp/templates/partials/scoreboard_table.html.twig b/webapp/templates/partials/scoreboard_table.html.twig index 3842a4bb28..2a983a5a6a 100644 --- a/webapp/templates/partials/scoreboard_table.html.twig +++ b/webapp/templates/partials/scoreboard_table.html.twig @@ -30,10 +30,13 @@ - {% set teamColspan = 2 %} + {% set teamColspan = 3 %} {% if showAffiliationLogos %} {% set teamColspan = teamColspan + 1 %} {% endif %} + {% if not public %} + {% set teamColspan = teamColspan - 1 %} + {% endif %} {# output table column groups (for the styles) #} @@ -51,6 +54,9 @@ {% if showAffiliationLogos %} {% endif %} + {% if public %} + + {% endif %} {% if enable_ranking %} @@ -190,6 +196,9 @@ {% endif %} {% endif %} + {% if public %} + + {% endif %} {% if color is null %} {% set color = "#FFFFFF" %} {% set colorClass = "_FFFFFF" %} @@ -339,6 +348,9 @@ {% if showAffiliationLogos %} {% endif %} + {% if public %} + + {% endif %} {% if enable_ranking %} @@ -352,6 +364,9 @@ {% if showAffiliationLogos %} {% set teamColspan = teamColspan + 1 %} {% endif %} + {% if public %} + {% set teamColspan = teamColspan + 1 %} + {% endif %} {% if enable_ranking %} @@ -430,6 +445,9 @@ {% endif %} {% endif %} + {% if public %} + + {% endif %} {% if color is null %} {% set color = "#FFFFFF" %} {% set colorClass = "_FFFFFF" %} @@ -483,7 +501,7 @@
{# Only print rank when score is different from the previous team #} - + {% if not displayRank %} ? {% elseif previousTeam is null or scoreboard.scores[previousTeam.teamid].rank != score.rank %} @@ -496,7 +514,10 @@ {% if showAffiliationLogos %} {% set problemSpan = 3 %} {% else %} - {% set problemSpan = 2 %} + {% set problemSpan = 2 %} + {% endif %} + {% if public %} + {% set problemSpan = problemSpan + 1 %} {% endif %} {% for problem in problems %}