fix(Dashboard drag&drop): behavior of dragged widgets when they exceed the grid limits, and ensures all widget clones are always deleted

This commit is contained in:
SimonGschnell
2025-08-12 09:53:45 +02:00
parent 5e7514ffff
commit 3e69495842
+12 -7
View File
@@ -439,7 +439,7 @@ export default {
})
this.dragEnd();
this.dragCancel();
}
}
if (!this.active)
return this.dragCancel();
this.checkPinnedWidgetAnimation();
@@ -454,14 +454,14 @@ export default {
let x = this.x + this.draggedOffset[0];
let y = this.y + this.draggedOffset[1];
if (x < 0) {
this.draggedOffset[0] -= x;
this.draggedOffset[0] += x;
x = 0;
} else if (x + this.draggedItem.w > this.cols) {
this.draggedOffset[0] += this.cols - this.draggedItem.w - x;
x = this.cols - this.draggedItem.w;
}
if (y < 0) {
this.draggedOffset[1] -= y;
this.draggedOffset[1] += y;
y = 0;
}
this.positionUpdates = this.dragGrid.move(this.draggedItem, x, y);
@@ -481,6 +481,7 @@ export default {
}
},
dragCancel() {
this.removeWidgetClones();
this.additionalRowComputed = false;
this.toggleDraggedItemOverlay(false);
this.mode = MODE_IDLE;
@@ -492,6 +493,7 @@ export default {
},
dragEnd() {
this.removeWidgetClones();
if (this.mode == MODE_IDLE)
return;
// clean up unused classes
@@ -501,10 +503,7 @@ export default {
ele.classList.remove("denied-dragging-animation");
})
let widgetClones = document.getElementsByClassName("widgetClone");
for (let i=0; i <widgetClones.length; i++){
this.$refs.container.removeChild(widgetClones[i]);
}
if (!this.active || this.x < 0 || this.y < 0 || this.x >= this.cols)
return this.dragCancel();
@@ -597,6 +596,12 @@ export default {
draggedItemNode.classList.remove("border-danger");
}
},
removeWidgetClones(){
let widgetClones = Array.from(document.getElementsByClassName("widgetClone"));
for (let i = 0; i < widgetClones.length; i++) {
this.$refs.container.removeChild(widgetClones[i]);
}
},
mouseDown(){
this.mode = MODE_MOUSE_DOWN;
},