151 lines
4.9 KiB
Svelte
151 lines
4.9 KiB
Svelte
<script>
|
|
import { CorrectionTemplate } from '../lib/correctionTemplates';
|
|
|
|
let className = '';
|
|
export { className as class };
|
|
export let cts = null;
|
|
export let nb_responses = 0;
|
|
export let question = null;
|
|
export let templates = [];
|
|
|
|
export let filter = "";
|
|
|
|
function addTemplate() {
|
|
const ct = new CorrectionTemplate()
|
|
if (question) {
|
|
ct.id_question = question.id;
|
|
}
|
|
templates.push(ct);
|
|
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);
|
|
if (idx >= 0) {
|
|
templates.splice(idx, 1);
|
|
}
|
|
templates = templates;
|
|
});
|
|
}
|
|
|
|
function submitTemplate(tpl) {
|
|
tpl.save().then(() => {
|
|
templates = templates;
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<div class="{className}">
|
|
{#each templates as template (template.id)}
|
|
<form class="row mb-2" on:submit|preventDefault={() => submitTemplate(template)}>
|
|
<div class="col-2">
|
|
<div class="input-group">
|
|
<input
|
|
placeholder="RegExp"
|
|
class="form-control"
|
|
class:bg-warning={template.regexp && template.regexp === filter}
|
|
bind:value={template.regexp}
|
|
>
|
|
<button
|
|
type="button"
|
|
class="btn btn-sm"
|
|
class:btn-outline-secondary={!template.regexp || template.regexp !== filter}
|
|
class:btn-outline-warning={template.regexp && template.regexp === filter}
|
|
on:click={() => { if (filter == template.regexp) filter = ''; else filter = template.regexp; } }
|
|
>
|
|
<i class="bi bi-filter"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="col-2">
|
|
<input placeholder="Intitulé" class="form-control" bind:value={template.label}>
|
|
</div>
|
|
<div class="col-1">
|
|
<input
|
|
type="number"
|
|
placeholder="-12"
|
|
class="form-control"
|
|
bind:value={template.score}
|
|
>
|
|
</div>
|
|
<div class="col">
|
|
<textarea
|
|
placeholder="Explication pour l'étudiant"
|
|
class="form-control form-control-sm"
|
|
bind:value={template.score_explaination}
|
|
></textarea>
|
|
</div>
|
|
<div class="col-1 d-flex flex-column">
|
|
<div class="text-end">
|
|
{#if cts && template.id && cts[template.id.toString()]}
|
|
{Math.trunc(Object.keys(cts[template.id.toString()]).length/nb_responses*1000)/10} %
|
|
{:else}
|
|
N/A
|
|
{/if}
|
|
</div>
|
|
<div class="d-flex justify-content-between">
|
|
<button
|
|
type="button"
|
|
class="btn btn-sm btn-danger"
|
|
on:click={() => delTemplate(template)}
|
|
>
|
|
<i class="bi bi-trash"></i>
|
|
</button>
|
|
<button
|
|
class="btn btn-sm btn-success"
|
|
>
|
|
<i class="bi bi-check"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
{/each}
|
|
<button
|
|
type="button"
|
|
class="btn btn-info me-1"
|
|
on:click={addTemplate}
|
|
disabled={templates.length > 0 && !templates[templates.length-1].id}
|
|
>
|
|
<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>
|