Skip to content

Commit

Permalink
hub: show maximum count for challenges with sub-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Oct 11, 2023
1 parent 53e31e2 commit 68aaaba
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions frontend/templates/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</td>
<td class="center narrow"><span class="category" :style="{backgroundColor: category_color(challenge.category)}">{{ challenge.category }}</span></td>
<td class="center narrow">{{ challenge.score }}</td>
<td class="center narrow">{{ (clear_count.challenges.find(i=>i.challenge===challenge.pk)||{count:0}).count }}</td>
<td class="center narrow">{{ get_challenge_count_string(challenge) }}</td>
</tr>
<tr v-if="challenge===opened && challenge.flags.length>1" v-for="(flag, flag_index) in challenge.flags" class="flag">
<td>
Expand All @@ -101,7 +101,7 @@
</td>
<td></td>
<td class="center narrow">{{ flag.score }}</td>
<td class="center narrow">{{ (clear_count.flags.find(i=>i.challenge===challenge.pk&&i.flag===flag_index)||{count:0}).count }}</td>
<td class="center narrow">{{ get_subchallenge_count_string(challenge, flag_index) }}</td>
</tr>
</template>
<tr v-if="user.is_staff">
Expand Down Expand Up @@ -216,6 +216,25 @@ <h1>{{ opened.name }}</h1>
} while (!color.valid());
return color.hex();
},
get_challenge_count_string(challenge) {
let count = (this.clear_count.flags.find(i => i.challenge === challenge.pk) || {count: 0}).count;
// are there any sub-flags?
if (challenge.flags.length > 1) {
let max_sub = 0;
for (let j = 0; j < challenge.flags.length; j++) {
let sub_count = this.get_subchallenge_count_string(challenge, j);
if (sub_count > max_sub) {
max_sub = sub_count;
}
}
return `${count} (${max_sub})`;
}
return count;
},
get_subchallenge_count_string(challenge, flag_index) {
let count = (this.clear_count.flags.find(i => i.challenge === challenge.pk && i.flag === flag_index) || {count: 0}).count;
return count;
}
},
updated: function () {
this.$nextTick(function () {
Expand Down

0 comments on commit 68aaaba

Please sign in to comment.