kit.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. export default {
  2. state: {
  3. sheet: null
  4. },
  5. mutations: {
  6. 'SET_KIT_SHEET' (state, id) {
  7. state.sheet = id
  8. }
  9. },
  10. actions: {
  11. async 'INIT_KIT' ({ state, commit, dispatch, getters }, payload) {
  12. const ids = await dispatch('GET_ALL_NODES_IDS', 'kit')
  13. return dispatch('GET_NODES', { ids, dataLevel: 'partial' })
  14. },
  15. async 'OPEN_KIT_NODE' ({ state, commit, dispatch }, id) {
  16. commit('SET_KIT_SHEET', id)
  17. commit('ADD_HISTORY_ENTRIES', [id])
  18. return dispatch('GET_NODE', { id, dataLevel: 'full' })
  19. },
  20. 'CLOSE_KIT_NODE' ({ state, commit }) {
  21. commit('SET_KIT_SHEET', null)
  22. }
  23. },
  24. getters: {
  25. sheets: (state, getters, rootState) => {
  26. const kitIds = rootState.ids.kit
  27. if (kitIds === undefined || rootState.nodes[kitIds[0]] === undefined) return
  28. return kitIds.map(id => rootState.nodes[id])
  29. },
  30. sheet: (state, getters, rootState) => {
  31. if (state.sheet === undefined || state.sheet === null) return state.sheet
  32. return rootState.nodes[state.sheet]
  33. }
  34. }
  35. }