Commit bc28406594ade9609028b0de265e187d5b7b3075

Authored by deaflynx
1 parent f035bbd9

Partial fix Edge Rule Chain page

@@ -310,12 +310,7 @@ export class EntityService { @@ -310,12 +310,7 @@ export class EntityService {
310 break; 310 break;
311 case EntityType.RULE_CHAIN: 311 case EntityType.RULE_CHAIN:
312 pageLink.sortOrder.property = 'name'; 312 pageLink.sortOrder.property = 'name';
313 - entitiesObservable = this.ruleChainService.getRuleChains(pageLink, ruleChainType.core, config);  
314 - // TODO: deaflynx: change solution  
315 - // console.log("route.routerState.snapshot.url", this.route.routerState.snapshot.url);  
316 - // if (this.route.url.includes('edges')) {  
317 - // entitiesObservable = this.ruleChainService.getRuleChains(pageLink, edgeRuleChainType, config);  
318 - // } else { entitiesObservable = this.ruleChainService.getRuleChains(pageLink, subType, config); } 313 + entitiesObservable = this.ruleChainService.getRuleChains(pageLink, subType, config);
319 break; 314 break;
320 case EntityType.DASHBOARD: 315 case EntityType.DASHBOARD:
321 pageLink.sortOrder.property = 'title'; 316 pageLink.sortOrder.property = 'title';
@@ -186,15 +186,15 @@ export class MenuService { @@ -186,15 +186,15 @@ export class MenuService {
186 icon: 'settings_ethernet', 186 icon: 'settings_ethernet',
187 pages: [ 187 pages: [
188 { 188 {
189 - name: 'rulechain.rulechains', 189 + name: 'rulechain.core-rulechains',
190 type: 'link', 190 type: 'link',
191 - path: '/ruleChains', 191 + path: '/ruleChains/core',
192 icon: 'settings_ethernet' 192 icon: 'settings_ethernet'
193 }, 193 },
194 { 194 {
195 name: 'rulechain.edge-rulechains', 195 name: 'rulechain.edge-rulechains',
196 type: 'link', 196 type: 'link',
197 - path: '/edgesRuleChains', 197 + path: '/ruleChains/edge',
198 icon: 'router' 198 icon: 'router'
199 } 199 }
200 ] 200 ]
@@ -40,7 +40,6 @@ const routes: Routes = [ @@ -40,7 +40,6 @@ const routes: Routes = [
40 component: EntitiesTableComponent, 40 component: EntitiesTableComponent,
41 data: { 41 data: {
42 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], 42 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
43 - title: 'edge.edges',  
44 edgeScope: 'tenant' 43 edgeScope: 'tenant'
45 }, 44 },
46 resolve: { 45 resolve: {
@@ -52,7 +51,6 @@ const routes: Routes = [ @@ -52,7 +51,6 @@ const routes: Routes = [
52 component: EntitiesTableComponent, 51 component: EntitiesTableComponent,
53 data: { 52 data: {
54 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], 53 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
55 - title: 'edge.rulechains',  
56 ruleChainScope: 'edge', 54 ruleChainScope: 'edge',
57 breadcrumb: { 55 breadcrumb: {
58 label: 'edge.rulechains', 56 label: 'edge.rulechains',
@@ -68,7 +66,6 @@ const routes: Routes = [ @@ -68,7 +66,6 @@ const routes: Routes = [
68 component: EntitiesTableComponent, 66 component: EntitiesTableComponent,
69 data: { 67 data: {
70 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], 68 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
71 - title: 'edge.assets',  
72 assetsType: 'edge', 69 assetsType: 'edge',
73 breadcrumb: { 70 breadcrumb: {
74 label: 'edge.assets', 71 label: 'edge.assets',
@@ -84,7 +81,6 @@ const routes: Routes = [ @@ -84,7 +81,6 @@ const routes: Routes = [
84 component: EntitiesTableComponent, 81 component: EntitiesTableComponent,
85 data: { 82 data: {
86 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], 83 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
87 - title: 'edge.devices',  
88 devicesType: 'edge', 84 devicesType: 'edge',
89 breadcrumb: { 85 breadcrumb: {
90 label: 'edge.devices', 86 label: 'edge.devices',
@@ -100,7 +96,6 @@ const routes: Routes = [ @@ -100,7 +96,6 @@ const routes: Routes = [
100 component: EntitiesTableComponent, 96 component: EntitiesTableComponent,
101 data: { 97 data: {
102 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], 98 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
103 - title: 'edge.entity-views',  
104 entityViewsType: 'edge', 99 entityViewsType: 'edge',
105 breadcrumb: { 100 breadcrumb: {
106 label: 'edge.entity-views', 101 label: 'edge.entity-views',
@@ -116,7 +111,6 @@ const routes: Routes = [ @@ -116,7 +111,6 @@ const routes: Routes = [
116 component: EntitiesTableComponent, 111 component: EntitiesTableComponent,
117 data: { 112 data: {
118 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], 113 auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
119 - title: 'edge.dashboards',  
120 dashboardsType: 'edge', 114 dashboardsType: 'edge',
121 breadcrumb: { 115 breadcrumb: {
122 label: 'edge.dashboards', 116 label: 'edge.dashboards',
@@ -35,7 +35,7 @@ import * as RxJs from 'rxjs'; @@ -35,7 +35,7 @@ import * as RxJs from 'rxjs';
35 import { Observable } from 'rxjs'; 35 import { Observable } from 'rxjs';
36 import * as RxJsOperators from 'rxjs/operators'; 36 import * as RxJsOperators from 'rxjs/operators';
37 import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb'; 37 import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb';
38 -import { ResolvedRuleChainMetaData, RuleChain } from '@shared/models/rule-chain.models'; 38 +import {ResolvedRuleChainMetaData, RuleChain, ruleChainType} from '@shared/models/rule-chain.models';
39 import { RuleChainService } from '@core/http/rule-chain.service'; 39 import { RuleChainService } from '@core/http/rule-chain.service';
40 import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component'; 40 import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component';
41 import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models'; 41 import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models';
@@ -158,6 +158,8 @@ const routes: Routes = [ @@ -158,6 +158,8 @@ const routes: Routes = [
158 children: [ 158 children: [
159 { 159 {
160 path: '', 160 path: '',
  161 + redirectTo: '/ruleChains/core',
  162 + pathMatch: 'full',
161 component: EntitiesTableComponent, 163 component: EntitiesTableComponent,
162 data: { 164 data: {
163 auth: [Authority.TENANT_ADMIN], 165 auth: [Authority.TENANT_ADMIN],
@@ -168,41 +170,129 @@ const routes: Routes = [ @@ -168,41 +170,129 @@ const routes: Routes = [
168 } 170 }
169 }, 171 },
170 { 172 {
171 - path: ':ruleChainId',  
172 - component: RuleChainPageComponent,  
173 - canDeactivate: [ConfirmOnExitGuard], 173 + path: 'core',
174 data: { 174 data: {
175 breadcrumb: { 175 breadcrumb: {
176 - labelFunction: ruleChainBreadcumbLabelFunction, 176 + label: 'rulechain.core-rulechains',
177 icon: 'settings_ethernet' 177 icon: 'settings_ethernet'
178 - } as BreadCrumbConfig<RuleChainPageComponent>,  
179 - auth: [Authority.TENANT_ADMIN],  
180 - title: 'rulechain.rulechain',  
181 - import: false 178 + }
182 }, 179 },
183 - resolve: {  
184 - ruleChain: RuleChainResolver,  
185 - ruleChainMetaData: ResolvedRuleChainMetaDataResolver,  
186 - ruleNodeComponents: RuleNodeComponentsResolver  
187 - } 180 + children: [
  181 + {
  182 + path: '',
  183 + component: EntitiesTableComponent,
  184 + data: {
  185 + auth: [Authority.TENANT_ADMIN],
  186 + title: 'rulechain.rulechains',
  187 + ruleChainScope: 'tenant',
  188 + type: ruleChainType.core
  189 + },
  190 + resolve: {
  191 + entitiesTableConfig: RuleChainsTableConfigResolver
  192 + },
  193 + },
  194 + {
  195 + path: ':ruleChainId',
  196 + component: RuleChainPageComponent,
  197 + canDeactivate: [ConfirmOnExitGuard],
  198 + data: {
  199 + breadcrumb: {
  200 + labelFunction: ruleChainBreadcumbLabelFunction,
  201 + icon: 'settings_ethernet'
  202 + } as BreadCrumbConfig<RuleChainPageComponent>,
  203 + auth: [Authority.TENANT_ADMIN],
  204 + title: 'rulechain.rulechain',
  205 + import: false
  206 + },
  207 + resolve: {
  208 + ruleChain: RuleChainResolver,
  209 + ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
  210 + ruleNodeComponents: RuleNodeComponentsResolver
  211 + }
  212 + },
  213 + {
  214 + path: 'ruleChain/import',
  215 + component: RuleChainPageComponent,
  216 + canActivate: [RuleChainImportGuard],
  217 + canDeactivate: [ConfirmOnExitGuard],
  218 + data: {
  219 + breadcrumb: {
  220 + labelFunction: importRuleChainBreadcumbLabelFunction,
  221 + icon: 'settings_ethernet'
  222 + } as BreadCrumbConfig<RuleChainPageComponent>,
  223 + auth: [Authority.TENANT_ADMIN],
  224 + title: 'rulechain.rulechain',
  225 + import: true
  226 + },
  227 + resolve: {
  228 + ruleNodeComponents: RuleNodeComponentsResolver
  229 + }
  230 + }
  231 + ]
188 }, 232 },
189 { 233 {
190 - path: 'ruleChain/import',  
191 - component: RuleChainPageComponent,  
192 - canActivate: [RuleChainImportGuard],  
193 - canDeactivate: [ConfirmOnExitGuard], 234 + path: 'edge',
194 data: { 235 data: {
195 breadcrumb: { 236 breadcrumb: {
196 - labelFunction: importRuleChainBreadcumbLabelFunction, 237 + label: 'rulechain.edge-rulechains',
197 icon: 'settings_ethernet' 238 icon: 'settings_ethernet'
198 - } as BreadCrumbConfig<RuleChainPageComponent>,  
199 - auth: [Authority.TENANT_ADMIN],  
200 - title: 'rulechain.rulechain',  
201 - import: true 239 + },
  240 + type: 'edge'
202 }, 241 },
203 - resolve: {  
204 - ruleNodeComponents: RuleNodeComponentsResolver  
205 - } 242 + children: [
  243 + {
  244 + path: '',
  245 + component: EntitiesTableComponent,
  246 + data: {
  247 + auth: [Authority.TENANT_ADMIN],
  248 + title: 'edge.rulechains',
  249 + ruleChainScope: 'edges',
  250 + type: ruleChainType.edge
  251 + },
  252 + resolve: {
  253 + entitiesTableConfig: RuleChainsTableConfigResolver
  254 + }
  255 + },
  256 + {
  257 + path: 'ruleChain/import',
  258 + component: RuleChainPageComponent,
  259 + canActivate: [RuleChainImportGuard],
  260 + canDeactivate: [ConfirmOnExitGuard],
  261 + data: {
  262 + breadcrumb: {
  263 + labelFunction: importRuleChainBreadcumbLabelFunction,
  264 + icon: 'settings_ethernet'
  265 + } as BreadCrumbConfig<RuleChainPageComponent>,
  266 + auth: [Authority.TENANT_ADMIN],
  267 + title: 'rulechain.rulechain',
  268 + import: true,
  269 + type: ruleChainType.edge
  270 + },
  271 + resolve: {
  272 + ruleNodeComponents: RuleNodeComponentsResolver
  273 + }
  274 + },
  275 + {
  276 + path: ':ruleChainId',
  277 + component: RuleChainPageComponent,
  278 + canDeactivate: [ConfirmOnExitGuard],
  279 + data: {
  280 + breadcrumb: {
  281 + labelFunction: ruleChainBreadcumbLabelFunction,
  282 + icon: 'settings_ethernet'
  283 + } as BreadCrumbConfig<RuleChainPageComponent>,
  284 + auth: [Authority.TENANT_ADMIN],
  285 + title: 'rulechain.rulechain',
  286 + import: false,
  287 + type: ruleChainType.edge
  288 + },
  289 + resolve: {
  290 + ruleChain: RuleChainResolver,
  291 + ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
  292 + ruleNodeComponents: RuleNodeComponentsResolver
  293 + }
  294 + }
  295 + ]
206 } 296 }
207 ] 297 ]
208 } 298 }
@@ -16,34 +16,48 @@ @@ -16,34 +16,48 @@
16 16
17 import { Injectable } from '@angular/core'; 17 import { Injectable } from '@angular/core';
18 18
19 -import { Resolve, Router } from '@angular/router'; 19 +import {ActivatedRouteSnapshot, Resolve, Router} from '@angular/router';
20 import { 20 import {
  21 + CellActionDescriptor,
21 checkBoxCell, 22 checkBoxCell,
22 DateEntityTableColumn, 23 DateEntityTableColumn,
23 EntityTableColumn, 24 EntityTableColumn,
24 - EntityTableConfig 25 + EntityTableConfig,
  26 + GroupActionDescriptor, HeaderActionDescriptor
25 } from '@home/models/entity/entities-table-config.models'; 27 } from '@home/models/entity/entities-table-config.models';
26 import { TranslateService } from '@ngx-translate/core'; 28 import { TranslateService } from '@ngx-translate/core';
27 import { DatePipe } from '@angular/common'; 29 import { DatePipe } from '@angular/common';
28 import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models'; 30 import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
29 import { EntityAction } from '@home/models/entity/entity-component.models'; 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 import { RuleChainService } from '@core/http/rule-chain.service'; 33 import { RuleChainService } from '@core/http/rule-chain.service';
32 import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component'; 34 import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
33 import { DialogService } from '@core/services/dialog.service'; 35 import { DialogService } from '@core/services/dialog.service';
34 import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component'; 36 import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component';
35 import { ImportExportService } from '@home/components/import-export/import-export.service'; 37 import { ImportExportService } from '@home/components/import-export/import-export.service';
36 import { ItemBufferService } from '@core/services/item-buffer.service'; 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 @Injectable() 49 @Injectable()
39 export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> { 50 export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> {
40 51
41 private readonly config: EntityTableConfig<RuleChain> = new EntityTableConfig<RuleChain>(); 52 private readonly config: EntityTableConfig<RuleChain> = new EntityTableConfig<RuleChain>();
  53 + private edgeId: string;
42 54
43 constructor(private ruleChainService: RuleChainService, 55 constructor(private ruleChainService: RuleChainService,
44 private dialogService: DialogService, 56 private dialogService: DialogService,
  57 + private dialog: MatDialog,
45 private importExport: ImportExportService, 58 private importExport: ImportExportService,
46 private itembuffer: ItemBufferService, 59 private itembuffer: ItemBufferService,
  60 + private edgeService: EdgeService,
47 private translate: TranslateService, 61 private translate: TranslateService,
48 private datePipe: DatePipe, 62 private datePipe: DatePipe,
49 private router: Router) { 63 private router: Router) {
@@ -63,41 +77,41 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -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 this.config.deleteEntityTitle = ruleChain => this.translate.instant('rulechain.delete-rulechain-title', 116 this.config.deleteEntityTitle = ruleChain => this.translate.instant('rulechain.delete-rulechain-title',
103 { ruleChainName: ruleChain.name }); 117 { ruleChainName: ruleChain.name });
@@ -105,21 +119,142 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -105,21 +119,142 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
105 this.config.deleteEntitiesTitle = count => this.translate.instant('rulechain.delete-rulechains-title', {count}); 119 this.config.deleteEntitiesTitle = count => this.translate.instant('rulechain.delete-rulechains-title', {count});
106 this.config.deleteEntitiesContent = () => this.translate.instant('rulechain.delete-rulechains-text'); 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 this.config.loadEntity = id => this.ruleChainService.getRuleChain(id.id); 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 this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id); 125 this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id);
112 this.config.onEntityAction = action => this.onRuleChainAction(action); 126 this.config.onEntityAction = action => this.onRuleChainAction(action);
113 this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root; 127 this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root;
114 this.config.entitySelectionEnabled = (ruleChain) => ruleChain && !ruleChain.root; 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 return this.config; 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 importRuleChain($event: Event) { 258 importRuleChain($event: Event) {
124 if ($event) { 259 if ($event) {
125 $event.stopPropagation(); 260 $event.stopPropagation();
@@ -139,6 +274,17 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -139,6 +274,17 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
139 this.router.navigateByUrl(`ruleChains/${ruleChain.id.id}`); 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 exportRuleChain($event: Event, ruleChain: RuleChain) { 288 exportRuleChain($event: Event, ruleChain: RuleChain) {
143 if ($event) { 289 if ($event) {
144 $event.stopPropagation(); 290 $event.stopPropagation();
@@ -183,4 +329,96 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -183,4 +329,96 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
183 return false; 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 }
@@ -1513,7 +1513,11 @@ @@ -1513,7 +1513,11 @@
1513 "no-relations-text": "No relations found" 1513 "no-relations-text": "No relations found"
1514 }, 1514 },
1515 "rulechain": { 1515 "rulechain": {
  1516 + "assign-new-rulechain": "Assign new rulechain",
  1517 + "assign-rulechain-to-edge-title": "Assign Rule Chain(s) To Edge",
  1518 + "assign-rulechain-to-edge-text": "Please select the rulechains to assign to the edge",
1516 "edge-rulechains": "Edge Rule chains", 1519 "edge-rulechains": "Edge Rule chains",
  1520 + "core-rulechains": "Core Rule chains",
1517 "rulechain": "Rule chain", 1521 "rulechain": "Rule chain",
1518 "rulechains": "Rule chains", 1522 "rulechains": "Rule chains",
1519 "root": "Root", 1523 "root": "Root",