@c8y/tutorial 1019.23.9 → 1019.24.0
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/package.json +6 -6
- package/src/grids/server-grid-example/server-grid-action-controls.factory.ts +27 -0
- package/src/grids/server-grid-example/server-grid-action-controls.module.ts +90 -0
- package/src/grids/server-grid-example/server-grid-example.component.ts +32 -7
- package/src/grids/server-grid-example/server-grid-example.module.ts +4 -3
- package/src/grids/server-grid-example/void-configuration-strategy.ts +37 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c8y/tutorial",
|
|
3
|
-
"version": "1019.
|
|
3
|
+
"version": "1019.24.0",
|
|
4
4
|
"description": "This package is used to scaffold a tutorial for Cumulocity IoT Web SDK which explains a lot of concepts.",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@c8y/devkit": "1019.
|
|
7
|
-
"@c8y/style": "1019.
|
|
8
|
-
"@c8y/ngx-components": "1019.
|
|
9
|
-
"@c8y/client": "1019.
|
|
10
|
-
"@c8y/bootstrap": "1019.
|
|
6
|
+
"@c8y/devkit": "1019.24.0",
|
|
7
|
+
"@c8y/style": "1019.24.0",
|
|
8
|
+
"@c8y/ngx-components": "1019.24.0",
|
|
9
|
+
"@c8y/client": "1019.24.0",
|
|
10
|
+
"@c8y/bootstrap": "1019.24.0",
|
|
11
11
|
"@angular/cdk": "^16.2.11",
|
|
12
12
|
"ngx-bootstrap": "11.0.2",
|
|
13
13
|
"leaflet": "1.7.1",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { ActionControlFactory, ActionControlHook, AppStateService } from '@c8y/ngx-components';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
@Injectable({ providedIn: 'root' })
|
|
6
|
+
export class ActionControlsFactory implements ActionControlFactory {
|
|
7
|
+
constructor(private appState: AppStateService) {}
|
|
8
|
+
|
|
9
|
+
get():
|
|
10
|
+
| ActionControlHook
|
|
11
|
+
| ActionControlHook[]
|
|
12
|
+
| Observable<ActionControlHook | ActionControlHook[]>
|
|
13
|
+
| Promise<ActionControlHook | ActionControlHook[]> {
|
|
14
|
+
return {
|
|
15
|
+
actionControls: {
|
|
16
|
+
text: 'Factory',
|
|
17
|
+
callback: () => alert('factory'),
|
|
18
|
+
type: 'factory',
|
|
19
|
+
icon: 'factory',
|
|
20
|
+
priority: -10
|
|
21
|
+
},
|
|
22
|
+
matchesGrid: () => {
|
|
23
|
+
return this.appState.currentApplication.value.contextPath === 'tutorial';
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import { NgModule } from '@angular/core';
|
|
3
|
+
import { ActivatedRoute } from '@angular/router';
|
|
4
|
+
import {
|
|
5
|
+
BuiltInActionType,
|
|
6
|
+
GridConfigContext,
|
|
7
|
+
hookDataGridActionControls
|
|
8
|
+
} from '@c8y/ngx-components';
|
|
9
|
+
import { isEqual } from 'lodash-es';
|
|
10
|
+
import { of } from 'rxjs';
|
|
11
|
+
import { ActionControlsFactory } from './server-grid-action-controls.factory';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Demostrates how `hookDataGridActionControls` can be used to
|
|
15
|
+
* add or override action controls in data grid.
|
|
16
|
+
*/
|
|
17
|
+
@NgModule({
|
|
18
|
+
imports: [CommonModule],
|
|
19
|
+
providers: [
|
|
20
|
+
hookDataGridActionControls({
|
|
21
|
+
actionControls: {
|
|
22
|
+
text: 'URL match',
|
|
23
|
+
callback: item => console.dir(item),
|
|
24
|
+
type: 'url',
|
|
25
|
+
icon: 'console',
|
|
26
|
+
/* Put icon on last position */
|
|
27
|
+
priority: -Infinity
|
|
28
|
+
},
|
|
29
|
+
/* This action matches agains the URL to hook into a grid */
|
|
30
|
+
matchesGrid: (route: ActivatedRoute) => {
|
|
31
|
+
return isEqual(
|
|
32
|
+
route.snapshot.url.map(segment => segment.path),
|
|
33
|
+
['grids', 'server-grid-example']
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
hookDataGridActionControls({
|
|
38
|
+
actionControls: [
|
|
39
|
+
{
|
|
40
|
+
text: 'Context match',
|
|
41
|
+
callback: item => console.dir(item),
|
|
42
|
+
type: 'context',
|
|
43
|
+
icon: 'source-code',
|
|
44
|
+
/* Negative priority places actions after the ones with no priority */
|
|
45
|
+
priority: -100
|
|
46
|
+
},
|
|
47
|
+
/* Action controls can be displayed for specific records only */
|
|
48
|
+
{
|
|
49
|
+
text: 'Odd',
|
|
50
|
+
callback: item => console.dir(item),
|
|
51
|
+
type: 'odd',
|
|
52
|
+
icon: 'rewind',
|
|
53
|
+
showIf: device => Number.parseInt(device.id) % 2 === 1
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
text: 'Even',
|
|
57
|
+
callback: item => console.dir(item),
|
|
58
|
+
type: 'even',
|
|
59
|
+
icon: 'forward11',
|
|
60
|
+
showIf: device => Number.parseInt(device.id) % 2 === 0
|
|
61
|
+
},
|
|
62
|
+
/* This action overrides the default 'Delete' action for 'Application' MOs only */
|
|
63
|
+
{
|
|
64
|
+
type: BuiltInActionType.Delete,
|
|
65
|
+
callback: () => alert('This shows how to override default action,'),
|
|
66
|
+
/* If you want to override a default action for all records simply always return `true` */
|
|
67
|
+
showIf: item => item?.type?.startsWith('c8y_Application')
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
text: 'Reload',
|
|
71
|
+
/* You can use the `reload` callback to triger data reload after your action */
|
|
72
|
+
callback: (item, reload) => {
|
|
73
|
+
console.dir(item);
|
|
74
|
+
reload();
|
|
75
|
+
},
|
|
76
|
+
type: 'reload',
|
|
77
|
+
icon: 'refresh'
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
/* This action matches agains grid config context to hook into a grid */
|
|
81
|
+
matchesGrid: (_: ActivatedRoute, context: GridConfigContext) => {
|
|
82
|
+
/* `matchesGrid` can also resolve asynchronously */
|
|
83
|
+
return of(context?.key === 'server-grid-example');
|
|
84
|
+
}
|
|
85
|
+
}),
|
|
86
|
+
/* For finer control on actions you can also provide a factory */
|
|
87
|
+
hookDataGridActionControls(ActionControlsFactory)
|
|
88
|
+
]
|
|
89
|
+
})
|
|
90
|
+
export class ServerGridActionControlsModule {}
|
|
@@ -5,20 +5,25 @@ import {
|
|
|
5
5
|
ActionControl,
|
|
6
6
|
BulkActionControl,
|
|
7
7
|
Column,
|
|
8
|
-
|
|
8
|
+
CoreModule,
|
|
9
|
+
DataSourceModifier,
|
|
10
|
+
DATA_GRID_CONFIGURATION_CONTEXT_PROVIDER,
|
|
11
|
+
DATA_GRID_CONFIGURATION_STRATEGY,
|
|
12
|
+
DisplayOptions,
|
|
9
13
|
GridConfig,
|
|
14
|
+
GridConfigContext,
|
|
15
|
+
GridConfigContextProvider,
|
|
10
16
|
LoadMoreMode,
|
|
11
|
-
|
|
12
|
-
ServerSideDataResult,
|
|
17
|
+
Pagination,
|
|
13
18
|
Row,
|
|
14
|
-
|
|
15
|
-
CoreModule
|
|
19
|
+
ServerSideDataResult
|
|
16
20
|
} from '@c8y/ngx-components';
|
|
17
21
|
import { DeviceGridModule } from '@c8y/ngx-components/device-grid';
|
|
18
22
|
import { ServerGridExampleService } from './server-grid-example.service';
|
|
19
23
|
import { TypeCellRendererComponent } from './type-data-grid-column/type.cell-renderer.component';
|
|
20
24
|
import { TypeFilteringFormRendererComponent } from './type-data-grid-column/type.filtering-form-renderer.component';
|
|
21
25
|
import { TypeHeaderCellRendererComponent } from './type-data-grid-column/type.header-cell-renderer.component';
|
|
26
|
+
import { VoidConfigurationStrategy } from './void-configuration-strategy';
|
|
22
27
|
|
|
23
28
|
/**
|
|
24
29
|
* This is an example of using DataGridComponent for displaying, filtering and sorting managed objects
|
|
@@ -36,9 +41,19 @@ import { TypeHeaderCellRendererComponent } from './type-data-grid-column/type.he
|
|
|
36
41
|
TypeFilteringFormRendererComponent,
|
|
37
42
|
TypeHeaderCellRendererComponent
|
|
38
43
|
],
|
|
39
|
-
providers: [
|
|
44
|
+
providers: [
|
|
45
|
+
ServerGridExampleService,
|
|
46
|
+
{
|
|
47
|
+
provide: DATA_GRID_CONFIGURATION_STRATEGY,
|
|
48
|
+
useClass: VoidConfigurationStrategy
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
provide: DATA_GRID_CONFIGURATION_CONTEXT_PROVIDER,
|
|
52
|
+
useExisting: ServerGridExampleComponent
|
|
53
|
+
}
|
|
54
|
+
]
|
|
40
55
|
})
|
|
41
|
-
export class ServerGridExampleComponent {
|
|
56
|
+
export class ServerGridExampleComponent implements GridConfigContextProvider {
|
|
42
57
|
title = 'Managed objects';
|
|
43
58
|
loadMoreItemsLabel = 'Load more managed objects';
|
|
44
59
|
loadingItemsLabel = 'Loading managed objects…';
|
|
@@ -68,6 +83,16 @@ export class ServerGridExampleComponent {
|
|
|
68
83
|
this.refresh.subscribe(() => this.onRefreshClick());
|
|
69
84
|
}
|
|
70
85
|
|
|
86
|
+
getGridConfigContext(): GridConfigContext {
|
|
87
|
+
return {
|
|
88
|
+
/**
|
|
89
|
+
* You can provide data here that can be used for grid configration storage,
|
|
90
|
+
* action control matchers, etc.
|
|
91
|
+
*/
|
|
92
|
+
key: 'server-grid-example'
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
71
96
|
/** Used in ngFor for columns iteration. */
|
|
72
97
|
trackByName(_index, column: Column): string {
|
|
73
98
|
return column.name;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { NgModule } from '@angular/core';
|
|
2
1
|
import { CommonModule } from '@angular/common';
|
|
3
|
-
import {
|
|
2
|
+
import { NgModule } from '@angular/core';
|
|
3
|
+
import { hookNavigator, hookRoute, NavigatorNode } from '@c8y/ngx-components';
|
|
4
|
+
import { ServerGridActionControlsModule } from './server-grid-action-controls.module';
|
|
4
5
|
|
|
5
6
|
@NgModule({
|
|
6
|
-
imports: [CommonModule],
|
|
7
|
+
imports: [CommonModule, ServerGridActionControlsModule],
|
|
7
8
|
providers: [
|
|
8
9
|
hookRoute({
|
|
9
10
|
path: 'grids/server-grid-example',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Inject, Injectable, Optional } from '@angular/core';
|
|
2
|
+
import {
|
|
3
|
+
AbstractConfigurationStrategy,
|
|
4
|
+
DATA_GRID_CONFIGURATION_CONTEXT,
|
|
5
|
+
DATA_GRID_CONFIGURATION_CONTEXT_PROVIDER,
|
|
6
|
+
GridConfig,
|
|
7
|
+
GridConfigContext,
|
|
8
|
+
GridConfigContextProvider
|
|
9
|
+
} from '@c8y/ngx-components';
|
|
10
|
+
import { Observable, of } from 'rxjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A <code>DataGridConfigurationStrategy</code> gives you the flexibility to implement
|
|
14
|
+
* the desired mechanism of how data grid configuration (column order, visibility, sorting,
|
|
15
|
+
* filtering, custom columns, pagination) can be persisted.
|
|
16
|
+
*/
|
|
17
|
+
@Injectable()
|
|
18
|
+
export class VoidConfigurationStrategy extends AbstractConfigurationStrategy {
|
|
19
|
+
constructor(
|
|
20
|
+
@Inject(DATA_GRID_CONFIGURATION_CONTEXT)
|
|
21
|
+
@Optional()
|
|
22
|
+
protected context: GridConfigContext,
|
|
23
|
+
@Inject(DATA_GRID_CONFIGURATION_CONTEXT_PROVIDER)
|
|
24
|
+
@Optional()
|
|
25
|
+
protected contextProvider: GridConfigContextProvider
|
|
26
|
+
) {
|
|
27
|
+
super(context, contextProvider);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getConfig$(): Observable<GridConfig> {
|
|
31
|
+
return of(null);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
saveConfig$(): Observable<GridConfig> {
|
|
35
|
+
return of(null);
|
|
36
|
+
}
|
|
37
|
+
}
|