boussole-pluss/frontend/pages/details.vue

96 lines
2.3 KiB
Vue
Raw Permalink Normal View History

<script lang="ts" setup>
2022-10-07 14:15:53 +00:00
import {type AxeResponses, type QuizResponse, useQuizStore} from "~/store/quiz";
import Quiz from "~/pages/quiz.vue";
import {type Axe, useAxeStore} from "~/store/axe";
2022-10-07 14:15:53 +00:00
const loading = ref(true);
const notFound = ref(false);
const quiz = ref<Quiz>();
const axes = ref<Axe[]>();
2022-10-07 14:15:53 +00:00
onMounted(() => {
if (!useRoute().query.quiz) {
navigateTo("/dashboard");
2022-10-07 14:15:53 +00:00
}
loading.value = true;
notFound.value = false;
const quizId = Number.parseInt(useRoute().query.quiz as string);
useQuizStore().findById(quizId)
.then((result: Quiz) => {
quiz.value = result;
})
.then(() => {
useAxeStore().findAxes().then(result => {
axes.value = result.filter(axe => {
return quiz.value.axes.filter(axeResponse => axeResponse.axeIdentifier === axe.identifier).length > 0;
});
});
})
.catch(() => {
notFound.value = true;
})
.finally(() => {
loading.value = false;
});
});
2022-10-07 14:15:53 +00:00
function getAverage(axe: Axe): number {
const axeResponses = quiz.value.axes.filter((response: AxeResponses) => response.axeIdentifier === axe.identifier);
if (axeResponses.length === 1) {
return axeResponses[0].average;
2022-10-07 14:15:53 +00:00
}
return 0;
}
2022-10-07 14:15:53 +00:00
function getResponses(axe: Axe): QuizResponse[] {
const axeResponses = quiz.value.axes.filter((response: AxeResponses) => response.axeIdentifier === axe.identifier);
if (axeResponses.length === 1) {
return axeResponses[0].responses;
2022-10-07 14:15:53 +00:00
}
return [];
}
function print() {
window.print();
2022-10-07 14:15:53 +00:00
}
</script>
<template>
<section v-if="!loading">
<span class="date">{{ formatDateTime(quiz.createdDate) }}</span>
<quiz-axe-details
v-for="axe in axes"
:axe="axe"
:average="getAverage(axe)"
:responses="getResponses(axe)"/>
</section>
<section v-else-if="notFound">
<p class="center">Le quizz demandé n'existe pas !</p>
</section>
<loader v-else class="center"/>
<div class="button-container">
<nuxt-link class="button gray button-back" to="/dashboard" aria-label="Retour à l'accueil"></nuxt-link>
<button class="button orange button-print" @click="print">Imprimer</button>
</div>
</template>
2022-10-07 14:15:53 +00:00
<style lang="scss" scoped>
section {
margin: $small 0;
}
2022-10-07 14:15:53 +00:00
.date {
font-weight: 700;
font-size: $tertiary-font-size;
color: $gray_4;
}
@media print {
.button-container {
display: none;
}
}
2022-10-07 14:15:53 +00:00
</style>