Changed deleted local ids to api ids

This commit is contained in:
Pünkösd Marcell 2020-12-05 20:16:33 +01:00
parent 4ff230007c
commit b6cf9d2ed5
2 changed files with 12 additions and 7 deletions

View File

@ -225,7 +225,6 @@ export default {
this.draggingLink = null; this.draggingLink = null;
} }
if (typeof target.className === 'string' && target.className.indexOf('node-delete') > -1) { if (typeof target.className === 'string' && target.className.indexOf('node-delete') > -1) {
// console.log('delete2', this.action.dragging);
this.nodeDelete(this.action.dragging); this.nodeDelete(this.action.dragging);
this.action.dragging = null; this.action.dragging = null;
} }
@ -261,13 +260,17 @@ export default {
})); }));
}, },
nodeDelete(id) { nodeDelete(id) {
const deleted_node = this.scene.nodes.find((node) => node.id === id);
console.log(deleted_node);
this.scene.nodes = this.scene.nodes.filter((node) => { this.scene.nodes = this.scene.nodes.filter((node) => {
return node.id !== id; return node.id !== id;
}) })
this.scene.links = this.scene.links.filter((link) => { this.scene.links = this.scene.links.filter((link) => {
return link.from !== id && link.to !== id return link.from !== id && link.to !== id
}) });
this.$emit('nodeDelete', id) this.$emit('nodeDelete', deleted_node);
}, },
dataUpdated(id, newData) { dataUpdated(id, newData) {
this.$emit('nodeDataEdited', id, newData); this.$emit('nodeDataEdited', id, newData);

View File

@ -49,7 +49,7 @@ export default {
pendingChanges: { pendingChanges: {
created: [], created: [],
updated: [], updated: [],
deleted: [] deleted: [] // Stores apiId instead of localId
}, },
model: { model: {
centerX: 0, centerX: 0,
@ -101,7 +101,7 @@ export default {
}, },
// Vuejs can not track changes of a set, so we do this magic hack to fix it // Vuejs can not track changes of a set, so we do this magic hack to fix it
enqueuePendingNodeDeletion(id) { enqueuePendingNodeDeletion({id, apiId}) {
let pending_deletes = new Set(this.pendingChanges.deleted); let pending_deletes = new Set(this.pendingChanges.deleted);
let pending_updates = new Set(this.pendingChanges.updated); let pending_updates = new Set(this.pendingChanges.updated);
let pending_creations = new Set(this.pendingChanges.created); let pending_creations = new Set(this.pendingChanges.created);
@ -110,7 +110,9 @@ export default {
if (pending_creations.has(id)) { if (pending_creations.has(id)) {
pending_creations.delete(id); pending_creations.delete(id);
} else { } else {
pending_deletes.add(id); if (apiId) {
pending_deletes.add(apiId);
}
} }
pending_updates.delete(id); pending_updates.delete(id);
@ -133,7 +135,7 @@ export default {
handleNodeMove() { handleNodeMove() {
// TODO // TODO
}, },
handleLinkBreak({from,to}) { handleLinkBreak({from, to}) {
this.enqueuePendingNodeUpdate(from); this.enqueuePendingNodeUpdate(from);
this.enqueuePendingNodeUpdate(to); this.enqueuePendingNodeUpdate(to);
}, },