From 58ab3ff8b71495660a595c4d76c12eec87535f4c Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Thu, 30 May 2024 08:16:05 +0200 Subject: [PATCH] Fixing small bugs - when editing a quiz, the last comment gets lost - deleting a quiz doesn't update the list (but does delete it) - uploading a new version doesn't work --- README.md | 6 ++++++ .../course-manage/course-manage.component.ts | 2 ++ frontend/src/lib/structs.spec.ts | 19 ++++++++++++++++++- frontend/src/lib/structs.ts | 6 ++++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca5d803..d0a18bc 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ This software is licensed under AGPL-3.0 or later, at your convenience. - bugs: - ui - on mobile devices, long answers are hidden partially + - stats: unuseful numbering (1.4, 2.8) for small values - stats - when all values are 0, it doesn't show nicely - features @@ -182,6 +183,11 @@ This software is licensed under AGPL-3.0 or later, at your convenience. # CHANGELOG +2024-05-30: +- when editing a quiz, the last comment gets lost +- deleting a quiz doesn't update the list (but does delete it) +- uploading a new version doesn't work + 2024-05-28: - recover user with a `/recover#secret` path - corrections bug: diff --git a/frontend/src/app/course/course-manage/course-manage.component.ts b/frontend/src/app/course/course-manage/course-manage.component.ts index 8eab3fa..4184579 100644 --- a/frontend/src/app/course/course-manage/course-manage.component.ts +++ b/frontend/src/app/course/course-manage/course-manage.component.ts @@ -94,6 +94,7 @@ export class CourseManageComponent { } this.stats.add(StatsService.quiz_delete); await this.updateDojo(); + await this.updateQuizzes(); } } @@ -106,6 +107,7 @@ export class CourseManageComponent { const quiz = await this.livequiz.getQuiz(this.updateQuizId!); quiz.json = q.toJson(); quiz.update(); + quiz.json = ""; this.stats.add(StatsService.quiz_update); } else { q.owners.push(this.user.id); diff --git a/frontend/src/lib/structs.spec.ts b/frontend/src/lib/structs.spec.ts index 7a749cd..57f477c 100644 --- a/frontend/src/lib/structs.spec.ts +++ b/frontend/src/lib/structs.spec.ts @@ -104,6 +104,12 @@ extro expect(q.questions[1].options.regexp).not.toBe(undefined); }); + it('doesn\'t lose last comment', () => { + const q = Quiz.fromStr(quiz1); + const qText = q.toText(); + expect(qText.trim()).toBe(quiz1); + }) + it('calculates the scores', () => { const q = Quiz.fromStr(readFileSync(`${__dirname}/../selenium/quiz2.md`).toString()); const attempts: DojoAttempt[] = JSON.parse(readFileSync(`${__dirname}/../selenium/quiz2.answers.json`).toString()) @@ -128,4 +134,15 @@ describe("(de)serialization", () => { s.update(); expect(s.toJson()).toBe(json_s); }) -}); \ No newline at end of file +}); + +const quiz1 = `# Test +## Multi + +Question + += 1 +- one +- three + +some more comments`; \ No newline at end of file diff --git a/frontend/src/lib/structs.ts b/frontend/src/lib/structs.ts index 5387322..a6ed79e 100644 --- a/frontend/src/lib/structs.ts +++ b/frontend/src/lib/structs.ts @@ -87,7 +87,7 @@ export class Quiz extends Nomad { continue; } const linePre = line.replace(/`(.*?)`/g, "$1"); - const interpret = linePre.match(/([#=~;-]*) *(.*)/); + const interpret = linePre.match(/^([#=~;-]*) *(.*) *$/); if (interpret?.length != 3) { console.error(`Cannot parse line ${line}`); continue; @@ -103,6 +103,8 @@ export class Quiz extends Nomad { if (maxChoices < 0) { current.options.regexp = new OptionRegexp(reg); } + current.intro = current.intro.trim(); + current.explanation = current.explanation.trim(); q.questions.push(current); } current = new Question(); @@ -164,7 +166,7 @@ export class Question { } toText(): string { - return `## ${this.title}\n\n${this.intro}\n\n` + this.options.toText(); + return `## ${this.title}\n\n${this.intro}\n\n` + this.options.toText() + `\n\n${this.explanation}`; } toJson(): JSONQuestion {