Make survey duplication synchronous (to avoid proposals randomization)
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
0cab193d6c
commit
8f5e2f380f
@ -34,10 +34,14 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let duplicateInProgress = false;
|
||||||
function duplicateSurvey() {
|
function duplicateSurvey() {
|
||||||
|
duplicateInProgress = true;
|
||||||
survey.duplicate().then((response) => {
|
survey.duplicate().then((response) => {
|
||||||
|
duplicateInProgress = false;
|
||||||
goto(`surveys/${response.id}`);
|
goto(`surveys/${response.id}`);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
duplicateInProgress = false;
|
||||||
ToastsStore.addErrorToast({
|
ToastsStore.addErrorToast({
|
||||||
msg: error,
|
msg: error,
|
||||||
});
|
});
|
||||||
@ -157,14 +161,19 @@
|
|||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
||||||
{#if survey.id}
|
{#if survey.id || duplicateInProgress}
|
||||||
<button type="button" class="btn btn-danger" on:click={deleteSurvey} disabled={deleteInProgress}>
|
<button type="button" class="btn btn-danger" on:click={deleteSurvey} disabled={deleteInProgress || duplicateInProgress}>
|
||||||
{#if deleteInProgress}
|
{#if deleteInProgress}
|
||||||
<div class="spinner-border spinner-border-sm text-light me-1" role="status"></div>
|
<div class="spinner-border spinner-border-sm text-light me-1" role="status"></div>
|
||||||
{/if}
|
{/if}
|
||||||
Supprimer
|
Supprimer
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn btn-secondary" on:click={duplicateSurvey}>Dupliquer avec ces nouveaux paramètres</button>
|
<button type="button" class="btn btn-secondary" on:click={duplicateSurvey} disabled={duplicateInProgress}>
|
||||||
|
{#if duplicateInProgress}
|
||||||
|
<div class="spinner-border spinner-border-sm text-dark me-1" role="status"></div>
|
||||||
|
{/if}
|
||||||
|
Dupliquer avec ces nouveaux paramètres
|
||||||
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -105,31 +105,35 @@ export class Survey {
|
|||||||
for (const q of questions) {
|
for (const q of questions) {
|
||||||
const oldQuestionId = q.id;
|
const oldQuestionId = q.id;
|
||||||
|
|
||||||
|
// This will create a new question with the same parameters
|
||||||
delete q.id;
|
delete q.id;
|
||||||
|
|
||||||
|
// Also alter id_survey
|
||||||
q.id_survey = response.id;
|
q.id_survey = response.id;
|
||||||
q.save().then((question) => {
|
|
||||||
|
// This save will create
|
||||||
|
const question = await q.save();
|
||||||
|
|
||||||
|
// Revert to the old question ID to perform the next retrievals
|
||||||
q.id = oldQuestionId;
|
q.id = oldQuestionId;
|
||||||
|
|
||||||
// Now recopy proposals
|
// Now recopy proposals
|
||||||
if (q.kind == "mcq" || q.kind == "ucq") {
|
if (q.kind == "mcq" || q.kind == "ucq") {
|
||||||
q.getProposals().then((proposals) => {
|
const proposals = await q.getProposals();
|
||||||
for (const p of proposals) {
|
for (const p of proposals) {
|
||||||
delete p.id;
|
delete p.id;
|
||||||
p.id_question = question.id;
|
p.id_question = question.id;
|
||||||
p.save();
|
await p.save();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now recopy correction templates
|
// Now recopy correction templates
|
||||||
getCorrectionTemplates(oldQuestionId).then((cts) => {
|
const cts = await getCorrectionTemplates(oldQuestionId);
|
||||||
for (const ct of cts) {
|
for (const ct of cts) {
|
||||||
delete ct.id;
|
delete ct.id;
|
||||||
ct.id_question = question.id;
|
ct.id_question = question.id;
|
||||||
ct.save();
|
ct.save();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
Reference in New Issue
Block a user