MODIFS CONFIGS : fetch ressources content
This commit is contained in:
@@ -4,58 +4,27 @@ import { defineStore } from 'pinia';
|
||||
import REST from '../api/rest-axios';
|
||||
|
||||
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 {
|
||||
getPartenaires,
|
||||
getGouvernance,
|
||||
} from '../utils/content/multiItemPages';
|
||||
import { getCleanDate, fetchFromRelationships, getRelatedEtape } from '../utils/content/contentFetchUtils';
|
||||
import { getCarteSensible, getTitreTexte, getChiffresCles, getDiaporama, getEntretien, getVideos } from '../utils/content/cleanParties';
|
||||
import { getPartenaires, getGouvernance, getRessources } from '../utils/content/multiItemPages';
|
||||
|
||||
export const useContentStore = defineStore('content', {
|
||||
state: () => ({
|
||||
contentType: '',
|
||||
pageTitle: '',
|
||||
content: {
|
||||
contentTitle: '',
|
||||
coordinates: {},
|
||||
adresse: {},
|
||||
etape_number: '',
|
||||
couleur: '',
|
||||
dates: {},
|
||||
previous: {},
|
||||
next: {},
|
||||
vignette: {},
|
||||
parties: [],
|
||||
liens: [],
|
||||
pieces_jointes: [],
|
||||
|
||||
intro: '',
|
||||
partenaires: [],
|
||||
gouvernances: [],
|
||||
},
|
||||
content: {},
|
||||
loading: false,
|
||||
error: null,
|
||||
}),
|
||||
actions: {
|
||||
async fetchContentData(path) {
|
||||
this.resetStore(false);
|
||||
const contentTypes = ['etape', 'static', 'gouvernance', 'partenaire'];
|
||||
const contentTypes = ['etape', 'static', 'gouvernance', 'partenaire', 'ressource'];
|
||||
try {
|
||||
const { contentType, rawContent } = await findContentByPath(contentTypes, path);
|
||||
this.contentType = contentType;
|
||||
|
||||
if (this.contentType !== 'gouvernance' && this.contentType !== 'partenaire') {
|
||||
if (this.contentType === 'etape' || this.contentType === 'static') {
|
||||
const vignettePromise = fetchFromRelationships('field_vignette', rawContent.relationships);
|
||||
const partiesPromise = fetchFromRelationships('field_parties', rawContent.relationships);
|
||||
|
||||
@@ -85,12 +54,7 @@ export const useContentStore = defineStore('content', {
|
||||
}
|
||||
|
||||
// pageTitle
|
||||
for (let tag of rawContent.attributes.metatag) {
|
||||
if (tag.tag === "meta") {
|
||||
this.pageTitle = tag.attributes.content;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.pageTitle = rawContent.attributes.metatag.find(tag => tag.tag === "meta")?.attributes.content;
|
||||
|
||||
// contentTitle
|
||||
this.content.contentTitle = rawContent.attributes.title;
|
||||
@@ -152,26 +116,33 @@ export const useContentStore = defineStore('content', {
|
||||
this.content.next = nextContent;
|
||||
}
|
||||
} else {
|
||||
// pages gouvernance (contact) et partenaire
|
||||
// ont plusieurs items par pages
|
||||
// pages gouvernance (contact), ressources et partenaire
|
||||
// ont plusieurs items par pages
|
||||
const intro = await REST.get(`/jsonapi/config_pages/intro_${this.contentType}/`);
|
||||
const introContent = intro.data.data[0];
|
||||
|
||||
this.pageTitle =
|
||||
`${introContent.attributes.field_titre} ${introContent.attributes.metatag.find(tag => tag.tag === "meta")?.attributes.content}`;
|
||||
`${introContent.attributes.field_titre} ${introContent.attributes.metatag.find(tag => tag.tag === "meta")?.attributes.content}`;
|
||||
|
||||
this.content.contentTitle = introContent.attributes.field_titre;
|
||||
this.content.intro = introContent.attributes.field_intro?.value;
|
||||
|
||||
let multiItemPageArray = [];
|
||||
let multiItemPageArray = [];
|
||||
|
||||
if (this.contentType === 'partenaire') {
|
||||
multiItemPageArray = await getPartenaires(rawContent);
|
||||
} else if (this.contentType === 'gouvernance') {
|
||||
multiItemPageArray = await getGouvernance(rawContent);
|
||||
switch (this.contentType) {
|
||||
case 'ressource':
|
||||
multiItemPageArray = await getRessources(rawContent);
|
||||
break;
|
||||
case 'partenaire':
|
||||
multiItemPageArray = await getPartenaires(rawContent);
|
||||
break;
|
||||
case 'gouvernance':
|
||||
multiItemPageArray = await getGouvernance(rawContent);
|
||||
break;
|
||||
}
|
||||
|
||||
this.content[`${this.contentType}s`] = multiItemPageArray;
|
||||
console.log(this.content);
|
||||
}
|
||||
} catch (error) {
|
||||
this.error = 'Failed to fetch data';
|
||||
|
Reference in New Issue
Block a user