1 |
|
2 | import {DraggingEvent, DragAndDropService} from "../dragAndDrop/dragAndDropService";
|
3 | import {Column} from "../entities/column";
|
4 | import {ColumnController} from "../columnController/columnController";
|
5 | import {Autowired} from "../context/context";
|
6 | import {GridOptionsWrapper} from "../gridOptionsWrapper";
|
7 | import {DropListener} from "./bodyDropTarget";
|
8 |
|
9 | export class BodyDropPivotTarget implements DropListener {
|
10 |
|
11 | @Autowired('columnController') private columnController: ColumnController;
|
12 | @Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
|
13 |
|
14 | private columnsToAggregate: Column[] = [];
|
15 | private columnsToGroup: Column[] = [];
|
16 | private columnsToPivot: Column[] = [];
|
17 |
|
18 | private pinned: string;
|
19 |
|
20 | constructor(pinned: string) {
|
21 | this.pinned = pinned;
|
22 | }
|
23 |
|
24 |
|
25 | public onDragEnter(draggingEvent: DraggingEvent): void {
|
26 | this.clearColumnsList();
|
27 |
|
28 |
|
29 | if (this.gridOptionsWrapper.isFunctionsReadOnly()) { return; }
|
30 |
|
31 | let dragColumns: Column[] = draggingEvent.dragItem.columns;
|
32 |
|
33 | dragColumns.forEach( column => {
|
34 |
|
35 | if (!column.isPrimary()) { return; }
|
36 |
|
37 | if (column.isAnyFunctionActive()) { return; }
|
38 |
|
39 | if (column.isAllowValue()) {
|
40 | this.columnsToAggregate.push(column);
|
41 | } else if (column.isAllowRowGroup()) {
|
42 | this.columnsToGroup.push(column);
|
43 | } else if (column.isAllowRowGroup()) {
|
44 | this.columnsToPivot.push(column);
|
45 | }
|
46 |
|
47 | });
|
48 | }
|
49 |
|
50 | public getIconName(): string {
|
51 | let totalColumns = this.columnsToAggregate.length + this.columnsToGroup.length + this.columnsToPivot.length;
|
52 | if (totalColumns > 0) {
|
53 | return this.pinned ? DragAndDropService.ICON_PINNED : DragAndDropService.ICON_MOVE;
|
54 | } else {
|
55 | return null;
|
56 | }
|
57 | }
|
58 |
|
59 |
|
60 | public onDragLeave(draggingEvent: DraggingEvent): void {
|
61 |
|
62 | this.clearColumnsList();
|
63 | }
|
64 |
|
65 | private clearColumnsList(): void {
|
66 | this.columnsToAggregate.length = 0;
|
67 | this.columnsToGroup.length = 0;
|
68 | this.columnsToPivot.length = 0;
|
69 | }
|
70 |
|
71 |
|
72 | public onDragging(draggingEvent: DraggingEvent): void {
|
73 | }
|
74 |
|
75 |
|
76 | public onDragStop(draggingEvent: DraggingEvent): void {
|
77 | if (this.columnsToAggregate.length>0) {
|
78 | this.columnController.addValueColumns(this.columnsToAggregate, "toolPanelDragAndDrop");
|
79 | }
|
80 | if (this.columnsToGroup.length>0) {
|
81 | this.columnController.addRowGroupColumns(this.columnsToGroup, "toolPanelDragAndDrop");
|
82 | }
|
83 | if (this.columnsToPivot.length>0) {
|
84 | this.columnController.addPivotColumns(this.columnsToPivot, "toolPanelDragAndDrop");
|
85 | }
|
86 | }
|
87 |
|
88 | } |
\ | No newline at end of file |