New form to change grade
This commit is contained in:
parent
b604e98f64
commit
7642a23947
3 changed files with 80 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import ScoreBadge from '$lib/components/ScoreBadge.svelte';
|
||||
import { ToastsStore } from '$lib/stores/toasts';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
|
@ -9,6 +10,8 @@
|
|||
let gradationStatus = {};
|
||||
let stats = {"mean": 0, "min": 999, "max": 0};
|
||||
|
||||
let chgrade = {grade: null, modal: null};
|
||||
|
||||
$: refresh_grades(work);
|
||||
|
||||
function refresh_grades(w) {
|
||||
|
@ -126,9 +129,9 @@
|
|||
<button
|
||||
class="btn btn-sm mr-1"
|
||||
class:btn-success={status.status == "success"}
|
||||
class:btn-danger={status.status == "failure"}
|
||||
class:btn-danger={status.status == "failure"}
|
||||
class:btn-outline-danger={status.status == "killed"}
|
||||
class:btn-outline-warning={status.status == "pending" || status.status == "running"}
|
||||
class:btn-outline-warning={status.status == "pending" || status.status == "running"}
|
||||
title="Relancer la notation"
|
||||
on:click={() => { grade.redoGradation(); gradationStatus[grade.id] = null; }}
|
||||
>
|
||||
|
@ -136,6 +139,13 @@
|
|||
</button>
|
||||
{/await}
|
||||
{/if}
|
||||
<button
|
||||
class="btn btn-sm btn-primary mr-1"
|
||||
title="Changer la note"
|
||||
on:click={() => { chgrade = { grade, modal: new bootstrap.Modal(document.getElementById('chgradeModal'))}; chgrade.modal.show(); }}
|
||||
>
|
||||
<i class="bi bi-pencil"></i>
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-sm btn-danger mr-1"
|
||||
title="Supprimer la note"
|
||||
|
@ -151,3 +161,28 @@
|
|||
</table>
|
||||
{/await}
|
||||
</div>
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="chgradeModal">
|
||||
<div class="modal-dialog">
|
||||
<form class="modal-content" on:submit|preventDefault={() => {chgrade.modal.hide(); try { chgrade.grade.save().then(() => refresh_grades(work)); } catch(err) { ToastsStore.addToast({color: "danger", title: "Impossible de changer la note", msg: err}) };}}>
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Changer la note {#if chgrade.grade}de {chgrade.grade.login}{/if}</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group row mb-2">
|
||||
<label class="col-2 col-form-label" for="new-grade">Note</label>
|
||||
<!-- svelte-ignore a11y-autofocus -->
|
||||
{#if chgrade.grade}
|
||||
<input type="number" class="form-control col" id="new-grade" autofocus placeholder="15" bind:value={chgrade.grade.score}>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Changer la note
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -15,6 +15,21 @@ export class Grade {
|
|||
this.comment = comment;
|
||||
}
|
||||
|
||||
async save() {
|
||||
const res = await fetch(`api/works/${this.id_work}/grades/${this.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {'Accept': 'application/json'},
|
||||
body: JSON.stringify(this),
|
||||
});
|
||||
if (res.status == 200) {
|
||||
const data = await res.json()
|
||||
this.update(data);
|
||||
return data;
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
async delete() {
|
||||
if (this.id) {
|
||||
const res = await fetch(`api/works/${this.id_work}/grades/${this.id}`, {
|
||||
|
|
Reference in a new issue