feat: linter

This commit is contained in:
Simon 2022-04-05 16:30:16 +02:00
parent d10d4b36bf
commit e2d263887d
3 changed files with 65 additions and 23 deletions

View File

@ -1,7 +1,7 @@
import {createWriteStream, existsSync, mkdirSync} from 'fs'; import { createWriteStream, existsSync, mkdirSync } from "fs";
import fs from "fs/promises"; import fs from "fs/promises";
import {pipeline} from 'stream'; import { pipeline } from "stream";
import {promisify} from 'util' import { promisify } from "util";
const streamPipeline = promisify(pipeline); const streamPipeline = promisify(pipeline);
const apiUrl = "https://admin.ceiba-conseil.com"; const apiUrl = "https://admin.ceiba-conseil.com";
@ -26,7 +26,7 @@ async function fetchJSONApi(path) {
async function fetchAsset(uuid) { async function fetchAsset(uuid) {
const url = `${apiUrl}/assets/${uuid}`; const url = `${apiUrl}/assets/${uuid}`;
return fetch(url) return fetch(url);
} }
async function fetchData() { async function fetchData() {
@ -49,15 +49,18 @@ async function fetchData() {
const data = (await fetchJSONApi(url)).data; const data = (await fetchJSONApi(url)).data;
await fs.writeFile("./src/data.json", JSON.stringify(data), "utf8"); await fs.writeFile("./src/data.json", JSON.stringify(data), "utf8");
const folder = 'public/answers' const folder = "public/answers";
if (!existsSync(folder)) mkdirSync(folder); if (!existsSync(folder)) mkdirSync(folder);
for (const score of data) { for (const score of data) {
for (const question of score.questions) { for (const question of score.questions) {
for (const answer of question.questions_id.answers) { for (const answer of question.questions_id.answers) {
const uuid = answer.answers_id.image const uuid = answer.answers_id.image;
if (uuid) { if (uuid) {
const response = await fetchAsset(uuid) const response = await fetchAsset(uuid);
await streamPipeline(response.body, createWriteStream(`${folder}/${uuid}.png`)); await streamPipeline(
response.body,
createWriteStream(`${folder}/${uuid}.png`)
);
} }
} }
} }

View File

@ -59,7 +59,7 @@ function formatScore(score) {
const title = score ? score.title : ""; const title = score ? score.title : "";
const questions = ref(formatScore(score)); const questions = ref(formatScore(score));
console.log(questions.value) console.log(questions.value);
function nextQuestion() { function nextQuestion() {
setTimeout(() => slides.value.go(">"), 100); setTimeout(() => slides.value.go(">"), 100);
} }
@ -98,15 +98,19 @@ const result = computed(() =>
: null : null
); );
function selectImage(event, question, answer) { function selectImage(event, question, answer) {
const input = document.querySelector(`input[name='question_${question.id}'][value='${answer.weight}']`) const input = document.querySelector(
`input[name='question_${question.id}'][value='${answer.weight}']`
);
if (input) { if (input) {
input.checked = true input.checked = true;
input.dispatchEvent(new Event("change")) input.dispatchEvent(new Event("change"));
} }
nextQuestion() nextQuestion();
} }
function geQuestionSlide(question) { function geQuestionSlide(question) {
slides.value.go(questions.value.findIndex((element, index) => element.id === question.id)) slides.value.go(
questions.value.findIndex((element) => element.id === question.id)
);
} }
</script> </script>
@ -131,14 +135,22 @@ function geQuestionSlide(question) {
<div class="top"> <div class="top">
<legend>{{ question.title }}</legend> <legend>{{ question.title }}</legend>
<template v-if="question.answers"> <template v-if="question.answers">
<div class="choice" v-for="answer in question.answers" :key="answer.id"> <div
class="choice"
v-for="answer in question.answers"
:key="answer.id"
>
<label> <label>
<input <input
type="radio" type="radio"
:data-answerId="answer.id" :data-answerId="answer.id"
:name="`question_${question.id}`" :name="`question_${question.id}`"
:value="answer.weight" :value="answer.weight"
@change="(event) => {question.weight = parseFloat(event.target.value)}" @change="
(event) => {
question.weight = parseFloat(event.target.value);
}
"
@click="nextQuestion" @click="nextQuestion"
/> />
{{ answer.title }} {{ answer.title }}
@ -148,9 +160,23 @@ function geQuestionSlide(question) {
</div> </div>
<div class="bottom"> <div class="bottom">
<template v-if="question.answers"> <template v-if="question.answers">
<Splide class="answers" :id="`question_${question.id}`" ref="question.splide"> <Splide
<SplideSlide v-for="answer in question.answers" :key="answer.id" @click="(event) => selectImage(event, {...question}, {...answer})"> class="answers"
<img width="200" height="200" :src="`/answers/${answer.image}.png`"> :id="`question_${question.id}`"
ref="question.splide"
>
<SplideSlide
v-for="answer in question.answers"
:key="answer.id"
@click="
(event) => selectImage(event, { ...question }, { ...answer })
"
>
<img
width="200"
height="200"
:src="`/answers/${answer.image}.png`"
/>
</SplideSlide> </SplideSlide>
</Splide> </Splide>
</template> </template>
@ -179,11 +205,24 @@ function geQuestionSlide(question) {
<template v-else> <template v-else>
<div class="noscore"> <div class="noscore">
<p> <p>
Aucun score peut vous être proposé, vous devez faire une selection sur les vecteurs suivants : Aucun score peut vous être proposé, vous devez faire une selection
sur les vecteurs suivants :
</p> </p>
<ul> <ul>
<li v-for="question in questions.filter(q => q.weight == null)" :key="question.id"> <li
<a @click="(event) => {geQuestionSlide(question);return false}" href="javascript:;">{{ question.title }}</a> v-for="question in questions.filter((q) => q.weight == null)"
:key="question.id"
>
<a
@click="
(event) => {
geQuestionSlide(question);
return false;
}
"
href="javascript:;"
>{{ question.title }}</a
>
</li> </li>
</ul> </ul>
</div> </div>
@ -265,6 +304,7 @@ label
display: flex display: flex
align-items: center align-items: center
justify-content: center justify-content: center
position: relative
&::before &::before
content: "PdE\AQTRA" content: "PdE\AQTRA"

View File

@ -115,5 +115,4 @@ ul
align-items: center align-items: center
justify-content: center justify-content: center
text-align: center text-align: center
</style> </style>