67 lines
2.1 KiB
Svelte
67 lines
2.1 KiB
Svelte
<script context="module">
|
|
import { getSurvey } from '../../../lib/surveys';
|
|
|
|
export async function load({ params, stuff }) {
|
|
return {
|
|
props: {
|
|
surveyP: stuff.survey,
|
|
},
|
|
};
|
|
}
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
import { goto } from '$app/navigation';
|
|
|
|
import { user } from '../../../stores/user';
|
|
import SurveyAdmin from '../../../components/SurveyAdmin.svelte';
|
|
import SurveyBadge from '../../../components/SurveyBadge.svelte';
|
|
import SurveyQuestions from '../../../components/SurveyQuestions.svelte';
|
|
import { getSurvey } from '../../../lib/surveys';
|
|
import { getQuestions } from '../../../lib/questions';
|
|
|
|
export let surveyP;
|
|
|
|
$: {
|
|
if (surveyP) {
|
|
surveyP.then((survey) => {
|
|
if (survey.direct && !$user.is_admin) {
|
|
goto(`surveys/${survey.id}/live`);
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
let edit = false;
|
|
</script>
|
|
|
|
{#await surveyP then survey}
|
|
{#if $user && $user.is_admin}
|
|
<button class="btn btn-primary ms-1 float-end" on:click={() => { edit = !edit; } } title="Éditer"><i class="bi bi-pencil"></i></button>
|
|
<a href="surveys/{survey.id}/responses" class="btn btn-success ms-1 float-end" title="Voir les réponses"><i class="bi bi-files"></i></a>
|
|
{#if survey.direct}
|
|
<a href="surveys/{survey.id}/live" class="btn btn-danger ms-1 float-end" title="Aller au direct"><i class="bi bi-film"></i></a>
|
|
{/if}
|
|
{/if}
|
|
<div class="d-flex align-items-center">
|
|
<h2>
|
|
<a href="surveys/" class="text-muted" style="text-decoration: none"><</a>
|
|
{survey.title}
|
|
</h2>
|
|
<SurveyBadge class="ms-2" {survey} />
|
|
</div>
|
|
|
|
{#if $user.is_admin && edit}
|
|
<SurveyAdmin {survey} on:saved={() => edit = false} />
|
|
{/if}
|
|
|
|
{#await getQuestions(survey.id)}
|
|
<div class="text-center">
|
|
<div class="spinner-border text-primary mx-3" role="status"></div>
|
|
<span>Chargement des questions …</span>
|
|
</div>
|
|
{:then questions}
|
|
<SurveyQuestions {survey} {questions} />
|
|
{/await}
|
|
{/await}
|