update node opening/closing

This commit is contained in:
axolotle
2021-06-22 16:16:25 +02:00
parent 5d8cd184dc
commit 5ab6e19cde
7 changed files with 32 additions and 16 deletions
+9 -4
View File
@@ -12,15 +12,20 @@
:class="{ active: i === nodes.length - 1 }" :class="{ active: i === nodes.length - 1 }"
:style="`--nth: ${i}`" :style="`--nth: ${i}`"
> >
<node-view-child-list :children="parent.children" :parent-id="parent.id" smartphone /> <node-view-child-list
:children="parent.children"
:parent-id="parent.id"
smartphone
@open-child="$emit('open-node', { parentId: parent.id, ...$event })"
/>
<node-view <node-view
:node="parent" :node="parent"
type="ref" type="ref"
mode="view" mode="view"
@open-node="$emit('open-node', $event)" @open-node="$emit('open-node', $event)"
@open-child="$emit('open-node', parent.id, $event)" @open-child="$emit('open-node', { parentId: parent.id, ...$event })"
@close-node="$emit('close-node', $event)" @close-node="$emit('close-node', { parentId: $event })"
/> />
<section <section
@@ -39,7 +44,7 @@
mode="view" mode="view"
type="prod" type="prod"
@open-node="$emit('open-node', $event)" @open-node="$emit('open-node', $event)"
@close-node="$emit('close-node', parent.id, $event)" @close-node="$emit('close-node', { parentId: parent.id, childId: $event })"
/> />
</div> </div>
</section> </section>
+1 -1
View File
@@ -41,7 +41,7 @@ export default {
methods: { methods: {
onOpen (childId) { onOpen (childId) {
this.$emit('open-child', childId) this.$emit('open-child', { childId })
} }
}, },
+2 -2
View File
@@ -71,8 +71,8 @@ export default {
methods: { methods: {
toCommaList, toCommaList,
onOpen (siblingId) { onOpen (parentId) {
this.$parent.$emit('open-node', siblingId) this.$parent.$emit('open-node', { parentId })
} }
} }
} }
+4 -4
View File
@@ -74,12 +74,12 @@ export default {
} }
}, },
openNode (parentId, childId) { openNode (ids) {
this.$store.dispatch('OPEN_NODE', [parentId, childId]) this.$store.dispatch('OPEN_NODE', ids)
}, },
closeNode (parentId, childId) { closeNode (ids) {
this.$store.dispatch('CLOSE_NODE', [parentId, childId]) this.$store.dispatch('CLOSE_NODE', ids)
} }
}, },
+5 -2
View File
@@ -58,8 +58,11 @@ export default {
methods: { methods: {
onOpen (node) { onOpen (node) {
// FIXME ALSO CHECK IF PARENT if (node.parents) {
this.$emit('open-node', node.id) this.$emit('open-node', { parentId: node.parents[0].id, childId: node.id })
} else {
this.$emit('open-node', { parentId: node.id })
}
} }
}, },
+9 -1
View File
@@ -106,7 +106,15 @@ export default {
methods: { methods: {
toCommaList, toCommaList,
trim trim,
onNodeClick (node) {
if (node.parents) {
this.$emit('open-node', { parentId: node.parents[0].id, childId: node.id })
} else {
this.$emit('open-node', { parentId: node.id })
}
}
}, },
created () { created () {
+2 -2
View File
@@ -132,14 +132,14 @@ export default {
router.push({ query }) router.push({ query })
}, },
async 'OPEN_NODE' ({ state, commit, dispatch }, [parentId, childId]) { async 'OPEN_NODE' ({ state, commit, dispatch }, { parentId, childId }) {
const stack = state.nodebook.find(stack => stack[0] === parentId) const stack = state.nodebook.find(stack => stack[0] === parentId)
if (stack && (childId === undefined || stack.includes(childId))) return if (stack && (childId === undefined || stack.includes(childId))) return
commit('ADD_NODEBOOK_NODE', [stack, parentId, childId]) commit('ADD_NODEBOOK_NODE', [stack, parentId, childId])
dispatch('UPDATE_QUERY_NODES') dispatch('UPDATE_QUERY_NODES')
}, },
'CLOSE_NODE' ({ state, commit, dispatch }, [parentId, childId]) { 'CLOSE_NODE' ({ state, commit, dispatch }, { parentId, childId }) {
const stack = state.nodebook.find(stack => stack.includes(parentId) && (childId ? stack.includes(childId) : true)) const stack = state.nodebook.find(stack => stack.includes(parentId) && (childId ? stack.includes(childId) : true))
commit('REMOVE_NODEBOOK_NODE', [stack, childId || parentId]) commit('REMOVE_NODEBOOK_NODE', [stack, childId || parentId])
dispatch('UPDATE_QUERY_NODES') dispatch('UPDATE_QUERY_NODES')