avancées centre de ressource
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import REST from '../api/rest-axios';
|
||||
|
||||
import { useLayoutStore } from './layout';
|
||||
|
||||
import { findContentByPath } from '../utils/content/findContentByPath';
|
||||
import { getCleanDate, fetchFromRelationships, getRelatedEtape } from '../utils/content/contentFetchUtils';
|
||||
import { getCarteSensible, getTitreTexte, getChiffresCles, getDiaporama, getEntretien, getVideos } from '../utils/content/cleanParties';
|
||||
import { getCarteSensible, getTitreTexte, getChiffresCles, getDiaporama, getEntretien, getVideos, getDocument, getGallerie } from '../utils/content/cleanParties';
|
||||
import { getPartenaires, getGouvernance, getRessources } from '../utils/content/multiItemPages';
|
||||
|
||||
export const useContentStore = defineStore('content', {
|
||||
@@ -24,39 +26,44 @@ export const useContentStore = defineStore('content', {
|
||||
const { contentType, rawContent } = await findContentByPath(contentTypes, path);
|
||||
this.contentType = contentType;
|
||||
|
||||
if (this.contentType === 'etape' || this.contentType === 'static') {
|
||||
if (
|
||||
this.contentType === 'etape'
|
||||
|| this.contentType === 'static'
|
||||
|| this.contentType === 'ressourceItem'
|
||||
) {
|
||||
const vignettePromise = fetchFromRelationships('field_vignette', rawContent.relationships);
|
||||
const partiesPromise = fetchFromRelationships('field_parties', rawContent.relationships);
|
||||
const partiesPromise = fetchFromRelationships(this.contentType === 'ressourceItem' ? 'field_parties_ressource' : 'field_parties', rawContent.relationships);
|
||||
|
||||
let previousEtapePromise, nextEtapePromise;
|
||||
|
||||
if (contentType === 'etape') {
|
||||
// related étapes
|
||||
|
||||
if (this.contentType === 'etape') {
|
||||
previousEtapePromise = getRelatedEtape('previous', path);
|
||||
nextEtapePromise = getRelatedEtape('next', path);
|
||||
|
||||
// coordinates
|
||||
this.content.coordinates = {
|
||||
lat: rawContent.attributes.field_geofield.lat,
|
||||
lon: rawContent.attributes.field_geofield.lon,
|
||||
};
|
||||
// adresse
|
||||
this.content.adresse = rawContent.attributes.field_adresse;
|
||||
// étape number
|
||||
this.content.etape_number = rawContent.attributes.field_arret_numero;
|
||||
// couleur
|
||||
this.content.couleur = rawContent.attributes.field_couleur;
|
||||
// dates
|
||||
this.content.dates = {
|
||||
start: getCleanDate(rawContent.attributes.field_dates.value),
|
||||
end: getCleanDate(rawContent.attributes.field_dates.end_value),
|
||||
}
|
||||
}
|
||||
|
||||
if (this.contentType === 'ressourceItem') {
|
||||
this.content.ressourceType = rawContent.attributes.field_type_de_ressource;
|
||||
this.content.auteurice = rawContent.attributes.field_autheurice;
|
||||
this.content.date = getCleanDate(rawContent.attributes.field_date_ressource);
|
||||
this.content.introduction = rawContent.attributes.field_introduction?.processed;
|
||||
|
||||
useLayoutStore().hideEtapeList(true);
|
||||
}
|
||||
|
||||
// pageTitle
|
||||
this.pageTitle = rawContent.attributes.metatag.find(tag => tag.tag === "meta")?.attributes.content;
|
||||
|
||||
// contentTitle
|
||||
this.content.contentTitle = rawContent.attributes.title;
|
||||
|
||||
const [vignetteData, partiesData] = await Promise.all([vignettePromise, partiesPromise]);
|
||||
@@ -76,7 +83,7 @@ export const useContentStore = defineStore('content', {
|
||||
if (partiesData) {
|
||||
const partiesPromises = partiesData.map(async (partie) => {
|
||||
const partieType = partie.type.replace(/^paragraph--/, "");
|
||||
let partieContent = { type: partieType };
|
||||
let partieContent = { type: partieType };
|
||||
|
||||
switch (partieType) {
|
||||
case 'carte_sensible':
|
||||
@@ -102,10 +109,41 @@ export const useContentStore = defineStore('content', {
|
||||
case 'video':
|
||||
partieContent.videos = getVideos(partie);
|
||||
break;
|
||||
case 'document':
|
||||
partieContent.document = await getDocument(partie);
|
||||
break;
|
||||
case 'galleries':
|
||||
partieContent.gallerie = await getGallerie(partie);
|
||||
break;
|
||||
}
|
||||
return partieContent;
|
||||
});
|
||||
|
||||
// liens
|
||||
if (rawContent.attributes.field_liens?.length) {
|
||||
this.content.liens = [];
|
||||
for (let lien of rawContent.attributes.field_liens) {
|
||||
this.content.liens.push({
|
||||
title: lien.title,
|
||||
url: lien.uri,
|
||||
});
|
||||
}
|
||||
}
|
||||
// pièces jointes
|
||||
if (rawContent.relationships.field_pieces_jointes?.data.length) {
|
||||
this.content.pieces_jointes = [];
|
||||
for (let pieceJointe of rawContent.relationships.field_pieces_jointes.data) {
|
||||
if (pieceJointe.meta.display) {
|
||||
const uuid = pieceJointe.id;
|
||||
const response = await REST.get(`/jsonapi/file/file/${uuid}`);
|
||||
this.content.pieces_jointes.push({
|
||||
title: pieceJointe.meta.description,
|
||||
url: response.data.data.attributes.uri.url,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.content.parties = await Promise.all(partiesPromises);
|
||||
}
|
||||
|
||||
@@ -132,6 +170,8 @@ export const useContentStore = defineStore('content', {
|
||||
switch (this.contentType) {
|
||||
case 'ressource':
|
||||
multiItemPageArray = await getRessources(rawContent);
|
||||
this.content.ressourceTypes = new Set(multiItemPageArray.map(item => item.ressourceType));
|
||||
useLayoutStore().hideEtapeList(true);
|
||||
break;
|
||||
case 'partenaire':
|
||||
multiItemPageArray = await getPartenaires(rawContent);
|
||||
@@ -142,7 +182,6 @@ export const useContentStore = defineStore('content', {
|
||||
}
|
||||
|
||||
this.content[`${this.contentType}s`] = multiItemPageArray;
|
||||
console.log(this.content);
|
||||
}
|
||||
} catch (error) {
|
||||
this.error = 'Failed to fetch data';
|
||||
@@ -157,6 +196,7 @@ export const useContentStore = defineStore('content', {
|
||||
this.content = {};
|
||||
this.loading = !forFrontDisplay;
|
||||
this.error = null;
|
||||
useLayoutStore().hideEtapeList(false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@@ -46,6 +46,23 @@ export const useLayoutStore = defineStore('layout', {
|
||||
|
||||
this.toggleEtapeListScroll(isIntersecting, listeEtape, column, headerRect.height, animationToggleRect.top);
|
||||
},
|
||||
hideEtapeList(souldListHide) {
|
||||
const etapeList = document.querySelector('#etapes-liste');
|
||||
const listContainer = etapeList.parentNode;
|
||||
if (souldListHide) {
|
||||
listContainer.style.minWidth = '30vw';
|
||||
etapeList.style.opacity = '0';
|
||||
setTimeout(() => {
|
||||
etapeList.style.display = 'none';
|
||||
}, 300);
|
||||
} else {
|
||||
listContainer.style.minWidth = 'unset';
|
||||
etapeList.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
etapeList.style.opacity = '1';
|
||||
}, 10);
|
||||
}
|
||||
},
|
||||
toggleEtapeListScroll(isIntersecting, listeEtape, column, headerHeight, animationToggleTop) {
|
||||
if (isIntersecting && !this.isEtapeListeScrollable
|
||||
|| !isIntersecting && this.isEtapeListeScrollable) {
|
||||
|
Reference in New Issue
Block a user