This commit is contained in:
parent
240a8576ca
commit
4d77cde945
@ -38,15 +38,15 @@
|
||||
{edit}
|
||||
>
|
||||
{#if $user && $user.is_admin}
|
||||
<button class="btn btn-sm btn-danger ms-1 float-end" on:click={() => dispatch('delete')}>
|
||||
<button type="button" class="btn btn-sm btn-danger ms-1 float-end" on:click={() => dispatch('delete')}>
|
||||
<i class="bi bi-trash-fill"></i>
|
||||
</button>
|
||||
{#if edit}
|
||||
<button class="btn btn-sm btn-success ms-1 float-end" on:click={saveQuestion}>
|
||||
<button type="button" class="btn btn-sm btn-success ms-1 float-end" on:click={saveQuestion}>
|
||||
<i class="bi bi-check"></i>
|
||||
</button>
|
||||
{:else}
|
||||
<button class="btn btn-sm btn-primary ms-1 float-end" on:click={editQuestion}>
|
||||
<button type="button" class="btn btn-sm btn-primary ms-1 float-end" on:click={editQuestion}>
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
{/if}
|
||||
@ -75,23 +75,27 @@
|
||||
<input class="form-control" id="q{qid}placeholder" bind:value={question.placeholder}>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
{#await question.getProposals()}
|
||||
<div class="text-center">
|
||||
<div class="spinner-border text-primary mx-3" role="status"></div>
|
||||
<span>Chargement des choix …</span>
|
||||
</div>
|
||||
{:then proposals}
|
||||
<QuestionProposals
|
||||
edit
|
||||
id_question={question.id}
|
||||
kind={question.kind}
|
||||
{proposals}
|
||||
readonly
|
||||
bind:value={value}
|
||||
on:change={() => { dispatch("change"); }}
|
||||
/>
|
||||
{/await}
|
||||
{:else if question.kind}
|
||||
{#if !question.id}
|
||||
Veuillez enregistrer la question pour pouvoir ajouter des propositions.
|
||||
{:else}
|
||||
{#await question.getProposals()}
|
||||
<div class="text-center">
|
||||
<div class="spinner-border text-primary mx-3" role="status"></div>
|
||||
<span>Chargement des choix …</span>
|
||||
</div>
|
||||
{:then proposals}
|
||||
<QuestionProposals
|
||||
edit
|
||||
id_question={question.id}
|
||||
kind={question.kind}
|
||||
{proposals}
|
||||
readonly
|
||||
bind:value={value}
|
||||
on:change={() => { dispatch("change"); }}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
{/if}
|
||||
{:else if question.kind == 'mcq' || question.kind == 'ucq'}
|
||||
{#await question.getProposals()}
|
||||
|
@ -38,7 +38,7 @@
|
||||
name={prefixid + 'proposal' + proposal.id_question}
|
||||
id={prefixid + 'p' + proposal.id}
|
||||
bind:group={valueCheck}
|
||||
value={proposal.id.toString()}
|
||||
value={proposal.id?proposal.id.toString():''}
|
||||
on:change={() => { value = valueCheck.join(','); dispatch("change"); }}
|
||||
>
|
||||
{:else}
|
||||
@ -49,7 +49,7 @@
|
||||
name={prefixid + 'proposal' + proposal.id_question}
|
||||
id={prefixid + 'p' + proposal.id}
|
||||
bind:group={value}
|
||||
value={proposal.id.toString()}
|
||||
value={proposal.id?proposal.id.toString():''}
|
||||
on:change={() => { dispatch("change"); }}
|
||||
>
|
||||
{/if}
|
||||
@ -111,6 +111,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-link"
|
||||
disabled={proposals.length > 0 && !proposals[proposals.length-1].id}
|
||||
on:click={addProposal}
|
||||
>
|
||||
ajouter
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
function saveSurvey() {
|
||||
survey.save().then((response) => {
|
||||
dispatch('saved');
|
||||
dispatch('saved', response);
|
||||
}, (error) => {
|
||||
ToastsStore.addErrorToast({
|
||||
msg: error.errmsg,
|
||||
@ -42,11 +42,22 @@
|
||||
|
||||
<form on:submit|preventDefault={saveSurvey}>
|
||||
|
||||
{#if survey.id}
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="title" class="col-form-label col-form-label-sm">Identifiant du questionnaire</label>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control-plaintext form-control-sm" id="title" value={survey.id}>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="title" class="col-form-label col-form-label-sm">Titre du questionnaire</label>
|
||||
</div>
|
||||
<div class="col-sm-8">{survey.id}
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control form-control-sm" id="title" bind:value={survey.title}>
|
||||
</div>
|
||||
</div>
|
||||
@ -69,22 +80,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="direct" class="col-form-label col-form-label-sm">Question en direct</label>
|
||||
{#if survey.id}
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="direct" class="col-form-label col-form-label-sm">Question en direct</label>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
{#await getQuestions(survey.id) then questions}
|
||||
<select id="direct" class="form-select form-select-sm" bind:value={survey.direct}>
|
||||
<option value={null}>Pas de direct</option>
|
||||
<option value={0}>Pause</option>
|
||||
{#each questions as question (question.id)}
|
||||
<option value={question.id}>{question.id} - {question.title}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
{#await getQuestions(survey.id) then questions}
|
||||
<select id="direct" class="form-select form-select-sm" bind:value={survey.direct}>
|
||||
<option value={null}>Pas de direct</option>
|
||||
<option value={0}>Pause</option>
|
||||
{#each questions as question (question.id)}
|
||||
<option value={question.id}>{question.id} - {question.title}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
|
@ -7,6 +7,7 @@
|
||||
{#if survey.direct != null}<span class="badge bg-danger {className}">Direct</span>
|
||||
{:else if survey.startAvailability() > Date.now()}<span class="badge bg-info {className}">Prévu</span>
|
||||
{:else if survey.endAvailability() > Date.now()}<span class="badge bg-warning {className}">En cours</span>
|
||||
{:else if !survey.__start_availability}<span class="badge bg-dark {className}">Nouveau</span>
|
||||
{:else if !survey.corrected}<span class="badge bg-primary text-light {className}">Terminé</span>
|
||||
{:else}<span class="badge bg-success {className}">Corrigé</span>
|
||||
{/if}
|
||||
|
@ -68,7 +68,12 @@ export class Question {
|
||||
headers: {'Accept': 'application/json'},
|
||||
});
|
||||
if (res.status == 200) {
|
||||
return (await res.json()).map((p) => new QuestionProposal(p))
|
||||
const data = await res.json();
|
||||
if (data === null) {
|
||||
return [];
|
||||
} else {
|
||||
return (data).map((p) => new QuestionProposal(p))
|
||||
}
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
@ -140,7 +145,12 @@ export async function getQuestion(qid) {
|
||||
export async function getQuestions(sid) {
|
||||
const res = await fetch(`api/surveys/${sid}/questions`, {headers: {'Accept': 'application/json'}})
|
||||
if (res.status == 200) {
|
||||
return (await res.json()).map((e) => new Question(e))
|
||||
const data = await res.json();
|
||||
if (data === null) {
|
||||
return [];
|
||||
} else {
|
||||
return (data).map((q) => new Question(q))
|
||||
}
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { getQuestions } from './questions';
|
||||
|
||||
|
||||
class Survey {
|
||||
export class Survey {
|
||||
constructor(res) {
|
||||
if (res) {
|
||||
this.update(res);
|
||||
|
24
ui/src/routes/surveys/new.svelte
Normal file
24
ui/src/routes/surveys/new.svelte
Normal file
@ -0,0 +1,24 @@
|
||||
<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 { Survey } from '../../lib/surveys';
|
||||
import { getQuestions } from '../../lib/questions';
|
||||
|
||||
let survey = new Survey();
|
||||
</script>
|
||||
|
||||
<div class="d-flex align-items-center">
|
||||
<h2>
|
||||
<a href="surveys/" class="text-muted" style="text-decoration: none"><</a>
|
||||
Nouveau questionnaire
|
||||
</h2>
|
||||
<SurveyBadge class="ms-2" {survey} />
|
||||
</div>
|
||||
|
||||
{#if $user.is_admin}
|
||||
<SurveyAdmin {survey} on:saved={(e) => { goto(`surveys/${e.detail.id}`)}} />
|
||||
{/if}
|
Reference in New Issue
Block a user