MODIFS CONFIGS : fetch ressources content

This commit is contained in:
Valentin Le Moign 2025-03-11 23:53:31 +01:00
parent 2ca44f2550
commit 9093caa557
24 changed files with 281 additions and 164 deletions

View File

@ -1,4 +1,4 @@
uuid: b0c240c8-beea-4be3-96b8-6543b6734b25
uuid: 39f683b9-ea9f-4e84-8dec-c30162c19b72
langcode: fr
status: true
dependencies: { }
@ -12,6 +12,6 @@ context:
fallback:
language: ''
menu:
path: /edit/partenaire
path: /edit/partenaires
weight: 0
description: ''

View File

@ -1,9 +1,9 @@
uuid: 86c7ea1e-a93e-4ddf-9887-e1f302a99ea9
uuid: 67828fd5-674e-4e52-9f2f-3457e06c0baa
langcode: fr
status: true
dependencies: { }
id: intro_partenaires
label: 'Intro partenaires'
id: intro_ressource
label: 'intro ressource'
token: false
context:
show_warning: true
@ -12,6 +12,6 @@ context:
fallback:
language: ''
menu:
path: /edit/partenaires
path: /edit/ressource
weight: 0
description: ''

View File

@ -1,4 +1,4 @@
uuid: c8c782e1-e597-4e4d-ac96-65142dbadedb
uuid: 3d095235-90fe-4b5f-ae32-ef10c26c1f47
langcode: fr
status: true
dependencies:

View File

@ -1,24 +0,0 @@
uuid: 03e534f2-ceae-4f84-89f2-a0f9997f8a9d
langcode: fr
status: true
dependencies:
config:
- config_pages.type.intro_partenaires
- field.field.config_pages.intro_partenaires.field_intro
module:
- text
id: config_pages.intro_partenaires.default
targetEntityType: config_pages
bundle: intro_partenaires
mode: default
content:
field_intro:
type: text_textarea
weight: 0
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
hidden:
label: true

View File

@ -0,0 +1,33 @@
uuid: c5c09811-6a65-4cff-9936-78dc896b9adf
langcode: fr
status: true
dependencies:
config:
- config_pages.type.intro_ressource
- field.field.config_pages.intro_ressource.field_intro
- field.field.config_pages.intro_ressource.field_titre
module:
- text
id: config_pages.intro_ressource.default
targetEntityType: config_pages
bundle: intro_ressource
mode: default
content:
field_intro:
type: text_textarea
weight: 1
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
field_titre:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
hidden:
label: true

View File

@ -112,7 +112,7 @@ content:
third_party_settings: { }
field_etape:
type: entity_reference_autocomplete
weight: 5
weight: 28
region: content
settings:
match_operator: CONTAINS
@ -148,7 +148,7 @@ content:
third_party_settings: { }
field_thematiques:
type: autocomplete_deluxe
weight: 4
weight: 27
region: content
settings:
match_operator: CONTAINS
@ -164,24 +164,20 @@ content:
no_empty_message: 'No terms could be found. Please type in order to add a new term.'
third_party_settings: { }
field_type_de_ressource:
type: entity_reference_autocomplete
weight: 3
type: options_select
weight: 26
region: content
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
settings: { }
third_party_settings: { }
path:
type: path
weight: 7
weight: 30
region: content
settings: { }
third_party_settings: { }
status:
type: boolean_checkbox
weight: 6
weight: 29
region: content
settings:
display_label: true

View File

@ -1,4 +1,4 @@
uuid: a79b589c-3286-425b-b508-38744f9ebeb1
uuid: cad2e853-7706-4477-a3cc-d810dcd76c96
langcode: fr
status: true
dependencies:
@ -18,7 +18,7 @@ content:
label: visually_hidden
settings: { }
third_party_settings: { }
weight: 1
weight: 0
region: content
field_titre:
type: string
@ -26,7 +26,7 @@ content:
settings:
link_to_entity: false
third_party_settings: { }
weight: 0
weight: 1
region: content
hidden:
search_api_excerpt: true

View File

@ -1,23 +0,0 @@
uuid: ac925def-bc83-4add-a5c9-88bc02e771b5
langcode: fr
status: true
dependencies:
config:
- config_pages.type.intro_partenaires
- field.field.config_pages.intro_partenaires.field_intro
module:
- text
id: config_pages.intro_partenaires.default
targetEntityType: config_pages
bundle: intro_partenaires
mode: default
content:
field_intro:
type: text_default
label: visually_hidden
settings: { }
third_party_settings: { }
weight: 0
region: content
hidden:
search_api_excerpt: true

View File

@ -0,0 +1,32 @@
uuid: 342c8cdf-4085-4e41-941f-b503beb0ad1f
langcode: fr
status: true
dependencies:
config:
- config_pages.type.intro_ressource
- field.field.config_pages.intro_ressource.field_intro
- field.field.config_pages.intro_ressource.field_titre
module:
- text
id: config_pages.intro_ressource.default
targetEntityType: config_pages
bundle: intro_ressource
mode: default
content:
field_intro:
type: text_default
label: visually_hidden
settings: { }
third_party_settings: { }
weight: 0
region: content
field_titre:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 0
region: content
hidden:
search_api_excerpt: true

