From c702ec1275ba6af33a72493a043059d6bc8e5e0b Mon Sep 17 00:00:00 2001 From: axolotle Date: Tue, 22 Jun 2021 22:30:17 +0200 Subject: [PATCH] update node formating --- src/store/nodes.js | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/store/nodes.js b/src/store/nodes.js index d41bca3..572b8f2 100644 --- a/src/store/nodes.js +++ b/src/store/nodes.js @@ -31,23 +31,21 @@ export default { }, 'ADD_NODES' (state, [nodes, dataLevel]) { - for (const node of nodes) { + function addNode (node, level) { const stateNode = node.id in state.nodes ? state.nodes[node.id] : undefined - // FIXME UPDATE AFTER DB MAJ + if (node.variant === null || Array.isArray(node.variant)) { node.variant = node.variant !== null ? ID_VARIANTS[node.variant[0].id] : 'dark' } if (node.type) { - node.type = node.type === 'texte' ? 'ref' : 'prod' + node.type = node.type === 'Textref' ? 'ref' : 'prod' } - // FIXME REMOVE AFTER DB MAJ + for (const relation of RELATIONS) { if (relation in node && node[relation]) { node[relation] = node[relation].map(subNode => { if (!(subNode.id in state.nodes)) { - subNode.variant = subNode.variant !== null ? ID_VARIANTS[subNode.variant[0].id] : 'black' - subNode.dataLevel = -1 - Vue.set(state.nodes, subNode.id, subNode) + addNode(subNode, -1) } return state.nodes[subNode.id] }) @@ -56,10 +54,34 @@ export default { node[relation] = [] } } - if (!stateNode || stateNode.dataLevel < dataLevel) { - node.dataLevel = dataLevel + + if (node.notes) { + node.notes.forEach(note => { + if (note.links && note.links.length) { + note.links = note.links.map(link => { + if (!(link.id in state.nodes) || state.nodes[link.id].dataLevel < 1) { + addNode(link, -1) + } + return state.nodes[link.id] + }) + } + }) } - Vue.set(state.nodes, node.id, stateNode ? { ...stateNode, ...node } : node) + + if (!stateNode || stateNode.dataLevel < level) { + node.dataLevel = level + } + if (stateNode === undefined) { + Vue.set(state.nodes, node.id, node) + } else { + for (const key in node) { + Vue.set(state.nodes[node.id], key, node[key]) + } + } + } + + for (const node of nodes) { + addNode(node, dataLevel) } } },