added prev next button to articles
This commit is contained in:
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -5,6 +5,11 @@
 | 
				
			|||||||
  <article class="article" v-else>
 | 
					  <article class="article" v-else>
 | 
				
			||||||
    <header>
 | 
					    <header>
 | 
				
			||||||
      <h1>{{ content.title }}</h1>
 | 
					      <h1>{{ content.title }}</h1>
 | 
				
			||||||
 | 
					      <nav v-if="index != -1">
 | 
				
			||||||
 | 
					        <a @click.prevent="onPrev" href="#">prev : {{ prevnext.prev.title }}</a>
 | 
				
			||||||
 | 
					        <a @click.prevent="onNext" href="#">next : {{ prevnext.next.title }}</a>
 | 
				
			||||||
 | 
					      </nav>
 | 
				
			||||||
 | 
					    </header>
 | 
				
			||||||
    <div class="taxonomy">
 | 
					    <div class="taxonomy">
 | 
				
			||||||
      <div class="thesaurus">
 | 
					      <div class="thesaurus">
 | 
				
			||||||
        <ul>
 | 
					        <ul>
 | 
				
			||||||
@@ -45,7 +50,6 @@
 | 
				
			|||||||
        <caption></caption>
 | 
					        <caption></caption>
 | 
				
			||||||
      </figure>
 | 
					      </figure>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
    </header>
 | 
					 | 
				
			||||||
  </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()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user