From 15bff5af96280be2dc3d3918804359cef2c53039 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 16 Sep 2022 10:55:51 +0200 Subject: [PATCH 1/4] Smarter survey and question deletion/duplucation --- ui/src/components/SurveyAdmin.svelte | 17 ++++++++++---- ui/src/components/WorkAdmin.svelte | 6 ++--- ui/src/lib/questions.js | 6 +++++ ui/src/lib/surveys.js | 33 +++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/ui/src/components/SurveyAdmin.svelte b/ui/src/components/SurveyAdmin.svelte index 07b1455..ab37557 100644 --- a/ui/src/components/SurveyAdmin.svelte +++ b/ui/src/components/SurveyAdmin.svelte @@ -13,17 +13,21 @@ dispatch('saved', response); }, (error) => { ToastsStore.addErrorToast({ - msg: error.errmsg, + msg: error, }); }) } + let deleteInProgress = false; function deleteSurvey() { + deleteInProgress = true; survey.delete().then((response) => { + deleteInProgress = false; goto(`surveys`); }, (error) => { + deleteInProgress = false; ToastsStore.addErrorToast({ - msg: error.errmsg, + msg: error, }); }) } @@ -33,7 +37,7 @@ goto(`surveys/${response.id}`); }).catch((error) => { ToastsStore.addErrorToast({ - msg: error.errmsg, + msg: error, }); }) } @@ -137,7 +141,12 @@
{#if survey.id} - + {/if}
diff --git a/ui/src/components/WorkAdmin.svelte b/ui/src/components/WorkAdmin.svelte index b9e7c55..c493a06 100644 --- a/ui/src/components/WorkAdmin.svelte +++ b/ui/src/components/WorkAdmin.svelte @@ -12,7 +12,7 @@ dispatch('saved', response); }, (error) => { ToastsStore.addErrorToast({ - msg: error.errmsg, + msg: error, }); }) } @@ -22,7 +22,7 @@ goto(`works`); }, (error) => { ToastsStore.addErrorToast({ - msg: error.errmsg, + msg: error, }); }) } @@ -32,7 +32,7 @@ goto(`works/${response.id}`); }).catch((error) => { ToastsStore.addErrorToast({ - msg: error.errmsg, + msg: error, }); }) } diff --git a/ui/src/lib/questions.js b/ui/src/lib/questions.js index bb81ab0..53e2115 100644 --- a/ui/src/lib/questions.js +++ b/ui/src/lib/questions.js @@ -120,6 +120,12 @@ export class Question { async delete() { if (this.id) { + // Start by deleting proposals + const proposals = await this.getProposals(); + for (const p of proposals) { + await p.delete(); + } + const res = await fetch(`api/questions/${this.id}`, { method: 'DELETE', headers: {'Accept': 'application/json'}, diff --git a/ui/src/lib/surveys.js b/ui/src/lib/surveys.js index b3904d3..9e1e69f 100644 --- a/ui/src/lib/surveys.js +++ b/ui/src/lib/surveys.js @@ -1,3 +1,4 @@ +import { getCorrectionTemplates } from './correctionTemplates'; import { getQuestions } from './questions'; import { Response } from './response'; import { Work } from './works'; @@ -101,9 +102,33 @@ export class Survey { // Now recopy questions const questions = await getQuestions(oldSurveyId); for (const q of questions) { + const oldQuestionId = q.id; + delete q.id; q.id_survey = response.id; - q.save(); + q.save().then((question) => { + q.id = oldQuestionId; + + // Now recopy proposals + if (q.kind == "mcq" || q.kind == "ucq") { + q.getProposals().then((proposals) => { + for (const p of proposals) { + delete p.id; + p.id_question = question.id; + p.save(); + } + }); + } + + // Now recopy correction templates + getCorrectionTemplates(oldQuestionId).then((cts) => { + for (const ct of cts) { + delete ct.id; + ct.id_question = question.id; + ct.save(); + } + }); + }); } return response; @@ -115,6 +140,12 @@ export class Survey { async delete() { if (this.id) { + // Start by deleting questions + const questions = await getQuestions(this.id); + for (const q of questions) { + await q.delete(); + } + const res = await fetch(`api/surveys/${this.id}`, { method: 'DELETE', headers: {'Accept': 'application/json'}, From 3bb6f0374ce323deff08053fd8807e3c32c7436f Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 16 Sep 2022 10:56:18 +0200 Subject: [PATCH 2/4] Can use responses page to edit the survey (as this is default admin page for survey) --- .../surveys/[sid]/responses/index.svelte | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ui/src/routes/surveys/[sid]/responses/index.svelte b/ui/src/routes/surveys/[sid]/responses/index.svelte index f90105f..6414f38 100644 --- a/ui/src/routes/surveys/[sid]/responses/index.svelte +++ b/ui/src/routes/surveys/[sid]/responses/index.svelte @@ -13,20 +13,26 @@ {#await surveyP then survey} - goto(`surveys/${survey.id}/admin`)} - /> + {#if $user && $user.is_admin} + + goto(`surveys/${survey.id}/admin`)} + /> + {/if}

< @@ -36,6 +42,10 @@

+ {#if $user && $user.is_admin && edit} + edit = false} /> + {/if} + {#await getQuestions(survey.id)}
From 85d9f1e2800372d7eb731135c3e2206b87b2a95c Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 16 Sep 2022 10:56:55 +0200 Subject: [PATCH 3/4] Use datetime field to edit start/end time --- ui/package-lock.json | 11 +++++++++++ ui/package.json | 1 + ui/src/components/DateTimeInput.svelte | 21 +++++++++++++++++++++ ui/src/components/SurveyAdmin.svelte | 5 +++-- ui/src/components/WorkAdmin.svelte | 5 +++-- 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 ui/src/components/DateTimeInput.svelte diff --git a/ui/package-lock.json b/ui/package-lock.json index 3ce834a..2c160ee 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -8,6 +8,7 @@ "name": "atsebayt", "version": "0.0.1", "dependencies": { + "dayjs": "^1.11.5", "svelte-frappe-charts": "^1.9.1", "vite": "^3.0.4" }, @@ -645,6 +646,11 @@ "node": ">= 8" } }, + "node_modules/dayjs": { + "version": "1.11.5", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.5.tgz", + "integrity": "sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==" + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3091,6 +3097,11 @@ "which": "^2.0.1" } }, + "dayjs": { + "version": "1.11.5", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.5.tgz", + "integrity": "sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==" + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", diff --git a/ui/package.json b/ui/package.json index 76e67f4..dc0668f 100644 --- a/ui/package.json +++ b/ui/package.json @@ -28,6 +28,7 @@ }, "type": "module", "dependencies": { + "dayjs": "^1.11.5", "svelte-frappe-charts": "^1.9.1", "vite": "^3.0.4" } diff --git a/ui/src/components/DateTimeInput.svelte b/ui/src/components/DateTimeInput.svelte new file mode 100644 index 0000000..d39ff70 --- /dev/null +++ b/ui/src/components/DateTimeInput.svelte @@ -0,0 +1,21 @@ + + + diff --git a/ui/src/components/SurveyAdmin.svelte b/ui/src/components/SurveyAdmin.svelte index ab37557..865e6a3 100644 --- a/ui/src/components/SurveyAdmin.svelte +++ b/ui/src/components/SurveyAdmin.svelte @@ -3,6 +3,7 @@ import { goto } from '$app/navigation'; import { getQuestions } from '../lib/questions'; + import DateTimeInput from './DateTimeInput.svelte'; import { ToastsStore } from '../stores/toasts'; const dispatch = createEventDispatcher(); @@ -108,7 +109,7 @@
- +
@@ -117,7 +118,7 @@
- +
diff --git a/ui/src/components/WorkAdmin.svelte b/ui/src/components/WorkAdmin.svelte index c493a06..8660e1d 100644 --- a/ui/src/components/WorkAdmin.svelte +++ b/ui/src/components/WorkAdmin.svelte @@ -2,6 +2,7 @@ import { createEventDispatcher } from 'svelte'; import { goto } from '$app/navigation'; + import DateTimeInput from './DateTimeInput.svelte'; import { ToastsStore } from '../stores/toasts'; const dispatch = createEventDispatcher(); @@ -102,7 +103,7 @@
- +
@@ -111,7 +112,7 @@
- +
From 73b33f9fb579c41d51045048ce3ac2649092a8dc Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 16 Sep 2022 11:14:50 +0200 Subject: [PATCH 4/4] Count submissions --- ui/src/components/SubmissionStatus.svelte | 26 +++++++++++++++++++++-- ui/src/routes/works/[wid]/rendus.svelte | 15 ++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/ui/src/components/SubmissionStatus.svelte b/ui/src/components/SubmissionStatus.svelte index 5a2b1d4..b7ad14a 100644 --- a/ui/src/components/SubmissionStatus.svelte +++ b/ui/src/components/SubmissionStatus.svelte @@ -1,4 +1,6 @@ {#if work.submission_url == '-'} {:else if work.submission_url} - {#await getUserRendu(work.submission_url, user)} + {#await renduP}
{:then rendu} {#if rendu === null} @@ -24,7 +46,7 @@ {/await} {:else} - {#await work.getSubmission(user.id)} + {#await submissionP}
{:then submission} diff --git a/ui/src/routes/works/[wid]/rendus.svelte b/ui/src/routes/works/[wid]/rendus.svelte index 2511e44..55ebb28 100644 --- a/ui/src/routes/works/[wid]/rendus.svelte +++ b/ui/src/routes/works/[wid]/rendus.svelte @@ -22,6 +22,14 @@ import { getUsers } from '../../../lib/users'; export let work = null; + let usersP = null; + work.then((w) => { + usersP = getUsers(w.promo, w.group); + usersP.then((users) => { nb_users = users.length; }); + }); + + let nb_rendus = 0; + let nb_users = 0; {#await work then w} @@ -29,12 +37,12 @@

< {w.title} + Rendus {Math.trunc(nb_rendus/nb_users*100)} % ({nb_rendus}/{nb_users})

- {#await getUsers(w.promo, w.group)} - {:then users} + {#await usersP then users} @@ -48,7 +56,7 @@
{user.login} - + { nb_rendus += 1; user.show_dl_btn = true; }} /> {#await getRepositories(w.id, user.id) then repos} @@ -82,6 +90,7 @@