themes.json: Use a exercice list instead of hash

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

View File

@ -57,9 +57,9 @@
<tr ng-repeat="lvl in [1,2,3,4,5]">
<th class="text-center"><nobr>Challenge {{ lvl }}</nobr></th>
<td ng-repeat="(tid,theme) in themes" class="text-center text-bold">
<a ng-href="exercices/{{ exercices[Utils.keys(theme.exercices)[lvl-1]].id_exercice }}" ng-if="exercices[Utils.keys(theme.exercices)[lvl-1]].team_tries || lvl == 1" ng-class="{'text-primary': exercices[Utils.keys(theme.exercices)[lvl-1]].solved_count == 0, 'text-success': exercices[Utils.keys(theme.exercices)[lvl-1]].solved_count >= 1, 'text-bold': exercices[Utils.keys(theme.exercices)[lvl-1]].solved_count >= 1, 'text-warning': exercices[Utils.keys(theme.exercices)[lvl-1]].solved_count == 0 && exercices[Utils.keys(theme.exercices)[lvl-1]].team_tries}">
<span ng-if="exercices[Utils.keys(theme.exercices)[lvl-1]].solved_count">{{ exercices[Utils.keys(theme.exercices)[lvl-1]].solved_count }}</span>
<span ng-if="!exercices[Utils.keys(theme.exercices)[lvl-1]].solved_count">{{ exercices[Utils.keys(theme.exercices)[lvl-1]].team_tries }}</span>
<a ng-href="exercices/{{ exercices[theme.exercices[lvl-1].id].id_exercice }}" ng-if="exercices[theme.exercices[lvl-1].id].team_tries || lvl == 1" ng-class="{'text-primary': exercices[theme.exercices[lvl-1].id].solved_count == 0, 'text-success': exercices[theme.exercices[lvl-1].id].solved_count >= 1, 'text-bold': exercices[theme.exercices[lvl-1].id].solved_count >= 1, 'text-warning': exercices[theme.exercices[lvl-1].id].solved_count == 0 && exercices[theme.exercices[lvl-1].id].team_tries}">
<span ng-if="exercices[theme.exercices[lvl-1].id].solved_count">{{ exercices[theme.exercices[lvl-1].id].solved_count }}</span>
<span ng-if="!exercices[theme.exercices[lvl-1].id].solved_count">{{ exercices[theme.exercices[lvl-1].id].team_tries }}</span>
</a>
</td>
</tr>

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;
}
}

View File

