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

View File

@ -59,7 +59,7 @@ function formatScore(score) {
const title = score ? score.title : "";
const questions = ref(formatScore(score));
console.log(questions.value)
console.log(questions.value);
function nextQuestion() {
setTimeout(() => slides.value.go(">"), 100);
}
@ -98,15 +98,19 @@ const result = computed(() =>
: null
);
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) {
input.checked = true
input.dispatchEvent(new Event("change"))
input.checked = true;
input.dispatchEvent(new Event("change"));
}
nextQuestion()
nextQuestion();
}
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>
@ -131,14 +135,22 @@ function geQuestionSlide(question) {
<div class="top">
<legend>{{ question.title }}</legend>
<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>
<input
type="radio"
:data-answerId="answer.id"
:name="`question_${question.id}`"
:value="answer.weight"
@change="(event) => {question.weight = parseFloat(event.target.value)}"
@change="
(event) => {
question.weight = parseFloat(event.target.value);
}
"
@click="nextQuestion"
/>
{{ answer.title }}
@ -148,9 +160,23 @@ function geQuestionSlide(question) {
</div>
<div class="bottom">
<template v-if="question.answers">
<Splide class="answers" :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`">
<Splide
class="answers"
: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>
</Splide>
</template>
@ -179,11 +205,24 @@ function geQuestionSlide(question) {
<template v-else>
<div class="noscore">
<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>
<ul>
<li 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
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>
</ul>
</div>
@ -265,6 +304,7 @@ label
display: flex
align-items: center
justify-content: center
position: relative
&::before
content: "PdE\AQTRA"

View File

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