This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
atsebay.t/ui/src/routes/surveys/[sid]/responses/index.svelte

106 lines
4.1 KiB
Svelte
Raw Normal View History

2022-02-28 09:52:27 +00:00
<script context="module">
2022-11-18 14:38:50 +00:00
import { getSurvey } from '$lib/surveys';
import { getUsers } from '$lib/users';
2022-02-28 09:52:27 +00:00
export async function load({ params, stuff }) {
return {
props: {
surveyP: stuff.survey,
},
};
}
</script>
<script lang="ts">
import { goto } from '$app/navigation';
2022-11-18 14:38:50 +00:00
import { user } from '$lib/stores/user';
import StartStopLiveSurvey from '$lib/components/StartStopLiveSurvey.svelte';
import SurveyAdmin from '$lib/components/SurveyAdmin.svelte';
import SurveyBadge from '$lib/components/SurveyBadge.svelte';
import SurveyQuestions from '$lib/components/SurveyQuestions.svelte';
import { getQuestions } from '$lib/questions';
2022-02-28 09:52:27 +00:00
export let surveyP;
2022-09-20 17:54:53 +00:00
let usersP = null;
surveyP.then((s) => {
usersP = getUsers(s.promo, s.group);
})
let edit = false;
2022-02-28 09:52:27 +00:00
</script>
{#await surveyP then survey}
{#if $user && $user.is_admin}
<button class="btn btn-primary ms-1 float-end" on:click={() => { edit = !edit; } } title="Éditer"><i class="bi bi-pencil"></i></button>
<StartStopLiveSurvey
{survey}
class="ms-1 float-end"
on:update={() => goto(`surveys/${survey.id}/admin`)}
/>
{/if}
2022-02-28 09:52:27 +00:00
<div class="d-flex align-items-center">
<h2>
<a href="surveys/{survey.id}" class="text-muted" style="text-decoration: none">&lt;</a>
{survey.title}
<small class="text-muted">Corrections</small>
</h2>
<SurveyBadge class="ms-2" {survey} />
</div>
{#if $user && $user.is_admin && edit}
<SurveyAdmin {survey} on:saved={() => edit = false} />
{/if}
2022-02-28 09:52:27 +00:00
{#await getQuestions(survey.id)}
<div class="text-center">
<div class="spinner-border text-primary mx-3" role="status"></div>
<span>Chargement des questions &hellip;</span>
</div>
{:then questions}
<div class="card mt-3 mb-5">
<table class="table table-hover table-striped mb-0">
<thead>
<tr>
<th>Question</th>
<th>Réponses</th>
<th>Moyenne</th>
</tr>
</thead>
<tbody ng-controller="SurveyGradesController">
{#each questions as question (question.id)}
2022-09-20 17:47:32 +00:00
<tr>
2022-02-28 09:52:27 +00:00
<td><a href="surveys/{survey.id}/responses/{question.id}">{question.title}</a></td>
{#await question.getResponses()}
<td colspan="2" class="text-center">
<div class="spinner-border mx-3" role="status"></div>
<span>Chargement &hellip;</span>
</td>
{:then responses}
<td>
{#if responses}
2022-03-28 08:53:45 +00:00
{responses.filter((r) => !r.time_scored || (r.time_reported && r.time_reported >= r.time_scored)).length} /
2022-02-28 09:52:27 +00:00
{responses.length}
2022-09-20 17:54:53 +00:00
{#await usersP then users}
<br>
{Math.trunc(responses.length/users.length*1000)/10}&nbsp;%
{/await}
2022-02-28 09:52:27 +00:00
{:else}
0
{/if}
</td>
<td>
{#if responses && responses.filter((r) => r.time_scored).length}
2022-09-20 17:47:32 +00:00
{Math.trunc(responses.reduce((p, c) => (p + (c.score?c.score:0)), 0)/responses.filter((r) => r.time_scored).length*10)/10}&nbsp;%
2022-02-28 09:52:27 +00:00
{:else}
--&nbsp;%
{/if}
</td>
{/await}
</tr>
{/each}
</tbody>
</table>
</div>
{/await}
{/await}