Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

abort drag&drop on cancel

ulfertsf38150df38d2
diff --git a/frontend/src/app/modules/grids/grid/drag-and-drop.service.ts b/frontend/src/app/modules/grids/grid/drag-and-drop.service.ts
index 3fb0c54c247..798b0ad4d10 100644
--- a/frontend/src/app/modules/grids/grid/drag-and-drop.service.ts
+++ b/frontend/src/app/modules/grids/grid/drag-and-drop.service.ts
@@ -10,6 +10,7 @@ export class GridDragAndDropService {
public draggedArea:GridWidgetArea|null;
public placeholderArea:GridWidgetArea|null;
public draggedHeight:number|null;
+ private aborted = false;
constructor(readonly layout:GridAreaService,
readonly move:GridMoveService) {
@@ -59,7 +60,12 @@ export class GridDragAndDropService {
this.draggedHeight = (document as any).getElementById(area.guid).offsetHeight - 2; // border width * 2
}
- public stop(area:GridWidgetArea, event:CdkDragEnd) {
+ public abort() {
+ document.dispatchEvent(new Event('mouseup'));
+ this.aborted = true;
+ }
+
+ public stop() {
if (!this.draggedArea) {
return;
}
@@ -69,6 +75,11 @@ export class GridDragAndDropService {
}
public drop(event:CdkDragDrop<GridArea>) {
+ if (this.aborted) {
+ this.aborted = false;
+ return;
+ }
+
// this.draggedArea is already reset to null at this point
let dropArea = event.container.data;
let draggedArea = event.previousContainer.data as GridWidgetArea;
diff --git a/frontend/src/app/modules/grids/grid/grid.component.html b/frontend/src/app/modules/grids/grid/grid.component.html
index 8dfbaa25eb4..c39a5264288 100644
--- a/frontend/src/app/modules/grids/grid/grid.component.html
+++ b/frontend/src/app/modules/grids/grid/grid.component.html
@@ -19,7 +19,7 @@
<div class="grid--area-content widget-box"
cdkDrag
(cdkDragStarted)="drag.start(area)"
- (cdkDragEnded)="drag.stop(area, $event)">
+ (cdkDragEnded)="drag.stop()">
<span *ngIf="drag.isDraggable"
class="grid--area-drag-handle
diff --git a/frontend/src/app/modules/grids/grid/grid.component.ts b/frontend/src/app/modules/grids/grid/grid.component.ts
index 7b005a702d6..5b2eb5ba04c 100644
--- a/frontend/src/app/modules/grids/grid/grid.component.ts
+++ b/frontend/src/app/modules/grids/grid/grid.component.ts
@@ -2,7 +2,8 @@ import {Component,
ComponentRef,
OnDestroy,
OnInit,
- Input} from "@angular/core";
+ Input,
+ HostListener} from "@angular/core";
import {GridResource} from "app/modules/hal/resources/grid-resource";
import {debugLog} from "app/helpers/debug_output";
import {DomSanitizer} from "@angular/platform-browser";
@@ -63,6 +64,13 @@ export class GridComponent implements OnDestroy, OnInit {
this.uiWidgets.forEach((widget) => widget.destroy());
}
+ @HostListener('window:keyup', ['$event'])
+ handleKeyboardEvent(event:KeyboardEvent) {
+ if (event.key === 'Escape' && this.drag.currentlyDragging) {
+ this.drag.abort();
+ }
+ }
+
public widgetComponent(area:GridWidgetArea) {
let widget = area.widget;