View File

@ -14,6 +14,7 @@ dependencies:
module:
- datetime
- entity_reference_revisions
- options
- text
- user
id: node.ressource.default
@ -71,12 +72,11 @@ content:
weight: 4
region: content
field_type_de_ressource:
type: entity_reference_label
type: list_default
label: above
settings:
link: true
settings: { }
third_party_settings: { }
weight: 102
weight: 108
region: content
links:
settings: { }

View File

@ -1,4 +1,4 @@
uuid: 3035b470-e4d9-4807-acd6-24a09525f537
uuid: 884f84e5-faeb-4719-a083-32cb215fd311
langcode: fr
status: true
dependencies:

View File

@ -1,4 +1,4 @@
uuid: bbddf173-169d-4977-ba3f-d1ec9f5aa452
uuid: 00096414-fab5-4bed-ac99-b819ad041ed9
langcode: fr
status: true
dependencies:

View File

@ -1,17 +1,17 @@
uuid: 52fa2fc6-d3ca-4fef-b91b-06be4145e8e3
uuid: e669e2a0-7ad6-4744-9bcf-efd428aa8070
langcode: fr
status: true
dependencies:
config:
- config_pages.type.intro_partenaires
- config_pages.type.intro_ressource
- field.storage.config_pages.field_intro
- filter.format.wysiwyg
module:
- text
id: config_pages.intro_partenaires.field_intro
id: config_pages.intro_ressource.field_intro
field_name: field_intro
entity_type: config_pages
bundle: intro_partenaires
bundle: intro_ressource
label: Intro
description: ''
required: false

View File

@ -0,0 +1,19 @@
uuid: 1a5ca231-32de-4adc-b066-22a8377bf323
langcode: fr
status: true
dependencies:
config:
- config_pages.type.intro_ressource
- field.storage.config_pages.field_titre
id: config_pages.intro_ressource.field_titre
field_name: field_titre
entity_type: config_pages
bundle: intro_ressource
label: titre
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string

View File

@ -9,7 +9,7 @@ id: node.ressource.field_autheurice
field_name: field_autheurice
entity_type: node
bundle: ressource
label: Autheur⋅ice
label: Auteur⋅ice
description: ''
required: false
translatable: false

View File

@ -1,29 +1,21 @@
uuid: 2c08a730-15f1-48fb-99b5-9b3abb866321
uuid: 0c898a0a-a009-4b3f-9abe-e6e4f5feb1e7
langcode: fr
status: true
dependencies:
config:
- field.storage.node.field_type_de_ressource
- node.type.ressource
- taxonomy.vocabulary.type_de_ressource
module:
- options
id: node.ressource.field_type_de_ressource
field_name: field_type_de_ressource
entity_type: node
bundle: ressource
label: 'Type de ressource'
description: ''
required: false
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
type_de_ressource: type_de_ressource
sort:
field: name
direction: asc
auto_create: false
auto_create_bundle: ''
field_type: entity_reference
settings: { }
field_type: list_string

View File

@ -1,17 +1,30 @@
uuid: 9dedf9d1-5a9a-4c71-9896-4d4f2b2b5387
uuid: f76ffe60-78f6-44ef-8171-f7b2d04f8881
langcode: fr
status: true
dependencies:
module:
- node
- taxonomy
- options
id: node.field_type_de_ressource
field_name: field_type_de_ressource
entity_type: node
type: entity_reference
type: list_string
settings:
target_type: taxonomy_term
module: core
allowed_values:
-
value: cartes_blanches
label: 'Cartes Blanches'
-
value: reportages
label: Reportages
-
value: videos
label: Vidéos
-
value: documents
label: Documents
allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true

View File

@ -20,4 +20,5 @@ permissions:
- 'restful get rest_menu_item'
- 'view intro_gouvernance config page entity'
- 'view intro_partenaire config page entity'
- 'view intro_ressource config page entity'
- 'view media'

View File

@ -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';

View File

