Skip to content

Commit 2f8357f

Browse files
committed
fix: wrong ongoing season fetched from the database
1 parent a0adcc4 commit 2f8357f

File tree

4 files changed

+109
-64
lines changed

4 files changed

+109
-64
lines changed

src/routes/admin/dashboard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export const setupAdminDashboardRoutes = function(app: Express, prisma: PrismaCl
99
orderBy: {
1010
end_at: 'desc',
1111
},
12+
where: {
13+
end_at: {
14+
lt: new Date(),
15+
gte: new Date(),
16+
},
17+
},
1218
});
1319

1420
// Get previous bloc deadlines

src/routes/home.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
4949
orderBy: {
5050
end_at: 'desc',
5151
},
52+
where: {
53+
end_at: {
54+
lt: new Date(),
55+
gte: new Date(),
56+
},
57+
},
58+
});
59+
const nextBlocDeadline = await prisma.intraBlocDeadline.findFirst({
60+
orderBy: {
61+
begin_at: 'asc',
62+
},
63+
where: {
64+
begin_at: {
65+
gt: new Date(),
66+
},
67+
},
5268
});
5369

5470
// Get the coalition of the current user
@@ -102,6 +118,7 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
102118
my_coalition,
103119
now,
104120
currentBlocDeadline,
121+
nextBlocDeadline,
105122
quiz_available,
106123
sortedCoalitionScores,
107124
rankingTypes,

templates/admin/dashboard.njk

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
<h5 class="card-title mb-0">Season deadlines</h5>
2323
</div>
2424
<div class="card-body">
25-
<p>Start: <span id="season-start" data-date="{{ currentBlocDeadline.begin_at | timestamp }}">{{ currentBlocDeadline.begin_at | timeAgo }}</span></p>
26-
<p>End: <span id="season-end" data-date="{{ currentBlocDeadline.end_at | timestamp }}">{{ currentBlocDeadline.end_at | timeFromNow }}</span></p>
25+
{% if currentBlocDeadline %}
26+
<p>Start: <span id="season-start" data-date="{{ currentBlocDeadline.begin_at | timestamp }}">{{ currentBlocDeadline.begin_at | timeAgo }}</span></p>
27+
<p>End: <span id="season-end" data-date="{{ currentBlocDeadline.end_at | timestamp }}">{{ currentBlocDeadline.end_at | timeFromNow }}</span></p>
28+
{% else %}
29+
<p>No season currently ongoing.</p>
30+
{% endif %}
2731
</div>
2832
</div>
2933
</div>

