reorganise library store
This commit is contained in:
@@ -15,12 +15,15 @@ import {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
state: {
|
state: {
|
||||||
tags: undefined,
|
|
||||||
strangeness: [0, 1, 2, 3, 4],
|
|
||||||
nodeDepartId: undefined,
|
|
||||||
trees: {},
|
trees: {},
|
||||||
mode: undefined,
|
|
||||||
nodebook: undefined,
|
nodebook: undefined,
|
||||||
|
|
||||||
|
// LibraryOptions options
|
||||||
|
strangeness: [0, 1, 2, 3, 4],
|
||||||
|
tagsOptions: [],
|
||||||
|
// LibraryOptions state
|
||||||
|
mode: undefined,
|
||||||
|
nodeDepartId: undefined,
|
||||||
search: ''
|
search: ''
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -58,8 +61,8 @@ export default {
|
|||||||
// │ │├─╯ │ │ │ ││││╰─╮
|
// │ │├─╯ │ │ │ ││││╰─╮
|
||||||
// ╰─╯╵ ╵ ╶┴╴╰─╯╵╰╯╶─╯
|
// ╰─╯╵ ╵ ╶┴╴╰─╯╵╰╯╶─╯
|
||||||
|
|
||||||
'SET_TAGS' (state, tags) {
|
'SET_TAGS_OPTIONS' (state, tags) {
|
||||||
state.tags = tags
|
state.tagsOptions = tags.map(tag => ({ value: tag.id, text: tag.name }))
|
||||||
},
|
},
|
||||||
|
|
||||||
'SET_MODE' (state, mode) {
|
'SET_MODE' (state, mode) {
|
||||||
@@ -144,7 +147,7 @@ export default {
|
|||||||
'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 => {
|
||||||
commit('SET_TAGS', data.tags)
|
commit('SET_TAGS_OPTIONS', data.tags)
|
||||||
return state.tags
|
return state.tags
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -170,29 +173,13 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
|
// LibraryOptions state
|
||||||
mode: state => state.mode,
|
mode: state => state.mode,
|
||||||
nodeDepartId: state => state.nodeDepartId,
|
nodeDepartId: state => state.nodeDepartId,
|
||||||
search: state => state.search,
|
search: state => state.search,
|
||||||
|
|
||||||
nodebook: (state, getters, rootState) => {
|
// LibraryOptions options
|
||||||
if (!state.nodebook) return []
|
tagsOptions: state => state.tagsOptions,
|
||||||
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 []
|
|
||||||
return state.tags.map(tag => ({ value: tag.id, text: tag.name }))
|
|
||||||
},
|
|
||||||
|
|
||||||
nodesDepartsOptions: (state, getters, rootState) => {
|
nodesDepartsOptions: (state, getters, rootState) => {
|
||||||
const departIds = rootState.ids.depart
|
const departIds = rootState.ids.depart
|
||||||
@@ -207,6 +194,18 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Library
|
||||||
|
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])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// LibraryList
|
||||||
orderedTextsDepart: (state, getters, rootState) => {
|
orderedTextsDepart: (state, getters, rootState) => {
|
||||||
const departIds = rootState.ids.depart
|
const departIds = rootState.ids.depart
|
||||||
if (departIds === undefined || rootState.nodes[departIds[0]] === undefined) return
|
if (departIds === undefined || rootState.nodes[departIds[0]] === undefined) return
|
||||||
@@ -224,8 +223,15 @@ export default {
|
|||||||
}, {})
|
}, {})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// LibraryTree
|
||||||
nodeTree: (state, rootState) => {
|
nodeTree: (state, rootState) => {
|
||||||
return state.trees[state.nodeDepartId] || { nodes: [], links: [] }
|
return state.trees[state.nodeDepartId] || { nodes: [], links: [] }
|
||||||
|
},
|
||||||
|
|
||||||
|
// Commons
|
||||||
|
activeNodes: state => {
|
||||||
|
if (!state.nodebook) return []
|
||||||
|
return state.nodebook.reduce((acc, ids) => [...acc, ...ids], [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user