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() {
|
||||
duplicateInProgress = true;
|
||||
survey.duplicate().then((response) => {
|
||||
duplicateInProgress = false;
|
||||
goto(`surveys/${response.id}`);
|
||||
}).catch((error) => {
|
||||
duplicateInProgress = false;
|
||||
ToastsStore.addErrorToast({
|
||||
msg: error,
|
||||
});
|
||||
@ -157,14 +161,19 @@
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-10">
|
||||
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
||||
{#if survey.id}
|
||||
<button type="button" class="btn btn-danger" on:click={deleteSurvey} disabled={deleteInProgress}>
|
||||
{#if survey.id || duplicateInProgress}
|
||||
<button type="button" class="btn btn-danger" on:click={deleteSurvey} disabled={deleteInProgress || duplicateInProgress}>
|
||||
{#if deleteInProgress}
|
||||
<div class="spinner-border spinner-border-sm text-light me-1" role="status"></div>
|
||||
{/if}
|
||||
Supprimer
|
||||
</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}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -105,31 +105,35 @@ export class Survey {
|
||||
for (const q of questions) {
|
||||
const oldQuestionId = q.id;
|
||||
|
||||
// This will create a new question with the same parameters
|
||||
delete q.id;
|
||||
|
||||
// Also alter id_survey
|
||||
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;
|
||||
|
||||
// Now recopy proposals
|
||||
if (q.kind == "mcq" || q.kind == "ucq") {
|
||||
q.getProposals().then((proposals) => {
|
||||
const proposals = await q.getProposals();
|
||||
for (const p of proposals) {
|
||||
delete p.id;
|
||||
p.id_question = question.id;
|
||||
p.save();
|
||||
await p.save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Now recopy correction templates
|
||||
getCorrectionTemplates(oldQuestionId).then((cts) => {
|
||||
const cts = await getCorrectionTemplates(oldQuestionId);
|
||||
for (const ct of cts) {
|
||||
delete ct.id;
|
||||
ct.id_question = question.id;
|
||||
ct.save();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
|
Reference in New Issue
Block a user