@ -17,8 +17,8 @@ export async function findContentByPath(contentTypes, path) {
};
}
// Handle special case for governance/partners (multiple items per page)
const pageRequested = window.location.href.split('/').pop().replace(/s?$/, '');
// Handle special case for gouvernance, ressources, partenaires (multiple items per page)
let pageRequested = window.location.href.split('/').pop().replace(/s?$/, '');
if (type === pageRequested
|| (type === 'gouvernance' && pageRequested === 'contact')
) {

View File

@ -1,4 +1,5 @@
import REST from '../../api/rest-axios';
import { getCleanDate } from './contentFetchUtils';
export async function getPartenaires(rawContent) {
const logoPromises = rawContent.map(item =>
@ -51,4 +52,79 @@ export async function getGouvernance(rawContent) {
);
return await Promise.all(itemPromises);
}
export async function getRessources(rawContent) {
const ressourcesPromises = rawContent.map(item =>
REST.get(item.links.self.href)
.then(async ressourceFetch => {
const partiesPromises = REST.get(item.relationships.field_parties_ressource.links.related.href)
.then(async partiesFetch => {
const parties = partiesFetch.data.data;
const vignettePartie = parties.find(parties => parties.type !== "paragraph--titre_texte");
if (vignettePartie) {
let vignettePromise;
let alt;
switch (vignettePartie.type) {
case 'paragraph--diaporama':
alt = vignettePartie.relationships.field_diaporama.data[0].meta.alt;
vignettePromise = REST.get(vignettePartie.relationships.field_diaporama.links.related.href)
.then(diaporamaFetch => {
return {
url: diaporamaFetch.data.data[0].attributes.image_style_uri.content_small,
alt
}
});
break;
case 'paragraph--video':
const videoId = vignettePartie.attributes.field_videos[0].split('?v=')[1];
vignettePromise = {
url: `https://img.youtube.com/vi/${videoId}/0.jpg`,
alt: item.attributes.title
}
break;
case 'paragraph--galleries':
vignettePromise = REST.get(vignettePartie.relationships.field_gallerie.links.related.href)
.then(gallerieFetch => {
alt = gallerieFetch.data.data.relationships.field_images.data[0].meta.alt;
const galleriePromise = REST.get(gallerieFetch.data.data.relationships.field_images.links.related.href)
.then(gallerieImageFetch => {
return {
url: gallerieImageFetch.data.data[0].attributes.image_style_uri.content_small,
alt
}
});
return galleriePromise;
});
break;
case 'paragraph--document':
alt = vignettePartie.relationships.field_vignette.data.meta.alt;
vignettePromise = REST.get(vignettePartie.relationships.field_vignette.links.related.href)
.then(documentFetch => {
return {
url: documentFetch.data.data.attributes.image_style_uri.content_small,
alt
}
});
break;
default:
vignettePromise = Promise.resolve(null);
}
return vignettePromise;
}
});
return partiesPromises.then(vignette => ({
ressourceType: item.attributes.field_type_de_ressource,
title: item.attributes.title,
auteurice: item.attributes.field_autheurice,
date: getCleanDate(item.attributes.field_date_ressource),
url: ressourceFetch.data.data.attributes.metatag.find(tag => tag.tag === "link")?.attributes.href,
vignette
}));
})
);
return await Promise.all(ressourcesPromises);
}

View File

@ -3,12 +3,7 @@
:enter-active-class="animationsAreEnabled ? 'v-enter-active' : 'no-transition'"
:leave-active-class="animationsAreEnabled ? 'v-leave-active' : 'no-transition'"
>
<div v-if="!loading && (
contentType === 'etape'
|| contentType === 'static'
|| contentType === 'gouvernance'
|| contentType === 'partenaire'
)">
<div v-if="!loading && contentType != ''">
<div class="content-wrapper">
<ModaleHeader
:contentType="contentType"
@ -46,20 +41,22 @@
<EquipeContent
v-if="contentType === 'gouvernance'"
:content="content"
:couleur="content.couleur || brandColor" />
:couleur="brandColor" />
<PartenairesContent
v-if="contentType === 'partenaire'"
:content="content" />
<CentreDeRessource
v-if="contentType === 'ressource'"
:content="content"
:couleur="brandColor" />
</main>
<PiecesJointes
:content="content"
:couleur="content.couleur || brandColor"
/>
:couleur="content.couleur || brandColor" />
<ModaleFooter
:contentType="contentType"
:content="content"
:couleur="content.couleur || brandColor"
/>
:contentType="contentType"
:content="content"
:couleur="content.couleur || brandColor" />
</div>
</div>
</Transition>
@ -76,6 +73,7 @@ import ModaleHeader from './components/ModaleHeader.vue';
import ModaleFooter from './components/ModaleFooter.vue';
import EquipeContent from './components/EquipeContent.vue';
import PartenairesContent from './components/PartenairesContent.vue';
import CentreDeRessource from './components/CentreDeRessource.vue';
import PiecesJointes from './components/PiecesJointes.vue';
import ModaleCarteSensible from './components/parties/ModaleCarteSensible.vue';

View File

@ -0,0 +1,14 @@
<template>
<div id="centre-de-ressource">
<div v-if="content.intro" class="intro">
<p v-html="content.intro"></p>
</div>
</div>
</template>
<script setup>
const props = defineProps({
content: Object,
couleur: String,
});
</script>

View File

@ -773,6 +773,22 @@ body{
font-size: $labeur-font-size-desktop;
width: $modale-width-desktop;
}
&:has(#centre-de-ressource) {
@media screen and (min-width: $tablet-min-width) {
left: 8vw;
width: 84vw;
.locality-title {
width: 42vw;
margin-left: 21vw;
}
}
@media screen and (min-width: $desktop-min-width) {
.locality-title {
width: 30vw;
margin-left: 27vw;
}
}
}
img {
width: 100%;
height: auto;
@ -1157,6 +1173,9 @@ body{
margin-top: 10vh;
}
}
#centre-de-ressource {
background-color: red;
}
}
> .pieces-jointes {
z-index: 1;