...
|
...
|
@@ -16,34 +16,48 @@ |
16
|
16
|
|
17
|
17
|
import { Injectable } from '@angular/core';
|
18
|
18
|
|
19
|
|
-import { Resolve, Router } from '@angular/router';
|
|
19
|
+import {ActivatedRouteSnapshot, Resolve, Router} from '@angular/router';
|
20
|
20
|
import {
|
|
21
|
+ CellActionDescriptor,
|
21
|
22
|
checkBoxCell,
|
22
|
23
|
DateEntityTableColumn,
|
23
|
24
|
EntityTableColumn,
|
24
|
|
- EntityTableConfig
|
|
25
|
+ EntityTableConfig,
|
|
26
|
+ GroupActionDescriptor, HeaderActionDescriptor
|
25
|
27
|
} from '@home/models/entity/entities-table-config.models';
|
26
|
28
|
import { TranslateService } from '@ngx-translate/core';
|
27
|
29
|
import { DatePipe } from '@angular/common';
|
28
|
30
|
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
|
29
|
31
|
import { EntityAction } from '@home/models/entity/entity-component.models';
|
30
|
|
-import {RuleChain, ruleChainType} from '@shared/models/rule-chain.models';
|
|
32
|
+import { RuleChain, ruleChainType } from '@shared/models/rule-chain.models';
|
31
|
33
|
import { RuleChainService } from '@core/http/rule-chain.service';
|
32
|
34
|
import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
|
33
|
35
|
import { DialogService } from '@core/services/dialog.service';
|
34
|
36
|
import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component';
|
35
|
37
|
import { ImportExportService } from '@home/components/import-export/import-export.service';
|
36
|
38
|
import { ItemBufferService } from '@core/services/item-buffer.service';
|
|
39
|
+import { EdgeService } from "@core/http/edge.service";
|
|
40
|
+import { map } from "rxjs/operators";
|
|
41
|
+import { forkJoin, Observable } from "rxjs";
|
|
42
|
+import {
|
|
43
|
+ AddEntitiesToEdgeDialogComponent,
|
|
44
|
+ AddEntitiesToEdgeDialogData
|
|
45
|
+} from "@home/dialogs/add-entities-to-edge-dialog.component";
|
|
46
|
+import { MatDialog } from "@angular/material/dialog";
|
|
47
|
+import {isUndefined} from "@core/utils";
|
37
|
48
|
|
38
|
49
|
@Injectable()
|
39
|
50
|
export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> {
|
40
|
51
|
|
41
|
52
|
private readonly config: EntityTableConfig<RuleChain> = new EntityTableConfig<RuleChain>();
|
|
53
|
+ private edgeId: string;
|
42
|
54
|
|
43
|
55
|
constructor(private ruleChainService: RuleChainService,
|
44
|
56
|
private dialogService: DialogService,
|
|
57
|
+ private dialog: MatDialog,
|
45
|
58
|
private importExport: ImportExportService,
|
46
|
59
|
private itembuffer: ItemBufferService,
|
|
60
|
+ private edgeService: EdgeService,
|
47
|
61
|
private translate: TranslateService,
|
48
|
62
|
private datePipe: DatePipe,
|
49
|
63
|
private router: Router) {
|
...
|
...
|
@@ -63,41 +77,41 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
63
|
77
|
}),
|
64
|
78
|
);
|
65
|
79
|
|
66
|
|
- this.config.addActionDescriptors.push(
|
67
|
|
- {
|
68
|
|
- name: this.translate.instant('rulechain.create-new-rulechain'),
|
69
|
|
- icon: 'insert_drive_file',
|
70
|
|
- isEnabled: () => true,
|
71
|
|
- onAction: ($event) => this.config.table.addEntity($event)
|
72
|
|
- },
|
73
|
|
- {
|
74
|
|
- name: this.translate.instant('rulechain.import'),
|
75
|
|
- icon: 'file_upload',
|
76
|
|
- isEnabled: () => true,
|
77
|
|
- onAction: ($event) => this.importRuleChain($event)
|
78
|
|
- }
|
79
|
|
- );
|
|
80
|
+ // this.config.addActionDescriptors.push(
|
|
81
|
+ // {
|
|
82
|
+ // name: this.translate.instant('rulechain.create-new-rulechain'),
|
|
83
|
+ // icon: 'insert_drive_file',
|
|
84
|
+ // isEnabled: () => true,
|
|
85
|
+ // onAction: ($event) => this.config.table.addEntity($event)
|
|
86
|
+ // },
|
|
87
|
+ // {
|
|
88
|
+ // name: this.translate.instant('rulechain.import'),
|
|
89
|
+ // icon: 'file_upload',
|
|
90
|
+ // isEnabled: () => true,
|
|
91
|
+ // onAction: ($event) => this.importRuleChain($event)
|
|
92
|
+ // }
|
|
93
|
+ // );
|
80
|
94
|
|
81
|
|
- this.config.cellActionDescriptors.push(
|
82
|
|
- {
|
83
|
|
- name: this.translate.instant('rulechain.open-rulechain'),
|
84
|
|
- icon: 'settings_ethernet',
|
85
|
|
- isEnabled: () => true,
|
86
|
|
- onAction: ($event, entity) => this.openRuleChain($event, entity)
|
87
|
|
- },
|
88
|
|
- {
|
89
|
|
- name: this.translate.instant('rulechain.export'),
|
90
|
|
- icon: 'file_download',
|
91
|
|
- isEnabled: () => true,
|
92
|
|
- onAction: ($event, entity) => this.exportRuleChain($event, entity)
|
93
|
|
- },
|
94
|
|
- {
|
95
|
|
- name: this.translate.instant('rulechain.set-root'),
|
96
|
|
- icon: 'flag',
|
97
|
|
- isEnabled: (ruleChain) => !ruleChain.root,
|
98
|
|
- onAction: ($event, entity) => this.setRootRuleChain($event, entity)
|
99
|
|
- }
|
100
|
|
- );
|
|
95
|
+ // this.config.cellActionDescriptors.push(
|
|
96
|
+ // {
|
|
97
|
+ // name: this.translate.instant('rulechain.open-rulechain'),
|
|
98
|
+ // icon: 'settings_ethernet',
|
|
99
|
+ // isEnabled: () => true,
|
|
100
|
+ // onAction: ($event, entity) => this.openRuleChain($event, entity)
|
|
101
|
+ // },
|
|
102
|
+ // {
|
|
103
|
+ // name: this.translate.instant('rulechain.export'),
|
|
104
|
+ // icon: 'file_download',
|
|
105
|
+ // isEnabled: () => true,
|
|
106
|
+ // onAction: ($event, entity) => this.exportRuleChain($event, entity)
|
|
107
|
+ // },
|
|
108
|
+ // {
|
|
109
|
+ // name: this.translate.instant('rulechain.set-root'),
|
|
110
|
+ // icon: 'flag',
|
|
111
|
+ // isEnabled: (ruleChain) => !ruleChain.root,
|
|
112
|
+ // onAction: ($event, entity) => this.setRootRuleChain($event, entity)
|
|
113
|
+ // }
|
|
114
|
+ // );
|
101
|
115
|
|
102
|
116
|
this.config.deleteEntityTitle = ruleChain => this.translate.instant('rulechain.delete-rulechain-title',
|
103
|
117
|
{ ruleChainName: ruleChain.name });
|
...
|
...
|
@@ -105,21 +119,142 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
105
|
119
|
this.config.deleteEntitiesTitle = count => this.translate.instant('rulechain.delete-rulechains-title', {count});
|
106
|
120
|
this.config.deleteEntitiesContent = () => this.translate.instant('rulechain.delete-rulechains-text');
|
107
|
121
|
|
108
|
|
- this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.core);
|
|
122
|
+ // this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge);
|
109
|
123
|
this.config.loadEntity = id => this.ruleChainService.getRuleChain(id.id);
|
110
|
|
- this.config.saveEntity = ruleChain => this.ruleChainService.saveRuleChain(ruleChain);
|
|
124
|
+ this.config.saveEntity = ruleChain => this.saveRuleChain(ruleChain);
|
111
|
125
|
this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id);
|
112
|
126
|
this.config.onEntityAction = action => this.onRuleChainAction(action);
|
113
|
127
|
this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root;
|
114
|
128
|
this.config.entitySelectionEnabled = (ruleChain) => ruleChain && !ruleChain.root;
|
115
|
129
|
}
|
116
|
130
|
|
117
|
|
- resolve(): EntityTableConfig<RuleChain> {
|
118
|
|
- this.config.tableTitle = this.translate.instant('rulechain.rulechains');
|
|
131
|
+ resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> {
|
|
132
|
+ // this.config.tableTitle = this.translate.instant('rulechain.rulechains');
|
|
133
|
+ const routeParams = route.params;
|
|
134
|
+ this.config.componentsData = {
|
|
135
|
+ ruleChainScope: route.data.ruleChainScope,
|
|
136
|
+ type: route.data.type
|
|
137
|
+ };
|
|
138
|
+ this.edgeId = routeParams.edgeId;
|
|
139
|
+ this.configureEntityFunctions(this.config.componentsData.ruleChainScope);
|
|
140
|
+ this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope);
|
|
141
|
+ this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope);
|
|
142
|
+ this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.ruleChainScope);
|
119
|
143
|
|
120
|
144
|
return this.config;
|
121
|
145
|
}
|
122
|
146
|
|
|
147
|
+ configureAddActions(ruleChainScope: string): Array<HeaderActionDescriptor> {
|
|
148
|
+ const actions: Array<HeaderActionDescriptor> = [];
|
|
149
|
+ if (ruleChainScope === 'tenant' || ruleChainScope === 'edges') {
|
|
150
|
+ actions.push(
|
|
151
|
+ {
|
|
152
|
+ name: this.translate.instant('rulechain.create-new-rulechain'),
|
|
153
|
+ icon: 'insert_drive_file',
|
|
154
|
+ isEnabled: () => true,
|
|
155
|
+ onAction: ($event) => this.config.table.addEntity($event)
|
|
156
|
+ },
|
|
157
|
+ {
|
|
158
|
+ name: this.translate.instant('rulechain.import'),
|
|
159
|
+ icon: 'file_upload',
|
|
160
|
+ isEnabled: () => true,
|
|
161
|
+ onAction: ($event) => this.importRuleChain($event)
|
|
162
|
+ }
|
|
163
|
+ )
|
|
164
|
+ }
|
|
165
|
+ if (ruleChainScope === 'edge') {
|
|
166
|
+ actions.push(
|
|
167
|
+ {
|
|
168
|
+ name: this.translate.instant('rulechain.assign-new-rulechain'),
|
|
169
|
+ icon: 'add',
|
|
170
|
+ isEnabled: () => true,
|
|
171
|
+ onAction: ($event) => this.addRuleChainsToEdge($event)
|
|
172
|
+ }
|
|
173
|
+ )
|
|
174
|
+ }
|
|
175
|
+ return actions;
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ configureEntityFunctions(ruleChainScope: string): void {
|
|
179
|
+ if (ruleChainScope === 'tenant') {
|
|
180
|
+ this.config.tableTitle = this.translate.instant('rulechain.core-rulechains');
|
|
181
|
+ this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.core);
|
|
182
|
+ } else if (ruleChainScope === 'edges') {
|
|
183
|
+ this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains');
|
|
184
|
+ this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge);
|
|
185
|
+ } else if (ruleChainScope === 'edge') {
|
|
186
|
+ if (this.edgeId) {
|
|
187
|
+ this.edgeService.getEdge(this.edgeId)
|
|
188
|
+ .pipe(map(edge => this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains')))
|
|
189
|
+ .subscribe();
|
|
190
|
+ }
|
|
191
|
+ this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.edgeId, pageLink);
|
|
192
|
+ this.config.deleteEnabled = () => false;
|
|
193
|
+ }
|
|
194
|
+ }
|
|
195
|
+
|
|
196
|
+ configureGroupActions(ruleChainScope: string): Array<GroupActionDescriptor<RuleChain>> {
|
|
197
|
+ const actions: Array<GroupActionDescriptor<RuleChain>> = [];
|
|
198
|
+ if (ruleChainScope === 'edge') {
|
|
199
|
+ actions.push(
|
|
200
|
+ {
|
|
201
|
+ name: this.translate.instant('rulechain.unassign-rulechains-from-edge'),
|
|
202
|
+ icon: 'portable_wifi_off',
|
|
203
|
+ isEnabled: true,
|
|
204
|
+ onAction: ($event, entities) => this.unassignRuleChainsFromEdge($event, entities)
|
|
205
|
+ }
|
|
206
|
+ )
|
|
207
|
+ }
|
|
208
|
+ return actions;
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ configureCellActions(ruleChainScope: string): Array<CellActionDescriptor<RuleChain>> {
|
|
212
|
+ const actions: Array<CellActionDescriptor<RuleChain>> = [];
|
|
213
|
+ if (ruleChainScope === 'tenant' || ruleChainScope === 'edges') {
|
|
214
|
+ actions.push(
|
|
215
|
+ {
|
|
216
|
+ name: this.translate.instant('rulechain.open-rulechain'),
|
|
217
|
+ icon: 'settings_ethernet',
|
|
218
|
+ isEnabled: () => true,
|
|
219
|
+ onAction: ($event, entity) => this.openRuleChain($event, entity)
|
|
220
|
+ },
|
|
221
|
+ {
|
|
222
|
+ name: this.translate.instant('rulechain.export'),
|
|
223
|
+ icon: 'file_download',
|
|
224
|
+ isEnabled: () => true,
|
|
225
|
+ onAction: ($event, entity) => this.exportRuleChain($event, entity)
|
|
226
|
+ },
|
|
227
|
+ {
|
|
228
|
+ name: this.translate.instant('rulechain.set-root'),
|
|
229
|
+ icon: 'flag',
|
|
230
|
+ isEnabled: (ruleChain) => !ruleChain.root,
|
|
231
|
+ onAction: ($event, entity) => this.setRootRuleChain($event, entity)
|
|
232
|
+ }
|
|
233
|
+ )
|
|
234
|
+ }
|
|
235
|
+ if (ruleChainScope === 'edges') {
|
|
236
|
+ actions.push(
|
|
237
|
+ {
|
|
238
|
+ name: this.translate.instant('rulechain.make-default!!!'),
|
|
239
|
+ icon: 'flag',
|
|
240
|
+ isEnabled: () => true,
|
|
241
|
+ onAction: ($event, entity) => this.setDefaultRootEdgeRuleChain($event, entity)
|
|
242
|
+ }
|
|
243
|
+ )
|
|
244
|
+ }
|
|
245
|
+ if (ruleChainScope === 'edge') {
|
|
246
|
+ actions.push(
|
|
247
|
+ {
|
|
248
|
+ name: this.translate.instant('edge.unassign-from-edge'),
|
|
249
|
+ icon: 'portable_wifi_off',
|
|
250
|
+ isEnabled: () => true,
|
|
251
|
+ onAction: ($event, entity) => this.unassignFromEdge($event, entity)
|
|
252
|
+ }
|
|
253
|
+ )
|
|
254
|
+ }
|
|
255
|
+ return actions;
|
|
256
|
+ }
|
|
257
|
+
|
123
|
258
|
importRuleChain($event: Event) {
|
124
|
259
|
if ($event) {
|
125
|
260
|
$event.stopPropagation();
|
...
|
...
|
@@ -139,6 +274,17 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
139
|
274
|
this.router.navigateByUrl(`ruleChains/${ruleChain.id.id}`);
|
140
|
275
|
}
|
141
|
276
|
|
|
277
|
+ saveRuleChain(ruleChain: RuleChain) {
|
|
278
|
+ if (isUndefined(ruleChain.type)) {
|
|
279
|
+ if (this.config.componentsData.ruleChainScope == 'tenant') {
|
|
280
|
+ ruleChain.type = ruleChainType.core;
|
|
281
|
+ } else if (this.config.componentsData.ruleChainScope == 'edges') {
|
|
282
|
+ ruleChain.type = ruleChainType.edge;
|
|
283
|
+ }
|
|
284
|
+ }
|
|
285
|
+ return this.ruleChainService.saveRuleChain(ruleChain);
|
|
286
|
+ }
|
|
287
|
+
|
142
|
288
|
exportRuleChain($event: Event, ruleChain: RuleChain) {
|
143
|
289
|
if ($event) {
|
144
|
290
|
$event.stopPropagation();
|
...
|
...
|
@@ -183,4 +329,96 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
183
|
329
|
return false;
|
184
|
330
|
}
|
185
|
331
|
|
|
332
|
+ setDefaultRootEdgeRuleChain($event: Event, ruleChain: RuleChain) {
|
|
333
|
+ if ($event) {
|
|
334
|
+ $event.stopPropagation();
|
|
335
|
+ }
|
|
336
|
+ this.dialogService.confirm(
|
|
337
|
+ this.translate.instant('rulechain.set-default-root-edge-rulechain-title', {ruleChainName: ruleChain.name}),
|
|
338
|
+ this.translate.instant('rulechain.set-default-root-edge-rulechain-text'),
|
|
339
|
+ this.translate.instant('action.no'),
|
|
340
|
+ this.translate.instant('action.yes'),
|
|
341
|
+ true
|
|
342
|
+ ).subscribe((res) => {
|
|
343
|
+ if (res) {
|
|
344
|
+ this.ruleChainService.setDefaultRootEdgeRuleChain(ruleChain.id.id).subscribe(
|
|
345
|
+ () => {
|
|
346
|
+ this.config.table.updateData();
|
|
347
|
+ }
|
|
348
|
+ );
|
|
349
|
+ }
|
|
350
|
+ }
|
|
351
|
+ );
|
|
352
|
+ }
|
|
353
|
+
|
|
354
|
+ addRuleChainsToEdge($event: Event) {
|
|
355
|
+ if ($event) {
|
|
356
|
+ $event.stopPropagation();
|
|
357
|
+ }
|
|
358
|
+ this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData,
|
|
359
|
+ boolean>(AddEntitiesToEdgeDialogComponent, {
|
|
360
|
+ disableClose: true,
|
|
361
|
+ panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
362
|
+ data: {
|
|
363
|
+ edgeId: this.edgeId,
|
|
364
|
+ entityType: EntityType.RULE_CHAIN
|
|
365
|
+ }
|
|
366
|
+ }).afterClosed()
|
|
367
|
+ .subscribe((res) => {
|
|
368
|
+ if (res) {
|
|
369
|
+ this.config.table.updateData();
|
|
370
|
+ }
|
|
371
|
+ });
|
|
372
|
+ }
|
|
373
|
+
|
|
374
|
+ unassignFromEdge($event: Event, ruleChain: RuleChain) {
|
|
375
|
+ if ($event) {
|
|
376
|
+ $event.stopPropagation();
|
|
377
|
+ }
|
|
378
|
+ this.dialogService.confirm(
|
|
379
|
+ this.translate.instant('rulechain.unassign-from-edges'),
|
|
380
|
+ this.translate.instant('rulechain.unassign-from-edges-text'),
|
|
381
|
+ this.translate.instant('action.no'),
|
|
382
|
+ this.translate.instant('action.yes'),
|
|
383
|
+ true
|
|
384
|
+ ).subscribe((res) => {
|
|
385
|
+ if (res) {
|
|
386
|
+ this.ruleChainService.unassignRuleChainFromEdge(this.config.componentsData.edgeId, ruleChain.id.id).subscribe(
|
|
387
|
+ () => {
|
|
388
|
+ this.config.table.updateData();
|
|
389
|
+ }
|
|
390
|
+ );
|
|
391
|
+ }
|
|
392
|
+ }
|
|
393
|
+ );
|
|
394
|
+ }
|
|
395
|
+
|
|
396
|
+ unassignRuleChainsFromEdge($event: Event, ruleChains: Array<RuleChain>) {
|
|
397
|
+ if ($event) {
|
|
398
|
+ $event.stopPropagation();
|
|
399
|
+ }
|
|
400
|
+ this.dialogService.confirm(
|
|
401
|
+ this.translate.instant('rulechain.unassign-rulechains-from-edge-title', {count: ruleChains.length}),
|
|
402
|
+ this.translate.instant('rulechain.unassign-rulechains-from-edge-text'),
|
|
403
|
+ this.translate.instant('action.no'),
|
|
404
|
+ this.translate.instant('action.yes'),
|
|
405
|
+ true
|
|
406
|
+ ).subscribe((res) => {
|
|
407
|
+ if (res) {
|
|
408
|
+ const tasks: Observable<any>[] = [];
|
|
409
|
+ ruleChains.forEach(
|
|
410
|
+ (ruleChain) => {
|
|
411
|
+ tasks.push(this.ruleChainService.unassignRuleChainFromEdge(this.config.componentsData.edgeId, ruleChain.id.id));
|
|
412
|
+ }
|
|
413
|
+ );
|
|
414
|
+ forkJoin(tasks).subscribe(
|
|
415
|
+ () => {
|
|
416
|
+ this.config.table.updateData();
|
|
417
|
+ }
|
|
418
|
+ );
|
|
419
|
+ }
|
|
420
|
+ }
|
|
421
|
+ );
|
|
422
|
+ }
|
|
423
|
+
|
186
|
424
|
} |
...
|
...
|
|