-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAwareItem.js
90 lines (86 loc) · 2.66 KB
/
DataAwareItem.js
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
// #region imports
import { CustomItemViewer, ResourceManager } from 'devexpress-dashboard/common'
import { CustomItem } from 'devexpress-dashboard/model'
import { FormItemTemplates } from 'devexpress-dashboard/designer'
// #endregion
// #region svgIcon
var svgIcon = '<svg id="dataAwareItemIcon" viewBox="0 0 24 24"><path stroke="#ffffff" fill="#4842f4" d="M12 2 L2 22 L22 22 Z" /></svg>';
// #endregion
// #region metadata
var dataAwareItemMetaData = {
bindings: [{
propertyName: 'dimensionValue',
dataItemType: 'Dimension',
displayName: 'Dimension',
enableColoring: true
}],
customProperties: [{
owner: CustomItem,
propertyName: 'backColorProperty',
valueType: 'string',
defaultValue: 'None'
}],
optionsPanelSections: [{
title: 'Background',
items: [{
dataField: 'backColorProperty',
label: { text: 'Backcolor' },
template: FormItemTemplates.buttonGroup,
editorOptions: {
items: [{ text: 'None' }, { text: 'Red' }, { text: 'Blue' }]
}
}]
}],
icon: 'dataAwareItemIcon',
title: 'Data Aware Item'
};
// #endregion
// #region viewer
class DataAwareItemViewer extends CustomItemViewer {
constructor(model, $container, options) {
super(model, $container, options);
}
renderContent(element, changeExisting) {
while (element.firstChild)
element.removeChild(element.firstChild);
var clientData = this._getDataSource();
clientData.forEach(function (item) {
var div = document.createElement('div');
div.style.color = item.color;
div.innerText = item.dimensionDisplayText;
element.appendChild(div);
});
element.style.background = this._getBackColorProperty();
};
_getDataSource() {
var clientData = [];
this.iterateData(function (dataRow) {
clientData.push({
dimensionDisplayText: dataRow.getDisplayText('dimensionValue')[0] || "",
color: dataRow.getColor()[0]
});
});
return clientData;
};
_getBackColorProperty() {
switch (this.getPropertyValue('backColorProperty')) {
case 'None': return "rgb(255,255,255)";
case 'Red': return "rgb(255,220,200)";
case 'Blue': return "rgb(135,206,235)";
}
};
}
// #endregion
// #region createItem
class DataAwareItem {
constructor(dashboardControl) {
ResourceManager.registerIcon(svgIcon);
this.name = "dataAwareItem";
this.metaData = dataAwareItemMetaData;
}
createViewerItem(model, $element, content) {
return new DataAwareItemViewer(model, $element, content);
}
}
export default DataAwareItem;
// #endregion