cedro 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/dist/assets/_virtual/_commonjsHelpers.js +1 -0
- package/dist/assets/_virtual/index.js +1 -0
- package/dist/assets/_virtual/modulepreload-polyfill.js +1 -0
- package/dist/assets/_virtual/named-references.js +1 -0
- package/dist/assets/_virtual/numeric-unicode-map.js +1 -0
- package/dist/assets/_virtual/surrogate-pairs.js +1 -0
- package/dist/assets/core/application.builder.js +1 -0
- package/dist/assets/core/application.core.js +1 -0
- package/dist/assets/core/jsxsupport.js +1 -0
- package/dist/assets/core/screeen.core.js +1 -0
- package/dist/assets/core/seo.js +1 -0
- package/dist/assets/core/themes.core.js +1 -0
- package/dist/assets/core/uid.js +1 -0
- package/dist/assets/index.js +1 -0
- package/dist/assets/material-icons-outlined.woff +0 -0
- package/dist/assets/material-icons-outlined.woff2 +0 -0
- package/dist/assets/material-icons-round.woff +0 -0
- package/dist/assets/material-icons-round.woff2 +0 -0
- package/dist/assets/material-icons-sharp.woff +0 -0
- package/dist/assets/material-icons-sharp.woff2 +0 -0
- package/dist/assets/material-icons-two-tone.woff +0 -0
- package/dist/assets/material-icons-two-tone.woff2 +0 -0
- package/dist/assets/material-icons.woff +0 -0
- package/dist/assets/material-icons.woff2 +0 -0
- package/dist/assets/node_modules/@fontsource/roboto/100.css +1 -0
- package/dist/assets/node_modules/@fontsource/roboto/300.css +1 -0
- package/dist/assets/node_modules/@fontsource/roboto/400.css +1 -0
- package/dist/assets/node_modules/@fontsource/roboto/500.css +1 -0
- package/dist/assets/node_modules/@fontsource/roboto/700.css +1 -0
- package/dist/assets/node_modules/@fontsource/roboto/900.css +1 -0
- package/dist/assets/node_modules/html-entities/lib/index.js +1 -0
- package/dist/assets/node_modules/html-entities/lib/named-references.js +2 -0
- package/dist/assets/node_modules/html-entities/lib/numeric-unicode-map.js +1 -0
- package/dist/assets/node_modules/html-entities/lib/surrogate-pairs.js +1 -0
- package/dist/assets/node_modules/material-icons/iconfont/material-icons.css +1 -0
- package/dist/assets/node_modules/navigo/lib/es/Q.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/constants.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/index.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/lifecycles.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/callHandler.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/checkForAfterHook.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/checkForAlreadyHook.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/checkForBeforeHook.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/checkForDeprecationMethods.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/checkForForceOp.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/checkForLeaveHook.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/checkForNotFoundHandler.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/errorOut.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/flushCurrent.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/matchPathToRegisteredRoutes.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/processMatches.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/setLocationPath.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/updateBrowserURL.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/updateState.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/middlewares/waitingList.js +1 -0
- package/dist/assets/node_modules/navigo/lib/es/utils.js +1 -0
- package/dist/assets/roboto-cyrillic-100-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-100-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-300-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-300-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-400-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-400-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-500-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-500-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-700-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-700-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-900-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-900-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-ext-100-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-ext-100-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-ext-300-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-ext-300-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-ext-400-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-ext-400-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-ext-500-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-ext-500-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-ext-700-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-ext-700-normal.woff2 +0 -0
- package/dist/assets/roboto-cyrillic-ext-900-normal.woff +0 -0
- package/dist/assets/roboto-cyrillic-ext-900-normal.woff2 +0 -0
- package/dist/assets/roboto-greek-100-normal.woff +0 -0
- package/dist/assets/roboto-greek-100-normal.woff2 +0 -0
- package/dist/assets/roboto-greek-300-normal.woff +0 -0
- package/dist/assets/roboto-greek-300-normal.woff2 +0 -0
- package/dist/assets/roboto-greek-400-normal.woff +0 -0
- package/dist/assets/roboto-greek-400-normal.woff2 +0 -0
- package/dist/assets/roboto-greek-500-normal.woff +0 -0
- package/dist/assets/roboto-greek-500-normal.woff2 +0 -0
- package/dist/assets/roboto-greek-700-normal.woff +0 -0
- package/dist/assets/roboto-greek-700-normal.woff2 +0 -0
- package/dist/assets/roboto-greek-900-normal.woff +0 -0
- package/dist/assets/roboto-greek-900-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-100-normal.woff +0 -0
- package/dist/assets/roboto-latin-100-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-300-normal.woff +0 -0
- package/dist/assets/roboto-latin-300-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-400-normal.woff +0 -0
- package/dist/assets/roboto-latin-400-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-500-normal.woff +0 -0
- package/dist/assets/roboto-latin-500-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-700-normal.woff +0 -0
- package/dist/assets/roboto-latin-700-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-900-normal.woff +0 -0
- package/dist/assets/roboto-latin-900-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-ext-100-normal.woff +0 -0
- package/dist/assets/roboto-latin-ext-100-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-ext-300-normal.woff +0 -0
- package/dist/assets/roboto-latin-ext-300-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-ext-400-normal.woff +0 -0
- package/dist/assets/roboto-latin-ext-400-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-ext-500-normal.woff +0 -0
- package/dist/assets/roboto-latin-ext-500-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-ext-700-normal.woff +0 -0
- package/dist/assets/roboto-latin-ext-700-normal.woff2 +0 -0
- package/dist/assets/roboto-latin-ext-900-normal.woff +0 -0
- package/dist/assets/roboto-latin-ext-900-normal.woff2 +0 -0
- package/dist/assets/roboto-vietnamese-100-normal.woff +0 -0
- package/dist/assets/roboto-vietnamese-100-normal.woff2 +0 -0
- package/dist/assets/roboto-vietnamese-300-normal.woff +0 -0
- package/dist/assets/roboto-vietnamese-300-normal.woff2 +0 -0
- package/dist/assets/roboto-vietnamese-400-normal.woff +0 -0
- package/dist/assets/roboto-vietnamese-400-normal.woff2 +0 -0
- package/dist/assets/roboto-vietnamese-500-normal.woff +0 -0
- package/dist/assets/roboto-vietnamese-500-normal.woff2 +0 -0
- package/dist/assets/roboto-vietnamese-700-normal.woff +0 -0
- package/dist/assets/roboto-vietnamese-700-normal.woff2 +0 -0
- package/dist/assets/roboto-vietnamese-900-normal.woff +0 -0
- package/dist/assets/roboto-vietnamese-900-normal.woff2 +0 -0
- package/dist/assets/types/select.item.type.js +1 -0
- package/dist/assets/ui/Icon.ui.js +1 -0
- package/dist/assets/ui/IconButton.ui.js +1 -0
- package/dist/assets/ui/Textbox.ui.js +1 -0
- package/dist/assets/ui/accordion.ui.js +1 -0
- package/dist/assets/ui/button.ui.js +1 -0
- package/dist/assets/ui/buttonColor.ui.js +1 -0
- package/dist/assets/ui/buttonmenu.ui.js +1 -0
- package/dist/assets/ui/buttonstack.ui.js +1 -0
- package/dist/assets/ui/checkbox.ui.js +1 -0
- package/dist/assets/ui/container.ui.js +1 -0
- package/dist/assets/ui/datagrid.ui.js +1 -0
- package/dist/assets/ui/dialog.js +1 -0
- package/dist/assets/ui/draggable.ui.js +1 -0
- package/dist/assets/ui/hpanel.ui.js +1 -0
- package/dist/assets/ui/iconButtonMenu.ui.js +1 -0
- package/dist/assets/ui/image.ui.js +1 -0
- package/dist/assets/ui/label.ui.js +1 -0
- package/dist/assets/ui/loading.ui.js +1 -0
- package/dist/assets/ui/menu.ui.js +1 -0
- package/dist/assets/ui/progressbar.ui.js +1 -0
- package/dist/assets/ui/radiobutton.ui.js +1 -0
- package/dist/assets/ui/scroll.ui.js +1 -0
- package/dist/assets/ui/select.ui.js +1 -0
- package/dist/assets/ui/styles/accordion.css +1 -0
- package/dist/assets/ui/styles/button.css +1 -0
- package/dist/assets/ui/styles/buttoncolor.css +1 -0
- package/dist/assets/ui/styles/container.css +1 -0
- package/dist/assets/ui/styles/datagrid.css +1 -0
- package/dist/assets/ui/styles/dialog.css +1 -0
- package/dist/assets/ui/styles/draggable.css +1 -0
- package/dist/assets/ui/styles/hpanel.css +1 -0
- package/dist/assets/ui/styles/icon.css +1 -0
- package/dist/assets/ui/styles/image.css +1 -0
- package/dist/assets/ui/styles/label.css +1 -0
- package/dist/assets/ui/styles/loading.css +1 -0
- package/dist/assets/ui/styles/main.css +1 -0
- package/dist/assets/ui/styles/menu.css +1 -0
- package/dist/assets/ui/styles/progressbar.css +1 -0
- package/dist/assets/ui/styles/scroll.css +1 -0
- package/dist/assets/ui/styles/select.css +1 -0
- package/dist/assets/ui/styles/stackbutton.css +1 -0
- package/dist/assets/ui/styles/tabs.css +1 -0
- package/dist/assets/ui/styles/textarea.css +1 -0
- package/dist/assets/ui/styles/textbox.css +1 -0
- package/dist/assets/ui/styles/toolbar.css +1 -0
- package/dist/assets/ui/styles/valuebar.css +1 -0
- package/dist/assets/ui/styles/vpanel.css +1 -0
- package/dist/assets/ui/styles/vstackbutton.css +1 -0
- package/dist/assets/ui/switch.ui.js +1 -0
- package/dist/assets/ui/tabs.ui.js +1 -0
- package/dist/assets/ui/textarea.ui.js +1 -0
- package/dist/assets/ui/toggle.ui.js +1 -0
- package/dist/assets/ui/toolbar.ui.js +1 -0
- package/dist/assets/ui/valuebar.ui.js +1 -0
- package/dist/assets/ui/vpanel.ui.js +1 -0
- package/dist/assets/ui/widget.builder.js +1 -0
- package/dist/assets/ui/widget.collection.js +1 -0
- package/dist/assets/ui/widget.ui.js +1 -0
- package/dist/cedro-logo.png +0 -0
- package/dist/cedro-logo.svg +97 -0
- package/dist/fangio.jpg +0 -0
- package/dist/material-icons-list.json/357/200/272Zone.Identifier +3 -0
- package/package.json +4 -2
- package/src/core/application.builder.tsx +122 -60
- package/src/core/application.core.tsx +110 -11
- package/src/core/themes.core.ts +160 -1
- package/src/core/uid.ts +3 -3
- package/src/interfaces/application.interface.ts +3 -2
- package/src/interfaces/widget.interface.ts +3 -0
- package/src/types/select.item.type.ts +11 -0
- package/src/ui/Icon.ui.tsx +158 -0
- package/src/ui/IconButton.ui.tsx +51 -9
- package/src/ui/{textbox.ui.tsx → Textbox.ui.tsx} +23 -15
- package/src/ui/accordion.ui.tsx +152 -0
- package/src/ui/button.ui.tsx +55 -14
- package/src/ui/buttonColor.ui.tsx +87 -0
- package/src/ui/buttonmenu.ui.tsx +133 -0
- package/src/ui/{buttonstack.ui.ts → buttonstack.ui.tsx} +67 -1
- package/src/ui/checkbox.ui.tsx +9 -13
- package/src/ui/container.ui.tsx +140 -76
- package/src/ui/datagrid.ui.tsx +514 -0
- package/src/ui/dialog.tsx +143 -56
- package/src/ui/hpanel.ui.tsx +37 -11
- package/src/ui/iconButtonMenu.ui.tsx +175 -0
- package/src/ui/image.ui.tsx +123 -112
- package/src/ui/index.ts +8 -8
- package/src/ui/label.ui.tsx +61 -3
- package/src/ui/loading.ui.ts +10 -10
- package/src/ui/menu.ui.ts +2 -2
- package/src/ui/progressbar.ui.tsx +9 -8
- package/src/ui/{radiobutton.tsx → radiobutton.ui.tsx} +9 -13
- package/src/ui/scroll.ui.ts +13 -12
- package/src/ui/select.ui.tsx +143 -0
- package/src/ui/styles/button.css +114 -32
- package/src/ui/styles/buttoncolor.css +8 -8
- package/src/ui/styles/container.css +29 -0
- package/src/ui/styles/icon.css +29 -0
- package/src/ui/styles/image.css +19 -19
- package/src/ui/styles/label.css +63 -0
- package/src/ui/styles/loading.css +12 -12
- package/src/ui/styles/main.css +5 -0
- package/src/ui/styles/progressbar.css +2 -1
- package/src/ui/styles/select.css +13 -0
- package/src/ui/styles/stackbutton.css +36 -0
- package/src/ui/styles/tabs.css +5 -7
- package/src/ui/styles/textarea.css +13 -13
- package/src/ui/switch.ui.tsx +9 -13
- package/src/ui/tabs.ui.tsx +43 -22
- package/src/ui/textarea.ui.tsx +48 -0
- package/src/ui/toolbar.ui.tsx +17 -12
- package/src/ui/valuebar.ui.tsx +11 -13
- package/src/ui/vpanel.ui.tsx +19 -13
- package/src/ui/widget.builder.ts +243 -159
- package/src/ui/widget.collection.ts +24 -2
- package/src/ui/widget.ui.ts +79 -19
- package/src/ui/Icon.ui.ts +0 -64
- package/src/ui/accordion.ui.ts +0 -71
- package/src/ui/buttonColor.ui.ts +0 -24
- package/src/ui/buttonmenu.ui.ts +0 -59
- package/src/ui/datagrid.ui.ts +0 -231
- package/src/ui/iconButtonMenu.ui.ts +0 -59
- package/src/ui/select.ui.ts +0 -73
- package/src/ui/textarea.ui.ts +0 -20
- /package/src/ui/{toggle.ui.ts → toggle.ui.tsx} +0 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import "./styles/datagrid.css";
|
|
2
|
+
import { Label } from "./label.ui";
|
|
3
|
+
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
4
|
+
import { Scroll } from "./scroll.ui";
|
|
5
|
+
import { normalizeWidget, WidgetEventProps, WidgetProps } from "./widget.builder";
|
|
6
|
+
import { UID } from "../core/uid";
|
|
7
|
+
import { decode } from "html-entities";
|
|
8
|
+
import { Button } from "./button.ui";
|
|
9
|
+
import { IconButton } from "./IconButton.ui";
|
|
10
|
+
import { ProgressBar } from "./progressbar.ui";
|
|
11
|
+
|
|
12
|
+
const DATA_GRID_HEADER_HEIGHT = 30;
|
|
13
|
+
const DATA_GRID_FOOTER_HEIGHT = 40;
|
|
14
|
+
const DATA_GRID_ROW_HEIGHT = 20;
|
|
15
|
+
const DATA_GRID_MIN_COLUMN_WIDTH = 24;
|
|
16
|
+
|
|
17
|
+
type DataGridColumn = {
|
|
18
|
+
header: string;
|
|
19
|
+
width: number | null;
|
|
20
|
+
handler: (args: any) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class DataGrid extends Widget {
|
|
24
|
+
headerContainer: Widget;
|
|
25
|
+
dataContainer: Widget;
|
|
26
|
+
footerContainer: Widget;
|
|
27
|
+
data: Array<any>;
|
|
28
|
+
verticalScrollbar: Scroll;
|
|
29
|
+
horizontalScrollbar: Scroll;
|
|
30
|
+
|
|
31
|
+
rowHeight: number;
|
|
32
|
+
|
|
33
|
+
columns: Array<DataGridColumn>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Initializes a new instance of the DataGrid class.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} id - The unique identifier for the DataGrid instance.
|
|
39
|
+
* @param {Widget|null} parent - The parent widget of the DataGrid instance.
|
|
40
|
+
* @return {void}
|
|
41
|
+
*/
|
|
42
|
+
constructor(id: string, parent: Widget | null = null) {
|
|
43
|
+
super(id, "div", parent);
|
|
44
|
+
|
|
45
|
+
this.rowHeight = DATA_GRID_ROW_HEIGHT;
|
|
46
|
+
|
|
47
|
+
this.headerContainer = new Widget(id + ".header", "div");
|
|
48
|
+
this.headerContainer.setType(WidgetTypes.FILL);
|
|
49
|
+
this.headerContainer.setFixedSize(DATA_GRID_HEADER_HEIGHT);
|
|
50
|
+
this.headerContainer.addClass("WUIDataGrid-Header");
|
|
51
|
+
|
|
52
|
+
this.dataContainer = new Widget(id + ".data", "div");
|
|
53
|
+
this.dataContainer.setType(WidgetTypes.FILL);
|
|
54
|
+
|
|
55
|
+
this.footerContainer = new Widget(id + ".footer", "div");
|
|
56
|
+
this.footerContainer.setType(WidgetTypes.FILL);
|
|
57
|
+
this.footerContainer.setFixedSize(DATA_GRID_FOOTER_HEIGHT);
|
|
58
|
+
|
|
59
|
+
this.setType(WidgetTypes.FILL);
|
|
60
|
+
this.setAlign(WidgetAlignTypes.VERTICAL);
|
|
61
|
+
|
|
62
|
+
this.addChild(this.headerContainer);
|
|
63
|
+
this.addChild(this.dataContainer);
|
|
64
|
+
this.addChild(this.footerContainer);
|
|
65
|
+
|
|
66
|
+
this.verticalScrollbar = new Scroll(id + ".VerticalScrollbar", this.dataContainer);
|
|
67
|
+
this.horizontalScrollbar = new Scroll(
|
|
68
|
+
id + ".HorizontalScrollbar",
|
|
69
|
+
this.dataContainer,
|
|
70
|
+
"horizontal"
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
this.horizontalScrollbar.subscribe({
|
|
74
|
+
event: "scroll",
|
|
75
|
+
then: (_e, _w) => {
|
|
76
|
+
this.renderHeaders();
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.columns = new Array<DataGridColumn>();
|
|
81
|
+
|
|
82
|
+
this.data = new Array<any>();
|
|
83
|
+
|
|
84
|
+
this.addClass("WUIDataGrid");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public hideFooter(): void {
|
|
88
|
+
this.footerContainer.setFixedSize(0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public showFooter(): void {
|
|
92
|
+
this.footerContainer.setFixedSize(DATA_GRID_FOOTER_HEIGHT);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Calculates the free width available in the data grid.
|
|
97
|
+
*
|
|
98
|
+
* The free width is calculated by subtracting the total width of all columns from the width of the data container.
|
|
99
|
+
* If the calculated free width is less than the minimum allowed column width, it is set to the minimum allowed column width.
|
|
100
|
+
*
|
|
101
|
+
* @return {number} The free width available in the data grid.
|
|
102
|
+
*/
|
|
103
|
+
private getFreeWidth(): number {
|
|
104
|
+
let freeW = 0;
|
|
105
|
+
for (let i = 0; i < this.columns.length; i++) {
|
|
106
|
+
let width = this.columns[i].width;
|
|
107
|
+
if (width) {
|
|
108
|
+
freeW += width;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
freeW = this.dataContainer.getW() - freeW;
|
|
113
|
+
|
|
114
|
+
if (freeW < DATA_GRID_MIN_COLUMN_WIDTH) {
|
|
115
|
+
freeW = DATA_GRID_MIN_COLUMN_WIDTH;
|
|
116
|
+
}
|
|
117
|
+
return freeW;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Calculates the total width of all columns in the data grid.
|
|
122
|
+
*
|
|
123
|
+
* @return {number} The total width of all columns.
|
|
124
|
+
*/
|
|
125
|
+
private getAllColumnsWidth(): number {
|
|
126
|
+
let returnValue = 0;
|
|
127
|
+
for (let i = 0; i < this.columns.length; i++) {
|
|
128
|
+
let width = this.columns[i].width;
|
|
129
|
+
if (width) {
|
|
130
|
+
returnValue += width;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return returnValue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public init(): void {
|
|
137
|
+
super.init();
|
|
138
|
+
this.createHeaders();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates the headers for the data grid based on the provided columns.
|
|
143
|
+
*
|
|
144
|
+
* If no columns are provided, the function will return immediately.
|
|
145
|
+
*
|
|
146
|
+
* @return {void}
|
|
147
|
+
*/
|
|
148
|
+
private createHeaders(): void {
|
|
149
|
+
if (!this.columns) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (let i = 0; i < this.columns.length; i++) {
|
|
154
|
+
const btn = new Label(this.id + "header." + i, "span");
|
|
155
|
+
btn.addClass("WUIDataGrid-HeaderLabel");
|
|
156
|
+
this.headerContainer.addChild(btn);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.renderHeaders();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Renders the headers of the data grid based on the provided columns.
|
|
164
|
+
*
|
|
165
|
+
* If no columns are provided, the function will return immediately.
|
|
166
|
+
*
|
|
167
|
+
* The headers are rendered as custom labels with their positions and sizes
|
|
168
|
+
* calculated based on the column widths and the scroll position of the data container.
|
|
169
|
+
*
|
|
170
|
+
* @return {void}
|
|
171
|
+
*/
|
|
172
|
+
private renderHeaders(): void {
|
|
173
|
+
if (!this.columns) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let startX = -this.dataContainer.getBody().scrollLeft;
|
|
178
|
+
for (let i = 0; i < this.columns.length; i++) {
|
|
179
|
+
const column = this.columns[i];
|
|
180
|
+
const btn = window.w.get(this.id + "header." + i) as Label;
|
|
181
|
+
const width = column.width ? column.width : this.getFreeWidth();
|
|
182
|
+
btn.setType(WidgetTypes.CUSTOM);
|
|
183
|
+
btn.setX(startX);
|
|
184
|
+
btn.setY(0);
|
|
185
|
+
btn.setW(width);
|
|
186
|
+
btn.setH(DATA_GRID_HEADER_HEIGHT);
|
|
187
|
+
btn.getBody().style.lineHeight = DATA_GRID_HEADER_HEIGHT + "px";
|
|
188
|
+
btn.setText(column.header);
|
|
189
|
+
this.headerContainer.addChild(btn);
|
|
190
|
+
startX += width;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Builds the rows of the data grid based on the provided data and columns.
|
|
196
|
+
*
|
|
197
|
+
* This function iterates over the data and creates a new row widget for each item.
|
|
198
|
+
* It then iterates over the columns and calls the column handler to render the cell content.
|
|
199
|
+
* The row and column widgets are positioned absolutely and added to the data container.
|
|
200
|
+
*
|
|
201
|
+
* @return {void}
|
|
202
|
+
*/
|
|
203
|
+
private buildRows(): void {
|
|
204
|
+
let rowY = 0;
|
|
205
|
+
|
|
206
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
207
|
+
const row = new Widget(this.id + ".row." + i, "div");
|
|
208
|
+
|
|
209
|
+
row.setType(WidgetTypes.CUSTOM);
|
|
210
|
+
row.getBody().style.position = "absolute";
|
|
211
|
+
row.getBody().style.overflow = "hidden";
|
|
212
|
+
row.addClass("WUIDataGrid-Row");
|
|
213
|
+
|
|
214
|
+
this.dataContainer.addChild(row);
|
|
215
|
+
|
|
216
|
+
for (let j = 0; j < this.columns.length; j++) {
|
|
217
|
+
const column = this.columns[j];
|
|
218
|
+
const fieldId = this.id + ".row." + i + ".column." + j;
|
|
219
|
+
column.handler({
|
|
220
|
+
data: this.data[i],
|
|
221
|
+
index: i,
|
|
222
|
+
fieldId: fieldId,
|
|
223
|
+
row: row,
|
|
224
|
+
});
|
|
225
|
+
const columnWidget = window.w.get(fieldId) as Widget;
|
|
226
|
+
columnWidget.getBody().style.position = "absolute";
|
|
227
|
+
}
|
|
228
|
+
rowY += this.rowHeight;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Renders the rows of the data grid.
|
|
234
|
+
*
|
|
235
|
+
* This function iterates over the data and columns, positioning and sizing each row and column widget accordingly.
|
|
236
|
+
*
|
|
237
|
+
* @return {void}
|
|
238
|
+
*/
|
|
239
|
+
private renderRows(): void {
|
|
240
|
+
let rowY = 0;
|
|
241
|
+
|
|
242
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
243
|
+
const row = window.w.get(this.id + ".row." + i) as Widget;
|
|
244
|
+
|
|
245
|
+
row.setX(0);
|
|
246
|
+
row.setY(rowY);
|
|
247
|
+
row.setW(this.getAllColumnsWidth());
|
|
248
|
+
row.setH(this.rowHeight);
|
|
249
|
+
|
|
250
|
+
let widgetX = 0;
|
|
251
|
+
for (let j = 0; j < this.columns.length; j++) {
|
|
252
|
+
const column = this.columns[j];
|
|
253
|
+
const fieldId = this.id + ".row." + i + ".column." + j;
|
|
254
|
+
const columnWidget = window.w.get(fieldId) as Widget;
|
|
255
|
+
columnWidget.setY(0);
|
|
256
|
+
columnWidget.setX(widgetX);
|
|
257
|
+
columnWidget.setH(this.rowHeight);
|
|
258
|
+
if (column.width) {
|
|
259
|
+
columnWidget.setW(column.width);
|
|
260
|
+
} else {
|
|
261
|
+
columnWidget.setW(this.getFreeWidth());
|
|
262
|
+
}
|
|
263
|
+
widgetX += column.width ? column.width : columnWidget.getW();
|
|
264
|
+
}
|
|
265
|
+
rowY += this.rowHeight;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Releases all resources held by this data grid.
|
|
271
|
+
*
|
|
272
|
+
* This function iterates over all rows in the data grid and calls the free method on each row widget.
|
|
273
|
+
* It then calls the free method on the superclass to release any additional resources.
|
|
274
|
+
*
|
|
275
|
+
* @return {void}
|
|
276
|
+
*/
|
|
277
|
+
public free(): void {
|
|
278
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
279
|
+
const row = window.w.get(this.id + ".row." + i) as Widget;
|
|
280
|
+
if (row) row.free();
|
|
281
|
+
}
|
|
282
|
+
this.verticalScrollbar.free();
|
|
283
|
+
this.horizontalScrollbar.free();
|
|
284
|
+
super.free();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Renders the data grid by calling the superclass's render method and then rendering the headers, rows, and scrollbars.
|
|
289
|
+
*
|
|
290
|
+
* @return {void}
|
|
291
|
+
*/
|
|
292
|
+
public render(): void {
|
|
293
|
+
super.render();
|
|
294
|
+
this.renderHeaders();
|
|
295
|
+
this.renderRows();
|
|
296
|
+
this.verticalScrollbar.render();
|
|
297
|
+
this.horizontalScrollbar.render();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public setRowHeight(rowHeight: number): void {
|
|
301
|
+
this.rowHeight = rowHeight;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public addColumn(header: string, width: number | null, handler: (args: any) => void) {
|
|
305
|
+
this.columns.push({ header, width, handler });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public getHeader(index: number): Label {
|
|
309
|
+
return window.w.get(this.id + "header." + index) as Label;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public setData(data: Array<any>): void {
|
|
313
|
+
this.data = data;
|
|
314
|
+
|
|
315
|
+
this.buildRows();
|
|
316
|
+
this.renderRows();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export type DataGridColumnType =
|
|
321
|
+
| "label"
|
|
322
|
+
| "button"
|
|
323
|
+
| "buttonmenu"
|
|
324
|
+
| "iconbutton"
|
|
325
|
+
| "textbox"
|
|
326
|
+
| "select"
|
|
327
|
+
| "checkbox"
|
|
328
|
+
| "switch"
|
|
329
|
+
| "image"
|
|
330
|
+
| "icon"
|
|
331
|
+
| "valuebar"
|
|
332
|
+
| "progressbar";
|
|
333
|
+
|
|
334
|
+
export type WDataGridProps = Omit<WidgetProps, "orientation"> & {
|
|
335
|
+
data?: any;
|
|
336
|
+
rowHeight?: number | null;
|
|
337
|
+
children: any;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export type WDataGridColumnProps = WidgetEventProps & {
|
|
341
|
+
header?: string | null;
|
|
342
|
+
widgetType?: DataGridColumnType | null;
|
|
343
|
+
field?: string | null;
|
|
344
|
+
width?: number | null;
|
|
345
|
+
classNames?: string | null;
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
var columnPropsBackup: Array<any> = []; //Guarda los eventos asociados a los widgets dentro de las columnas de la grilla.
|
|
349
|
+
|
|
350
|
+
export const WDataGrid = (props: WDataGridProps) => {
|
|
351
|
+
if (!props.id) {
|
|
352
|
+
props.id = "Grid." + UID();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return normalizeWidget(
|
|
356
|
+
<div id={props.id} w-data-grid w-data={props.data} w-row-height={props.rowHeight}>
|
|
357
|
+
{props.children}
|
|
358
|
+
</div>,
|
|
359
|
+
props
|
|
360
|
+
);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
export const WDataGridColumn = (props: WDataGridColumnProps) => {
|
|
364
|
+
columnPropsBackup.push(props);
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<div
|
|
368
|
+
w-data-grid-column
|
|
369
|
+
w-header={props.header}
|
|
370
|
+
w-widget-type={props.widgetType}
|
|
371
|
+
w-field={props.field}
|
|
372
|
+
w-width={props.width}
|
|
373
|
+
w-class-names={props.classNames}
|
|
374
|
+
></div>
|
|
375
|
+
);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
export function createDataGrid(id: string, content: any, parent: Widget | null = null): DataGrid {
|
|
379
|
+
const data = JSON.parse(decode(content.getAttribute("w-data")));
|
|
380
|
+
const rowHeight = content.getAttribute("w-row-height");
|
|
381
|
+
|
|
382
|
+
let newGrid = new DataGrid(id, parent);
|
|
383
|
+
|
|
384
|
+
if (rowHeight !== null) {
|
|
385
|
+
newGrid.setRowHeight(parseInt(rowHeight));
|
|
386
|
+
} else {
|
|
387
|
+
newGrid.setRowHeight(DATA_GRID_ROW_HEIGHT);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
content.childNodes.forEach((column: HTMLElement, index: number) => {
|
|
391
|
+
if (column.getAttribute("w-data-grid-column") !== null) {
|
|
392
|
+
const columnHeader = column.getAttribute("w-header");
|
|
393
|
+
const columnField = column.getAttribute("w-field");
|
|
394
|
+
const columnWidth = column.getAttribute("w-width");
|
|
395
|
+
const columnType = column.getAttribute("w-widget-type") || "label";
|
|
396
|
+
const columnClassNames = column.getAttribute("w-class-names");
|
|
397
|
+
|
|
398
|
+
let props = {} as WidgetProps;
|
|
399
|
+
|
|
400
|
+
if (columnPropsBackup[index]) {
|
|
401
|
+
props = columnPropsBackup[index];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (columnHeader === null) {
|
|
405
|
+
throw new Error("Data grid column header is null");
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (columnField === null) {
|
|
409
|
+
throw new Error("Data grid column field is null");
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const width = columnWidth ? parseInt(columnWidth) : 100;
|
|
413
|
+
|
|
414
|
+
newGrid.addColumn(columnHeader, width, (args) => {
|
|
415
|
+
if (columnType === "label") {
|
|
416
|
+
const newLabel = new Label(args.fieldId);
|
|
417
|
+
|
|
418
|
+
args.row.addChild(newLabel);
|
|
419
|
+
const lbl = window.w.get(args.fieldId) as Label;
|
|
420
|
+
lbl.setText(args.data[columnField]);
|
|
421
|
+
if (columnClassNames) {
|
|
422
|
+
lbl.addClass(columnClassNames);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
lbl.subscribe({
|
|
426
|
+
event: "click",
|
|
427
|
+
then: (_e, _w) => {
|
|
428
|
+
if (props.onClick) {
|
|
429
|
+
props.onClick(args);
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
} else if (columnType === "button") {
|
|
434
|
+
const newButton = new Button(args.fieldId);
|
|
435
|
+
|
|
436
|
+
args.row.addChild(newButton);
|
|
437
|
+
const btn = window.w.get(args.fieldId) as Button;
|
|
438
|
+
btn.setVariant("text");
|
|
439
|
+
btn.setColor("warning");
|
|
440
|
+
|
|
441
|
+
btn.setText(args.data[columnField]);
|
|
442
|
+
if (columnClassNames) {
|
|
443
|
+
btn.addClass(columnClassNames);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
btn.subscribe({
|
|
447
|
+
event: "click",
|
|
448
|
+
then: (_e, _w) => {
|
|
449
|
+
if (props.onClick) {
|
|
450
|
+
props.onClick(args);
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
} else if (columnType === "iconbutton") {
|
|
455
|
+
const newButton = new IconButton(args.fieldId, args.data[columnField]);
|
|
456
|
+
|
|
457
|
+
args.row.addChild(newButton);
|
|
458
|
+
const btn = window.w.get(args.fieldId) as IconButton;
|
|
459
|
+
btn.setVariant("text");
|
|
460
|
+
btn.setColor("primary");
|
|
461
|
+
|
|
462
|
+
if (columnClassNames) {
|
|
463
|
+
btn.addClass(columnClassNames);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
btn.subscribe({
|
|
467
|
+
event: "click",
|
|
468
|
+
then: (_e, _w) => {
|
|
469
|
+
if (props.onClick) {
|
|
470
|
+
props.onClick(args);
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
} else if (columnType === "progressbar") {
|
|
475
|
+
const newProgressBar = new ProgressBar(args.fieldId);
|
|
476
|
+
|
|
477
|
+
args.row.addChild(newProgressBar);
|
|
478
|
+
const prg = window.w.get(args.fieldId) as ProgressBar;
|
|
479
|
+
prg.setPaddingBar(2);
|
|
480
|
+
|
|
481
|
+
if (columnClassNames) {
|
|
482
|
+
prg.addClass(columnClassNames);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
prg.setValue(args.data[columnField]);
|
|
486
|
+
} else if (columnType === "valuebar") {
|
|
487
|
+
throw new Error("Valuebar not implemented");
|
|
488
|
+
} else if (columnType === "buttonmenu") {
|
|
489
|
+
throw new Error("Buttonmenu not implemented");
|
|
490
|
+
} else if (columnType === "textbox") {
|
|
491
|
+
throw new Error("Textbox not implemented");
|
|
492
|
+
} else if (columnType === "select") {
|
|
493
|
+
throw new Error("Select not implemented");
|
|
494
|
+
} else if (columnType === "checkbox") {
|
|
495
|
+
throw new Error("Checkbox not implemented");
|
|
496
|
+
} else if (columnType === "switch") {
|
|
497
|
+
throw new Error("Switch not implemented");
|
|
498
|
+
} else if (columnType === "image") {
|
|
499
|
+
throw new Error("Image not implemented");
|
|
500
|
+
} else if (columnType === "icon") {
|
|
501
|
+
throw new Error("Icon not implemented");
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
newGrid.setAlign(WidgetAlignTypes.VERTICAL);
|
|
508
|
+
|
|
509
|
+
newGrid.setData(data as Array<any>);
|
|
510
|
+
|
|
511
|
+
columnPropsBackup = []; //Limpia las propiedades de las columnas de la grilla actual.
|
|
512
|
+
|
|
513
|
+
return newGrid;
|
|
514
|
+
}
|