@c8y/tutorial 1021.80.1 → 1022.3.2
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/cumulocity.config.ts +23 -1
- package/package.json +13 -12
- package/src/__mocks/index.ts +168 -1
- package/src/app/app.config.ts +59 -0
- package/src/bootstrap.ts +13 -9
- package/src/bottom-drawer/bottom-drawer-content-example.component.html +28 -0
- package/src/bottom-drawer/bottom-drawer-content-example.component.ts +33 -0
- package/src/bottom-drawer/bottom-drawer-example.component.html +7 -0
- package/src/bottom-drawer/bottom-drawer-example.component.ts +33 -0
- package/src/bottom-drawer/bottom-drawer.providers.ts +17 -0
- package/src/breadcrumbs/index.ts +13 -1
- package/src/client-interceptor/index.ts +16 -1
- package/src/component-styles/syntactically-awesome-style-sheets-example/syntactically-awesome-style-sheets-example.component.scss +4 -2
- package/src/countdown/countdown-example.module.ts +1 -1
- package/src/dashboard/widget-guide-context-dashboard/widget-guide-context-dashboard.component.ts +1 -9
- package/src/date-time-range/date-time-range-example.component.ts +0 -1
- package/src/dynamic-forms/index.ts +13 -1
- package/src/grids/index.ts +13 -1
- package/src/grids/server-grid-example/last-updated-data-grid-column/last-updated.cell-renderer.component.ts +2 -1
- package/src/grids/server-grid-example/server-grid-example.component.html +2 -1
- package/src/grids/tree-grid-example/client-tree-grid-example.component.html +18 -0
- package/src/grids/tree-grid-example/client-tree-grid-example.component.ts +169 -0
- package/src/grids/tree-grid-example/client-tree-grid.data.ts +147 -0
- package/src/grids/tree-grid-example/server-tree-grid-example.component.html +30 -0
- package/src/grids/tree-grid-example/server-tree-grid-example.component.ts +156 -0
- package/src/grids/tree-grid-example/server-tree-grid-example.service.ts +255 -0
- package/src/grids/tree-grid-example/tree-grid-example-tab.factory.ts +31 -0
- package/src/grids/tree-grid-example/tree-grid-example.module.ts +36 -0
- package/src/hello/index.ts +18 -1
- package/src/hooks/action/logout-action/logout-action.component.ts +3 -4
- package/src/hooks/generic-wizard/minimal-setup/minimal-setup.component.ts +4 -1
- package/src/hooks/generic-wizard/minimal-setup/multiple-entries-one.component.ts +9 -2
- package/src/hooks/generic-wizard/minimal-setup/multiple-entries-two.component.ts +9 -2
- package/src/hooks/generic-wizard/wizard.module.ts +9 -2
- package/src/hooks/index.ts +13 -1
- package/src/hooks/navigator/index.ts +12 -1
- package/src/hooks/route/index.ts +42 -1
- package/src/hooks/stepper/basic-view/basic-view.component.ts +11 -2
- package/src/hooks/stepper/stepper-hook.module.ts +7 -2
- package/src/hooks/stepper/steps/step1.component.ts +26 -3
- package/src/hooks/stepper/steps/step2.component.ts +4 -1
- package/src/hooks/widget-config/additional-config/additional-config.component.ts +16 -0
- package/src/hooks/widget-config/basic-view/basic-edit.component.html +18 -0
- package/src/hooks/widget-config/basic-view/basic-edit.component.ts +31 -0
- package/src/hooks/widget-config/widget-config.providers.ts +59 -0
- package/src/i18n.ts +3 -0
- package/src/lazy/index.ts +38 -1
- package/src/lazy-widget/index.ts +26 -1
- package/src/list/index.ts +13 -1
- package/src/main.ts +7 -10
- package/src/maps/{map-examples.module.ts → index.ts} +4 -9
- package/src/provider-configuration/index.ts +0 -2
- package/src/provider-configuration/introduction-example/{introduction.module.ts → index.ts} +5 -7
- package/src/redirect-to-last-route/index.ts +16 -1
- package/src/redirect-to-last-route/redirect-to-last-route-guard.service.ts +11 -2
- package/src/selector/alarm-event-selector-example/alarm-event-selector.module.ts +1 -1
- package/src/selector/asset-selector-example/general-example/asset-selector-example.component.ts +1 -2
- package/src/translations/index.ts +13 -1
- package/src/user-menu/index.ts +23 -1
- package/src/widget/demo-widget-config.component.ts +11 -3
- package/src/widget/demo-widget.component.ts +6 -2
- package/src/widget/index.ts +41 -1
- package/src/widget-resolvers/alternative-event.resolver.ts +8 -2
- package/src/widget-resolvers/index.ts +47 -1
- package/src/widget-resolvers/widget-resolvers-config/widget-resolvers-config.component.ts +7 -3
- package/src/widget-resolvers/widget-resolvers.component.ts +5 -1
- package/src/__mocks/mock.module.ts +0 -173
- package/src/app/app.module.ts +0 -76
- package/src/breadcrumbs/breadcrumbs.module.ts +0 -14
- package/src/client-interceptor/client-interceptor.module.ts +0 -12
- package/src/dynamic-forms/dynamic-forms.module.ts +0 -16
- package/src/grids/grids.module.ts +0 -17
- package/src/hello/hello.module.ts +0 -20
- package/src/hooks/hooks.module.ts +0 -19
- package/src/hooks/navigator/navigator.module.ts +0 -21
- package/src/hooks/route/route.module.ts +0 -51
- package/src/lazy/lazy-routing.module.ts +0 -21
- package/src/lazy/lazy.hooks.ts +0 -24
- package/src/lazy-widget/lazy-widget.module.ts +0 -30
- package/src/list/lists.module.ts +0 -17
- package/src/redirect-to-last-route/redirect-to-last-route.module.ts +0 -20
- package/src/translations/translations.module.ts +0 -18
- package/src/user-menu/user-menu.module.ts +0 -13
- package/src/user-menu/user-menu.ts +0 -26
- package/src/widget/demo-widget.module.ts +0 -55
- package/src/widget-resolvers/widget-resolvers.module.ts +0 -52
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Component, OnInit } from '@angular/core';
|
|
2
|
+
import { RouterModule } from '@angular/router';
|
|
3
|
+
import {
|
|
4
|
+
ActionControl,
|
|
5
|
+
BuiltInActionType,
|
|
6
|
+
BulkActionControl,
|
|
7
|
+
Column,
|
|
8
|
+
CoreModule,
|
|
9
|
+
CustomColumnConfig,
|
|
10
|
+
GridConfig,
|
|
11
|
+
Pagination,
|
|
12
|
+
Row
|
|
13
|
+
} from '@c8y/ngx-components';
|
|
14
|
+
import { DeviceGridModule } from '@c8y/ngx-components/device-grid';
|
|
15
|
+
import { data } from './client-tree-grid.data';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is an example of using DataGridComponent to display a static set of data
|
|
19
|
+
* and allow user for filering and sorting it on client side.
|
|
20
|
+
*/
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'c8y-client-tree-grid-example',
|
|
23
|
+
templateUrl: './client-tree-grid-example.component.html',
|
|
24
|
+
standalone: true,
|
|
25
|
+
imports: [CoreModule, DeviceGridModule, RouterModule]
|
|
26
|
+
})
|
|
27
|
+
export class ClientGridExampleComponent implements OnInit {
|
|
28
|
+
/** This will be used as a title for the data grid. */
|
|
29
|
+
title = 'Devices';
|
|
30
|
+
/**
|
|
31
|
+
* This defines what columns will be displayed in the grid.
|
|
32
|
+
* In this example we're just displaying properties from the items from the loaded data file.
|
|
33
|
+
*/
|
|
34
|
+
columns: Column[] = [
|
|
35
|
+
{
|
|
36
|
+
name: 'name',
|
|
37
|
+
header: 'Name',
|
|
38
|
+
path: 'name',
|
|
39
|
+
filterable: true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'id',
|
|
43
|
+
header: 'ID',
|
|
44
|
+
path: 'id',
|
|
45
|
+
filterable: true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'serialNumber',
|
|
49
|
+
header: 'Serial number',
|
|
50
|
+
path: 'serialNumber',
|
|
51
|
+
filterable: true
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'firmwareVersion',
|
|
55
|
+
header: 'Firmware',
|
|
56
|
+
path: 'firmwareVersion',
|
|
57
|
+
filterable: true
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
/** Initial pagination settings. */
|
|
61
|
+
pagination: Pagination = {
|
|
62
|
+
pageSize: 30,
|
|
63
|
+
currentPage: 1
|
|
64
|
+
};
|
|
65
|
+
/** Will allow for selecting items and perform bulk actions on them. */
|
|
66
|
+
selectable = true;
|
|
67
|
+
/**
|
|
68
|
+
* Defines actions for individual rows.
|
|
69
|
+
* `type` can be one of the predefined ones, or a custom one.
|
|
70
|
+
* `callback` executes the action (based on the selected item object).
|
|
71
|
+
*/
|
|
72
|
+
actionControls: ActionControl[] = [
|
|
73
|
+
{
|
|
74
|
+
type: BuiltInActionType.Edit,
|
|
75
|
+
callback: selectedItem => this.onItemEdit(selectedItem)
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: BuiltInActionType.Delete,
|
|
79
|
+
callback: selectedItem => this.onItemDelete(selectedItem)
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Defines actions for multiple rows.
|
|
84
|
+
* `type` can be one of the predefined ones, or a custom one.
|
|
85
|
+
* `callback` executes the action (based on the ids of selected items).
|
|
86
|
+
*/
|
|
87
|
+
bulkActionControls: BulkActionControl[] = [
|
|
88
|
+
{
|
|
89
|
+
type: BuiltInActionType.Export,
|
|
90
|
+
callback: selectedItemIds => this.onItemsExport(selectedItemIds)
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: BuiltInActionType.Delete,
|
|
94
|
+
callback: selectedItemIds => this.onItemsDelete(selectedItemIds)
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
/** Static data to display. */
|
|
98
|
+
data: any[];
|
|
99
|
+
|
|
100
|
+
ngOnInit() {
|
|
101
|
+
// load static data from another file, could be loaded from anywhere
|
|
102
|
+
this.data = this.dataToRows(data);
|
|
103
|
+
console.log('data loaded:', this.data);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Executes an edit action on the selected item. */
|
|
107
|
+
onItemEdit(selectedItem) {
|
|
108
|
+
console.log('item to edit:');
|
|
109
|
+
console.dir(selectedItem);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Executes a delete action on the selected item. */
|
|
113
|
+
onItemDelete(selectedItem) {
|
|
114
|
+
console.log('item to delete:');
|
|
115
|
+
console.dir(selectedItem);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Executes an action on selected items, whenever the selection changes. */
|
|
119
|
+
onItemsSelect(selectedItemIds) {
|
|
120
|
+
console.log('selected items:');
|
|
121
|
+
console.dir(selectedItemIds);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Executes an export action of the selected multiple items. */
|
|
125
|
+
onItemsExport(selectedItemIds) {
|
|
126
|
+
console.log('items to export:');
|
|
127
|
+
console.dir(selectedItemIds);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Executes a delete action on the selected multiple items. */
|
|
131
|
+
onItemsDelete(selectedItemIds) {
|
|
132
|
+
console.log('items to delete:');
|
|
133
|
+
console.dir(selectedItemIds);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Executes logic when data grid config changes. */
|
|
137
|
+
onConfigChange(config: GridConfig) {
|
|
138
|
+
console.log('configuration changed:');
|
|
139
|
+
console.dir(config);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
onFilter(filter) {
|
|
143
|
+
console.log('filter changed:');
|
|
144
|
+
console.log(filter);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
onAddCustomColumn(customColumnConfig: CustomColumnConfig) {
|
|
148
|
+
console.log('custom column added:');
|
|
149
|
+
console.log(customColumnConfig);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
onRemoveCustomColumn(column: Column) {
|
|
153
|
+
console.log('custom column removed:');
|
|
154
|
+
console.log(column);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private dataToRows(data: any[], parentRow?: Row): Row[] {
|
|
158
|
+
return data.map(item => {
|
|
159
|
+
const row = {
|
|
160
|
+
...item,
|
|
161
|
+
hasChildren: item.childNodes?.length > 0,
|
|
162
|
+
parentRow
|
|
163
|
+
};
|
|
164
|
+
row.childNodes =
|
|
165
|
+
item.childNodes?.length > 0 ? this.dataToRows(item.childNodes, row) : undefined;
|
|
166
|
+
return row;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Just a sample set of data. */
|
|
2
|
+
export const data = [
|
|
3
|
+
{
|
|
4
|
+
id: '1000000001',
|
|
5
|
+
name: 'SmartTemp XT-200 Environmental Sensor',
|
|
6
|
+
serialNumber: 'SN-XT200-9F4G7K',
|
|
7
|
+
firmwareVersion: '1.3.2',
|
|
8
|
+
childNodes: [
|
|
9
|
+
{
|
|
10
|
+
id: '1000000101',
|
|
11
|
+
name: 'Temperature Probe',
|
|
12
|
+
serialNumber: 'CH-TEMP-234XF',
|
|
13
|
+
firmwareVersion: '2.1.0',
|
|
14
|
+
childNodes: [
|
|
15
|
+
{
|
|
16
|
+
id: '1000000111',
|
|
17
|
+
name: 'Thermistor Core',
|
|
18
|
+
serialNumber: 'CMP-TC-0021',
|
|
19
|
+
firmwareVersion: '1.0.5'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: '1000000112',
|
|
23
|
+
name: 'Shielding Module',
|
|
24
|
+
serialNumber: 'CMP-SH-3992',
|
|
25
|
+
firmwareVersion: '1.1.1'
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: '1000000102',
|
|
31
|
+
name: 'Humidity Sensor',
|
|
32
|
+
serialNumber: 'CH-HMD-92JF3',
|
|
33
|
+
firmwareVersion: '2.0.3',
|
|
34
|
+
childNodes: [
|
|
35
|
+
{
|
|
36
|
+
id: '1000000121',
|
|
37
|
+
name: 'Moisture Grid',
|
|
38
|
+
serialNumber: 'CMP-MG-1200',
|
|
39
|
+
firmwareVersion: '1.0.2'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: '1000000122',
|
|
43
|
+
name: 'Condensation Shield',
|
|
44
|
+
serialNumber: 'CMP-CS-8902',
|
|
45
|
+
firmwareVersion: '1.0.7'
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: '1000000002',
|
|
53
|
+
name: 'AquaSense Flow Meter V3',
|
|
54
|
+
serialNumber: 'SN-AQ3-V3J8L2',
|
|
55
|
+
firmwareVersion: '4.0.1',
|
|
56
|
+
childNodes: [
|
|
57
|
+
{
|
|
58
|
+
id: '1000000201',
|
|
59
|
+
name: 'Flow Rate Sensor',
|
|
60
|
+
serialNumber: 'CH-FLOW-12LD9',
|
|
61
|
+
firmwareVersion: '3.2.0',
|
|
62
|
+
childNodes: [
|
|
63
|
+
{
|
|
64
|
+
id: '1000000211',
|
|
65
|
+
name: 'Turbine Core',
|
|
66
|
+
serialNumber: 'CMP-TUR-3456',
|
|
67
|
+
firmwareVersion: '1.1.3'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: '1000000212',
|
|
71
|
+
name: 'Velocity Encoder',
|
|
72
|
+
serialNumber: 'CMP-VEL-0082',
|
|
73
|
+
firmwareVersion: '1.0.9'
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: '1000000202',
|
|
79
|
+
name: 'Pressure Gauge',
|
|
80
|
+
serialNumber: 'CH-PRES-77XMN',
|
|
81
|
+
firmwareVersion: '3.1.1',
|
|
82
|
+
childNodes: [
|
|
83
|
+
{
|
|
84
|
+
id: '1000000221',
|
|
85
|
+
name: 'Sensor Diaphragm',
|
|
86
|
+
serialNumber: 'CMP-DIA-4712',
|
|
87
|
+
firmwareVersion: '1.2.5'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: '1000000222',
|
|
91
|
+
name: 'Analog-to-Digital Module',
|
|
92
|
+
serialNumber: 'CMP-ADM-9913',
|
|
93
|
+
firmwareVersion: '1.3.0'
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: '1000000003',
|
|
101
|
+
name: 'SkyLink Drone Beacon',
|
|
102
|
+
serialNumber: 'SN-SKYB-239DKT',
|
|
103
|
+
firmwareVersion: '2.5.0',
|
|
104
|
+
childNodes: [
|
|
105
|
+
{
|
|
106
|
+
id: '1000000301',
|
|
107
|
+
name: 'GPS Module',
|
|
108
|
+
serialNumber: 'CH-GPS-0039H',
|
|
109
|
+
firmwareVersion: '1.9.0',
|
|
110
|
+
childNodes: [
|
|
111
|
+
{
|
|
112
|
+
id: '1000000311',
|
|
113
|
+
name: 'Antenna Array',
|
|
114
|
+
serialNumber: 'CMP-ANT-2100',
|
|
115
|
+
firmwareVersion: '1.0.4'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: '1000000312',
|
|
119
|
+
name: 'Triangulation Processor',
|
|
120
|
+
serialNumber: 'CMP-TRI-3029',
|
|
121
|
+
firmwareVersion: '1.1.2'
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: '1000000302',
|
|
127
|
+
name: 'Altitude Sensor',
|
|
128
|
+
serialNumber: 'CH-ALT-112PK',
|
|
129
|
+
firmwareVersion: '2.4.3',
|
|
130
|
+
childNodes: [
|
|
131
|
+
{
|
|
132
|
+
id: '1000000321',
|
|
133
|
+
name: 'Barometric Core',
|
|
134
|
+
serialNumber: 'CMP-BAR-0192',
|
|
135
|
+
firmwareVersion: '1.0.8'
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: '1000000322',
|
|
139
|
+
name: 'Drift Compensator',
|
|
140
|
+
serialNumber: 'CMP-DRF-6674',
|
|
141
|
+
firmwareVersion: '1.2.1'
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<c8y-title>Data grid examples</c8y-title>
|
|
2
|
+
|
|
3
|
+
<c8y-data-grid
|
|
4
|
+
class="content-fullpage d-flex d-col border-top border-bottom"
|
|
5
|
+
[title]="title"
|
|
6
|
+
[loadMoreItemsLabel]="loadMoreItemsLabel"
|
|
7
|
+
[loadingItemsLabel]="loadingItemsLabel"
|
|
8
|
+
[displayOptions]="displayOptions"
|
|
9
|
+
[columns]="columns"
|
|
10
|
+
[pagination]="pagination"
|
|
11
|
+
[childNodePagination]="childNodePagination"
|
|
12
|
+
[infiniteScroll]="infiniteScroll"
|
|
13
|
+
[treeGrid]="true"
|
|
14
|
+
[serverSideDataCallback]="serverSideDataCallback"
|
|
15
|
+
[refresh]="refresh"
|
|
16
|
+
(rowClick)="onRowClick($event)"
|
|
17
|
+
[actionControls]="actionControls"
|
|
18
|
+
[selectable]="selectable"
|
|
19
|
+
parentNodeLabelProperty="name"
|
|
20
|
+
(itemsSelect)="onItemsSelect($event)"
|
|
21
|
+
[bulkActionControls]="bulkActionControls"
|
|
22
|
+
(onConfigChange)="onConfigChange($event)"
|
|
23
|
+
>
|
|
24
|
+
<c8y-ui-empty-state
|
|
25
|
+
[icon]="'search'"
|
|
26
|
+
[title]="'No results to display.' | translate"
|
|
27
|
+
[subtitle]="'Refine your search terms or check your spelling.' | translate"
|
|
28
|
+
[horizontal]="true"
|
|
29
|
+
></c8y-ui-empty-state>
|
|
30
|
+
</c8y-data-grid>
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Component, EventEmitter } from '@angular/core';
|
|
2
|
+
import { RouterModule } from '@angular/router';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ActionControl,
|
|
6
|
+
BulkActionControl,
|
|
7
|
+
Column,
|
|
8
|
+
CoreModule,
|
|
9
|
+
DataSourceModifier,
|
|
10
|
+
DisplayOptions,
|
|
11
|
+
GridConfig,
|
|
12
|
+
GridConfigContext,
|
|
13
|
+
GridConfigContextProvider,
|
|
14
|
+
LoadMoreMode,
|
|
15
|
+
Pagination,
|
|
16
|
+
Row,
|
|
17
|
+
ServerSideDataResult
|
|
18
|
+
} from '@c8y/ngx-components';
|
|
19
|
+
import { DeviceGridModule } from '@c8y/ngx-components/device-grid';
|
|
20
|
+
import { ServerTreeGridExampleService } from './server-tree-grid-example.service';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This is an example of using DataGridComponent for displaying, filtering and sorting managed objects
|
|
24
|
+
* using customized columns and dynamically built inventory queries.
|
|
25
|
+
*/
|
|
26
|
+
@Component({
|
|
27
|
+
selector: 'c8y-server-tree-grid-example',
|
|
28
|
+
templateUrl: './server-tree-grid-example.component.html',
|
|
29
|
+
standalone: true,
|
|
30
|
+
imports: [CoreModule, DeviceGridModule, RouterModule],
|
|
31
|
+
providers: [ServerTreeGridExampleService]
|
|
32
|
+
})
|
|
33
|
+
export class ServerTreeGridExampleComponent implements GridConfigContextProvider {
|
|
34
|
+
title = 'Managed objects';
|
|
35
|
+
loadMoreItemsLabel = 'Load more managed objects';
|
|
36
|
+
loadingItemsLabel = 'Loading managed objects…';
|
|
37
|
+
|
|
38
|
+
displayOptions: DisplayOptions = {
|
|
39
|
+
bordered: true,
|
|
40
|
+
striped: true,
|
|
41
|
+
filter: true,
|
|
42
|
+
gridHeader: true,
|
|
43
|
+
hover: true
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
columns: Column[];
|
|
47
|
+
pagination: Pagination;
|
|
48
|
+
childNodePagination: Pagination;
|
|
49
|
+
infiniteScroll: LoadMoreMode = 'auto';
|
|
50
|
+
serverSideDataCallback: any;
|
|
51
|
+
|
|
52
|
+
refresh: EventEmitter<any> = new EventEmitter<any>();
|
|
53
|
+
|
|
54
|
+
selectable = true;
|
|
55
|
+
actionControls: ActionControl[];
|
|
56
|
+
bulkActionControls: BulkActionControl[];
|
|
57
|
+
|
|
58
|
+
constructor(private service: ServerTreeGridExampleService) {
|
|
59
|
+
this.columns = this.service.getColumns();
|
|
60
|
+
this.pagination = this.service.getPagination();
|
|
61
|
+
this.childNodePagination = this.service.getChildNodePagination();
|
|
62
|
+
this.actionControls = this.service.getActionControls();
|
|
63
|
+
this.bulkActionControls = this.service.getBulkActionControls();
|
|
64
|
+
// we're setting up `serverSideDataCallback` to execute a method from this component with bound `this`
|
|
65
|
+
this.serverSideDataCallback = this.onDataSourceModifier.bind(this);
|
|
66
|
+
// we're setting up `onRefreshClick` to be executed on refresh event
|
|
67
|
+
this.refresh.subscribe(() => this.onRefreshClick());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getGridConfigContext(): GridConfigContext {
|
|
71
|
+
return {
|
|
72
|
+
/**
|
|
73
|
+
* You can provide data here that can be used for grid configration storage,
|
|
74
|
+
* action control matchers, etc.
|
|
75
|
+
*/
|
|
76
|
+
key: 'server-grid-example'
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Used in ngFor for columns iteration. */
|
|
81
|
+
trackByName(_index, column: Column): string {
|
|
82
|
+
return column.name;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* This method loads data when data grid requests it (e.g. on initial load or on column settings change).
|
|
87
|
+
* It gets the object with current data grid setup and is supposed to return:
|
|
88
|
+
* full response, list of items, paging object, the number of items in the filtered subset, the number of all items.
|
|
89
|
+
*/
|
|
90
|
+
async onDataSourceModifier(
|
|
91
|
+
dataSourceModifier: DataSourceModifier
|
|
92
|
+
): Promise<ServerSideDataResult> {
|
|
93
|
+
const { parentRow } = dataSourceModifier;
|
|
94
|
+
if (parentRow) {
|
|
95
|
+
const { res, data, paging } = await this.service.getChildDevices(
|
|
96
|
+
parentRow?.id,
|
|
97
|
+
parentRow?.pagination
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
data.forEach(row => {
|
|
101
|
+
row.hasChildren = row.childDevices.count > 0;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const serverSideDataResult: ServerSideDataResult = {
|
|
105
|
+
res,
|
|
106
|
+
data,
|
|
107
|
+
paging,
|
|
108
|
+
filteredSize: parentRow.childDevices.count,
|
|
109
|
+
size: parentRow.childDevices.count,
|
|
110
|
+
parentRow
|
|
111
|
+
};
|
|
112
|
+
return serverSideDataResult;
|
|
113
|
+
} else {
|
|
114
|
+
const { res, data, paging } = await this.service.getData(
|
|
115
|
+
dataSourceModifier.columns,
|
|
116
|
+
dataSourceModifier.pagination
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
data.forEach(row => {
|
|
120
|
+
row.hasChildren = row.childDevices.count > 0;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const filteredSize: number = await this.service.getCount(
|
|
124
|
+
dataSourceModifier.columns,
|
|
125
|
+
dataSourceModifier.pagination
|
|
126
|
+
);
|
|
127
|
+
const size: number = await this.service.getTotal();
|
|
128
|
+
|
|
129
|
+
const serverSideDataResult: ServerSideDataResult = { res, data, paging, filteredSize, size };
|
|
130
|
+
return serverSideDataResult;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Executes an action on row click. */
|
|
135
|
+
onRowClick(row: Row) {
|
|
136
|
+
console.log('row clicked:');
|
|
137
|
+
console.dir(row);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Executes an action on the selected items. */
|
|
141
|
+
onItemsSelect(selectedItemIds: string[]) {
|
|
142
|
+
console.log('selected item ids:');
|
|
143
|
+
console.dir(selectedItemIds);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Executes an action on grid config change. */
|
|
147
|
+
onConfigChange(gridConfig: GridConfig) {
|
|
148
|
+
console.log('grid config changed:');
|
|
149
|
+
console.dir(gridConfig);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Executes an action on refresh event. */
|
|
153
|
+
onRefreshClick() {
|
|
154
|
+
console.log('refresh clicked');
|
|
155
|
+
}
|
|
156
|
+
}
|