added prev next button to articles

This commit is contained in:
Bachir Soussi Chiadmi 2019-07-14 17:12:18 +02:00
parent ddffd26c77
commit d84750ef8f
3 changed files with 98 additions and 41 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,47 +5,51 @@
<article class="article" v-else> <article class="article" v-else>
<header> <header>
<h1>{{ content.title }}</h1> <h1>{{ content.title }}</h1>
<div class="taxonomy"> <nav v-if="index != -1">
<div class="thesaurus"> <a @click.prevent="onPrev" href="#">prev : {{ prevnext.prev.title }}</a>
<ul> <a @click.prevent="onNext" href="#">next : {{ prevnext.next.title }}</a>
<li </nav>
v-for="term in content.field_thesaurus" v-bind:key="term.id" </header>
>{{ term.name }}</li> <div class="taxonomy">
</ul> <div class="thesaurus">
</div>
<div class="tags">
<ul>
<li
v-for="term in content.field_tags" v-bind:key="term.id"
>{{ term.name }}</li>
</ul>
</div>
</div>
<div class="body" v-html="content.body"></div>
<div class="linked-materials">
<ul> <ul>
<li v-for="node in content.field_linked_materials" v-bind:key="node.id"> <li
<section :uuid="node.id"> v-for="term in content.field_thesaurus" v-bind:key="term.id"
<h1>{{ node.title }}</h1> >{{ term.name }}</li>
<h3>{{ node.field_reference }}</h3>
<h2>{{ node.field_short_description }}</h2>
</section>
</li>
</ul> </ul>
</div> </div>
<div class="visuels"> <div class="tags">
<figure <ul>
v-for="visuel in content.field_visuel" v-bind:key="visuel.id" <li
> v-for="term in content.field_tags" v-bind:key="term.id"
<img >{{ term.name }}</li>
:src="visuel.src" </ul>
:alt="visuel.alt"
:title="visuel.title"
/>
<caption></caption>
</figure>
</div> </div>
</header> </div>
<div class="body" v-html="content.body"></div>
<div class="linked-materials">
<ul>
<li v-for="node in content.field_linked_materials" v-bind:key="node.id">
<section :uuid="node.id">
<h1>{{ node.title }}</h1>
<h3>{{ node.field_reference }}</h3>
<h2>{{ node.field_short_description }}</h2>
</section>
</li>
</ul>
</div>
<div class="visuels">
<figure
v-for="visuel in content.field_visuel" v-bind:key="visuel.id"
>
<img
:src="visuel.src"
:alt="visuel.alt"
:title="visuel.title"
/>
<caption></caption>
</figure>
</div>
</article> </article>
</template> </template>
@ -53,6 +57,7 @@
import router from 'vuejs/route' import router from 'vuejs/route'
import { JSONAPI } from 'vuejs/api/json-axios' import { JSONAPI } from 'vuejs/api/json-axios'
import qs from 'querystring' import qs from 'querystring'
import { mapState, mapActions } from 'vuex'
export default { export default {
name: "Article", name: "Article",
@ -60,6 +65,8 @@ export default {
props: ['item'], props: ['item'],
data(){ data(){
return { return {
index:-1,
prevnext:{},
uuid:null, uuid:null,
content:null content:null
} }
@ -68,6 +75,20 @@ export default {
this.getArticle() this.getArticle()
}, },
methods: { methods: {
...mapActions({
getItemIndex: 'Blabla/getItemIndex',
getPrevNextItems: 'Blabla/getPrevNextItems'
}),
getIndex(){
console.log("Article getIndex");
this.getItemIndex(this.uuid).then((index) => {
this.index = index
// console.log('article index', index, this);
this.getPrevNextItems(index).then((pn) => {
this.prevnext = pn
})
})
},
getArticle(){ getArticle(){
console.log(this.$route); console.log(this.$route);
// get the article uuid // get the article uuid
@ -82,6 +103,7 @@ export default {
} }
if(this.uuid){ if(this.uuid){
this.getIndex()
this.loadArticle() this.loadArticle()
}else{ }else{
// if for any reason we dont have the uuid // if for any reason we dont have the uuid
@ -157,6 +179,30 @@ export default {
console.log('article.content',this.content); console.log('article.content',this.content);
},
onNext(){
console.log('clicked on next', this.prevnext.next);
let alias = this.prevnext.next.view_node.replace(/^.?\/blabla\//g, '')
this.$router.push({
name:`article`,
params: { alias:alias },
query: { uuid: this.prevnext.next.uuid }
})
},
onPrev(){
console.log('clicked on prev', this.prevnext.next);
let alias = this.prevnext.prev.view_node.replace(/^.?\/blabla\//g, '')
this.$router.push({
name:`article`,
params: { alias:alias },
query: { uuid: this.prevnext.prev.uuid }
})
}
},
watch: {
'$route' (to, from) {
console.log('route change')
this.getArticle()
} }
} }
} }

View File

@ -53,10 +53,21 @@ export default {
}) })
}, },
nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) { nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) {
console.log("Search nextPage", $infiniteLoadingstate); console.log("blabla nextPage", $infiniteLoadingstate);
commit('incrementPage') commit('incrementPage')
commit('setInfiniteState', $infiniteLoadingstate) commit('setInfiniteState', $infiniteLoadingstate)
dispatch('getItems') dispatch('getItems')
},
getItemIndex({ dispatch, commit, state}, uuid) {
return state.items.findIndex((e) =>{
return e.uuid == uuid
})
},
getPrevNextItems({ dispatch, commit, state }, index) {
return {
prev:state.items[index-1],
next:state.items[index+1]
}
} }
} }
} }