@ -49,12 +49,12 @@
{/if}
<Row cols={{ lg: 3, md: 2, sm: 1 }}>
{#each Object.keys($themes) as th, index}
{#each $themes as th, index}
<Col class="mb-3">
<CardTheme
class="{$my && $my.team_id && $myThemes[$themes[th].id].exercice_solved > 0?'border-light ':''}{$themes[th].exercice_coeff_max > 1?'border-success ':''}"
theme={$themes[th]}
on:click={goto(`${$themes[th].urlid}`)}
class="{$my && $my.team_id && $myThemes[th.id].exercice_solved > 0?'border-light ':''}{th.exercice_coeff_max > 1?'border-success ':''}"
theme={th}
on:click={goto(`${th.urlid}`)}
/>
</Col>
{/each}

View File

@ -50,56 +50,56 @@
{#if $current_theme.exercices}
<ul class="list-group">
{#each Object.keys($current_theme.exercices) as k, index}
{#each $current_theme.exercices as exercice, index}
<li
class="list-group-item"
class:list-group-item-action={$my && $my.exercices[k]}
on:click={goto(`${$current_theme.urlid}/${$current_theme.exercices[k].urlid}`)}
on:keypress={goto(`${$current_theme.urlid}/${$current_theme.exercices[k].urlid}`)}
class:list-group-item-action={$my && $my.exercices[exercice.id]}
on:click={goto(`${$current_theme.urlid}/${exercice.urlid}`)}
on:keypress={goto(`${$current_theme.urlid}/${exercice.urlid}`)}
>
<div class="row">
<div class="col-1" style="margin-top: -0.5rem; margin-bottom: -0.5rem; text-align: right; border-right: 5px solid #{$my && $my.exercices[k] && $my.exercices[k].solved_rank ? '62c462' : 'bbb'}">
<div class="col-1" style="margin-top: -0.5rem; margin-bottom: -0.5rem; text-align: right; border-right: 5px solid #{$my && $my.exercices[exercice.id] && $my.exercices[exercice.id].solved_rank ? '62c462' : 'bbb'}">
</div>
<div class="col-10">
<div style="position: absolute; margin-left: calc(var(--bs-gutter-x) * -.5 - 15px); margin-top: -0.5rem;">
<svg style="height: 50px; width: 23px;">
<rect
style="fill:#{$my && $my.exercices[k] && (index < 1 || ($my.exercices[Object.keys($current_theme.exercices)[index-1]] && $my.exercices[Object.keys($current_theme.exercices)[index-1]].solved_rank)) ? '62c462' : 'bbb'}"
style="fill:#{$my && $my.exercices[exercice.id] && (index < 1 || ($my.exercices[$current_theme.exercices[index-1].id] && $my.exercices[$current_theme.exercices[index-1].id].solved_rank)) ? '62c462' : 'bbb'}"
width="5"
height="30"
x="10"
y="0" />
<path
style="fill:#{$my && $my.exercices[k] ? ($my.exercices[k].solved_rank ? '62c462' : ($current_theme.exercices[k].curcoeff > 1.0 ? 'f89406' : '5bc0de')) : '555'}"
style="fill:#{$my && $my.exercices[exercice.id] ? ($my.exercices[exercice.id].solved_rank ? '62c462' : (exercice.curcoeff > 1.0 ? 'f89406' : '5bc0de')) : '555'}"
d="m 22,20 a 9.5700617,9.5700617 0 0 1 -9.5690181,9.57006 9.5700617,9.5700617 0 0 1 -9.57110534,-9.56797 9.5700617,9.5700617 0 0 1 9.56692984,-9.57215 9.5700617,9.5700617 0 0 1 9.5731926,9.56588" />
</svg>
</div>
{#each $current_theme.exercices[k].tags as tag, idx}
{#each exercice.tags as tag, idx}
<Badge href="tags/{tag}" pill color="secondary" class="mx-1 float-end">#{tag}</Badge>
{/each}
<h5 class="fw-bold">
{#if $my && $my.exercices[k]}
{#if $my && $my.exercices[exercice.id]}
<span style="white-space: nowrap">
{#if $my.exercices[k].wip}
{#if $my.exercices[exercice.id].wip}
<Icon name="cone-striped" aria-hidden="true" title="Cette étape est encore en construction." />
{/if}
{$current_theme.exercices[k].title}
{exercice.title}
</span>
{:else}
<span style="white-space: nowrap">
<Icon name="lock-fill" aria-hidden="true" title="Vous n'avez pas encore accès à ce défi" />
{$current_theme.exercices[k].title}
{exercice.title}
</span>
{/if}
{#if $current_theme.exercices[k].curcoeff > 1.0}
{#if exercice.curcoeff > 1.0}
<Icon name="gift" aria-hidden="true" title="Un bonus est actuellement appliqué lors de la résolution de ce défi" />
{/if}
</h5>
<p>{@html $current_theme.exercices[k].headline}</p>
<p>{@html exercice.headline}</p>
</div>
<div class="d-none d-md-block col-1">
{#if $my && $my.exercices[k]}
<a class="float-right" href="{$current_theme.urlid}/{$current_theme.exercices[k].urlid}" style="font-size: 3rem">
{#if $my && $my.exercices[exercice.id]}
<a class="float-right" href="{$current_theme.urlid}/{exercice.urlid}" style="font-size: 3rem">
<Icon name="chevron-right" aria-hidden="true" />
</a>
{:else}

View File

@ -22,10 +22,11 @@
$: {
let tmp_exercices = [];
for (let th in $themes) {
for (let ex in $themes[th].exercices) {
if ($themes[th].exercices[ex].tags.indexOf(data.tag) >= 0) {
tmp_exercices.push({theme: $themes[th], exercice: $themes[th].exercices[ex], index: th + "," + ex});
for (let k in $themes) {
const th = $themes[k];
for (const ex of th.exercices) {
if (ex.tags.indexOf(data.tag) >= 0) {
tmp_exercices.push({theme: th, exercice: ex, index: k + "," + ex});
}
}
}

View File

@ -10,6 +10,7 @@ var GlobalScoreCoefficient float64 = 1
// exportedExercice is a structure representing a challenge, as exposed to players.
type exportedExercice struct {
Id int64 `json:"id"`
Title string `json:"title"`
Headline string `json:"headline,omitempty"`
URLId string `json:"urlid"`
@ -22,16 +23,16 @@ type exportedExercice struct {
// exportedTheme is a structure representing a Theme, as exposed to players.
type exportedTheme struct {
Name string `json:"name"`
URLId string `json:"urlid"`
Authors string `json:"authors"`
Headline string `json:"headline,omitempty"`
Intro string `json:"intro"`
Image string `json:"image,omitempty"`
PartnerImage string `json:"partner_img,omitempty"`
PartnerLink string `json:"partner_href,omitempty"`
PartnerText string `json:"partner_txt,omitempty"`
Exercices map[string]exportedExercice `json:"exercices"`
Name string `json:"name"`
URLId string `json:"urlid"`
Authors string `json:"authors"`
Headline string `json:"headline,omitempty"`
Intro string `json:"intro"`
Image string `json:"image,omitempty"`
PartnerImage string `json:"partner_img,omitempty"`
PartnerLink string `json:"partner_href,omitempty"`
PartnerText string `json:"partner_txt,omitempty"`
Exercices []exportedExercice `json:"exercices"`
}
// Exportedthemes exports themes from the database, to be displayed to players.
@ -44,10 +45,11 @@ func ExportThemes() (interface{}, error) {
if exercices, err := theme.GetExercices(); err != nil {
return nil, err
} else {
exos := map[string]exportedExercice{}
exos := []exportedExercice{}
for _, exercice := range exercices {
tags, _ := exercice.GetTags()
exos[fmt.Sprintf("%d", exercice.Id)] = exportedExercice{
exos = append(exos, exportedExercice{
exercice.Id,
exercice.Title,
exercice.Headline,
exercice.URLId,
@ -56,7 +58,7 @@ func ExportThemes() (interface{}, error) {
exercice.Coefficient,
exercice.SolvedCount(),
exercice.TriedTeamCount(),
}
})
}
imgpath := ""