diff --git a/atsebayt/src/components/SurveyAdmin.svelte b/atsebayt/src/components/SurveyAdmin.svelte index 0ab89cc..c0148e5 100644 --- a/atsebayt/src/components/SurveyAdmin.svelte +++ b/atsebayt/src/components/SurveyAdmin.svelte @@ -3,6 +3,7 @@ import { goto } from '$app/navigation'; import { getQuestions } from '../lib/questions'; + import { ToastsStore } from '../stores/toasts'; const dispatch = createEventDispatcher(); export let survey = null; @@ -11,7 +12,9 @@ survey.save().then((response) => { dispatch('saved'); }, (error) => { - console.log(error) + ToastsStore.addErrorToast({ + msg: error.errmsg, + }); }) } @@ -19,7 +22,9 @@ survey.delete().then((response) => { goto(`surveys`); }, (error) => { - console.log(error) + ToastsStore.addErrorToast({ + msg: error.errmsg, + }); }) } @@ -27,7 +32,9 @@ survey.duplicate().then((response) => { goto(`surveys/${response.id}`); }).catch((error) => { - console.log(error) + ToastsStore.addErrorToast({ + msg: error.errmsg, + }); }) } diff --git a/atsebayt/src/components/SurveyBadge.svelte b/atsebayt/src/components/SurveyBadge.svelte index 2d87b5a..b224a82 100644 --- a/atsebayt/src/components/SurveyBadge.svelte +++ b/atsebayt/src/components/SurveyBadge.svelte @@ -4,7 +4,7 @@ export { className as class }; -{#if survey.direct}Direct +{#if survey.direct != null}Direct {:else if survey.startAvailability() > Date.now()}Prévu {:else if survey.endAvailability() > Date.now()}En cours {:else if !survey.corrected}Terminé diff --git a/atsebayt/src/components/SurveyList.svelte b/atsebayt/src/components/SurveyList.svelte index cd16519..0d8c415 100644 --- a/atsebayt/src/components/SurveyList.svelte +++ b/atsebayt/src/components/SurveyList.svelte @@ -12,7 +12,7 @@ req_surveys.then((surveys) => { for (const survey of surveys) { - if (survey.direct) { + if (survey.direct != null) { direct = survey; } } @@ -39,7 +39,7 @@ {:then surveys} {#each surveys as survey, sid (survey.id)} - {#if survey.shown && (!$user || (!$user.was_admin || $user.promo == survey.promo) || $user.is_admin)} + {#if (survey.shown || survey.direct != null) && (!$user || (!$user.was_admin || $user.promo == survey.promo) || $user.is_admin)} {#if $user && $user.is_admin && (sid == 0 || surveys[sid-1].promo != survey.promo)} @@ -47,7 +47,7 @@ {/if} - goto(survey.direct?`surveys/${survey.id}/live`:$user.is_admin?`surveys/${survey.id}/responses`:`surveys/${survey.id}`)}> + goto(survey.direct != null ?`surveys/${survey.id}/live`:$user.is_admin?`surveys/${survey.id}/responses`:`surveys/${survey.id}`)}> {survey.title} diff --git a/atsebayt/src/components/SurveyQuestions.svelte b/atsebayt/src/components/SurveyQuestions.svelte index a906418..1051e60 100644 --- a/atsebayt/src/components/SurveyQuestions.svelte +++ b/atsebayt/src/components/SurveyQuestions.svelte @@ -1,5 +1,6 @@ + +
+ {#each $ToastsStore.toasts as toast} + + {/each} +
diff --git a/atsebayt/src/lib/questions.js b/atsebayt/src/lib/questions.js index 81ba6b5..f6903d4 100644 --- a/atsebayt/src/lib/questions.js +++ b/atsebayt/src/lib/questions.js @@ -74,6 +74,18 @@ export class Question { } } + async getMyResponse() { + const res = await fetch(`api/questions/${this.id}/response`, { + method: 'GET', + headers: {'Accept': 'application/json'}, + }); + if (res.status == 200) { + return new Response(await res.json()); + } else { + throw new Error((await res.json()).errmsg); + } + } + async getResponses() { const res = await fetch(`api/surveys/${this.id_survey}/questions/${this.id}/responses`, { method: 'GET', diff --git a/atsebayt/src/routes/__layout.svelte b/atsebayt/src/routes/__layout.svelte index db852dc..df45380 100644 --- a/atsebayt/src/routes/__layout.svelte +++ b/atsebayt/src/routes/__layout.svelte @@ -42,6 +42,8 @@