mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4444] drag and drop fixes (#4674)
* more granular control over drag and drop * fix performance, internal drop-zone directive
This commit is contained in:
committed by
Eugenio Romano
parent
2edee23bdd
commit
55113f37b6
@@ -26,8 +26,7 @@
|
||||
role="columnheader"
|
||||
tabindex="0"
|
||||
title="{{ col.title | translate }}"
|
||||
(dragover)="onDragOver($event)"
|
||||
(drop)="onHeaderDrop($event, col)">
|
||||
adf-drop-zone dropTarget="header" [dropColumn]="col">
|
||||
<span *ngIf="col.srTitle" class="adf-sr-only">{{ col.srTitle | translate }}</span>
|
||||
<span *ngIf="col.title" class="adf-datatable-cell-value">{{ col.title | translate}}</span>
|
||||
</div>
|
||||
@@ -98,8 +97,7 @@
|
||||
(keydown.enter)="onEnterKeyPressed(row, $event)"
|
||||
[adf-context-menu]="getContextMenuActions(row, col)"
|
||||
[adf-context-menu-enabled]="contextMenu"
|
||||
(dragover)="onDragOver($event)"
|
||||
(drop)="onCellDrop($event, col, row)">
|
||||
adf-drop-zone dropTarget="cell" [dropColumn]="col" [dropRow]="row">
|
||||
<div *ngIf="!col.template" class="adf-datatable-cell-container">
|
||||
<ng-container [ngSwitch]="col.type">
|
||||
<div *ngSwitchCase="'image'" class="adf-cell-value">
|
||||
|
@@ -701,42 +701,6 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
const name = this.getNameColumnValue();
|
||||
return name ? row.getValue(name.key) : '';
|
||||
}
|
||||
|
||||
onDragOver(event: Event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
onHeaderDrop(event: Event, column: DataColumn) {
|
||||
event.preventDefault();
|
||||
|
||||
this.elementRef.nativeElement.dispatchEvent(
|
||||
new CustomEvent('header-drop', {
|
||||
detail: {
|
||||
target: 'header',
|
||||
event,
|
||||
column
|
||||
},
|
||||
bubbles: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
onCellDrop(event: Event, column: DataColumn, row: DataRow) {
|
||||
event.preventDefault();
|
||||
|
||||
this.elementRef.nativeElement.dispatchEvent(
|
||||
new CustomEvent('cell-drop', {
|
||||
detail: {
|
||||
target: 'cell',
|
||||
event,
|
||||
column,
|
||||
row
|
||||
},
|
||||
bubbles: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export interface DataTableDropEvent {
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Directive, Input, ElementRef, NgZone, OnInit, OnDestroy } from '@angular/core';
|
||||
import { DataRow } from '../../data/data-row.model';
|
||||
import { DataColumn } from '../../data/data-column.model';
|
||||
|
||||
@Directive({
|
||||
selector: '[adf-drop-zone]'
|
||||
})
|
||||
export class DropZoneDirective implements OnInit, OnDestroy {
|
||||
private element: HTMLElement;
|
||||
|
||||
@Input()
|
||||
dropTarget: 'header' | 'cell' = 'cell';
|
||||
|
||||
@Input()
|
||||
dropRow: DataRow;
|
||||
|
||||
@Input()
|
||||
dropColumn: DataColumn;
|
||||
|
||||
constructor(elementRef: ElementRef, private ngZone: NgZone) {
|
||||
this.element = elementRef.nativeElement;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.ngZone.runOutsideAngular(() => {
|
||||
this.element.addEventListener('dragover', this.onDragOver.bind(this));
|
||||
this.element.addEventListener('drop', this.onDrop.bind(this));
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.element.removeEventListener('dragover', this.onDragOver);
|
||||
this.element.removeEventListener('drop', this.onDrop);
|
||||
}
|
||||
|
||||
onDragOver(event: Event) {
|
||||
const domEvent = new CustomEvent(`${this.dropTarget}-dragover`, {
|
||||
detail: {
|
||||
target: this.dropTarget,
|
||||
event,
|
||||
column: this.dropColumn,
|
||||
row: this.dropRow
|
||||
},
|
||||
bubbles: true
|
||||
});
|
||||
|
||||
this.element.dispatchEvent(domEvent);
|
||||
|
||||
if (domEvent.defaultPrevented) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
onDrop(event: Event) {
|
||||
const domEvent = new CustomEvent(`${this.dropTarget}-drop`, {
|
||||
detail: {
|
||||
target: this.dropTarget,
|
||||
event,
|
||||
column: this.dropColumn,
|
||||
row: this.dropRow
|
||||
},
|
||||
bubbles: true
|
||||
});
|
||||
|
||||
this.element.dispatchEvent(domEvent);
|
||||
|
||||
if (domEvent.defaultPrevented) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user