templates/home.njk

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,85 +5,103 @@
55
{% if not quiz_available %}
66
{# This section is only displayed when the quiz is not available. #}
77
<div class="container-lg mw-900">
8-
<div class="card w-100 mb-4" id="leaderboards" style="overflow: hidden;">
9-
<div class="card-header pe-2 d-flex align-items-center" style="background-color: #6c757d;">
10-
<div class="d-inline-block pe-3 lh-lg flex-grow-1" style="color: #fff; font-weight: bold;">Leaderboards</div>
11-
<div class="d-inline-block">
8+
{% if currentBlocDeadline %}
9+
<div class="card w-100 mb-4" id="leaderboards" style="overflow: hidden;">
10+
<div class="card-header pe-2 d-flex align-items-center" style="background-color: #6c757d;">
11+
<div class="d-inline-block pe-3 lh-lg flex-grow-1" style="color: #fff; font-weight: bold;">Leaderboards</div>
12+
<div class="d-inline-block">
1213

14+
</div>
15+
</div>
16+
<div class="">
17+
<ol class="list-group list-group-numbered custom-numbers noborder">
18+
{% for coalitionId, sortedCoalitionScore in sortedCoalitionScores %}
19+
<li class="list-group-item big-coalition-row" style="background-color: {{ coalitionsObject[coalitionId].intra_coalition.color | rgba(0.5) }}; background-image: url({{ coalitionsObject[coalitionId].intra_coalition.cover_url }})">
20+
<a href="/coalitions/{{ coalitionsObject[coalitionId].intra_coalition.id }}">
21+
<div class="big-coalition-logo">
22+
<img src="{{ coalitionsObject[coalitionId].intra_coalition.image_url }}" style="filter: invert(1);" />
23+
</div>
24+
<div class="big-coalition-content">
25+
<h5 class="coalition-name"><b>{{ coalitionsObject[coalitionId].intra_coalition.name | striptags(true) | escape }}</b></h5>
26+
<p class="coalition-description">{{ sortedCoalitionScore.score | thousands }} points</p>
27+
</div>
28+
</a>
29+
</li>
30+
{% endfor %}
31+
</ol>
1332
</div>
1433
</div>
15-
<div class="">
16-
<ol class="list-group list-group-numbered custom-numbers noborder">
17-
{% for coalitionId, sortedCoalitionScore in sortedCoalitionScores %}
18-
<li class="list-group-item big-coalition-row" style="background-color: {{ coalitionsObject[coalitionId].intra_coalition.color | rgba(0.5) }}; background-image: url({{ coalitionsObject[coalitionId].intra_coalition.cover_url }})">
19-
<a href="/coalitions/{{ coalitionsObject[coalitionId].intra_coalition.id }}">
20-
<div class="big-coalition-logo">
21-
<img src="{{ coalitionsObject[coalitionId].intra_coalition.image_url }}" style="filter: invert(1);" />
22-
</div>
23-
<div class="big-coalition-content">
24-
<h5 class="coalition-name"><b>{{ coalitionsObject[coalitionId].intra_coalition.name | striptags(true) | escape }}</b></h5>
25-
<p class="coalition-description">{{ sortedCoalitionScore.score | thousands }} points</p>
26-
</div>
27-
</a>
28-
</li>
29-
{% endfor %}
30-
</ol>
31-
</div>
32-
</div>
3334

34-
<div class="card w-100 mb-4" id="score-history">
35-
<div class="card-header pe-2 d-flex align-items-center" style="background-color: #6c757d;">
36-
<div class="d-inline-block pe-3 lh-lg flex-grow-1" style="color: #fff; font-weight: bold;">Score History</div>
37-
<div class="d-inline-block">
35+
<div class="card w-100 mb-4" id="score-history">
36+
<div class="card-header pe-2 d-flex align-items-center" style="background-color: #6c757d;">
37+
<div class="d-inline-block pe-3 lh-lg flex-grow-1" style="color: #fff; font-weight: bold;">Score History</div>
38+
<div class="d-inline-block">
3839

40+
</div>
3941
</div>
40-
</div>
41-
<div class="card-body">
42-
<div class="mb-4">
43-
<canvas height="300" class="codam-chart" data-url="/charts/coalitions/scores/history" id="coalition-score-history"></canvas>
44-
</div>
45-
<div class="progress mb-2" role="progressbar" aria-label="Progress of the current season" aria-valuenow="{{ now | timestamp }}" aria-valuemin="{{ currentBlocDeadline.begin_at | timestamp }}" aria-valuemax="{{ currentBlocDeadline.end_at | timestamp }}">
46-
<div class="progress-bar" style="width: {{ now | timestamp | perc3(currentBlocDeadline.begin_at | timestamp, currentBlocDeadline.end_at | timestamp) }}%;"></div>
42+
<div class="card-body">
43+
<div class="mb-4">
44+
<canvas height="300" class="codam-chart" data-url="/charts/coalitions/scores/history" id="coalition-score-history"></canvas>
45+
</div>
46+
<div class="progress mb-2" role="progressbar" aria-label="Progress of the current season" aria-valuenow="{{ now | timestamp }}" aria-valuemin="{{ currentBlocDeadline.begin_at | timestamp }}" aria-valuemax="{{ currentBlocDeadline.end_at | timestamp }}">
47+
<div class="progress-bar" style="width: {{ now | timestamp | perc3(currentBlocDeadline.begin_at | timestamp, currentBlocDeadline.end_at | timestamp) }}%;"></div>
48+
</div>
49+
<p style="text-align: center;">The current season <b title="{{ currentBlocDeadline.end_at }}">ends {{ currentBlocDeadline.end_at | timeFromNow }}</b>!</p>
4750
</div>
48-
<p style="text-align: center;">The current season <b title="{{ currentBlocDeadline.end_at }}">ends {{ currentBlocDeadline.end_at | timeFromNow }}</b>!</p>
4951
</div>
50-
</div>
5152

52-
{% for rankingType in rankingTypes %}
53-
<div class="card w-100 mb-4" id="ranking-{{ rankingType.type }}">
53+
{% for rankingType in rankingTypes %}
54+
<div class="card w-100 mb-4" id="ranking-{{ rankingType.type }}">
55+
<div class="card-header pe-2 d-flex align-items-center" style="background-color: #6c757d;">
56+
<div class="d-inline-block pe-3 lh-lg flex-grow-1" style="color: #fff; font-weight: bold;">{{ rankingType.name | striptags(true) | escape }}</div>
57+
<div class="d-inline-block">
58+
59+
</div>
60+
</div>
61+
<div class="card-body p-0">
62+
<p class="p-4 pb-2">{{ rankingType.description | striptags(true) | escape | nl2br }}</p>
63+
<table class="table coalition-colored mb-0">
64+
<tbody>
65+
{% for ranking in rankings[rankingType.type] %}
66+
<tr style="background: {{ ranking.coalition.color | rgba(0.25) }}; vertical-align: middle;">
67+
<td class="fs-5 p-2" style="width: 25px;">{{ ranking.rank }}.</td>
68+
<td class="p-0">
69+
<div class="d-inline-flex flex-row justify-content-start align-items-center text-light">
70+
<a href="/profile/{{ ranking.user.login | striptags(true) | escape }}" class="p-2 text-light" style="text-decoration: none;">
71+
<img loading="lazy" src="{{ ranking.user.image }}" class="user-picture rounded-circle d-inline-block me-2" height="32" />
72+
<span>{{ ranking.user.usual_full_name | striptags(true) | escape }}</span>
73+
</a>
74+
</div>
75+
</td>
76+
<td class="text-end ps-2 pe-2 mt-0 mb-2">{{ ranking.score | thousands }}</td>
77+
</tr>
78+
{% endfor %}
79+
</tbody>
80+
</table>
81+
{# if no rankings, display a message #}
82+
{% if rankings[rankingType.type] | length == 0 %}
83+
<p class="text-muted p-4"><i>No rankings available (yet).</i></p>
84+
{% endif %}
85+
</div>
86+
</div>
87+
{% endfor %}
88+
{% else %}
89+
<div class="card w-100 mb-4" id="no-season">
5490
<div class="card-header pe-2 d-flex align-items-center" style="background-color: #6c757d;">
55-
<div class="d-inline-block pe-3 lh-lg flex-grow-1" style="color: #fff; font-weight: bold;">{{ rankingType.name | striptags(true) | escape }}</div>
91+
<div class="d-inline-block pe-3 lh-lg flex-grow-1" style="color: #fff; font-weight: bold;">No season ongoing</div>
5692
<div class="d-inline-block">
5793

5894
</div>
5995
</div>
60-
<div class="card-body p-0">
61-
<p class="p-4 pb-2">{{ rankingType.description | striptags(true) | escape | nl2br }}</p>
62-
<table class="table coalition-colored mb-0">
63-
<tbody>
64-
{% for ranking in rankings[rankingType.type] %}
65-
<tr style="background: {{ ranking.coalition.color | rgba(0.25) }}; vertical-align: middle;">
66-
<td class="fs-5 p-2" style="width: 25px;">{{ ranking.rank }}.</td>
67-
<td class="p-0">
68-
<div class="d-inline-flex flex-row justify-content-start align-items-center text-light">
69-
<a href="/profile/{{ ranking.user.login | striptags(true) | escape }}" class="p-2 text-light" style="text-decoration: none;">
70-
<img loading="lazy" src="{{ ranking.user.image }}" class="user-picture rounded-circle d-inline-block me-2" height="32" />
71-
<span>{{ ranking.user.usual_full_name | striptags(true) | escape }}</span>
72-
</a>
73-
</div>
74-
</td>
75-
<td class="text-end ps-2 pe-2 mt-0 mb-2">{{ ranking.score | thousands }}</td>
76-
</tr>
77-
{% endfor %}
78-
</tbody>
79-
</table>
80-
{# if no rankings, display a message #}
81-
{% if rankings[rankingType.type] | length == 0 %}
82-
<p class="text-muted p-4"><i>No rankings available (yet).</i></p>
96+
<div class="card-body">
97+
{% if nextBlocDeadline %}
98+
<p>The next season will start <b title="{{ nextBlocDeadline.begin_at }}">{{ nextBlocDeadline.begin_at | timeFromNow }}</b>!</p>
99+
{% else %}
100+
<p>There is currently no upcoming season scheduled. Please contact staff for more information.</p>
83101
{% endif %}
84102
</div>
85103
</div>
86-
{% endfor %}
104+
{% endif %}
87105
</div>
88106
{% else %}
89107
{# This section is only displayed when the quiz is available. #}

0 commit comments

Comments
 (0)