blabla.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. items: [],
  10. page: 0,
  11. // infinteState will come from vue-infinite-loading plugin
  12. // implemented in vuejs/components/Content/Base.vue
  13. infiniteLoadingState: null
  14. },
  15. // getters
  16. getters : {},
  17. // mutations
  18. mutations : {
  19. setItems (state, items) {
  20. state.items = state.items.concat(items)
  21. },
  22. incrementPage(state){
  23. state.page += 1;
  24. },
  25. setInfiniteState(state, infiniteLoadingstate){
  26. state.infiniteLoadingState = infiniteLoadingstate
  27. }
  28. },
  29. // actions
  30. actions : {
  31. getItems({ dispatch, commit, state }){
  32. REST.get(`/blabla_rest?_format=json&page=${state.page}`, {})
  33. .then(({ data }) => {
  34. console.log('blabla REST: data', data)
  35. if(data.length){
  36. commit('setItems',data)
  37. // console.log('items.length', this.items.length);
  38. if(state.infiniteLoadingState)
  39. state.infiniteLoadingState.loaded()
  40. }else{
  41. if(state.infiniteLoadingState)
  42. state.infiniteLoadingState.complete()
  43. }
  44. })
  45. .catch(( error ) => {
  46. console.warn('Issue with blabla', error)
  47. Promise.reject(error)
  48. })
  49. },
  50. nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) {
  51. console.log("blabla nextPage", $infiniteLoadingstate);
  52. commit('incrementPage')
  53. commit('setInfiniteState', $infiniteLoadingstate)
  54. dispatch('getItems')
  55. },
  56. getItemIndex({ dispatch, commit, state}, uuid) {
  57. return state.items.findIndex((e) =>{
  58. return e.uuid == uuid
  59. })
  60. },
  61. getPrevNextItems({ dispatch, commit, state }, index) {
  62. return {
  63. prev:state.items[index-1],
  64. next:state.items[index+1]
  65. }
  66. }
  67. }
  68. }