update library opening strategy
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import Vue from 'vue'
|
||||
import router from '@/router'
|
||||
|
||||
import api from '@/api'
|
||||
import {
|
||||
AllTags
|
||||
} from '@/api/queries'
|
||||
import {
|
||||
parseNodesQueryParams,
|
||||
getUniqueNodesIds,
|
||||
getRelatedNodesIds,
|
||||
buildTree
|
||||
@@ -16,10 +18,38 @@ export default {
|
||||
tags: undefined,
|
||||
strangeness: [0, 1, 2, 3, 4],
|
||||
nodeDepartId: undefined,
|
||||
trees: {}
|
||||
trees: {},
|
||||
mode: undefined,
|
||||
nodebook: undefined
|
||||
},
|
||||
|
||||
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)
|
||||
} else {
|
||||
stack.push(childId)
|
||||
}
|
||||
},
|
||||
|
||||
'REMOVE_NODEBOOK_NODE' (state, [stack, nodeId]) {
|
||||
if (stack[0] === nodeId) {
|
||||
state.nodebook.splice(state.nodebook.indexOf(stack), 1)
|
||||
} else {
|
||||
stack.splice(stack.indexOf(nodeId), 1)
|
||||
}
|
||||
},
|
||||
|
||||
'SET_TAGS' (state, tags) {
|
||||
state.tags = tags
|
||||
},
|
||||
@@ -34,9 +64,30 @@ export default {
|
||||
},
|
||||
|
||||
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')
|
||||
await dispatch('GET_NODES', { ids: departIds, dataLevel: 'initial' })
|
||||
dispatch('GET_ALL_TAGS')
|
||||
return departIds
|
||||
},
|
||||
|
||||
@@ -78,12 +129,42 @@ 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')
|
||||
}
|
||||
},
|
||||
|
||||
getters: {
|
||||
mode: (state) => state.mode,
|
||||
|
||||
nodebook: (state, getters, rootState) => {
|
||||
if (!state.nodebook) return []
|
||||
return state.nodebook.map(([parentId, ...childrenIds]) => {
|
||||
return {
|
||||
parent: rootState.nodes[parentId],
|
||||
children: childrenIds.map(id => rootState.nodes[id])
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
activeNodes: (state) => {
|
||||
if (!state.nodebook) return []
|
||||
return state.nodebook.reduce((acc, ids) => [...acc, ...ids], [])
|
||||
},
|
||||
|
||||
tagsOptions: state => {
|
||||
if (state.tags === undefined) return
|
||||
if (state.tags === undefined) return []
|
||||
return state.tags.map(tag => ({ value: tag.id, text: tag.name }))
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user