update AllNodesOfVariant to also get content
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
query AllNodesOfVariant ($variantId: Int!) {
|
||||
nodes: allmapitemsof(familyId: $variantId) {
|
||||
id
|
||||
FRAGMENTS
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ export default {
|
||||
},
|
||||
|
||||
actions: {
|
||||
async 'INIT_KIT' ({ state, commit, dispatch, getters }, payload) {
|
||||
const ids = await dispatch('GET_ALL_NODES_IDS', 'kit')
|
||||
'INIT_KIT' ({ state, commit, dispatch, getters }) {
|
||||
const ids = dispatch('GET_ALL_NODES_IDS', { variant: 'kit', dataLevel: 'partial' })
|
||||
return dispatch('GET_NODES', { ids, dataLevel: 'partial' })
|
||||
},
|
||||
|
||||
@@ -28,9 +28,11 @@ export default {
|
||||
|
||||
getters: {
|
||||
sheets: (state, getters, rootState) => {
|
||||
const kitIds = rootState.ids.kit
|
||||
if (kitIds === undefined || rootState.nodes[kitIds[0]] === undefined) return
|
||||
return kitIds.map(id => rootState.nodes[id])
|
||||
const ids = rootState.ids.kit
|
||||
if (ids === undefined) return
|
||||
const nodes = ids.map(id => rootState.nodes[id])
|
||||
if (nodes.some(node => node === undefined)) return
|
||||
return nodes
|
||||
},
|
||||
|
||||
sheet: (state, getters, rootState) => {
|
||||
|
||||
@@ -106,13 +106,12 @@ export default {
|
||||
// │ │ │╶┤├┬╯├─┤├┬╯╰─┤
|
||||
// ╰─╴╶┴╴└─╯╵ ╰╵ ╵╵ ╰╶─╯
|
||||
|
||||
async 'INIT_LIBRARY' ({ state, commit, dispatch, rootState }) {
|
||||
const departIds = await dispatch('GET_ALL_NODES_IDS', 'depart')
|
||||
await dispatch('GET_NODES', { ids: departIds, dataLevel: 'initial' })
|
||||
async 'INIT_LIBRARY' ({ state, commit, dispatch, rootState }, { dataLevel = 'initial' } = {}) {
|
||||
await dispatch('GET_ALL_NODES_IDS', { variant: 'depart', dataLevel })
|
||||
if (state.nodebook && state.nodebook.length) {
|
||||
commit('UPDATE_OPTIONS_VISIBILITY', false)
|
||||
}
|
||||
return departIds
|
||||
return rootState.ids.depart
|
||||
},
|
||||
|
||||
async 'INIT_LIBRARY_TREE' ({ state, commit, dispatch, rootState }) {
|
||||
@@ -126,7 +125,7 @@ export default {
|
||||
},
|
||||
|
||||
async 'INIT_LIBRARY_LIST' ({ state, commit, dispatch }) {
|
||||
const departIds = await dispatch('INIT_LIBRARY')
|
||||
const departIds = await dispatch('INIT_LIBRARY', { dataLevel: 'partial' })
|
||||
const nodes = await dispatch('GET_NODES', { ids: departIds, dataLevel: 'partial' })
|
||||
commit('SET_TAGS_OPTIONS', nodes)
|
||||
return nodes
|
||||
|
||||
+12
-23
@@ -5,7 +5,9 @@ import {
|
||||
DATA_LEVELS,
|
||||
ID_VARIANTS,
|
||||
VARIANT_IDS,
|
||||
RELATIONS // FIXME REMOVE WHEN DB MAJ
|
||||
RELATIONS,
|
||||
reduceQueryIds,
|
||||
reduceQueryLevels
|
||||
} from '@/store/utils'
|
||||
import {
|
||||
AllNodesOfVariant
|
||||
@@ -116,35 +118,22 @@ export default {
|
||||
},
|
||||
|
||||
actions: {
|
||||
async 'GET_ALL_NODES_IDS' ({ state, commit }, variant) {
|
||||
async 'GET_ALL_NODES_IDS' ({ state, commit }, { variant, dataLevel = 'initial' }) {
|
||||
if (state.ids[variant] === undefined) {
|
||||
// FIXME UPDATE WHEN QUERY OK
|
||||
// await api.query(AllNodesOfVariant, { variantId: VARIANT_IDS[variant] }).then(data => {
|
||||
await api.query(AllNodesOfVariant, { variantId: VARIANT_IDS[variant] }).then(data => {
|
||||
commit('SET_ALL_NODES_IDS', [variant, data.nodes])
|
||||
const levels = reduceQueryLevels(DATA_LEVELS[dataLevel])
|
||||
await api.queryAllNodes(VARIANT_IDS[variant], levels).then(({ nodes }) => {
|
||||
commit('SET_ALL_NODES_IDS', [variant, nodes])
|
||||
commit('ADD_NODES', [nodes, DATA_LEVELS[dataLevel]])
|
||||
})
|
||||
}
|
||||
return state.ids[variant]
|
||||
},
|
||||
|
||||
async 'GET_NODES' ({ state, commit, getters }, { ids, dataLevel = 'partial' }) {
|
||||
const lvl = DATA_LEVELS[dataLevel]
|
||||
const nodesIdsToQuery = []
|
||||
let lowestLvl = lvl
|
||||
for (const id of ids) {
|
||||
const nodeLvl = id in state.nodes ? state.nodes[id].dataLevel : -1
|
||||
if (nodeLvl < lvl) {
|
||||
nodesIdsToQuery.push(id)
|
||||
}
|
||||
if (nodeLvl < lowestLvl) {
|
||||
lowestLvl = nodeLvl
|
||||
}
|
||||
}
|
||||
|
||||
if (nodesIdsToQuery.length) {
|
||||
const levelsToQuery = Array(lvl - lowestLvl).fill(lowestLvl + 1).map((v, i) => v + i)
|
||||
await api.queryNodes(nodesIdsToQuery, levelsToQuery).then(data => {
|
||||
commit('ADD_NODES', [data.nodes, lvl])
|
||||
const { idsToQuery, levelsToQuery } = reduceQueryIds(ids, dataLevel, state.nodes)
|
||||
if (idsToQuery) {
|
||||
await api.queryNodes(idsToQuery, levelsToQuery).then(data => {
|
||||
commit('ADD_NODES', [data.nodes, DATA_LEVELS[dataLevel]])
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,32 @@ export function parseNodesQueryParams ({ mode, nodes = [] }) {
|
||||
}
|
||||
|
||||
|
||||
export function reduceQueryLevels (lvl, lowestLvl = -1) {
|
||||
return Array(lvl - lowestLvl).fill(lowestLvl + 1).map((v, i) => v + i)
|
||||
}
|
||||
|
||||
|
||||
export function reduceQueryIds (ids, dataLevel, data) {
|
||||
const lvl = DATA_LEVELS[dataLevel]
|
||||
const idsToQuery = []
|
||||
let lowestLvl = lvl
|
||||
for (const id of ids) {
|
||||
const nodeLvl = id in data ? data[id].dataLevel : -1
|
||||
if (nodeLvl < lvl) {
|
||||
idsToQuery.push(id)
|
||||
}
|
||||
if (nodeLvl < lowestLvl) {
|
||||
lowestLvl = nodeLvl
|
||||
}
|
||||
}
|
||||
|
||||
return idsToQuery.length === 0 ? {} : {
|
||||
idsToQuery,
|
||||
levelsToQuery: reduceQueryLevels(lvl, lowestLvl)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function getUniqueNodesIds (tree) {
|
||||
function extractId (ids, node) {
|
||||
ids.add(node.id)
|
||||
|
||||
Reference in New Issue
Block a user