From 6a543156263698b931703264fa02bfd2e3dcb397 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 19 Nov 2022 17:22:50 +0100 Subject: [PATCH 1/2] Display number of items left to correct to admin on surveylist --- surveys.go | 29 ++++++++++++++++++++- ui/src/lib/components/SurveyList.svelte | 34 ++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/surveys.go b/surveys.go index fd3181e..ec3eb6d 100644 --- a/surveys.go +++ b/surveys.go @@ -80,7 +80,34 @@ func declareAPIAuthSurveysRoutes(router *gin.RouterGroup) { } s := c.MustGet("survey").(*Survey) - if (s.Promo == u.Promo && s.Shown) || (u != nil && u.IsAdmin) { + if u.IsAdmin { + questions, err := s.GetQuestions() + if err != nil { + log.Println("Unable to getQuestions:", err) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve questions. Please try again later."}) + return + } + + itemCount := 0 + itemCorrected := 0 + for _, q := range questions { + res, err := q.GetResponses() + if err != nil { + log.Printf("Unable to GetResponses(qid=%d): %s", q.Id, err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during responses retrieval."}) + return + } + + for _, r := range res { + itemCount += 1 + if r.TimeScored != nil && (r.TimeReported == nil || r.TimeScored.After(*r.TimeReported)) { + itemCorrected += 1 + } + } + } + + c.JSON(http.StatusOK, map[string]int{"count": itemCount, "corrected": itemCorrected}) + } else if s.Promo == u.Promo && s.Shown { score, err := s.GetScore(u) if err != nil { log.Printf("Unable to GetScore(uid=%d;sid=%d): %s", u.Id, s.Id, err.Error()) diff --git a/ui/src/lib/components/SurveyList.svelte b/ui/src/lib/components/SurveyList.svelte index 02ce0df..1176d9f 100644 --- a/ui/src/lib/components/SurveyList.svelte +++ b/ui/src/lib/components/SurveyList.svelte @@ -40,7 +40,11 @@ Intitulé Date {#if $user} - Score + {#if $user.is_admin} + À corriger + {:else} + Score + {/if} {/if} @@ -84,14 +88,38 @@ {/if} {#if $user} - {#if !survey.corrected} + {#if !survey.corrected && !$user.is_admin} N/A {:else} {#await getScore(survey)}
{:then score} - {score.score} + {#if score.count !== undefined} + 0} + class:badge={survey.corrected} + class:bg-danger={survey.corrected && score.count-score.corrected > 0} + class:bg-dark={survey.corrected && score.count-score.corrected <= 0} + title="{score.count-score.corrected}/{score.count}" + > + {#if score.count == 0 || survey.corrected} + {score.count-score.corrected} + {:else} + {Math.trunc((1-score.corrected/score.count)*100)} % + {/if} + + {:else} + = 18} + class:bg-info={score.score < 18 && score.score >= 15} + class:bg-warning={score.score < 15 && score.score >= 9} + class:bg-danger={score.score < 9} + > + {score.score} + + {/if} {:catch error} {/await} From f7d747cd76b11750e6fdc5f1525fbdbc823a1737 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 19 Nov 2022 18:48:05 +0100 Subject: [PATCH 2/2] In corrections, highlight significant texts --- .../CorrectionResponseFooter.svelte | 24 +++++++++++++++++++ .../lib/components/CorrectionResponses.svelte | 20 +++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ui/src/lib/components/CorrectionResponseFooter.svelte b/ui/src/lib/components/CorrectionResponseFooter.svelte index 68af856..84d765a 100644 --- a/ui/src/lib/components/CorrectionResponseFooter.svelte +++ b/ui/src/lib/components/CorrectionResponseFooter.svelte @@ -38,14 +38,37 @@ for (const t of templates) { if (my_tpls[t.id] === undefined && cts[t.id.toString()]) { my_tpls[t.id] = cts[t.id.toString()][response.id_user] !== undefined; + + // Hack to autocorrect only if this has already been checked previously + if (autoCorrectionInProgress && cts[t.id.toString()][response.id_user] !== undefined) { + autoCorrectionInProgress = false; + } } } } } + + let element = null; + let scrollY = 0; + let autoCorrectionInProgress = true; + $: { + if (element && scrollY > element.offsetParent.offsetTop - 500 && !my_correction) { + let tmp = false; + [tmp, autoCorrectionInProgress] = [autoCorrectionInProgress, true]; + if (!tmp) { + autoCorrection(response.id_user, my_tpls).then((r) => { + my_correction = r; + autoCorrectionInProgress = false; + }) + } + } + } +
@@ -69,6 +92,7 @@ >