|
@@ -24,16 +24,15 @@ export default {
|
|
|
},
|
|
|
|
|
|
mutations: {
|
|
|
- 'SET_MODE' (state, mode) {
|
|
|
- state.mode = mode
|
|
|
- },
|
|
|
+ // ╷ ╶┬╴┌─╮┌─╮╭─┐┌─╮╷ ╷
|
|
|
+ // │ │ │╶┤├┬╯├─┤├┬╯╰─┤
|
|
|
+ // ╰─╴╶┴╴└─╯╵ ╰╵ ╵╵ ╰╶─╯
|
|
|
|
|
|
'SET_NODEBOOK' (state, nodes) {
|
|
|
state.nodebook = nodes
|
|
|
},
|
|
|
|
|
|
'ADD_NODEBOOK_NODE' (state, [stack, parentId, childId]) {
|
|
|
- console.log('ADD_NODEBOOK_NODE', stack, parentId, childId)
|
|
|
if (stack === undefined) {
|
|
|
stack = childId === undefined ? [parentId] : [parentId, childId]
|
|
|
state.nodebook.push(stack)
|
|
@@ -50,39 +49,31 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ 'ADD_NODE_TREE' (state, [id, tree]) {
|
|
|
+ Vue.set(state.trees, id, tree)
|
|
|
+ },
|
|
|
+
|
|
|
+ // ╭─╮┌─╮╶┬╴╶┬╴╭─╮╭╮╷╭─╴
|
|
|
+ // │ │├─╯ │ │ │ ││││╰─╮
|
|
|
+ // ╰─╯╵ ╵ ╶┴╴╰─╯╵╰╯╶─╯
|
|
|
+
|
|
|
'SET_TAGS' (state, tags) {
|
|
|
state.tags = tags
|
|
|
},
|
|
|
|
|
|
- 'SET_NODE_DEPART_ID' (state, id) {
|
|
|
- state.nodeDepartId = id
|
|
|
+ 'SET_MODE' (state, mode) {
|
|
|
+ state.mode = mode
|
|
|
},
|
|
|
|
|
|
- 'ADD_NODE_TREE' (state, [id, tree]) {
|
|
|
- Vue.set(state.trees, id, tree)
|
|
|
+ 'SET_NODE_DEPART_ID' (state, id) {
|
|
|
+ state.nodeDepartId = id
|
|
|
}
|
|
|
},
|
|
|
|
|
|
actions: {
|
|
|
- async 'UPDATE_NODEBOOK' ({ state, commit, dispatch }, query) {
|
|
|
- const { mode = 'tree', nodebook } = parseNodesQueryParams(query)
|
|
|
- commit('SET_MODE', mode)
|
|
|
- await dispatch('GET_NODES', { ids: [].concat(...nodebook), dataLevel: 'full' })
|
|
|
- commit('SET_NODEBOOK', nodebook)
|
|
|
- },
|
|
|
-
|
|
|
- 'UPDATE_QUERY_NODES' ({ state }, from) {
|
|
|
- const query = {
|
|
|
- mode: state.mode,
|
|
|
- nodes: [...state.nodebook.map(ids => ids.join(','))]
|
|
|
- }
|
|
|
- router.push({ query })
|
|
|
- },
|
|
|
-
|
|
|
- 'UPDATE_QUERY_MODE' (store, mode) {
|
|
|
- if (router.currentRoute.query.mode === mode) return
|
|
|
- router.push({ query: { mode } })
|
|
|
- },
|
|
|
+ // ╷ ╶┬╴┌─╮┌─╮╭─┐┌─╮╷ ╷
|
|
|
+ // │ │ │╶┤├┬╯├─┤├┬╯╰─┤
|
|
|
+ // ╰─╴╶┴╴└─╯╵ ╰╵ ╵╵ ╰╶─╯
|
|
|
|
|
|
async 'INIT_LIBRARY' ({ state, commit, dispatch, rootState }) {
|
|
|
const departIds = await dispatch('GET_ALL_NODES_IDS', 'depart')
|
|
@@ -109,6 +100,42 @@ export default {
|
|
|
return dispatch('GET_NODES', { ids: departIds, dataLevel: 'partial' })
|
|
|
},
|
|
|
|
|
|
+ async 'UPDATE_NODEBOOK' ({ state, commit, dispatch }, query) {
|
|
|
+ const { mode = 'tree', nodebook } = parseNodesQueryParams(query)
|
|
|
+ commit('SET_MODE', mode)
|
|
|
+ await dispatch('GET_NODES', { ids: [].concat(...nodebook), dataLevel: 'full' })
|
|
|
+ commit('SET_NODEBOOK', nodebook)
|
|
|
+ },
|
|
|
+
|
|
|
+ // ╭╮╷╭─╮┌─╮┌─╴╭─╴
|
|
|
+ // ││││ ││ │├─╴╰─╮
|
|
|
+ // ╵╰╯╰─╯└─╯╰─╴╶─╯
|
|
|
+
|
|
|
+ 'UPDATE_QUERY_NODES' ({ state }, from) {
|
|
|
+ const query = {
|
|
|
+ mode: state.mode,
|
|
|
+ nodes: [...state.nodebook.map(ids => ids.join(','))]
|
|
|
+ }
|
|
|
+ router.push({ query })
|
|
|
+ },
|
|
|
+
|
|
|
+ async 'OPEN_NODE' ({ state, commit, dispatch }, [parentId, childId]) {
|
|
|
+ const stack = state.nodebook.find(stack => stack[0] === parentId)
|
|
|
+ if (stack && (childId === undefined || stack.includes(childId))) return
|
|
|
+ commit('ADD_NODEBOOK_NODE', [stack, parentId, childId])
|
|
|
+ dispatch('UPDATE_QUERY_NODES')
|
|
|
+ },
|
|
|
+
|
|
|
+ 'CLOSE_NODE' ({ state, commit, dispatch }, [parentId, childId]) {
|
|
|
+ const stack = state.nodebook.find(stack => stack.includes(parentId) && (childId ? stack.includes(childId) : true))
|
|
|
+ commit('REMOVE_NODEBOOK_NODE', [stack, childId || parentId])
|
|
|
+ dispatch('UPDATE_QUERY_NODES')
|
|
|
+ },
|
|
|
+
|
|
|
+ // ╭─╮┌─╮╶┬╴╶┬╴╭─╮╭╮╷╭─╴
|
|
|
+ // │ │├─╯ │ │ │ ││││╰─╮
|
|
|
+ // ╰─╯╵ ╵ ╶┴╴╰─╯╵╰╯╶─╯
|
|
|
+
|
|
|
'GET_ALL_TAGS' ({ state, commit }) {
|
|
|
if (state.tags !== undefined) return state.tags
|
|
|
return api.query(AllTags).then(data => {
|
|
@@ -131,17 +158,9 @@ export default {
|
|
|
return getters.nodeTree
|
|
|
},
|
|
|
|
|
|
- async 'OPEN_NODE' ({ state, commit, dispatch }, [parentId, childId]) {
|
|
|
- const stack = state.nodebook.find(stack => stack[0] === parentId)
|
|
|
- if (stack && (childId === undefined || stack.includes(childId))) return
|
|
|
- commit('ADD_NODEBOOK_NODE', [stack, parentId, childId])
|
|
|
- dispatch('UPDATE_QUERY_NODES')
|
|
|
- },
|
|
|
-
|
|
|
- 'CLOSE_NODE' ({ state, commit, dispatch }, [parentId, childId]) {
|
|
|
- const stack = state.nodebook.find(stack => stack.includes(parentId) && (childId ? stack.includes(childId) : true))
|
|
|
- commit('REMOVE_NODEBOOK_NODE', [stack, childId || parentId])
|
|
|
- dispatch('UPDATE_QUERY_NODES')
|
|
|
+ 'UPDATE_QUERY_MODE' (store, mode) {
|
|
|
+ if (router.currentRoute.query.mode === mode) return
|
|
|
+ router.push({ query: { mode } })
|
|
|
}
|
|
|
},
|
|
|
|