Skip to content

Commit 0b60833

Browse files
committed
fix: colorize negative scores in tables
1 parent b58176e commit 0b60833

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

src/handlers/filters.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ export const setupNunjucksFilters = function(app: Express): void {
1818
return num.toString().replace(/\./, ',').replace(/\B(?=(\d{3})+(?!\d))/g, '.');
1919
});
2020

21+
// Add formatting for numbers to be colored red
22+
nunjucksEnv.addFilter('colorNegative', (num: number | string) => {
23+
const number = typeof num === 'string' ? parseFloat(num.replace(/\./g, '').replace(',', '.')) : num;
24+
if (number < 0) {
25+
return `<span style="color: orangered; font-weight: bold;">${num}</span>`;
26+
}
27+
return num;
28+
});
29+
2130
// Add formatting filter for seconds to hh:mm format
2231
nunjucksEnv.addFilter('formatSeconds', (seconds: number) => {
2332
const hours = Math.floor(seconds / 3600);

templates/admin/points/history.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<td><a href="/admin/points/history/{{ score.id }}" target="scorejson">{{ score.id }}</a></td>
2929
<td title="{{ score.created_at }}">{{ score.created_at | timeAgo }}</td>
3030
<td>{{ coalitions[score.coalition_id].intra_coalition.name | striptags(true) | escape }}</td>
31-
<td>{{ score.amount }}</td>
31+
<td>{{ score.amount | thousands | colorNegative }}</td>
3232
<td><a href="/profile/{{ score.user.intra_user.login | striptags(true) | escape }}">{{ score.user.intra_user.login | striptags(true) | escape }}</a></td>
3333
<td style="white-space: normal; word-wrap: break-word;">{{ score.reason | striptags(true) | escape }}</td>
3434
<td>{{ score.fixed_type_id if score.fixed_type_id else "" }}</td>

templates/admin/points/manual/added.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<tr class="points-added-row" style="background: {{ score.coalition.intra_coalition.color | rgba(0.25) }}">
4343
<td><a href="/profile/{{ score.user.intra_user.login }}">{{ score.user.intra_user.login }}</a></td>
4444
<td>{{ score.coalition.intra_coalition.name | striptags(true) | escape }}</td>
45-
<td>{{ score.amount | thousands }}</td>
45+
<td>{{ score.amount | thousands | colorNegative }}</td>
4646
<td>{{ score.reason | striptags(true) | escape }}</td>
4747
</tr>
4848
{% endfor %}

templates/admin/points/manual/custom.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ else {
139139
<td>{{ score.created_at | timeAgo }}</td>
140140
<td><a href="/profile/{{ score.user.intra_user.login }}/">{{ score.user.intra_user.login }}</a></td>
141141
<td>{{ score.coalition.intra_coalition.name | striptags(true) | escape }}</td>
142-
<td>{{ score.amount | thousands }}</td>
142+
<td>{{ score.amount | thousands | colorNegative }}</td>
143143
<td>{{ score.reason | striptags(true) | escape }}</td>
144144
</tr>
145145
{% endfor %}

templates/coalition.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
<tr>
121121
<td title="{{ score.created_at }}">{{ score.created_at | timeAgo }}</td>
122122
<td><a href="/profile/{{ score.user.intra_user.login | striptags(true) | escape }}">{{ score.user.intra_user.login | striptags(true) | escape }}</a></td>
123-
<td>{{ score.amount }}</td>
123+
<td>{{ score.amount | thousands | colorNegative}}</td>
124124
<td style="white-space: normal; word-wrap: break-word;"><small>{{ score.reason | striptags(true) | escape }}</small></td>
125125
</tr>
126126
{% endfor %}
@@ -152,7 +152,7 @@
152152
<tr>
153153
<td title="{{ score.created_at }}">{{ score.created_at | timeAgo }}</td>
154154
<td><a href="/profile/{{ score.user.intra_user.login | striptags(true) | escape }}">{{ score.user.intra_user.login | striptags(true) | escape }}</a></td>
155-
<td>{{ score.amount }}</td>
155+
<td>{{ score.amount | thousands | colorNegative }}</td>
156156
<td style="white-space: normal; word-wrap: break-word;"><small>{{ score.reason | striptags(true) | escape }}</small></td>
157157
</tr>
158158
{% endfor %}

templates/profile.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
{% for score in latestScores %}
7777
<tr style="background: {{ score.coalition.intra_coalition.color | rgba(0.25) }}">
7878
<td title="{{ score.created_at }}">{{ score.created_at | timeAgo }}</td>
79-
<td>{{ score.amount | thousands }}</td>
79+
<td>{{ score.amount | thousands | colorNegative }}</td>
8080
<td style="white-space: normal; word-wrap: break-word;">{{ score.reason | striptags(true) | escape }}</td>
8181
</tr>
8282
{% endfor %}

0 commit comments

Comments
 (0)