Skip to content

Commit b3f1417

Browse files
Improve hearts on scoreboard by using separate column
1 parent 71b45e4 commit b3f1417

File tree

6 files changed

+61
-30
lines changed

6 files changed

+61
-30
lines changed

webapp/public/js/domjudge.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -301,30 +301,20 @@ function getScoreboards(mobile)
301301

302302
function getRank(row)
303303
{
304-
return row.getElementsByTagName("td")[0];
304+
return row.querySelector('.rank');
305305
}
306306

307307
function getHeartCol(row) {
308-
var tds = row.getElementsByTagName("td");
309-
var td = null;
310-
// search for td before the team name
311-
for (var i = 1; i < 4; i++) {
312-
if (tds[i].classList.contains("scoretn")) {
313-
td = tds[i - 1];
308+
const tds = row.getElementsByTagName("td");
309+
let td = null;
310+
// search for td to store the hearts
311+
for (let i = 1; i < 5; i++) {
312+
if (tds[i] && tds[i].classList.contains("heart")) {
313+
td = tds[i];
314314
break;
315315
}
316316
}
317-
if (td === null) {
318-
td = tds[1];
319-
}
320-
if (td !== null) {
321-
if (td.children.length) {
322-
return td.children[0];
323-
}
324-
return td;
325-
}
326-
327-
return null;
317+
return td;
328318
}
329319

330320
function getTeamname(row)
@@ -397,11 +387,10 @@ function toggle(id, show, mobile)
397387
});
398388
}
399389

400-
function addHeart(rank, row, id, isFav, mobile)
390+
function getHeart(rank, row, id, isFav, mobile)
401391
{
402-
var heartCol = getHeartCol(row);
403392
var iconClass = isFav ? "fas fa-heart" : "far fa-heart";
404-
return heartCol.innerHTML + "<span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + (isFav ? "false" : "true") + "," + mobile + ")\"></span>";
393+
return "<span class=\"heart " + iconClass + "\" onclick=\"toggle(" + id + "," + (isFav ? "false" : "true") + "," + mobile + ")\"></span>";
405394
}
406395

