blabla.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { JSONAPI } from 'vuejs/api/json-axios'
  2. import { REST } from 'vuejs/api/rest-axios'
  3. import { MA } from 'vuejs/api/ma-axios'
  4. import qs from 'querystring'
  5. export default {
  6. namespaced: true,
  7. // initial state
  8. state : {
  9. contenttype:null,
  10. items: [],
  11. page: 0,
  12. // infinteState will come from vue-infinite-loading plugin
  13. // implemented in vuejs/components/Content/Base.vue
  14. infiniteLoadingState: null
  15. },
  16. // getters
  17. getters : {},
  18. // mutations
  19. mutations : {
  20. setItems (state, items) {
  21. state.items = state.items.concat(items)
  22. },
  23. incrementPage(state){
  24. state.page += 1;
  25. },
  26. setInfiniteState(state, infiniteLoadingstate){
  27. state.infiniteLoadingState = infiniteLoadingstate
  28. }
  29. },
  30. // actions
  31. actions : {
  32. getItems({ dispatch, commit, state }){
  33. // if(!state.contenttype){
  34. // REST.get('/entity/node_type/article?_format=json', {})
  35. // .then(({ data }) => {
  36. // console.log('blabla REST contenttype : data', data);
  37. // })
  38. // .catch(( error ) => {
  39. // console.warn('Issue with blabla contenttype', error)
  40. // Promise.reject(error)
  41. // })
  42. // }
  43. return REST.get(`/blabla_rest?_format=json&page=${state.page}`, {})
  44. .then(({ data }) => {
  45. console.log('blabla REST: data', data)
  46. if(data.length){
  47. commit('setItems',data)
  48. // console.log('items.length', this.items.length);
  49. if(state.infiniteLoadingState)
  50. state.infiniteLoadingState.loaded()
  51. }else{
  52. if(state.infiniteLoadingState)
  53. state.infiniteLoadingState.complete()
  54. }
  55. })
  56. .catch(( error ) => {
  57. console.warn('Issue with blabla getitems', error)
  58. Promise.reject(error)
  59. })
  60. },
  61. nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) {
  62. console.log("blabla nextPage", $infiniteLoadingstate);
  63. commit('incrementPage')
  64. commit('setInfiniteState', $infiniteLoadingstate)
  65. dispatch('getItems')
  66. },
  67. getItemIndex({ dispatch, commit, state}, uuid) {
  68. return state.items.findIndex((e) =>{
  69. return e.uuid == uuid
  70. })
  71. },
  72. getPrevNextItems({ dispatch, commit, state }, index) {
  73. return {
  74. prev:state.items[index-1],
  75. next:state.items[index+1]
  76. }
  77. }
  78. }
  79. }