2022-03-29 23:30:23 +02:00
|
|
|
<script setup>
|
|
|
|
import data from "@/data.json";
|
|
|
|
|
|
|
|
import { ref, computed } from "vue";
|
|
|
|
|
|
|
|
import { useStore } from "@/stores";
|
|
|
|
|
|
|
|
import { Splide, SplideSlide } from "@splidejs/vue-splide";
|
2022-04-06 11:01:37 +02:00
|
|
|
import Question from "./Question.vue";
|
2022-03-29 23:30:23 +02:00
|
|
|
import "@splidejs/splide/dist/css/splide.min.css";
|
|
|
|
import ScoreHeader from "./ScoreHeader.vue";
|
2023-04-27 22:31:59 +02:00
|
|
|
import html2canvas from "html2canvas";
|
2022-03-29 23:30:23 +02:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const score = data.find((score) => score.id == props.id);
|
|
|
|
const slides = ref();
|
|
|
|
|
|
|
|
const store = useStore();
|
|
|
|
const language = store.language;
|
|
|
|
|
|
|
|
function formatAnswers(answers) {
|
|
|
|
return answers
|
|
|
|
.map((answer) => answer.answers_id)
|
|
|
|
.map((answer) => {
|
|
|
|
const translation = answer.translations.filter(
|
|
|
|
(item) => item.languages_code == language
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
id: answer.id,
|
2023-01-17 16:46:50 +01:00
|
|
|
title: translation.length > 0 ? translation[0].title : answer.title,
|
2022-03-29 23:30:23 +02:00
|
|
|
weight: answer.weight,
|
2022-04-05 12:05:59 +02:00
|
|
|
image: answer.image,
|
2022-03-29 23:30:23 +02:00
|
|
|
};
|
2023-03-07 11:14:59 +01:00
|
|
|
});
|
2022-03-29 23:30:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function formatScore(score) {
|
|
|
|
return score.questions
|
|
|
|
.map((question) => question.questions_id)
|
|
|
|
.map((question) => {
|
|
|
|
const translation = question.translations.filter(
|
|
|
|
(item) => item.languages_code == language
|
|
|
|
);
|
2022-04-06 13:13:09 +02:00
|
|
|
const answers = formatAnswers(question.answers);
|
2022-03-29 23:30:23 +02:00
|
|
|
return {
|
|
|
|
id: question.id,
|
2022-04-06 13:13:09 +02:00
|
|
|
weight: answers[0].weight,
|
2023-01-17 16:46:50 +01:00
|
|
|
title: translation.length > 0 ? translation[0].title : question.title,
|
2023-05-02 18:09:39 +02:00
|
|
|
function: question.function,
|
2022-04-06 13:13:09 +02:00
|
|
|
answers: answers,
|
2022-04-05 12:05:59 +02:00
|
|
|
splide: ref(),
|
2022-03-29 23:30:23 +02:00
|
|
|
};
|
2023-03-07 11:14:59 +01:00
|
|
|
});
|
2022-03-29 23:30:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const title = score ? score.title : "";
|
|
|
|
const questions = ref(formatScore(score));
|
2022-04-05 16:36:17 +02:00
|
|
|
|
2022-03-29 23:30:23 +02:00
|
|
|
const scoreSum = computed(() => {
|
|
|
|
return questions.value
|
2022-04-05 12:05:59 +02:00
|
|
|
.map((question) => question.weight)
|
2022-03-29 23:30:23 +02:00
|
|
|
.reduce((value, currentValue) => value + currentValue, 0);
|
|
|
|
});
|
|
|
|
const displayScoreResult = computed(
|
2022-04-05 12:05:59 +02:00
|
|
|
() => !questions.value.filter((q) => q.weight == null).length
|
2022-03-29 23:30:23 +02:00
|
|
|
);
|
|
|
|
function getResultsFromScore(score) {
|
|
|
|
return score.results
|
|
|
|
.map((result) => result.results_id)
|
|
|
|
.map((result) => {
|
|
|
|
const translation = result.translations.filter(
|
|
|
|
(item) => item.languages_code == language
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
id: result.id,
|
|
|
|
max: result.max,
|
|
|
|
min: result.min,
|
|
|
|
pde_qtra: result.pde_qtra,
|
|
|
|
effets: translation.length > 0 ? translation[0].effets : "",
|
|
|
|
facteur: translation.length > 0 ? translation[0].facteur : "",
|
|
|
|
pde: translation.length > 0 ? translation[0].pde : "",
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const results = ref(getResultsFromScore(score));
|
|
|
|
const result = computed(() =>
|
|
|
|
displayScoreResult.value
|
|
|
|
? results.value
|
2023-03-07 12:22:19 +01:00
|
|
|
.filter((r) => !r.min || r.min <= scoreSum.value)
|
2022-03-29 23:30:23 +02:00
|
|
|
.filter((r) => !r.max || r.max >= scoreSum.value)[0]
|
|
|
|
: null
|
|
|
|
);
|
2022-04-06 11:01:37 +02:00
|
|
|
function goQuestionSlide(question) {
|
|
|
|
console.log(slides.value);
|
2022-04-05 16:30:16 +02:00
|
|
|
slides.value.go(
|
|
|
|
questions.value.findIndex((element) => element.id === question.id)
|
|
|
|
);
|
2022-04-05 16:20:51 +02:00
|
|
|
}
|
2022-04-06 11:01:37 +02:00
|
|
|
function answerSelected(question, answerWeight) {
|
|
|
|
questions.value.find((q) => q.id === question.id).weight = answerWeight;
|
2022-04-06 14:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function nextQuestion() {
|
2023-04-24 23:15:13 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
slides.value.go(">");
|
|
|
|
console.log(slides);
|
|
|
|
}, 100);
|
2022-04-06 11:01:37 +02:00
|
|
|
}
|
2023-04-27 22:31:59 +02:00
|
|
|
|
|
|
|
async function share() {
|
|
|
|
console.log(document.querySelector(".latest"));
|
|
|
|
const canvas = await html2canvas(document.querySelector("html"));
|
|
|
|
let anchor = document.createElement("a");
|
|
|
|
anchor.download = "download.png";
|
|
|
|
anchor.href = canvas.toDataURL("image/png");
|
|
|
|
anchor.click();
|
|
|
|
anchor.remove();
|
|
|
|
}
|
2022-03-29 23:30:23 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<ScoreHeader v-if="title" :title="title" />
|
|
|
|
<Splide
|
|
|
|
ref="slides"
|
2022-04-05 12:05:59 +02:00
|
|
|
class="questions"
|
2022-03-29 23:30:23 +02:00
|
|
|
v-if="questions"
|
|
|
|
:options="{
|
|
|
|
pagination: false,
|
|
|
|
speed: 700,
|
2022-04-04 11:56:13 +02:00
|
|
|
height: '100%',
|
2022-03-29 23:30:23 +02:00
|
|
|
arrows: false,
|
|
|
|
direction: 'ttb',
|
|
|
|
wheel: true,
|
|
|
|
releaseWheel: true,
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
<SplideSlide v-for="question in questions" :key="question.id">
|
2022-04-06 14:29:04 +02:00
|
|
|
<Question
|
|
|
|
:question="question"
|
|
|
|
@answerSelected="answerSelected"
|
|
|
|
@nextQuestion="nextQuestion"
|
|
|
|
/>
|
2022-03-29 23:30:23 +02:00
|
|
|
</SplideSlide>
|
2023-04-27 22:31:59 +02:00
|
|
|
<SplideSlide class="latest">
|
2022-03-29 23:30:23 +02:00
|
|
|
<template v-if="displayScoreResult && result">
|
2023-04-24 23:15:13 +02:00
|
|
|
<div>
|
|
|
|
<h2 class="center">Probabilité d'échec</h2>
|
|
|
|
<h2 class="center">{{ result.pde_qtra }}</h2>
|
|
|
|
<div class="gradient">
|
|
|
|
<div
|
|
|
|
v-for="(item, index) in [...Array(7).keys()]"
|
|
|
|
:class="{ active: result && result.pde_qtra === index + 1 }"
|
|
|
|
:key="item"
|
|
|
|
>
|
|
|
|
{{ index + 1 }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="details">
|
|
|
|
<p>Rappel des paramètres choisis :</p>
|
|
|
|
<ul>
|
|
|
|
<li v-for="question in questions" :key="question.id">
|
|
|
|
{{ question.title }} :
|
|
|
|
{{
|
|
|
|
question.answers.find(
|
|
|
|
(answer) => answer.weight === question.weight
|
|
|
|
).title
|
|
|
|
}}
|
|
|
|
</li>
|
|
|
|
</ul>
|
2022-03-29 23:30:23 +02:00
|
|
|
</div>
|
2023-04-27 22:31:59 +02:00
|
|
|
<button @click="() => share()">Partager</button>
|
2022-03-29 23:30:23 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
2022-04-05 16:20:51 +02:00
|
|
|
<div class="noscore">
|
|
|
|
<p>
|
2022-04-06 09:35:17 +02:00
|
|
|
Aucun score ne peut vous être proposé, vous devez faire une
|
|
|
|
sélection sur les paramètres suivants :
|
2022-04-05 16:20:51 +02:00
|
|
|
</p>
|
|
|
|
<ul>
|
2022-04-05 16:30:16 +02:00
|
|
|
<li
|
|
|
|
v-for="question in questions.filter((q) => q.weight == null)"
|
|
|
|
:key="question.id"
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
@click="
|
|
|
|
(event) => {
|
2022-04-06 11:01:37 +02:00
|
|
|
goQuestionSlide(question);
|
2022-04-05 16:30:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
"
|
|
|
|
href="javascript:;"
|
|
|
|
>{{ question.title }}</a
|
|
|
|
>
|
2022-04-05 16:20:51 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2022-03-29 23:30:23 +02:00
|
|
|
</template>
|
|
|
|
</SplideSlide>
|
|
|
|
</Splide>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="sass" scoped>
|
2023-04-24 23:15:13 +02:00
|
|
|
.center
|
|
|
|
text-align: center
|
2022-04-05 16:20:51 +02:00
|
|
|
.noscore
|
|
|
|
display: flex
|
|
|
|
justify-content: center
|
|
|
|
align-items: center
|
|
|
|
height: 100%
|
2023-01-17 12:48:20 +01:00
|
|
|
color: var(--color-text)
|
2022-04-05 16:20:51 +02:00
|
|
|
flex-direction: column
|
|
|
|
|
|
|
|
p
|
|
|
|
font-size: 1rem
|
|
|
|
text-align: center
|
|
|
|
margin-bottom: 1rem
|
|
|
|
a
|
2023-01-17 12:48:20 +01:00
|
|
|
color: var(--color-text)
|
2022-04-05 12:05:59 +02:00
|
|
|
.questions
|
2022-03-29 23:30:23 +02:00
|
|
|
position: fixed
|
|
|
|
top: var(--header-size)
|
|
|
|
left: 0
|
|
|
|
right: 0
|
|
|
|
bottom: 0
|
|
|
|
background: transparent
|
|
|
|
|
2022-04-05 12:05:59 +02:00
|
|
|
|
2022-03-29 23:30:23 +02:00
|
|
|
.splide__slide
|
|
|
|
position: relative
|
|
|
|
padding: 1rem
|
|
|
|
|
|
|
|
.splide__track
|
|
|
|
overflow: visible!important
|
|
|
|
|
|
|
|
legend
|
|
|
|
font-size: 1.1rem
|
|
|
|
font-weight: bold
|
|
|
|
|
|
|
|
label
|
|
|
|
display: inline-block
|
|
|
|
width: 100%
|
|
|
|
padding: .3rem
|
|
|
|
|
2022-04-04 16:44:10 +02:00
|
|
|
.latest
|
2023-04-24 23:15:13 +02:00
|
|
|
background-color: var(--color-highlight-background)
|
|
|
|
color: var(--color-highlight-text)
|
|
|
|
text-align: center
|
|
|
|
display: flex
|
|
|
|
align-items: center
|
|
|
|
justify-content: center
|
|
|
|
|
|
|
|
h2
|
|
|
|
font-size: 2rem
|
|
|
|
font-weight: bold
|
|
|
|
& + h2
|
|
|
|
line-height: 2rem
|
|
|
|
font-size: 2.6rem
|
|
|
|
|
2023-04-27 22:31:59 +02:00
|
|
|
@media (max-height: 600px)
|
|
|
|
font-size: 1.5rem
|
|
|
|
& + h2
|
|
|
|
font-size: 2rem
|
|
|
|
|
2023-04-24 23:15:13 +02:00
|
|
|
ul
|
|
|
|
text-align: left
|
|
|
|
padding-left: 1.5rem
|
|
|
|
list-style-type: disc
|
|
|
|
|
|
|
|
.details
|
2023-04-27 22:31:59 +02:00
|
|
|
text-align: left !important
|
|
|
|
font-family: serif
|
|
|
|
font-size: .9rem
|
|
|
|
line-height: normal
|
|
|
|
background: var(--color-highlight-background)
|
2023-04-24 23:15:13 +02:00
|
|
|
border: 1px solid var(--color-highlight-text)
|
|
|
|
padding: 1rem
|
2022-04-04 16:44:10 +02:00
|
|
|
|
2022-03-29 23:30:23 +02:00
|
|
|
.gradient
|
|
|
|
padding: 0 1rem
|
|
|
|
height: 3rem
|
|
|
|
background-image: linear-gradient(to right, red, red, rgb(255, 255, 0), rgb(255, 255, 0), green, green)
|
|
|
|
display: flex
|
2023-04-24 23:15:13 +02:00
|
|
|
margin: 2.5rem auto
|
2022-03-29 23:30:23 +02:00
|
|
|
align-items: center
|
|
|
|
border-radius: 3px
|
2023-04-24 23:15:13 +02:00
|
|
|
max-width: 30rem
|
|
|
|
text-shadow: 1px 1px 4px var(--color-highlight-text-invert),-1px -1px 4px var(--color-highlight-text-invert), -1px 1px 4px var(--color-highlight-text-invert), 1px -1px 4px var(--color-highlight-text-invert)
|
|
|
|
color: var(--color-highlight-text)
|
2022-03-29 23:30:23 +02:00
|
|
|
|
|
|
|
div
|
|
|
|
width: calc(100%/7)
|
|
|
|
text-align: center
|
|
|
|
align-self: center
|
2023-04-24 23:15:13 +02:00
|
|
|
font-weight: bold
|
2022-03-29 23:30:23 +02:00
|
|
|
|
|
|
|
.active
|
2022-04-05 16:30:16 +02:00
|
|
|
position: relative
|
2022-03-29 23:30:23 +02:00
|
|
|
|
2023-04-24 23:15:13 +02:00
|
|
|
&:before
|
|
|
|
content: ""
|
|
|
|
border: 1px solid var(--color-highlight-text)
|
|
|
|
border-radius: 3px
|
|
|
|
top: -2.8rem
|
|
|
|
bottom: -1.5rem
|
|
|
|
position: absolute
|
|
|
|
width: 100%
|
|
|
|
font-weight: bold
|
|
|
|
display: flex
|
|
|
|
align-items: center
|
|
|
|
justify-content: center
|
|
|
|
|
|
|
|
&::after
|
|
|
|
content: "PdE"
|
2022-03-29 23:30:23 +02:00
|
|
|
position: absolute
|
2023-04-24 23:15:13 +02:00
|
|
|
font-size: 1rem
|
|
|
|
top: -2rem
|
|
|
|
bottom: -1.5rem
|
|
|
|
left: 0
|
|
|
|
right: 0
|
2022-03-29 23:30:23 +02:00
|
|
|
line-height: .7rem
|
2023-04-24 23:15:13 +02:00
|
|
|
text-shadow: none
|
2022-04-05 12:05:59 +02:00
|
|
|
|
|
|
|
.splide__arrows
|
|
|
|
position: inherit
|
2022-03-29 23:30:23 +02:00
|
|
|
</style>
|