2019-07-13 15:40:14 +02:00
|
|
|
<template>
|
2020-12-22 16:36:06 +01:00
|
|
|
<div class="loading" v-if="!article || loading">
|
2021-06-01 22:46:15 +02:00
|
|
|
<span>{{ $t('default.Loading…') }}</span>
|
2019-07-14 15:21:04 +02:00
|
|
|
</div>
|
|
|
|
<article class="article" v-else>
|
2019-07-25 21:23:23 +02:00
|
|
|
<nav class="prevnext top">
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
v-if="prevnext.prev"
|
2020-12-24 19:05:45 +01:00
|
|
|
:href="prevnext.prev.view_node"
|
2019-07-25 21:23:23 +02:00
|
|
|
v-html="prevnext.prev.title"
|
2021-03-08 15:01:09 +01:00
|
|
|
@click.prevent="onPrevNext(prevnext.prev)"
|
2019-07-25 21:23:23 +02:00
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
v-if="prevnext.next"
|
2020-12-24 19:05:45 +01:00
|
|
|
:href="prevnext.next.view_node"
|
2019-07-25 21:23:23 +02:00
|
|
|
v-html="prevnext.next.title"
|
2021-03-08 15:01:09 +01:00
|
|
|
@click.prevent="onPrevNext(prevnext.next)"
|
2019-07-25 21:23:23 +02:00
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
2020-02-20 10:36:49 +01:00
|
|
|
<div class="cols">
|
|
|
|
<div class="col col-left">
|
2020-12-22 16:36:06 +01:00
|
|
|
<section v-if="image_accroche" class="accroche">
|
2020-02-20 10:36:49 +01:00
|
|
|
<figure>
|
|
|
|
<img
|
2020-12-22 16:36:06 +01:00
|
|
|
:src="image_accroche.url"
|
|
|
|
:alt="image_accroche.alt"
|
|
|
|
:title="image_accroche.title"
|
|
|
|
@click="setLightboxIndex(0)"
|
2020-02-19 17:59:26 +01:00
|
|
|
/>
|
2020-02-20 10:36:49 +01:00
|
|
|
</figure>
|
|
|
|
</section>
|
2021-08-02 21:53:08 +02:00
|
|
|
<!-- <section class="taxonomy">
|
2020-02-20 10:36:49 +01:00
|
|
|
<div class="thesaurus">
|
|
|
|
<ul>
|
|
|
|
<li
|
2020-12-22 16:36:06 +01:00
|
|
|
v-for="term in article.thesaurus" v-bind:key="term.id"
|
2020-02-20 10:36:49 +01:00
|
|
|
>{{ term.name }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="tags">
|
|
|
|
<ul>
|
|
|
|
<li
|
2020-12-22 16:36:06 +01:00
|
|
|
v-for="term in article.tags" v-bind:key="term.id"
|
2020-02-20 10:36:49 +01:00
|
|
|
>{{ term.name }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2021-08-02 21:53:08 +02:00
|
|
|
</section> -->
|
2020-12-22 16:36:06 +01:00
|
|
|
<section v-if="article.showroom" class="showroom">
|
|
|
|
<h2>{{ article.showroom.name }}</h2>
|
|
|
|
<a class="mail" :href="'mail:'+article.showroom.field_public_email">
|
|
|
|
{{ article.showroom.field_public_email }}</a>
|
2020-02-20 12:57:35 +01:00
|
|
|
<br/>
|
2020-12-22 16:36:06 +01:00
|
|
|
<a class="phone" :href="'tel:' + article.showroom.field_public_phone">
|
|
|
|
{{ article.showroom.field_public_phone }}</a>
|
2020-02-20 12:57:35 +01:00
|
|
|
</section>
|
2020-02-20 10:36:49 +01:00
|
|
|
</div> <!-- //col-left -->
|
|
|
|
<div class="col col-right">
|
2020-12-22 16:36:06 +01:00
|
|
|
<section class="body" v-html="article.body"></section>
|
2020-02-20 12:12:35 +01:00
|
|
|
<CoolLightBox
|
2020-12-22 16:36:06 +01:00
|
|
|
:items="lightbox_items"
|
2020-02-20 12:12:35 +01:00
|
|
|
:index="lightbox_index"
|
2020-12-07 23:11:31 +01:00
|
|
|
:loop="true"
|
2020-12-22 16:36:06 +01:00
|
|
|
srcName="url"
|
2020-02-20 12:12:35 +01:00
|
|
|
@close="lightbox_index = null">
|
|
|
|
</CoolLightBox>
|
|
|
|
<div class="gallery-wrapper">
|
|
|
|
<div
|
|
|
|
class="image"
|
2020-12-22 16:36:06 +01:00
|
|
|
v-for="(image, imageIndex) in lightbox_items"
|
|
|
|
v-if="imageIndex > 0"
|
2020-02-20 12:12:35 +01:00
|
|
|
:key="imageIndex"
|
|
|
|
@click="setLightboxIndex(imageIndex)"
|
|
|
|
:style="{ backgroundImage: 'url(' + image.thumb + ')' }"
|
|
|
|
></div>
|
|
|
|
</div>
|
|
|
|
<aside class="linked-materials">
|
2021-06-09 13:06:52 +02:00
|
|
|
<h3 class="field__label">{{ $t('materio.Linked Materials') }}</h3>
|
2021-03-30 16:43:56 +02:00
|
|
|
<div class="cards-list">
|
2020-02-20 12:12:35 +01:00
|
|
|
<ul class="">
|
2020-12-22 16:36:06 +01:00
|
|
|
<li v-for="node in article.linked_materials" v-bind:key="node.id">
|
2020-02-20 12:12:35 +01:00
|
|
|
<Card :item="node" />
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</aside>
|
2020-02-20 10:36:49 +01:00
|
|
|
</div> <!-- // col-right -->
|
|
|
|
</div> <!-- // cols -->
|
2019-07-25 21:23:23 +02:00
|
|
|
<nav class="prevnext bottom">
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
v-if="prevnext.prev"
|
2020-12-24 19:05:45 +01:00
|
|
|
:href="prevnext.prev.view_node"
|
2019-07-25 21:23:23 +02:00
|
|
|
v-html="prevnext.prev.title"
|
2021-03-08 15:01:09 +01:00
|
|
|
@click.prevent="onPrevNext(prevnext.prev)"
|
2019-07-25 21:23:23 +02:00
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
v-if="prevnext.next"
|
2020-12-24 19:05:45 +01:00
|
|
|
:href="prevnext.next.view_node"
|
2019-07-25 21:23:23 +02:00
|
|
|
v-html="prevnext.next.title"
|
2021-03-08 15:01:09 +01:00
|
|
|
@click.prevent="onPrevNext(prevnext.next)"
|
2019-07-25 21:23:23 +02:00
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
2019-07-13 15:40:14 +02:00
|
|
|
</article>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-07-14 15:21:04 +02:00
|
|
|
import router from 'vuejs/route'
|
2019-07-25 21:23:23 +02:00
|
|
|
import store from 'vuejs/store'
|
2020-12-10 22:46:27 +01:00
|
|
|
|
2021-09-16 21:40:18 +02:00
|
|
|
// import JSONAPI from 'vuejs/api/json-axios'
|
2022-03-08 14:30:49 +01:00
|
|
|
// import REST from 'vuejs/api/rest-axios'
|
2021-09-16 21:40:18 +02:00
|
|
|
import MGQ from 'vuejs/api/graphql-axios'
|
2020-12-10 22:46:27 +01:00
|
|
|
import { print } from 'graphql/language/printer'
|
|
|
|
import gql from 'graphql-tag'
|
2020-12-22 16:36:06 +01:00
|
|
|
// import materiauFields from 'vuejs/api/gql/materiau.fragment.gql'
|
|
|
|
import articleFields from 'vuejs/api/gql/article.fragment.gql'
|
2020-12-10 22:46:27 +01:00
|
|
|
|
2020-12-23 19:11:46 +01:00
|
|
|
// import qs from 'querystring-es3'
|
2019-07-25 21:23:23 +02:00
|
|
|
import Card from 'vuejs/components/Content/Card'
|
|
|
|
|
2019-07-14 17:12:18 +02:00
|
|
|
import { mapState, mapActions } from 'vuex'
|
2019-07-13 15:40:14 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "Article",
|
2019-07-14 15:21:04 +02:00
|
|
|
router,
|
2019-07-25 21:23:23 +02:00
|
|
|
store,
|
2019-07-14 15:21:04 +02:00
|
|
|
props: ['item'],
|
|
|
|
data(){
|
|
|
|
return {
|
2019-07-14 17:12:18 +02:00
|
|
|
index:-1,
|
|
|
|
prevnext:{},
|
2020-12-24 17:11:51 +01:00
|
|
|
nid:null,
|
|
|
|
path: null,
|
2020-12-24 19:05:45 +01:00
|
|
|
article:{},
|
2020-12-22 16:36:06 +01:00
|
|
|
image_accroche: null,
|
|
|
|
lightbox_items: null,
|
2019-07-25 21:23:23 +02:00
|
|
|
loading:true,
|
2020-02-20 12:12:35 +01:00
|
|
|
lightbox_index:null,
|
2019-07-14 15:21:04 +02:00
|
|
|
}
|
|
|
|
},
|
2020-12-24 19:05:45 +01:00
|
|
|
metaInfo () {
|
|
|
|
return {
|
|
|
|
title: this.article.title
|
|
|
|
}
|
|
|
|
},
|
2019-07-25 21:23:23 +02:00
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
items: state => state.Blabla.items
|
|
|
|
})
|
|
|
|
},
|
2019-07-14 15:21:04 +02:00
|
|
|
created(){
|
|
|
|
this.getArticle()
|
|
|
|
},
|
|
|
|
methods: {
|
2019-07-14 17:12:18 +02:00
|
|
|
...mapActions({
|
2019-07-25 21:23:23 +02:00
|
|
|
getItems: 'Blabla/getItems',
|
2019-07-14 17:12:18 +02:00
|
|
|
getItemIndex: 'Blabla/getItemIndex',
|
|
|
|
getPrevNextItems: 'Blabla/getPrevNextItems'
|
|
|
|
}),
|
2019-07-14 15:21:04 +02:00
|
|
|
getArticle(){
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('getArticle', this.$route)
|
2021-03-06 16:46:19 +01:00
|
|
|
if (this.$route.params.id) {
|
2019-07-14 16:29:17 +02: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 == 'article') {
|
2019-07-14 16:29:17 +02: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
|
2019-07-14 16:29:17 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
if (this.id) {
|
2019-07-14 15:21:04 +02:00
|
|
|
this.loadArticle()
|
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'})
|
2019-07-14 15:21:04 +02:00
|
|
|
}
|
|
|
|
},
|
2019-07-25 21:23:23 +02:00
|
|
|
getIndex(){
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log("Article getIndex article.id:", this.article.id)
|
2020-12-24 19:05:45 +01:00
|
|
|
this.getItemIndex(this.article.id).then((index) => {
|
2019-07-25 21:23:23 +02:00
|
|
|
this.index = index
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('article index', index, this)
|
2019-07-25 21:23:23 +02:00
|
|
|
this.getPrevNextItems(index).then((pn) => {
|
|
|
|
this.prevnext = pn
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2019-07-14 15:21:04 +02:00
|
|
|
loadArticle(){
|
2020-12-24 17:11:51 +01:00
|
|
|
console.log('loadArticle')
|
2020-12-23 18:05:25 +01:00
|
|
|
this.loading = true
|
2020-12-24 17:11:51 +01:00
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
const ast = gql`{
|
2021-03-06 16:46:19 +01:00
|
|
|
article(id: ${this.id}, lang: "${drupalDecoupled.lang_code}") {
|
2020-12-22 16:36:06 +01:00
|
|
|
...ArticleFields
|
|
|
|
}
|
|
|
|
}
|
2021-03-31 18:42:05 +02:00
|
|
|
${articleFields}
|
2020-12-22 16:36:06 +01:00
|
|
|
`
|
|
|
|
MGQ.post('', { query: print(ast)
|
|
|
|
})
|
2021-03-06 16:46:19 +01:00
|
|
|
.then(({ data:{data:{article}}}) => {
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('loadArticle', article)
|
2021-03-06 16:46:19 +01:00
|
|
|
this.parseDataGQL(article)
|
2020-12-22 16:36:06 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.warn('Issue with loadArticle', error)
|
|
|
|
Promise.reject(error)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
parseDataGQL(article){
|
|
|
|
console.log('parseDataGQL article', article)
|
|
|
|
this.article = article
|
|
|
|
|
2020-12-24 19:05:45 +01:00
|
|
|
// get the prev next items
|
2021-03-31 18:42:05 +02:00
|
|
|
if (!this.items.length) {
|
2020-12-24 19:05:45 +01:00
|
|
|
// if items list not yet loaded preload them
|
|
|
|
this.getItems().then(() => {
|
|
|
|
// then get the index
|
|
|
|
this.getIndex()
|
|
|
|
})
|
2021-03-31 18:42:05 +02:00
|
|
|
} else {
|
2020-12-24 19:05:45 +01:00
|
|
|
// or directly get the index
|
|
|
|
this.getIndex()
|
|
|
|
}
|
|
|
|
|
2020-12-22 16:36:06 +01:00
|
|
|
this.image_accroche = article.images[0]
|
|
|
|
|
|
|
|
this.lightbox_items = [];
|
|
|
|
|
|
|
|
// fill the lightbox
|
2021-03-31 18:42:05 +02:00
|
|
|
for (let i = 0; i < article.images.length; i++) {
|
2020-12-22 16:36:06 +01:00
|
|
|
article.images[i].thumb = article.images[i].style_articlecardmedium.url
|
|
|
|
this.lightbox_items.push(article.images[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse embeded videos pushing it in lightbox
|
2021-03-31 18:42:05 +02:00
|
|
|
for (let i = 0; i < article.videos.length; i++) {
|
2020-12-22 16:36:06 +01:00
|
|
|
let videoUrl = article.videos[i].url
|
|
|
|
let provider_regex = /https:\/\/(www\.)?(?<provider>youtube|vimeo)\.com\/.+/;
|
|
|
|
let match = provider_regex.exec(videoUrl)
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('provider', match.groups.provider)
|
2020-12-22 16:36:06 +01:00
|
|
|
let video_id = null;
|
|
|
|
let video_thumb = null;
|
|
|
|
switch (match.groups.provider) {
|
|
|
|
case 'vimeo':
|
|
|
|
let vimeo_regex = /https:\/\/vimeo\.com\/(?<id>\d+)/;
|
|
|
|
video_id = vimeo_regex.exec(videoUrl).groups.id || null;
|
|
|
|
// TODO: get the vimeo thumb https://coderwall.com/p/fdrdmg/get-a-thumbnail-from-a-vimeo-video
|
|
|
|
video_thumb = "http://blogpeda.ac-poitiers.fr/ent-lyc/files/2015/06/Vimeo_icon_block.png"
|
2021-03-31 18:42:05 +02:00
|
|
|
break
|
2020-12-22 16:36:06 +01:00
|
|
|
case 'youtube':
|
|
|
|
let youtube_regex = /https:\/\/(www\.)?youtube\.com\/watch\?v=(?<id>.+)/;
|
|
|
|
video_id = youtube_regex.exec(videoUrl).groups.id || null;
|
|
|
|
video_thumb = "http://img.youtube.com/vi/"+video_id+"/0.jpg"
|
2021-03-31 18:42:05 +02:00
|
|
|
break
|
2020-12-22 16:36:06 +01:00
|
|
|
}
|
2021-03-31 18:42:05 +02:00
|
|
|
// console.log('video_id', video_id)
|
2020-12-22 16:36:06 +01:00
|
|
|
|
|
|
|
this.lightbox_items.push({
|
|
|
|
url: videoUrl,
|
|
|
|
title: "",
|
|
|
|
description: "",
|
|
|
|
thumb: video_thumb
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('Article this.content.lightbox_items', this.lightbox_items)
|
2020-12-22 16:36:06 +01:00
|
|
|
|
|
|
|
// update main page title
|
|
|
|
this.$store.commit('Common/setPagetitle', article.title)
|
|
|
|
|
|
|
|
this.loading = false;
|
2019-07-14 15:21:04 +02:00
|
|
|
},
|
2021-03-08 15:01:09 +01:00
|
|
|
onPrevNext(pn){
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('clicked on prev/next; prevnext', pn)
|
2021-03-08 15:01:09 +01:00
|
|
|
let alias = pn.view_node.replace(/^\/\D{2,3}\/blabla\//g, '')
|
2021-03-31 18:42:05 +02:00
|
|
|
console.log('alias', alias)
|
2021-01-27 21:21:20 +01:00
|
|
|
|
2019-07-14 17:12:18 +02:00
|
|
|
this.$router.push({
|
|
|
|
name:`article`,
|
2021-03-08 15:01:09 +01:00
|
|
|
params: { alias:alias, id: pn.nid }
|
2019-07-14 17:12:18 +02:00
|
|
|
})
|
2020-02-20 12:12:35 +01:00
|
|
|
},
|
|
|
|
setLightboxIndex(index) {
|
|
|
|
this.lightbox_index = index
|
2019-07-14 17:12:18 +02:00
|
|
|
}
|
|
|
|
},
|
2019-07-25 21:23:23 +02:00
|
|
|
components: {
|
|
|
|
Card
|
|
|
|
},
|
2019-07-14 17:12:18 +02:00
|
|
|
watch: {
|
|
|
|
'$route' (to, from) {
|
|
|
|
console.log('route change')
|
|
|
|
this.getArticle()
|
2019-07-14 15:21:04 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-13 15:40:14 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|