reorganise library store
This commit is contained in:
@@ -24,16 +24,15 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
'SET_MODE' (state, mode) {
|
// ╷ ╶┬╴┌─╮┌─╮╭─┐┌─╮╷ ╷
|
||||||
state.mode = mode
|
// │ │ │╶┤├┬╯├─┤├┬╯╰─┤
|
||||||
},
|
// ╰─╴╶┴╴└─╯╵ ╰╵ ╵╵ ╰╶─╯
|
||||||
|
|
||||||
'SET_NODEBOOK' (state, nodes) {
|
'SET_NODEBOOK' (state, nodes) {
|
||||||
state.nodebook = nodes
|
state.nodebook = nodes
|
||||||
},
|
},
|
||||||
|
|
||||||
'ADD_NODEBOOK_NODE' (state, [stack, parentId, childId]) {
|
'ADD_NODEBOOK_NODE' (state, [stack, parentId, childId]) {
|
||||||
console.log('ADD_NODEBOOK_NODE', stack, parentId, childId)
|
|
||||||
if (stack === undefined) {
|
if (stack === undefined) {
|
||||||
stack = childId === undefined ? [parentId] : [parentId, childId]
|
stack = childId === undefined ? [parentId] : [parentId, childId]
|
||||||
state.nodebook.push(stack)
|
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) {
|
'SET_TAGS' (state, tags) {
|
||||||
state.tags = tags
|
state.tags = tags
|
||||||
},
|
},
|
||||||
|
|
||||||
'SET_NODE_DEPART_ID' (state, id) {
|
'SET_MODE' (state, mode) {
|
||||||
state.nodeDepartId = id
|
state.mode = mode
|
||||||
},
|
},
|
||||||
|
|
||||||
'ADD_NODE_TREE' (state, [id, tree]) {
|
'SET_NODE_DEPART_ID' (state, id) {
|
||||||
Vue.set(state.trees, id, tree)
|
state.nodeDepartId = id
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
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 }) {
|
async 'INIT_LIBRARY' ({ state, commit, dispatch, rootState }) {
|
||||||
const departIds = await dispatch('GET_ALL_NODES_IDS', 'depart')
|
const departIds = await dispatch('GET_ALL_NODES_IDS', 'depart')
|
||||||
@@ -109,6 +100,42 @@ export default {
|
|||||||
return dispatch('GET_NODES', { ids: departIds, dataLevel: 'partial' })
|
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 }) {
|
'GET_ALL_TAGS' ({ state, commit }) {
|
||||||
if (state.tags !== undefined) return state.tags
|
if (state.tags !== undefined) return state.tags
|
||||||
return api.query(AllTags).then(data => {
|
return api.query(AllTags).then(data => {
|
||||||
@@ -131,17 +158,9 @@ export default {
|
|||||||
return getters.nodeTree
|
return getters.nodeTree
|
||||||
},
|
},
|
||||||
|
|
||||||
async 'OPEN_NODE' ({ state, commit, dispatch }, [parentId, childId]) {
|
'UPDATE_QUERY_MODE' (store, mode) {
|
||||||
const stack = state.nodebook.find(stack => stack[0] === parentId)
|
if (router.currentRoute.query.mode === mode) return
|
||||||
if (stack && (childId === undefined || stack.includes(childId))) return
|
router.push({ query: { mode } })
|
||||||
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')
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user