407396
function initFavouriteTeams()
@@ -426,20 +415,32 @@ function initFavouriteTeams()
426415
if (teamname === null) {
427416
continue;
428417
}
429-
var firstCol = getRank(scoreboard[j]);
418+
let rankElement;
419+
if (mobile) {
420+
rankElement = getRank(scoreboard[j + 1]);
421+
} else {
422+
rankElement = getRank(scoreboard[j]);
423+
}
430424
var heartCol = getHeartCol(scoreboard[j]);
431-
var rank = firstCol.innerHTML;
425+
if (!heartCol) {
426+
continue;
427+
}
428+
var rank = rankElement.innerHTML.trim();
432429
for (var i = 0; i < favTeams.length; i++) {
433430
if (teamname === favTeams[i]) {
434431
found = true;
435-
heartCol.innerHTML = addHeart(rank, scoreboard[j], teamIndex, found, mobile);
432+
heartCol.innerHTML = getHeart(rank, scoreboard[j], teamIndex, found, mobile);
436433
toAdd[cntFound] = scoreboard[j].cloneNode(true);
437434
if (mobile) {
438435
toAddMobile[cntFound] = scoreboard[j + 1].cloneNode(true);
439436
}
440-
if (rank.trim().length === 0) {
437+
if (rank.length === 0) {
441438
// make rank explicit in case of tie
442-
getRank(toAdd[cntFound]).innerHTML += lastRank;
439+
if (mobile) {
440+
getRank(toAddMobile[cntFound]).innerHTML += lastRank;
441+
} else {
442+
getRank(toAdd[cntFound]).innerHTML += lastRank;
443+
}
443444
}
444445
scoreboard[j].style.background = "lightyellow";
445446
const scoretn = scoreboard[j].querySelector('.scoretn');
@@ -455,7 +456,7 @@ function initFavouriteTeams()
455456
}
456457
}
457458
if (!found) {
458-
heartCol.innerHTML = addHeart(rank, scoreboard[j], teamIndex, found, mobile);
459+
heartCol.innerHTML = getHeart(rank, scoreboard[j], teamIndex, found, mobile);
459460
}
460461
if (rank !== "") {
461462
lastRank = rank;

webapp/public/style_domjudge.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ del {
198198
.scoreboard td.no-border, .scoreboard th.no-border {
199199
border: none;
200200
}
201+
.scoreboard td.heart {
202+
padding-left: 0.5rem;
203+
padding-right: 0.5rem;
204+
}
201205
.scoreboard td.rank {
202206
padding-left: 0.3em;
203207
padding-right: 0.3em;

webapp/src/Controller/Jury/TeamAffiliationController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function viewAction(Request $request, ScoreboardService $scoreboardServic
142142
'ajax' => true,
143143
],
144144
'maxWidth' => $this->config->get('team_column_width'),
145+
'public' => false,
145146
];
146147

147148
if ($currentContest = $this->dj->getCurrentContest()) {

webapp/src/Controller/Jury/TeamController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public function viewAction(
247247
'showFlags' => (bool)$this->config->get('show_flags'),
248248
'showContest' => count($this->dj->getCurrentContests()) > 1,
249249
'maxWidth' => $this->config->get("team_column_width"),
250+
'public' => false,
250251
];
251252

252253
$currentContest = $this->dj->getCurrentContest();

webapp/templates/partials/scoreboard_summary.html.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
{% set summaryColspan = summaryColspan + 1 %}
1212
{% endif %}
1313
{% endif %}
14+
{% if public %}
15+
{% set summaryColspan = summaryColspan + 1 %}
16+
{% endif %}
1417
<td class="scoresummary" title="Summary" colspan="{{ summaryColspan }}">Summary</td>
1518
{% if enable_ranking %}
1619
{% if scoreboard.showPoints %}

webapp/templates/partials/scoreboard_table.html.twig

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
3131
<table class="d-none d-md-table scoreboard desktop-scoreboard center {% if jury %}scoreboard_jury{% endif %}">
3232
33-
{% set teamColspan = 2 %}
33+
{% set teamColspan = 3 %}
3434
{% if showAffiliationLogos %}
3535
{% set teamColspan = teamColspan + 1 %}
3636
{% endif %}
37+
{% if not public %}
38+
{% set teamColspan = teamColspan - 1 %}
39+
{% endif %}
3740
3841
{# output table column groups (for the styles) #}
3942
<colgroup>
@@ -51,6 +54,9 @@
5154
{% if showAffiliationLogos %}
5255
<col id="scorelogos"/>
5356
{% endif %}
57+
{% if public %}
58+
<col id="scorehearts"/>
59+
{% endif %}
5460
<col id="scoreteamname"/>
5561
</colgroup>
5662
{% if enable_ranking %}
@@ -190,6 +196,9 @@
190196
{% endif %}
191197
</td>
192198
{% endif %}
199+
{% if public %}
200+
<td class="scoreaf heart"></td>
201+
{% endif %}
193202
{% if color is null %}
194203
{% set color = "#FFFFFF" %}
195204
{% set colorClass = "_FFFFFF" %}
@@ -339,6 +348,9 @@
339348
{% if showAffiliationLogos %}
340349
<col id="scorelogosmobile"/>
341350
{% endif %}
351+
{% if public %}
352+
<col id="scoreheartmobile"/>
353+
{% endif %}
342354
<col id="scoreteamnamemobile"/>
343355
</colgroup>
344356
{% if enable_ranking %}
@@ -352,6 +364,9 @@
352364
{% if showAffiliationLogos %}
353365
{% set teamColspan = teamColspan + 1 %}
354366
{% endif %}
367+
{% if public %}
368+
{% set teamColspan = teamColspan + 1 %}
369+
{% endif %}
355370
356371
<tr class="scoreheader" data-static="{{ static }}" style="font-size: 75%;">
357372
{% if enable_ranking %}
@@ -430,6 +445,9 @@
430445
{% endif %}
431446
</td>
432447
{% endif %}
448+
{% if public %}
449+
<td class="scoreaf heart"></td>
450+
{% endif %}
433451
{% if color is null %}
434452
{% set color = "#FFFFFF" %}
435453
{% set colorClass = "_FFFFFF" %}
@@ -483,7 +501,7 @@
483501
<tr style="height: 32px;">
484502
<td>
485503
{# Only print rank when score is different from the previous team #}
486-
<span class="d-block me-2">
504+
<span class="d-block me-2 rank">
487505
{% if not displayRank %}
488506
?
489507
{% elseif previousTeam is null or scoreboard.scores[previousTeam.teamid].rank != score.rank %}
@@ -496,7 +514,10 @@
496514
{% if showAffiliationLogos %}
497515
{% set problemSpan = 3 %}
498516
{% else %}
499-
{% set problemSpan = 2 %}
517+
{% set problemSpan = 2 %}
518+
{% endif %}
519+
{% if public %}
520+
{% set problemSpan = problemSpan + 1 %}
500521
{% endif %}
501522
<td colspan="{{ problemSpan }}">
502523
{% for problem in problems %}

0 commit comments

Comments
 (0)