contenu des étapes

This commit is contained in:
Valentin
2024-09-29 21:36:21 +02:00
parent ebb3ceb6d5
commit a4452388cd
25 changed files with 1410 additions and 500 deletions

View File

@@ -3,6 +3,9 @@ import { createPinia } from 'pinia'
import '../scss/main.scss'
import Modale from './vuejs/Modale.vue'
import VueImageZoomer from 'vue-image-zoomer'
import 'vue-image-zoomer/dist/style.css';
import { useContentStore } from './stores/content';
import router from './router/router';
@@ -48,7 +51,9 @@ import router from './router/router';
}
function initVueContentModale(){
const app = createApp(Modale).use(createPinia()).use(router);
const app = createApp(Modale)
.use(createPinia()).use(router)
.use(VueImageZoomer);
const store = useContentStore();
app.mount('#content-modale');

View File

@@ -1,3 +1,5 @@
// query et traitement des contenus
import { defineStore } from 'pinia';
import REST from '../api/rest-axios';
@@ -21,12 +23,15 @@ export const useContentStore = defineStore('content', {
},
},
geofield: {},
galeries: [],
// galeries: [],
parties: [],
saison: {},
thematiques: [],
vignette: {},
couleur: '',
sensibleMap: {},
previous: {},
next: {},
},
page: {
title: '',
@@ -43,7 +48,7 @@ export const useContentStore = defineStore('content', {
this.page = {};
try {
const response = await REST.get(`/jsonapi/node/etape/`);
for (let etape of response.data.data) {
for (let [index, etape] of response.data.data.entries()) {
if (etape.attributes.drupal_internal__nid == nid) {
for (let metatag of etape.attributes.metatag) {
if (metatag.tag === "link") {
@@ -53,34 +58,113 @@ export const useContentStore = defineStore('content', {
this.etape.title = etape.attributes.title;
this.etape.adresse = etape.attributes.field_adresse;
this.etape.etape_number = etape.attributes.field_arret_numero;
//this.etape.dates = etape.attributes.field_dates;
this.etape.dates = {
start: {
d: etape.attributes.field_dates.value.split('-')[2],
m: new Intl.DateTimeFormat('fr-FR', { month: 'long' }).format(new Date(etape.attributes.field_dates.value)),
y: etape.attributes.field_dates.value.split('-')[0],
},
end: {
d: etape.attributes.field_dates.end_value.split('-')[2],
m: new Intl.DateTimeFormat('fr-FR', { month: 'long' }).format(new Date(etape.attributes.field_dates.end_value)),
y: etape.attributes.field_dates.end_value.split('-')[0],
},
start: this.getCleanDate(etape.attributes.field_dates.value),
end: this.getCleanDate(etape.attributes.field_dates.end_value),
}
this.etape.geofield = etape.attributes.field_geofield;
this.etape.galeries = await this.fetchEtapeContent('field_galleries', etape.relationships);
// this.etape.galeries = await this.fetchEtapeContent('field_galleries', etape.relationships);
const partiesFetch = await this.fetchEtapeContent('field_parties', etape.relationships);
let partiesArray = []
for (let partie of partiesFetch) {
partiesArray.push({ title: partie.attributes.field_titre, text: partie.attributes.field_texte.value });
if (partiesFetch) {
for (let partie of partiesFetch) {
let partieContent = {
title: partie.attributes.field_titre || '',
text: partie.attributes.field_texte.value || '',
diaporama: [],
chiffresCles: [],
videos: [],
}
if (partie.relationships.field_diaporama) {
const diaporama = await REST.get(partie.relationships.field_diaporama.links.related.href);
partie.relationships.field_diaporama.data.forEach((element, i) => {
partieContent.diaporama[i] = {};
partieContent.diaporama[i].alt = element.meta.alt;
});
diaporama.data.data.forEach((element, i) => {
partieContent.diaporama[i].url = element.attributes.uri.url;
});
}
if (partie.attributes.field_chiffres_cles) {
for (let chiffre of partie.attributes.field_chiffres_cles) {
partieContent.chiffresCles.push(chiffre.processed);
}
}
if (partie.attributes.field_videos) {
for (let video of partie.attributes.field_videos) {
const videoId = video.split('?v=')[1];
const videoUrl = `https://www.youtube.com/embed/${videoId}`;
partieContent.videos.push(videoUrl);
}
}
partiesArray.push(partieContent);
}
}
this.etape.parties = partiesArray;
this.etape.saison = await this.fetchEtapeContent('field_saison', etape.relationships);
this.etape.saison = await this.fetchEtapeContent('field_saison', etape.relationships);
this.etape.thematiques = await this.fetchEtapeContent('field_thematiques', etape.relationships);
const vignetteFetch = await this.fetchEtapeContent('field_vignette', etape.relationships);
this.etape.vignette = { url: vignetteFetch.attributes.uri.url, alt: etape.attributes.field_vignette_alt };
const sensibleMapFetch = await this.fetchEtapeContent('field_carte_sensible', etape.relationships);
if (sensibleMapFetch) {
this.etape.sensibleMap = { url: sensibleMapFetch.attributes.uri.url, alt: etape.relationships.field_carte_sensible.data.meta.alt };
}
this.etape.couleur = etape.attributes.field_couleur;
// get previous and next étape infos
// the list from the json api /node is not ordered
// and i need authentification to get the json view ordered list
// so i get it from the displayed list in the page
const orderedEtapesList = document.querySelectorAll('#etapes-liste li');
if (orderedEtapesList) {
const processEtape = async (etapeItemNid, etapesList, key) => {
for (let etape of etapesList) {
if (etape.attributes.drupal_internal__nid == etapeItemNid) {
const vignetteFetch = await REST.get(etape.relationships.field_vignette.links.related.href);
this.etape[key] = {
nid: etape.attributes.drupal_internal__nid,
couleur: etape.attributes.field_couleur,
title: etape.attributes.title,
postalCode: etape.attributes.field_adresse.postal_code,
dates: {
start: this.getCleanDate(etape.attributes.field_dates.value),
end: this.getCleanDate(etape.attributes.field_dates.end_value),
},
vignette: {
url: vignetteFetch.data.data.attributes.uri.url,
alt: etape.relationships.field_vignette.data.meta.alt,
},
};
break;
}
}
};
for (let li of orderedEtapesList) {
if (li.querySelector('a').dataset.nodeNid === nid) {
const previousEtapeItemNid = li.previousElementSibling?.querySelector('a').dataset.nodeNid;
const nextEtapeItemNid = li.nextElementSibling?.querySelector('a').dataset.nodeNid;
if (previousEtapeItemNid) {
await processEtape(previousEtapeItemNid, response.data.data, 'previous');
}
if (nextEtapeItemNid) {
await processEtape(nextEtapeItemNid, response.data.data, 'next');
}
}
}
}
this.setActiveItemInMenu();
break;
}
@@ -171,6 +255,13 @@ export const useContentStore = defineStore('content', {
console.error('Issue with getNodeData', error);
}
}
},
getCleanDate(date) {
return {
d: date.split('-')[2],
m: new Intl.DateTimeFormat('fr-FR', { month: 'long' }).format(new Date(date)),
y: date.split('-')[0],
}
}
},
});

View File

@@ -0,0 +1,93 @@
<template>
<transition name="fade">
<div v-if="isOpen" class="image-viewer-wrapper">
<div v-if="!swiperContent.length" class="img-modale simple-viewer">
<figure class="img-wrapper">
<img :src="image.src" :alt="image.alt">
<figcaption>{{ image.alt }}</figcaption>
</figure>
</div>
<div v-else class="img-modale swiper-viewer">
<div class="swiper-wrapper">
<swiper-container
:slidesPerView="1"
:centeredSlides="true"
:loop="true"
:navigation="true"
:pagination="true"
:initialSlide="currentImgIndex"
:injectStyles="[`
.swiper-button-next, .swiper-button-prev {
color: white;
top: 50%;
}
.swiper-pagination-bullet:not(.swiper-pagination-bullet-active) {
background: white;
opacity: 0.8;
}
`]"
>
<swiper-slide v-for="media in swiperContent">
<figure>
<img :src="media.src" :alt="media.alt" class="popup-img">
<figcaption>{{ media.alt }}</figcaption>
</figure>
</swiper-slide>
</swiper-container>
</div>
</div>
<button @click="close" class="close-button">
<div></div>
<div></div>
</button>
</div>
</transition>
</template>
<script setup>
import { ref, watch } from 'vue';
const props = defineProps({
isOpen: Boolean,
image: {
type: Object,
required: true,
},
swiperContent: {
type: Array,
required: true,
}
});
const currentImgIndex = ref(0);
watch(
() => props.isOpen,
() => {
if (props.isOpen && props.swiperContent.length) {
for (let i = 0; i < props.swiperContent.length; i++) {
const currentImgSrc = props.image.src;
const truncatedSrc = currentImgSrc.substring(currentImgSrc.indexOf("/sites"));
if (props.swiperContent[i].src === truncatedSrc) {
currentImgIndex.value = i;
break;
}
}
}
})
const emit = defineEmits(['close']);
const close = () => {
emit('close');
};
</script>
<style scoped>
.fade-enter-active, .fade-leave-active {
transition: opacity 0.3s ease;
}
.fade-enter-from, .fade-leave-to {
opacity: 0;
}
</style>

View File

@@ -1,43 +1,129 @@
<template>
<Transition>
<div v-if="isEtapeValid">
<header>
<div class="cover">
<img :src="etape.vignette.url" :alt="etape.vignette.alt">
</div>
<div class="cartouche" :style="{ backgroundColor: etape.couleur }">
<p>Étape n°{{etape.etape_number}}</p>
<p>Du {{etape.dates.start.d}} {{etape.dates.start.m}} au {{ etape.dates.end.d }} {{ etape.dates.end.m }} {{ etape.dates.end.y }}</p>
</div>
<div class="brand-pattern" :style="{ backgroundColor: etape.couleur }">
<div class="pattern"></div>
</div>
<div class="locality">
<div class="top-triangle"></div>
<div class="locality-title">
<h1>{{etape.title}} <em>({{ etape.adresse.postal_code }})</em></h1>
<div class="content-wrapper">
<header>
<div class="cover">
<img :src="etape.vignette.url" :alt="etape.vignette.alt">
</div>
</div>
</header>
<main>
<div v-for="partie in etape.parties" class="partie">
<div class="partie-title">
<h3>
<div class="underline" :style="{ backgroundColor: etape.couleur }"></div>
<p v-html="partie.title"></p>
</h3>
<div class="cartouche" :style="{ backgroundColor: etape.couleur }">
<p>Étape n°{{etape.etape_number}}</p>
<p>Du {{etape.dates.start.d}} {{etape.dates.start.m}} au {{ etape.dates.end.d }} {{ etape.dates.end.m }} {{ etape.dates.end.y }}</p>
</div>
<p v-html="partie.text"></p>
</div>
</main>
<div class="brand-pattern" :style="{ backgroundColor: etape.couleur }">
<div class="pattern"></div>
</div>
<div class="locality">
<div class="top-triangle"></div>
<div class="locality-title">
<h1>{{etape.title}} <em>({{ etape.adresse.postal_code }})</em></h1>
</div>
</div>
</header>
<main>
<div v-if="etape.sensibleMap" id="sensible-map">
<figure>
<vue-image-zoomer
:regular="etape.sensibleMap.url"
:zoom="etape.sensibleMap.url"
:zoom-amount="3.5"
alt="Carte sensible du territoire"
hover-message="Survolez pour zoomer dans la carte"
/>
<figcaption class="caption">{{ etape.sensibleMap.alt }}</figcaption>
</figure>
</div>
<div v-for="partie in etape.parties" class="partie" @click="handleImageClick">
<div v-if="Object.keys(partie.chiffresCles).length" class="chiffres-cles">
<h3>
<div class="underline" :style="{ backgroundColor: etape.couleur }"></div>
<p>Chiffres clés</p>
</h3>
<div>
<div v-for="chiffre in partie.chiffresCles">
<div v-html="chiffre.split('<br />')[0]" class="chiffre" :style="{ borderLeft: `solid 10px ${etape.couleur}` }"></div>
<p v-html="chiffre.split('<br />')[1]" class="chiffre-caption" :style="{ borderLeft: `solid 10px ${etape.couleur}` }"></p>
</div>
</div>
</div>
<div class="partie-title">
<h3>
<div class="underline" :style="{ backgroundColor: etape.couleur }"></div>
<p v-html="partie.title"></p>
</h3>
</div>
<div v-html="partie.text" v-alt class="partie-content"></div>
<swiper-container
v-if="partie.diaporama.length"
class="diaporama"
:slidesPerView="1.5"
:centeredSlides="true"
:loop="true"
:navigation="true"
:pagination="true"
:injectStyles="[`.swiper-button-next, .swiper-button-prev { z-index: 11; }`]"
>
<swiper-slide v-for="image in partie.diaporama" style="width: 100%">
<figure>
<img :src="image.url" :alt="image.alt">
<figcaption class="caption">{{ image.alt }}</figcaption>
</figure>
</swiper-slide>
</swiper-container>
<div v-if="partie.videos.length" class="videos">
<iframe v-for="video in partie.videos" :src="video" frameborder="0" width="100%" style="aspect-ratio: 16 / 9;"></iframe>
</div>
</div>
<div class="brand-pattern pattern-bottom" :style="{ backgroundColor: etape.couleur }">
<div class="pattern"></div>
</div>
<div v-if="etape.previous || etape.next" class="related-etape-links">
<div v-if="etape.previous" class="card previous" @click="store.fetchEtapeData(etape.previous.nid)">
<div class="icon">
<div :style="{ backgroundColor: etape.previous.couleur }"></div>
<div :style="{ backgroundColor: etape.previous.couleur }"></div>
<div :style="{ backgroundColor: etape.previous.couleur }"></div>
</div>
<div class="card-content">
<div class="infos">
<div class="titre">{{ etape.previous.title }} <span>({{ etape.previous.postalCode }})</span></div>
<div class="date">Du {{ etape.previous.dates.start.d }} {{ etape.previous.dates.start.m }}<br>au {{ etape.previous.dates.end.d }} {{ etape.previous.dates.end.m }} {{ etape.previous.dates.end.y }}</div>
</div>
<div class="vignette">
<img :src="etape.previous.vignette.url" :alt="etape.previous.vignette.alt">
</div>
</div>
</div>
<div v-if="etape.next" class="card next" @click="store.fetchEtapeData(etape.next.nid)">
<div class="icon">
<div :style="{ backgroundColor: etape.next.couleur }"></div>
<div :style="{ backgroundColor: etape.next.couleur }"></div>
<div :style="{ backgroundColor: etape.next.couleur }"></div>
</div>
<div class="card-content">
<div class="infos">
<div class="titre">{{ etape.next.title }} <span>({{ etape.next.postalCode }})</span></div>
<div class="date">Du {{ etape.next.dates.start.d }} {{ etape.next.dates.start.m }}<br>au {{ etape.next.dates.end.d }} {{ etape.next.dates.end.m }} {{ etape.next.dates.end.y }}</div>
</div>
<div class="vignette">
<img :src="etape.next.vignette.url" :alt="etape.next.vignette.alt">
</div>
</div>
</div>
</div>
</main>
</div>
<!--
<div v-if="loading">Loading...</div>
<div v-if="error">{{ error }}</div>
{{etape.adresse.locality}}
-->
<div><pre>{{href}}</pre></div>
<!-- <div><pre>{{href}}</pre></div>
<div><pre><b>GEOFIELD</b>{{etape.geofield}}</pre></div>
@@ -46,12 +132,12 @@
<div><pre><b>PARTIES</b>{{etape.parties}}</pre></div>
<div><pre><b>SAISON</b>{{etape.saison}}</pre></div>
<div><pre><b>THEMATIQUES</b>{{etape.thematiques}}</pre></div>
<div>
</div>
-->
</div>
</Transition>
<ImageModale :isOpen="isModaleOpen" :image="currentImage" :swiperContent="swiperPopupContent" @close="closeImageModale" />
<Transition>
<div v-if="isPageValid">
<header>
@@ -65,10 +151,19 @@
</template>
<script setup>
import { ref, computed, watch } from 'vue';
import { ref, computed, watch, onMounted } from 'vue';
import { storeToRefs } from 'pinia';
import { useContentStore } from '../stores/content';
import { useRoute, useRouter } from 'vue-router';
import ImageModale from './ImageModale.vue';
import { VueImageZoomer } from 'vue-image-zoomer'
import 'vue-image-zoomer/dist/style.css';
// web element usage bc its 2024
// (idk how it works but it does)
import { register } from 'swiper/element/bundle';
register();
const router = useRouter();
const store = useContentStore();
@@ -76,60 +171,126 @@ const route = useRoute();
const { loading, error, href, etape, page } = storeToRefs(store);
watch(() => route.params.id, (newId) => {
if (!newId) {
store.emptyAll();
watch(
() => route.params.id,
(newId) => {
if (!newId) {
store.emptyAll();
} else {
store.fetchEtapeData(newId);
if (!etape.value.data) {
store.fetchStaticData(newId);
if (!etape.value?.data) {
store.fetchStaticData(newId);
}
window.scrollTo({ top: 0, behavior: 'smooth' });
}
},
{ immediate: true }
);
watch(
() => etape.value.couleur,
(newColor) => {
if (newColor) {
document.documentElement.style.setProperty('--etape-couleur', etape.value.couleur);
}
window.scrollTo({top: 0, behavior: 'smooth'});
}
});
);
watch(() => href.value, (newHref) => {
const relativePath = newHref.split('.fr')[1];
if (relativePath && (relativePath !== '' || relativePath !== '/')) {
router.push(relativePath);
watch(
() => href.value,
(newHref) => {
const relativePath = newHref.split('.fr')[1];
if (relativePath && relativePath !== '' && relativePath !== '/') {
router.push(relativePath);
}
}
});
);
const isEtapeValid = computed(() => {
return etape.value && !isObjectEmpty(etape.value);
});
const isObjectEmpty = (obj) => {
if (!obj || typeof obj !== 'object') return true;
const isPageValid = computed(() => {
return page.value && !isObjectEmpty(page.value);
});
return !Object.keys(obj).some((key) => {
const value = obj[key];
if (Array.isArray(value)) return value.length > 0;
if (typeof value === 'object') return !isObjectEmpty(value);
return value !== null && value !== undefined && value !== '';
});
};
// Utility function to check if an object and its children are empty
function isObjectEmpty(obj) {
if (obj === null || obj === undefined || typeof obj !== 'object') {
return true;
const isEtapeValid = computed(() => etape.value && !isObjectEmpty(etape.value));
const isPageValid = computed(() => page.value && !isObjectEmpty(page.value));
const vAlt = {
mounted : (el) => {
const images = el.querySelectorAll('img');
images.forEach((img) => {
const altText = img.getAttribute('alt');
if (altText) {
const paragraph = document.createElement('p');
paragraph.classList.add('caption');
paragraph.textContent = altText;
img.after(paragraph);
}
});
}
for (const key in obj) {
if (Object.hasOwnProperty.call(obj, key)) {
const value = obj[key];
if (Array.isArray(value)) {
if (value.length > 0) {
return false;
}
} else if (typeof value === 'object') {
if (!isObjectEmpty(value)) {
return false;
}
} else if (value !== null && value !== undefined && value !== '') {
return false;
};
const isModaleOpen = ref(false);
const currentImage = ref({ src: '', alt: '' });
const swiperPopupContent = ref([]);
const body = document.querySelector('body');
const hamburger = document.querySelector('#hamburger');
const menu = document.querySelector('#menu');
const openImageModale = (src, alt, swiperMedia) => {
currentImage.value = { src, alt };
swiperPopupContent.value = swiperMedia;
isModaleOpen.value = true;
body.classList.add('no-scroll');
hamburger.style.opacity = 0;
menu.style.display = "none";
};
const closeImageModale = () => {
isModaleOpen.value = false;
swiperPopupContent.value = [];
body.classList.remove('no-scroll');
menu.style.display = "flex";
setTimeout(() => {
hamburger.style.opacity = 1;
}, 300);
};
const handleImageClick = (event) => {
const img = event.target;
if (img.tagName === 'IMG') {
const isSwiper = img.parentElement.parentElement.tagName === 'SWIPER-SLIDE';
let swiperMedia = [];
if (isSwiper) {
const swiperEl = img.parentElement.parentElement.parentElement;
for (let swiperSlide of swiperEl.children) {
swiperMedia.push({src: swiperSlide.querySelector('img').getAttribute('src'), alt: swiperSlide.querySelector('figcaption')?.textContent});
}
}
openImageModale(img.src, img.alt, swiperMedia);
}
return true;
}
};
</script>
/*
return {
loading,
error,
etape,
page,
isEtapeValid,
isPageValid
};
*/
</script>
<style>
<style scss>
.v-enter-active,
.v-leave-active {
transition: all 0.3s ease;
@@ -145,4 +306,23 @@ function isObjectEmpty(obj) {
transform: translateY(0%);
opacity: 1;
}
:root {
--swiper-navigation-color: #1a1918; /* cf main.scss */
--swiper-pagination-color: var(--etape-couleur);
--swiper-navigation-top-offset: calc(100% - 1.5rem);
--swiper-navigation-sides-offset: 5vw; /* cf main.scss */
}
.diaporama {
--swiper-navigation-size: 1.5rem;
}
swiper-slide img:not(.popup-img) { /* cf main.scss */
cursor: pointer;
transition: transform 0.3s ease-out;
&:hover {
transform: scale(1.01);
}
}
</style>