UNPKG

3.12 kBPlain TextView Raw
1
2import {DraggingEvent, DragAndDropService} from "../dragAndDrop/dragAndDropService";
3import {Column} from "../entities/column";
4import {ColumnController} from "../columnController/columnController";
5import {Autowired} from "../context/context";
6import {GridOptionsWrapper} from "../gridOptionsWrapper";
7import {DropListener} from "./bodyDropTarget";
8
9export 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 /** Callback for when drag enters */
25 public onDragEnter(draggingEvent: DraggingEvent): void {
26 this.clearColumnsList();
27
28 // in pivot mode, we don't accept any drops if functions are read only
29 if (this.gridOptionsWrapper.isFunctionsReadOnly()) { return; }
30
31 let dragColumns: Column[] = draggingEvent.dragItem.columns;
32
33 dragColumns.forEach( column => {
34 // we don't allow adding secondary columns
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 /** Callback for when drag leaves */
60 public onDragLeave(draggingEvent: DraggingEvent): void {
61 // if we are taking columns out of the center, then we remove them from the report
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 /** Callback for when dragging */
72 public onDragging(draggingEvent: DraggingEvent): void {
73 }
74
75 /** Callback for when drag stops */
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