Add categories to sort/filter works/surveys
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-11-20 15:28:27 +01:00
commit 4c76dd9728
17 changed files with 586 additions and 25 deletions

View file

@ -5,6 +5,7 @@
import DateFormat from '$lib/components/DateFormat.svelte';
import SurveyBadge from '$lib/components/SurveyBadge.svelte';
import SubmissionStatus from '$lib/components/SubmissionStatus.svelte';
import { getCategories } from '$lib/categories';
import { getSurveys } from '$lib/surveys';
import { getScore } from '$lib/users';
@ -21,6 +22,13 @@
}
});
let categories = {};
getCategories().then((cs) => {
for (const c of cs) {
categories[c.id] = c;
}
});
function gotoSurvey(survey) {
if (survey.kind === "w") {
goto(`works/${survey.id}`);
@ -60,12 +68,30 @@
{#each surveys as survey, sid (survey.kind + survey.id)}
{#if (survey.shown || survey.direct == null || ($user && $user.is_admin)) && (!$user || (!$user.was_admin || $user.promo == survey.promo) || $user.is_admin)}
{#if $user && $user.is_admin && (sid == 0 || surveys[sid-1].promo != survey.promo)}
<tr class="bg-info text-light">
<tr class="bg-warning text-light">
<th colspan="5" class="fw-bold">
{survey.promo}
</th>
</tr>
{/if}
{#if $user && (sid == 0 || surveys[sid-1].id_category != survey.id_category) && categories[survey.id_category]}
<tr class="bg-primary text-light">
<th colspan="5" class="fw-bold" on:click={() => categories[survey.id_category].expand = !categories[survey.id_category].expand}>
{#if categories[survey.id_category].expand}
<i class="bi bi-chevron-down"></i>
{:else}
<i class="bi bi-chevron-right"></i>
{/if}
{categories[survey.id_category].label}
{#if $user && $user.is_admin}
<a href="categories/{survey.id_category}" class="float-end btn btn-sm btn-light" style="margin: -6px;">
<i class="bi bi-pencil" on:click={() => categories[survey.id_category].expand = !categories[survey.id_category].expand}></i>
</a>
{/if}
</th>
</tr>
{/if}
{#if categories[survey.id_category] && categories[survey.id_category].expand}
<tr on:click={e => gotoSurvey(survey)}>
<td>
{#if !survey.shown}<i class="bi bi-eye-slash-fill" title="Ce questionnaire n'est pas affiché aux étudiants"></i>{/if}
@ -127,6 +153,7 @@
{/if}
{/if}
</tr>
{/if}
{/if}
{/each}
</tbody>