2021-08-30 10:46:18 +00:00
|
|
|
<script>
|
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
CardBody,
|
|
|
|
CardHeader,
|
|
|
|
CardText,
|
|
|
|
Icon,
|
|
|
|
ListGroup,
|
|
|
|
ListGroupItem,
|
2021-08-31 23:41:22 +00:00
|
|
|
Spinner,
|
2021-08-30 10:46:18 +00:00
|
|
|
} from 'sveltestrap';
|
|
|
|
|
|
|
|
import { settings } from '../stores/settings.js';
|
|
|
|
|
|
|
|
export let hints = [];
|
2021-08-31 23:41:22 +00:00
|
|
|
export let exercice = {};
|
|
|
|
export let refresh_my = null;
|
|
|
|
|
|
|
|
let hints_submitted = {};
|
|
|
|
|
|
|
|
function waitDiff(i, hint) {
|
|
|
|
refresh_my((my) => {
|
|
|
|
let openedHint = false;
|
|
|
|
|
|
|
|
if (my && my.exercices[exercice.id].hints) {
|
|
|
|
my.exercices[exercice.id].hints.forEach((h) => {
|
|
|
|
if (h.id == hint.id && (h.content || h.file)) {
|
|
|
|
openedHint = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openedHint) {
|
|
|
|
hints_submitted[hint.id] = false;
|
|
|
|
hinterror = "";
|
|
|
|
} else if (i > 0) {
|
|
|
|
setTimeout(waitDiff, 650, i-1, hint);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function openHint(hint) {
|
|
|
|
hints_submitted[hint.id] = true;
|
|
|
|
hinterror = "";
|
|
|
|
|
|
|
|
const response = await fetch(
|
2021-09-01 09:20:41 +00:00
|
|
|
"openhint/" + exercice.id,
|
2021-08-31 23:41:22 +00:00
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({ id: hint.id }),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if (response.status < 300) {
|
|
|
|
waitDiff(15, hint);
|
|
|
|
} else {
|
|
|
|
hints_submitted[hint.id] = false;
|
|
|
|
|
|
|
|
let data = "";
|
|
|
|
try {
|
|
|
|
data = await response.json();
|
|
|
|
} catch(e) {
|
|
|
|
data = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data && data.errmsg)
|
|
|
|
hinterror = data.errmsg;
|
|
|
|
}
|
|
|
|
}
|
2021-08-30 10:46:18 +00:00
|
|
|
|
|
|
|
let hinterror = "";
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if hints.length}
|
|
|
|
<Card class="mb-2">
|
2021-08-31 23:41:22 +00:00
|
|
|
<CardHeader class="bg-info text-light">
|
2021-08-30 10:46:18 +00:00
|
|
|
<Icon name="lightbulb-fill" />
|
|
|
|
Indices
|
|
|
|
</CardHeader>
|
|
|
|
{#if hinterror}
|
|
|
|
<CardBody>
|
|
|
|
<CardText class="text-danger">
|
|
|
|
{hinterror}
|
|
|
|
</CardText>
|
|
|
|
</CardBody>
|
|
|
|
{/if}
|
|
|
|
<ListGroup>
|
|
|
|
{#each hints as hint (hint.id)}
|
2021-08-31 23:47:44 +00:00
|
|
|
<ListGroupItem tag="a" href="{hint.file}" target="_self" class="d-flex align-items-center">
|
2021-08-30 10:46:18 +00:00
|
|
|
{#if hint.file}
|
2021-08-31 23:41:22 +00:00
|
|
|
<h1 class="me-3">
|
|
|
|
<Icon name="arrow-down-circle" />
|
|
|
|
</h1>
|
2021-08-30 10:46:18 +00:00
|
|
|
{/if}
|
2021-08-31 23:47:44 +00:00
|
|
|
<div class="flex-fill" style="min-width:0">
|
2021-08-30 10:46:18 +00:00
|
|
|
{#if !(hint.content || hint.file)}
|
2021-08-31 23:41:22 +00:00
|
|
|
<button type="button" on:click={openHint(hint)} class="float-end btn btn-info" class:disabled={hints_submitted[hint.id]}>
|
|
|
|
{#if hints_submitted[hint.id]}
|
|
|
|
<Spinner size="sm" class="me-2" />
|
|
|
|
{:else}
|
|
|
|
<Icon name="lock" aria-hidden="true" />
|
|
|
|
{/if}
|
2021-08-30 10:46:18 +00:00
|
|
|
Débloquer
|
|
|
|
</button>
|
|
|
|
{/if}
|
|
|
|
{#if !hint.file && hint.hidden}
|
|
|
|
<button type="button" ng-click="hint.hidden = false;" class="float-end btn btn-info">
|
|
|
|
<Icon name="lock" aria-hidden="true" />
|
|
|
|
Afficher
|
|
|
|
</button>
|
|
|
|
{/if}
|
2021-08-31 23:41:22 +00:00
|
|
|
<h4 class="fw-bold">{hint.title}</h4>
|
2021-08-30 10:46:18 +00:00
|
|
|
{#if hint.file}
|
2021-08-31 23:47:44 +00:00
|
|
|
<p style="overflow-x: auto">
|
2021-08-30 10:46:18 +00:00
|
|
|
Cliquez ici pour télécharger l'indice.<br>
|
|
|
|
b2sum :
|
|
|
|
<samp class="cksum" title="Somme de contrôle BLAKE2b : {hint.content}">{hint.content}</samp>
|
|
|
|
</p>
|
|
|
|
{:else if hint.content && !hint.hidden}
|
|
|
|
<p>{@html hint.content}</p>
|
|
|
|
{:else}
|
|
|
|
<p>
|
2021-08-31 23:41:22 +00:00
|
|
|
Débloquer cet indice vous fera perdre {hint.cost * $settings.hintCurrentCoefficient} {hint.cost * $settings.hintCurrentCoefficient == 1 ? "point" : "points"}.
|
2021-08-30 10:46:18 +00:00
|
|
|
</p>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</ListGroupItem>
|
|
|
|
{/each}
|
|
|
|
</ListGroup>
|
|
|
|
</Card>
|
|
|
|
{/if}
|