colophon.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { REST } from 'api/rest-axios'
  2. import router from '../../router'
  3. export default {
  4. namespaced: true,
  5. router,
  6. // initial state
  7. state: {
  8. colophon: [],
  9. colophonHome: []
  10. },
  11. // getters
  12. getters: {},
  13. // mutations
  14. mutations: {
  15. setColophon (state, colophon) {
  16. state.colophon = colophon
  17. for (let i = 0; i < colophon.length; i++) {
  18. if (colophon[i].uuid !== 'schema') {
  19. state.colophonHome.push(colophon[i])
  20. }
  21. }
  22. }
  23. },
  24. // actions
  25. actions: {
  26. getColophon ({ dispatch, commit, state }) {
  27. REST.get(`${window.apipath}/colophon`, {})
  28. .then(({ data }) => {
  29. console.log('colophon getColophon REST: data', data)
  30. // commit('setColophon', data.content)
  31. dispatch('getPages', data.content.pages)
  32. .then((pages) => {
  33. console.log('all pages returned: pages', pages)
  34. commit('setColophon', pages)
  35. })
  36. })
  37. .catch((error) => {
  38. console.warn('Issue with getColophon', error)
  39. Promise.reject(error)
  40. })
  41. },
  42. // async get pages
  43. getPages ({ dispatch, commit, state }, pages) {
  44. return Promise.all(pages.map(function (page) {
  45. return REST.get(`${window.apipath}/colophon/` + page.uuid, {})
  46. .then(({ data }) => {
  47. console.log('colophon getPages REST: page, data', page, data)
  48. // // work arround
  49. // if (!Array.isArray(data.content)) {
  50. // data.content = [data.content]
  51. // }
  52. return data.content
  53. })
  54. .catch((error) => {
  55. console.warn('colophon Issue with getPages', error)
  56. Promise.reject(error)
  57. })
  58. }))
  59. }
  60. }
  61. }