update node formating

This commit is contained in:
axolotle
2021-06-22 22:30:17 +02:00
parent 1a1c4875a1
commit c702ec1275
+32 -10
View File
@@ -31,23 +31,21 @@ export default {
}, },
'ADD_NODES' (state, [nodes, dataLevel]) { '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 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)) { if (node.variant === null || Array.isArray(node.variant)) {
node.variant = node.variant !== null ? ID_VARIANTS[node.variant[0].id] : 'dark' node.variant = node.variant !== null ? ID_VARIANTS[node.variant[0].id] : 'dark'
} }
if (node.type) { 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) { for (const relation of RELATIONS) {
if (relation in node && node[relation]) { if (relation in node && node[relation]) {
node[relation] = node[relation].map(subNode => { node[relation] = node[relation].map(subNode => {
if (!(subNode.id in state.nodes)) { if (!(subNode.id in state.nodes)) {
subNode.variant = subNode.variant !== null ? ID_VARIANTS[subNode.variant[0].id] : 'black' addNode(subNode, -1)
subNode.dataLevel = -1
Vue.set(state.nodes, subNode.id, subNode)
} }
return state.nodes[subNode.id] return state.nodes[subNode.id]
}) })
@@ -56,10 +54,34 @@ export default {
node[relation] = [] 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)
} }
} }
}, },