2020-12-25 17:37:15 +01:00
|
|
|
<template>
|
|
|
|
<div class="loading" v-if="!thematique || loading">
|
|
|
|
<span>Loading ...</span>
|
|
|
|
</div>
|
|
|
|
<article class="thematique" v-else>
|
|
|
|
<div class="cols">
|
|
|
|
<div class="col col-left">
|
|
|
|
<section class="body" v-html="thematique.body"></section>
|
2021-03-05 11:44:54 +01:00
|
|
|
<section class="visuel">
|
2021-03-06 16:46:19 +01:00
|
|
|
<img :src="image_accroche.style_cardfull_url" alt="">
|
2021-03-05 11:44:54 +01:00
|
|
|
</section>
|
2020-12-25 17:37:15 +01:00
|
|
|
</div> <!-- //col-left -->
|
|
|
|
<div class="col col-right">
|
|
|
|
<aside class="linked-materials">
|
|
|
|
<div class="card-list">
|
|
|
|
<ul class="">
|
|
|
|
<li v-for="node in thematique.linked_materials" v-bind:key="node.id">
|
|
|
|
<Card :item="node" />
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</aside>
|
|
|
|
</div> <!-- // col-right -->
|
|
|
|
</div> <!-- // cols -->
|
|
|
|
</article>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import router from 'vuejs/route'
|
|
|
|
import store from 'vuejs/store'
|
|
|
|
|
|
|
|
// import { JSONAPI } from 'vuejs/api/json-axios'
|
|
|
|
import { REST } from 'vuejs/api/rest-axios'
|
|
|
|
import { MGQ } from 'vuejs/api/graphql-axios'
|
|
|
|
import { print } from 'graphql/language/printer'
|
|
|
|
import gql from 'graphql-tag'
|
|
|
|
// import materiauFields from 'vuejs/api/gql/materiau.fragment.gql'
|
|
|
|
import thematiqueFields from 'vuejs/api/gql/thematique.fragment.gql'
|
|
|
|
|
|
|
|
// import qs from 'querystring-es3'
|
|
|
|
import Card from 'vuejs/components/Content/Card'
|
|
|
|
|
|
|
|
import { mapState, mapActions } from 'vuex'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "Thematique",
|
|
|
|
router,
|
|
|
|
store,
|
|
|
|
data(){
|
|
|
|
return {
|
|
|
|
nid:null,
|
|
|
|
path: null,
|
|
|
|
thematique:{},
|
|
|
|
image_accroche: null,
|
|
|
|
loading:true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
metaInfo () {
|
|
|
|
return {
|
|
|
|
title: this.thematique.title
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// computed: {
|
|
|
|
// ...mapState({
|
|
|
|
// items: state => state.Blabla.items
|
|
|
|
// })
|
|
|
|
// },
|
|
|
|
created(){
|
|
|
|
this.getThematique()
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
// ...mapActions({
|
|
|
|
// getItems: 'Blabla/getItems',
|
|
|
|
// getItemIndex: 'Blabla/getItemIndex',
|
|
|
|
// getPrevNextItems: 'Blabla/getPrevNextItems'
|
|
|
|
// }),
|
|
|
|
getThematique(){
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('getThematique', this.$route)
|
2021-03-06 16:46:19 +01:00
|
|
|
if (this.$route.params.id) {
|
2020-12-25 17:37:15 +01:00
|
|
|
// we come from internal link with vuejs
|
2021-03-06 16:46:19 +01:00
|
|
|
// using path to load from route is hasardous
|
|
|
|
// this.path = this.$route.path
|
|
|
|
this.id = this.$route.params.id
|
2021-03-31 18:42:05 +02:00
|
|
|
} else if (drupalDecoupled.entity_type == 'node' && drupalDecoupled.entity_bundle == 'thematique') {
|
2020-12-25 17:37:15 +01:00
|
|
|
// we landed in an internal page
|
2021-03-06 16:46:19 +01:00
|
|
|
// get the id from drupalDeclouped, provided by materio_decoupled.module
|
|
|
|
this.id = drupalDecoupled.entity_id
|
2020-12-25 17:37:15 +01:00
|
|
|
}
|
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
if (this.id) {
|
2020-12-25 17:37:15 +01:00
|
|
|
this.loadThematique()
|
2021-03-31 18:42:05 +02:00
|
|
|
} else {
|
2021-03-06 16:46:19 +01:00
|
|
|
// if for any reason we dont have the id redirect to home
|
|
|
|
this.$router.replace({name:'home'})
|
2020-12-25 17:37:15 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
loadThematique(){
|
|
|
|
console.log('loadThematique')
|
|
|
|
this.loading = true
|
2021-03-06 16:46:19 +01:00
|
|
|
//
|
2021-03-31 18:42:05 +02:00
|
|
|
const ast = gql`{
|
2021-03-06 16:46:19 +01:00
|
|
|
thematique(id: ${this.id}, lang: "${drupalDecoupled.lang_code}") {
|
2020-12-25 17:37:15 +01:00
|
|
|
...ThematiqueFields
|
|
|
|
}
|
|
|
|
}
|
2021-03-31 18:42:05 +02:00
|
|
|
${thematiqueFields}
|
2020-12-25 17:37:15 +01:00
|
|
|
`
|
2021-03-06 16:46:19 +01:00
|
|
|
// ?XDEBUG_SESSION_START=1
|
2020-12-25 17:37:15 +01:00
|
|
|
MGQ.post('', { query: print(ast)
|
|
|
|
})
|
2021-03-06 16:46:19 +01:00
|
|
|
.then(({ data:{data:{thematique}}}) => {
|
|
|
|
console.log('loaded Thematique', thematique)
|
|
|
|
this.parseDataGQL(thematique)
|
2020-12-25 17:37:15 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.warn('Issue with loadThematique', error)
|
|
|
|
Promise.reject(error)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
parseDataGQL(thematique){
|
|
|
|
console.log('parseDataGQL thematique', thematique)
|
2021-03-05 11:44:54 +01:00
|
|
|
if (thematique) {
|
|
|
|
this.thematique = thematique
|
2020-12-25 17:37:15 +01:00
|
|
|
|
2021-03-05 11:44:54 +01:00
|
|
|
if (thematique.images) {
|
|
|
|
this.image_accroche = thematique.images[0]
|
|
|
|
}
|
2020-12-25 17:37:15 +01:00
|
|
|
|
2021-03-05 11:44:54 +01:00
|
|
|
// update main page title
|
|
|
|
this.$store.commit('Common/setPagetitle', thematique.title)
|
2020-12-25 17:37:15 +01:00
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
} else {
|
2021-03-05 11:44:54 +01:00
|
|
|
console.warn('Thematique not loaded');
|
|
|
|
}
|
2020-12-25 17:37:15 +01:00
|
|
|
this.loading = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
Card
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'$route' (to, from) {
|
|
|
|
console.log('route change')
|
|
|
|
this.getThematique()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|