-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSimpleTableItem.js
125 lines (112 loc) · 4.82 KB
/
SimpleTableItem.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
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
window.SimpleTableCustomItem = (function () {
const CustomItem = DevExpress.Dashboard.Model.CustomItem;
const FormItemTemplates = DevExpress.Dashboard.Designer.FormItemTemplates;
const SIMPLE_TABLE_EXTENSION_NAME = 'CustomItemSimpleTable';
const svgIcon = `<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="` + SIMPLE_TABLE_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="M21,2H3C2.5,2,2,2.5,2,3v18c0,0.5,0.5,1,1,1h18c0.5,0,1-0.5,1-1V3
C22,2.5,21.5,2,21,2z M14,4v4h-4V4H14z M10,10h4v4h-4V10z M4,4h4v4H4V4z M4,10h4v4H4V10z M4,20v-4h4v4H4z M10,20v-4h4v4H10z M20,20
h-4v-4h4V20z M20,14h-4v-4h4V14z M20,8h-4V4h4V8z"/>
</svg>`;
const simpleTableMetadata = {
bindings: [{
propertyName: 'customDimensions',
dataItemType: 'Dimension',
array: true,
displayName: "Custom Dimensions"
}, {
propertyName: 'customMeasure',
dataItemType: 'Measure',
displayName: "Custom Measure"
}],
customProperties: [{
ownerType: CustomItem,
propertyName: 'showHeaders',
valueType: 'string',
defaultValue: 'Auto',
}, {
ownerType: CustomItem,
propertyName: 'textColor',
valueType: 'string',
defaultValue: 'Dark',
}],
optionsPanelSections: [{
title: "Custom Options",
items: [{
dataField: 'showHeaders',
template: FormItemTemplates.buttonGroup,
editorOptions: {
items: [{ text: 'Auto' }, { text: 'Off' }, { text: 'On' }],
}
},{
dataField: 'textColor',
label: { text: 'Text Color' },
template: FormItemTemplates.buttonGroup,
editorOptions: {
items: [{ text: 'Light' }, { text: 'Dark' }]
}
}]
}],
icon: SIMPLE_TABLE_EXTENSION_NAME,
title: 'Simple Table'
};
class SimpleTableItemViewer extends DevExpress.Dashboard.CustomItemViewer {
constructor(model, $container, options) {
super(model, $container, options);
}
renderContent($element, changeExisting) {
let element = $element.jquery ? $element[0] : $element;
if (!changeExisting) {
while (element.firstChild)
element.removeChild(element.firstChild);
element.style.overflow = 'auto';
this.tableElt = document.createElement('table');
this.tableElt.setAttribute("border", "1");
this.tableElt.setAttribute("cellspacing", "0");
element.append(this.tableElt);
}
this._update(this.getPropertyValue('showHeaders'));
}
_getTextColor() {
switch (this.getPropertyValue('textColor')) {
case 'Light': return "gray";
case 'Dark': return "black";
}
}
_update(mode) {
while (this.tableElt.firstChild)
this.tableElt.removeChild(this.tableElt.firstChild);
if (mode !== 'Off') {
let bindingValues = this.getBindingValue('customDimensions').concat(this.getBindingValue('customMeasure'));
this._addTableRow(bindingValues.map(function (item) { return item.displayName(); }), true);
}
this.iterateData(rowDataObject => {
let valueTexts = rowDataObject.getDisplayText('customDimensions').concat(rowDataObject.getDisplayText('customMeasure'));
this._addTableRow(valueTexts, false);
});
}
_addTableRow(rowValues, isHeader) {
const row = document.createElement('tr');
rowValues.forEach(text => {
const cell = document.createElement(isHeader ? 'th' : 'td');
cell.style.padding = '3px';
cell.innerText = text;
cell.style.color = this._getTextColor();
row.appendChild(cell);
});
this.tableElt.appendChild(row);
}
}
class SimpleTableItem {
constructor(dashboardControl) {
dashboardControl.registerIcon(svgIcon);
this.name = SIMPLE_TABLE_EXTENSION_NAME;
this.metaData = simpleTableMetadata;
}
createViewerItem(model, $element, content) {
return new SimpleTableItemViewer(model, $element, content);
}
}
return SimpleTableItem;
})();