themes.json: Use a exercice list instead of hash

This commit is contained in:
nemunaire 2023-01-24 14:15:48 +01:00
commit ef1eafb789
11 changed files with 82 additions and 82 deletions

View file

@ -36,7 +36,7 @@
<hr>
{/if}
{/if}
{#if theme.exercices[exercice.id].next}
{#if theme.exercices[exercice.id] && theme.exercices[exercice.id].next}
<a href="{theme.urlid}/{theme.exercices[theme.exercices[exercice.id].next].urlid}" class="btn btn-success">Passer au défi suivant</a>
{/if}
</CardBody>

View file

@ -20,21 +20,21 @@
</DropdownToggle>
<DropdownMenu class="niceborder">
<div>
{#each Object.keys($themes) as th, index}
<DropdownItem href="{$themes[th].urlid}">
{$themes[th].name}
{#if $max_solved > 1 && $themes[th].solved == $max_solved}
{#each $themes as th, index}
<DropdownItem href="{th.urlid}">
{th.name}
{#if $max_solved > 1 && th.solved == $max_solved}
<Badge color="danger">
<Icon name="heart-fill" />
</Badge>
{/if}
{#if $themes[th].exercice_coeff_max > 1}
{#if th.exercice_coeff_max > 1}
<Badge color="success">
<Icon name="gift-fill" />
</Badge>
{/if}
<Badge>
{#if $my && $my.team_id}{$myThemes[$themes[th].id].exercice_solved}/{/if}{$themes[th].exercice_count}
{#if $my && $my.team_id}{$myThemes[th.id].exercice_solved}/{/if}{th.exercice_count}
</Badge>
</DropdownItem>
{/each}

View file

@ -10,7 +10,7 @@
import DateFormat from '$lib/components/DateFormat.svelte';
import { my } from '$lib/stores/my.js';
import { themes } from '$lib/stores/themes.js';
import { themes, exercices_idx } from '$lib/stores/themes.js';
let req = null;
function refresh_scores() {
@ -55,9 +55,9 @@
<Badge color="primary"><Icon name="question" /></Badge>
{row.reason}
{/if}
{#if row.id_exercice && $my.exercices[row.id_exercice]}
sur <a href="/{$themes[$my.exercices[row.id_exercice].theme_id].urlid}/{$themes[$my.exercices[row.id_exercice].theme_id].exercices[row.id_exercice].urlid}">
{$themes[$my.exercices[row.id_exercice].theme_id].exercices[row.id_exercice].title}
{#if row.id_exercice && $exercices_idx[row.id_exercice]}
sur <a href="/{$themes[$exercices_idx[row.id_exercice].id_theme].urlid}/{$exercices_idx[row.id_exercice].urlid}">
{$exercices_idx[row.id_exercice].title}
</a>
{/if}
</Column>

View file

@ -13,32 +13,32 @@
</script>
<Breadcrumb listClassName="mb-0 px-3 py-2">
{#each Object.keys(theme.exercices) as k, index}
<BreadcrumbItem active={k == exercice.id}>
{#if k == exercice.id}
{#each theme.exercices as ex, index}
<BreadcrumbItem active={ex.id == exercice.id}>
{#if ex.id == exercice.id}
<strong class="text-info">
{theme.exercices[k].title}
{#if theme.exercices[k].curcoeff > 1.0}
{ex.title}
{#if ex.curcoeff > 1.0}
<Icon name="gift" aria-hidden="true" />
{/if}
{#if $my && $my.team_id && $my.exercices[k] && $my.exercices[k].solved}
{#if $my && $my.team_id && $my.exercices[ex.id] && $my.exercices[ex.id].solved}
<Icon name="check" class="text-success" aria-hidden="true" />
{/if}
</strong>
{:else if $my && $my.exercices[k]}
<a href="{theme.urlid}/{theme.exercices[k].urlid}" class:text-success={$my.exercices[k].solved}>
{theme.exercices[k].title}
{#if theme.exercices[k].curcoeff > 1.0}
{:else if $my && $my.exercices[ex.id]}
<a href="{theme.urlid}/{ex.urlid}" class:text-success={$my.exercices[ex.id].solved}>
{ex.title}
{#if ex.curcoeff > 1.0}
<Icon name="gift" aria-hidden="true" />
{/if}
{#if $my.team_id && $my.exercices[k].solved}
{#if $my.team_id && $my.exercices[ex.id].solved}
<Icon name="check" class="text-success" aria-hidden="true" />
{/if}
</a>
{:else}
<span class="text-muted">
{theme.exercices[k].title}
{#if theme.exercices[k].curcoeff > 1.0}
{ex.title}
{#if ex.curcoeff > 1.0}
<Icon name="gift" aria-hidden="true" />
{/if}
</span>

View file

@ -12,8 +12,8 @@ export const myThemes = derived([my, themesStore], ([$my, $themesStore]) => {
mythemes[key] = {exercice_solved: 0};
if ($my && $my.exercices) {
for (let k in $themesStore[key].exercices) {
if ($my.exercices[k] && $my.exercices[k].solved_rank) {
for (const exercice of $themesStore[key].exercices) {
if ($my.exercices[exercice.id] && $my.exercices[exercice.id].solved_rank) {
mythemes[key].exercice_solved++;
}
}
@ -51,15 +51,15 @@ export const themes = derived(
export const tags = derived([my, themesStore], ([$my, $themesStore]) => {
const tags = {};
for (let key in $themesStore) {
for (let k in $themesStore[key].exercices) {
$themesStore[key].exercices[k].tags.forEach((tag) => {
for (const key in $themesStore) {
for (const exercice of $themesStore[key].exercices) {
exercice.tags.forEach((tag) => {
if (!tags[tag])
tags[tag] = {count: 1, solved: 0};
else
tags[tag].count += 1;
if ($my && $my.exercices && $my.exercices[k] && $my.exercices[k].solved_rank)
if ($my && $my.exercices && $my.exercices[exercice.id] && $my.exercices[exercice.id].solved_rank)
tags[tag].solved += 1;
});
}

View file

@ -53,12 +53,11 @@ export const themes = derived(
const theme = $themesStore[key];
themes[key] = theme
themes[key].exercice_count = Object.keys(theme.exercices).length;
themes[key].exercice_count = theme.exercices.length;
themes[key].exercice_coeff_max = 0;
themes[key].max_gain = 0;
let last_exercice = null;
for (let k in theme.exercices) {
for (const k in theme.exercices) {
const exercice = theme.exercices[k];
themes[key].max_gain += exercice.gain;
@ -66,11 +65,8 @@ export const themes = derived(
themes[key].exercice_coeff_max = exercice.curcoeff;
}
if (last_exercice != null)
themes[key].exercices[last_exercice].next = k;
last_exercice = k;
exercice.id = k;
if (k > 0)
themes[key].exercices[k-1].next = k;
}
}
@ -101,8 +97,9 @@ export const exercices_idx = derived(
for (const key in $themesStore) {
const theme = $themesStore[key];
for (let k in theme.exercices) {
ret[k] = theme.exercices[k];
for (let exercice of theme.exercices) {
ret[exercice.id] = exercice;
ret[exercice.id].id_theme = key;
}
}
@ -117,8 +114,8 @@ export const exercices_idx_urlid = derived(
for (const key in $themesStore) {
const theme = $themesStore[key];
for (let k in theme.exercices) {
ret[theme.exercices[k].urlid] = theme.exercices[k];
for (let exercice of theme.exercices) {
ret[exercice.urlid] = exercice;
}
}