-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgantt-item.ts
168 lines (147 loc) · 5.6 KB
/
gantt-item.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import { ICustomItemExtension, CustomItemViewer } from 'devexpress-dashboard/common';
import { ICustomItemMetaData } from 'devexpress-dashboard/model/items/custom-item/meta';
import dxGantt from 'devextreme/ui/gantt';
import notify from "devextreme/ui/notify";
const GANTT_EXTENSION_NAME = 'GanttItem';
const svgIcon = `<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="` + GANTT_EXTENSION_NAME + `" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<path class="dx-dashboard-contrast-icon" d="M23,2c0-0.6-0.4-1-1-1H2C1.4,1,1,1.4,1,2v20c0,0.6,0.4,1,1,1h20c0.6,0,1-0.4,1-1 V2z M21,21H3V3h18V21z"/>
<path class="dx-dashboard-accent-icon" d="M12,9H5V5h7V9z M19,10H9v4h10V10z M15,15H7v4h8V15z"/>
</svg>`;
const ganttItemMeta: ICustomItemMetaData = {
bindings: [{
propertyName: 'ID',
dataItemType: 'Dimension',
displayName: 'ID',
array: false,
enableInteractivity: true,
emptyPlaceholder: 'Set ID',
selectedPlaceholder: 'Configure ID'
}, {
propertyName: 'ParentID',
dataItemType: 'Dimension',
displayName: 'Parent ID',
array: false,
enableInteractivity: true,
emptyPlaceholder: 'Set Parent ID',
selectedPlaceholder: 'Configure Parent ID'
}, {
propertyName: 'Text',
dataItemType: 'Dimension',
displayName: 'Text',
array: false,
enableInteractivity: true,
emptyPlaceholder: 'Set Text',
selectedPlaceholder: 'Configure Text'
}, {
propertyName: 'StartDate',
dataItemType: 'Dimension',
displayName: 'Start Date',
array: false,
enableInteractivity: true,
emptyPlaceholder: 'Set Start Date',
selectedPlaceholder: 'Configure Start Date'
}, {
propertyName: 'FinishDate',
dataItemType: 'Dimension',
displayName: 'Finish Date',
array: false,
enableInteractivity: true,
emptyPlaceholder: 'Set Finish Date',
selectedPlaceholder: 'Configure Finish Date'
}],
interactivity: {
filter: true
},
icon: GANTT_EXTENSION_NAME,
title: 'Gantt Chart'
};
export class GanttItemExtension implements ICustomItemExtension {
name = GANTT_EXTENSION_NAME;
metaData = ganttItemMeta;
constructor(dashboardControl: any) {
dashboardControl.registerIcon(svgIcon);
}
public createViewerItem = (model: any, element: any, content: any) => {
return new GanttItemViewer(model, element, content);
}
}
export class GanttItemViewer extends CustomItemViewer {
dxGanttWidget?: dxGantt;
constructor(model: any, container: any, options: any) {
super(model, container, options);
}
_getDataSource() {
let data: any[] = [];
let datesValid: boolean = true;
this.iterateData(function (dataRow) {
data.push({
id: dataRow.getValue('ID')[0],
parentId: dataRow.getValue('ParentID')[0],
title: dataRow.getValue('Text')[0],
start: dataRow.getValue('StartDate')[0],
end: dataRow.getValue('FinishDate')[0],
clientDataRow: dataRow
});
let currentItem = data[data.length - 1];
if ((currentItem.start && !(currentItem.start instanceof Date)) || (currentItem.end && !(currentItem.end instanceof Date)))
datesValid = false;
});
if (!datesValid) {
notify("Gantt: 'Start Date' or 'Finish Date' is not a Date object.", "warning", 3000);
return [];
}
return data;
};
_getDxGanttWidgetSettings() {
return {
rootValue: -1,
tasks: {
dataSource: this._getDataSource()
},
columns: [{
dataField: "title",
caption: "Subject",
width: 300,
}, {
dataField: "start",
caption: "Start Date"
}, {
dataField: "end",
caption: "End Date"
}],
onTaskClick: (e: any) => {
let tasks = e.component.option("tasks.dataSource");
let clickedTask = tasks.filter((item: any) => item.id === e.key)[0];
this.setMasterFilter(clickedTask.clientDataRow);
},
scaleType: "days",
taskListWidth: 500
};
}
override renderContent(element: HTMLElement, changeExisting: boolean, afterRenderCallback?: any) {
if (!changeExisting) {
while (element.firstChild)
element.removeChild(element.firstChild);
this.dxGanttWidget = new dxGantt(element, <any>this._getDxGanttWidgetSettings());
} else {
this.dxGanttWidget?.option(<any>this._getDxGanttWidgetSettings());
}
}
override setSelection(values: Array<Array<any>>): void {
super.setSelection(values);
let tasks: any = this.dxGanttWidget?.option("tasks.dataSource");
tasks.forEach((item: any) => {
if (this.isSelected(item.clientDataRow))
this.dxGanttWidget?.option("selectedRowKey", item.id);
});
}
override clearSelection(): void {
super.clearSelection();
this.dxGanttWidget?.option("selectedRowKey", null);
}
override setSize(width: number, height: number): void {
super.setSize(width, height);
this.dxGanttWidget?.repaint();
}
}