Compare commits
2 Commits
1532ede587
...
f7d747cd76
Author | SHA1 | Date | |
---|---|---|---|
f7d747cd76 | |||
6a54315626 |
29
surveys.go
29
surveys.go
@ -80,7 +80,34 @@ func declareAPIAuthSurveysRoutes(router *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
s := c.MustGet("survey").(*Survey)
|
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)
|
score, err := s.GetScore(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to GetScore(uid=%d;sid=%d): %s", u.Id, s.Id, err.Error())
|
log.Printf("Unable to GetScore(uid=%d;sid=%d): %s", u.Id, s.Id, err.Error())
|
||||||
|
@ -38,14 +38,37 @@
|
|||||||
for (const t of templates) {
|
for (const t of templates) {
|
||||||
if (my_tpls[t.id] === undefined && cts[t.id.toString()]) {
|
if (my_tpls[t.id] === undefined && cts[t.id.toString()]) {
|
||||||
my_tpls[t.id] = cts[t.id.toString()][response.id_user] !== undefined;
|
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;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:window bind:scrollY={scrollY}/>
|
||||||
<form
|
<form
|
||||||
class="row"
|
class="row"
|
||||||
|
bind:this={element}
|
||||||
on:submit|preventDefault={submitCorrection}
|
on:submit|preventDefault={submitCorrection}
|
||||||
>
|
>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
@ -69,6 +92,7 @@
|
|||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
class="form-check-label"
|
class="form-check-label"
|
||||||
|
class:fw-bold={template.regexp && (template.regexp[0] == "!" ? !response.value.match(new RegExp(template.regexp.substring(1))) : response.value.match(new RegExp(template.regexp)))}
|
||||||
for="r{response.id}t{template.id}"
|
for="r{response.id}t{template.id}"
|
||||||
>
|
>
|
||||||
{template.label}
|
{template.label}
|
||||||
|
@ -35,6 +35,24 @@
|
|||||||
filteredResponses = responses.filter((r) => (notCorrected || r.time_scored <= r.time_reported || !r.time_scored) && (!filter || ((filter[0] == '!' && !r.value.match(filter.substring(1))) || r.value.match(filter))));
|
filteredResponses = responses.filter((r) => (notCorrected || r.time_scored <= r.time_reported || !r.time_scored) && (!filter || ((filter[0] == '!' && !r.value.match(filter.substring(1))) || r.value.match(filter))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeTags(htmlStr) {
|
||||||
|
return htmlStr.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
.replace(/'/g, "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
function hilightText(input, templates) {
|
||||||
|
for (const { regexp } of templates) {
|
||||||
|
if (regexp) {
|
||||||
|
input = input.replace(new RegExp(regexp, 'g'), '<ins class="fw-bold">$&</ins>')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
export async function applyCorrections() {
|
export async function applyCorrections() {
|
||||||
for (const r of filteredResponses) {
|
for (const r of filteredResponses) {
|
||||||
const my_correction = { };
|
const my_correction = { };
|
||||||
@ -96,7 +114,7 @@
|
|||||||
class="card-text"
|
class="card-text"
|
||||||
style="white-space: pre-line"
|
style="white-space: pre-line"
|
||||||
>
|
>
|
||||||
{response.value}
|
{@html hilightText(escapeTags(response.value), templates)}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
<ResponseCorrected
|
<ResponseCorrected
|
||||||
|
@ -40,7 +40,11 @@
|
|||||||
<th>Intitulé</th>
|
<th>Intitulé</th>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
{#if $user}
|
{#if $user}
|
||||||
<th>Score</th>
|
{#if $user.is_admin}
|
||||||
|
<th>À corriger</th>
|
||||||
|
{:else}
|
||||||
|
<th>Score</th>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -84,14 +88,38 @@
|
|||||||
</td>
|
</td>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $user}
|
{#if $user}
|
||||||
{#if !survey.corrected}
|
{#if !survey.corrected && !$user.is_admin}
|
||||||
<td>N/A</td>
|
<td>N/A</td>
|
||||||
{:else}
|
{:else}
|
||||||
<td>
|
<td>
|
||||||
{#await getScore(survey)}
|
{#await getScore(survey)}
|
||||||
<div class="spinner-border spinner-border-sm" role="status"></div>
|
<div class="spinner-border spinner-border-sm" role="status"></div>
|
||||||
{:then score}
|
{:then score}
|
||||||
{score.score}
|
{#if score.count !== undefined}
|
||||||
|
<span
|
||||||
|
class:fw-bolder={score.count-score.corrected > 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}
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
|
<span
|
||||||
|
class="badge"
|
||||||
|
class:bg-success={score.score >= 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}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
{:catch error}
|
{:catch error}
|
||||||
<i class="bi text-warning bi-exclamation-triangle-fill" title={error}></i>
|
<i class="bi text-warning bi-exclamation-triangle-fill" title={error}></i>
|
||||||
{/await}
|
{/await}
|
||||||
|
Reference in New Issue
Block a user