Add the ability to generate response templates, based on proposals
This commit is contained in:
parent
ab3c94119d
commit
9d95360e99
|
@ -19,6 +19,35 @@
|
|||
templates = templates;
|
||||
}
|
||||
|
||||
function genTemplates() {
|
||||
question.getProposals().then((proposals) => {
|
||||
let i = 0;
|
||||
for (const p of proposals) {
|
||||
// Search proposal in templates
|
||||
let found = false;
|
||||
for (const tpl of templates) {
|
||||
if (tpl.regexp.indexOf(p.id.toString()) !== -1) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
const ct = new CorrectionTemplate()
|
||||
ct.id_question = question.id;
|
||||
ct.regexp = p.id.toString();
|
||||
ct.label = String.fromCharCode(97 + i);
|
||||
ct.save().then((ct) => {
|
||||
templates.push(ct);
|
||||
templates = templates;
|
||||
});
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function delTemplate(tpl) {
|
||||
tpl.delete().then(() => {
|
||||
const idx = templates.findIndex((e) => e.id === tpl.id);
|
||||
|
@ -109,4 +138,13 @@
|
|||
>
|
||||
<i class="bi bi-plus"></i> Ajouter un template
|
||||
</button>
|
||||
{#if question.kind == "mcq" || question.kind == "ucq"}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-info me-1"
|
||||
on:click={genTemplates}
|
||||
>
|
||||
<i class="bi bi-magic"></i> Générer les templates
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
|
Reference in New Issue