Commit 685e89ea87d72b5e9139a040708902e97335ac43

Authored by Volodymyr Babak
1 parent 90fb9a5f

Code review fixes

@@ -45,7 +45,6 @@ import { ActionNotificationShow } from '@core/notification/notification.actions' @@ -45,7 +45,6 @@ import { ActionNotificationShow } from '@core/notification/notification.actions'
45 import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; 45 import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
46 import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component'; 46 import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component';
47 import { OAuth2ClientInfo } from '@shared/models/oauth2.models'; 47 import { OAuth2ClientInfo } from '@shared/models/oauth2.models';
48 -import { EdgeService } from "@core/http/edge.service";  
49 48
50 @Injectable({ 49 @Injectable({
51 providedIn: 'root' 50 providedIn: 'root'
@@ -70,7 +70,6 @@ import { @@ -70,7 +70,6 @@ import {
70 import { alarmFields } from '@shared/models/alarm.models'; 70 import { alarmFields } from '@shared/models/alarm.models';
71 import { EdgeService } from "@core/http/edge.service"; 71 import { EdgeService } from "@core/http/edge.service";
72 import { ruleChainType } from "@shared/models/rule-chain.models"; 72 import { ruleChainType } from "@shared/models/rule-chain.models";
73 -import { Router } from "@angular/router";  
74 73
75 @Injectable({ 74 @Injectable({
76 providedIn: 'root' 75 providedIn: 'root'
@@ -91,8 +90,7 @@ export class EntityService { @@ -91,8 +90,7 @@ export class EntityService {
91 private dashboardService: DashboardService, 90 private dashboardService: DashboardService,
92 private entityRelationService: EntityRelationService, 91 private entityRelationService: EntityRelationService,
93 private attributeService: AttributeService, 92 private attributeService: AttributeService,
94 - private utils: UtilsService,  
95 - private router: Router 93 + private utils: UtilsService
96 ) { } 94 ) { }
97 95
98 private getEntityObservable(entityType: EntityType, entityId: string, 96 private getEntityObservable(entityType: EntityType, entityId: string,
@@ -322,9 +320,10 @@ export class EntityService { @@ -322,9 +320,10 @@ export class EntityService {
322 break; 320 break;
323 case EntityType.RULE_CHAIN: 321 case EntityType.RULE_CHAIN:
324 pageLink.sortOrder.property = 'name'; 322 pageLink.sortOrder.property = 'name';
325 - if (this.router.url.includes('edge')) {  
326 - entitiesObservable = this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge, config); 323 + if (subType) {
  324 + entitiesObservable = this.ruleChainService.getRuleChains(pageLink, subType, config);
327 } else { 325 } else {
  326 + // safe fallback to default core type
328 entitiesObservable = this.ruleChainService.getRuleChains(pageLink, ruleChainType.core, config); 327 entitiesObservable = this.ruleChainService.getRuleChains(pageLink, ruleChainType.core, config);
329 } 328 }
330 break; 329 break;
@@ -230,7 +230,7 @@ export class MenuService { @@ -230,7 +230,7 @@ export class MenuService {
230 name: 'rulechain.rulechains', 230 name: 'rulechain.rulechains',
231 type: 'link', 231 type: 'link',
232 path: '/ruleChains', 232 path: '/ruleChains',
233 - icon: 'settings_ethernet', 233 + icon: 'settings_ethernet'
234 }, 234 },
235 { 235 {
236 id: guid(), 236 id: guid(),
@@ -17,14 +17,13 @@ @@ -17,14 +17,13 @@
17 import { BaseData, HasId } from '@shared/models/base-data'; 17 import { BaseData, HasId } from '@shared/models/base-data';
18 import { FormBuilder, FormGroup } from '@angular/forms'; 18 import { FormBuilder, FormGroup } from '@angular/forms';
19 import { PageComponent } from '@shared/components/page.component'; 19 import { PageComponent } from '@shared/components/page.component';
20 -import { Directive, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core'; 20 +import { Directive, EventEmitter, Input, OnInit, Output } from '@angular/core';
21 import { Store } from '@ngrx/store'; 21 import { Store } from '@ngrx/store';
22 import { AppState } from '@core/core.state'; 22 import { AppState } from '@core/core.state';
23 import { EntityAction } from '@home/models/entity/entity-component.models'; 23 import { EntityAction } from '@home/models/entity/entity-component.models';
24 import { EntityTableConfig } from '@home/models/entity/entities-table-config.models'; 24 import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
25 import { PageLink } from '@shared/models/page/page-link'; 25 import { PageLink } from '@shared/models/page/page-link';
26 import { deepTrim } from '@core/utils'; 26 import { deepTrim } from '@core/utils';
27 -import { WINDOW } from "@core/services/window.service";  
28 27
29 // @dynamic 28 // @dynamic
30 @Directive() 29 @Directive()
@@ -24,16 +24,16 @@ import { DebugEventType, Event, EventType } from '@shared/models/event.models'; @@ -24,16 +24,16 @@ import { DebugEventType, Event, EventType } from '@shared/models/event.models';
24 import { TimePageLink } from '@shared/models/page/page-link'; 24 import { TimePageLink } from '@shared/models/page/page-link';
25 import { TranslateService } from '@ngx-translate/core'; 25 import { TranslateService } from '@ngx-translate/core';
26 import { DatePipe } from '@angular/common'; 26 import { DatePipe } from '@angular/common';
27 -import { MatDialog } from '@angular/material/dialog'; 27 +import { MatDialog } from '@angular/material/dialog';
28 import { EntityId } from '@shared/models/id/entity-id'; 28 import { EntityId } from '@shared/models/id/entity-id';
29 import { EventService } from '@app/core/http/event.service'; 29 import { EventService } from '@app/core/http/event.service';
30 -import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component'; 30 +import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component';
31 import { EntityTypeResource } from '@shared/models/entity-type.models'; 31 import { EntityTypeResource } from '@shared/models/entity-type.models';
32 import { Observable } from 'rxjs'; 32 import { Observable } from 'rxjs';
33 import { PageData } from '@shared/models/page/page-data'; 33 import { PageData } from '@shared/models/page/page-data';
34 -import { Direction } from '@shared/models/page/sort-order';  
35 -import { DialogService } from '@core/services/dialog.service';  
36 -import { ContentType } from '@shared/models/constants'; 34 +import { Direction } from '@shared/models/page/sort-order';
  35 +import { DialogService } from '@core/services/dialog.service';
  36 +import { ContentType } from '@shared/models/constants';
37 import { 37 import {
38 EventContentDialogComponent, 38 EventContentDialogComponent,
39 EventContentDialogData 39 EventContentDialogData
@@ -29,6 +29,7 @@ import { EntityService } from '@core/http/entity.service'; @@ -29,6 +29,7 @@ import { EntityService } from '@core/http/entity.service';
29 import { TruncatePipe } from '@shared/pipe/truncate.pipe'; 29 import { TruncatePipe } from '@shared/pipe/truncate.pipe';
30 import { RuleChainService } from '@core/http/rule-chain.service'; 30 import { RuleChainService } from '@core/http/rule-chain.service';
31 import { MatAutocompleteTrigger } from '@angular/material/autocomplete'; 31 import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
  32 +import { ruleChainType } from '@app/shared/models/rule-chain.models';
32 33
33 @Component({ 34 @Component({
34 selector: 'tb-rule-chain-autocomplete', 35 selector: 'tb-rule-chain-autocomplete',
@@ -187,8 +188,9 @@ export class RuleChainAutocompleteComponent implements ControlValueAccessor, OnI @@ -187,8 +188,9 @@ export class RuleChainAutocompleteComponent implements ControlValueAccessor, OnI
187 188
188 fetchRuleChain(searchText?: string): Observable<Array<BaseData<EntityId>>> { 189 fetchRuleChain(searchText?: string): Observable<Array<BaseData<EntityId>>> {
189 this.searchText = searchText; 190 this.searchText = searchText;
  191 + // voba: at the moment device profiles are not supported by edge, so 'core' hardcoded
190 return this.entityService.getEntitiesByNameFilter(EntityType.RULE_CHAIN, searchText, 192 return this.entityService.getEntitiesByNameFilter(EntityType.RULE_CHAIN, searchText,
191 - 50, null, {ignoreLoading: true}); 193 + 50, ruleChainType.core, {ignoreLoading: true});
192 } 194 }
193 195
194 clear() { 196 clear() {
@@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
33 <tb-rule-node #tbRuleNode 33 <tb-rule-node #tbRuleNode
34 [ruleNode]="ruleNode" 34 [ruleNode]="ruleNode"
35 [ruleChainId]="ruleChainId" 35 [ruleChainId]="ruleChainId"
  36 + [ruleChainType]="ruleChainType"
36 [isEdit]="true" 37 [isEdit]="true"
37 [isAdd]="true" 38 [isAdd]="true"
38 [isReadOnly]="false"> 39 [isReadOnly]="false">
@@ -53,6 +53,7 @@ @@ -53,6 +53,7 @@
53 <tb-entity-autocomplete required 53 <tb-entity-autocomplete required
54 [excludeEntityIds]="[ruleChainId]" 54 [excludeEntityIds]="[ruleChainId]"
55 [entityType]="entityType.RULE_CHAIN" 55 [entityType]="entityType.RULE_CHAIN"
  56 + [entitySubtype]="ruleChainType"
56 formControlName="targetRuleChainId"> 57 formControlName="targetRuleChainId">
57 </tb-entity-autocomplete> 58 </tb-entity-autocomplete>
58 <div formGroupName="additionalInfo" fxLayout="column"> 59 <div formGroupName="additionalInfo" fxLayout="column">
@@ -25,6 +25,7 @@ import { Subscription } from 'rxjs'; @@ -25,6 +25,7 @@ import { Subscription } from 'rxjs';
25 import { RuleChainService } from '@core/http/rule-chain.service'; 25 import { RuleChainService } from '@core/http/rule-chain.service';
26 import { RuleNodeConfigComponent } from './rule-node-config.component'; 26 import { RuleNodeConfigComponent } from './rule-node-config.component';
27 import { Router } from '@angular/router'; 27 import { Router } from '@angular/router';
  28 +import { ruleChainType } from '@app/shared/models/rule-chain.models';
28 29
29 @Component({ 30 @Component({
30 selector: 'tb-rule-node', 31 selector: 'tb-rule-node',
@@ -42,6 +43,9 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O @@ -42,6 +43,9 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
42 ruleChainId: string; 43 ruleChainId: string;
43 44
44 @Input() 45 @Input()
  46 + ruleChainType: string;
  47 +
  48 + @Input()
45 isEdit: boolean; 49 isEdit: boolean;
46 50
47 @Input() 51 @Input()
@@ -147,7 +151,11 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O @@ -147,7 +151,11 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
147 $event.stopPropagation(); 151 $event.stopPropagation();
148 } 152 }
149 if (this.ruleNode.targetRuleChainId) { 153 if (this.ruleNode.targetRuleChainId) {
150 - this.router.navigateByUrl(`/ruleChains/${this.ruleNode.targetRuleChainId}`); 154 + if (this.ruleChainType === ruleChainType.edge) {
  155 + this.router.navigateByUrl(`/edges/ruleChains/${this.ruleNode.targetRuleChainId}`);
  156 + } else {
  157 + this.router.navigateByUrl(`/ruleChains/${this.ruleNode.targetRuleChainId}`);
  158 + }
151 } 159 }
152 } 160 }
153 } 161 }
@@ -116,6 +116,7 @@ @@ -116,6 +116,7 @@
116 <tb-rule-node #tbRuleNode 116 <tb-rule-node #tbRuleNode
117 [ruleNode]="editingRuleNode" 117 [ruleNode]="editingRuleNode"
118 [ruleChainId]="ruleChain.id?.id" 118 [ruleChainId]="ruleChain.id?.id"
  119 + [ruleChainType]="ruleChainType"
119 [isEdit]="true" 120 [isEdit]="true"
120 [isReadOnly]="false"> 121 [isReadOnly]="false">
121 </tb-rule-node> 122 </tb-rule-node>
@@ -1305,13 +1305,15 @@ export class RuleChainPageComponent extends PageComponent @@ -1305,13 +1305,15 @@ export class RuleChainPageComponent extends PageComponent
1305 ruleNode.configuration = deepClone(ruleNode.component.configurationDescriptor.nodeDefinition.defaultConfiguration); 1305 ruleNode.configuration = deepClone(ruleNode.component.configurationDescriptor.nodeDefinition.defaultConfiguration);
1306 const ruleChainId = this.ruleChain.id ? this.ruleChain.id.id : null; 1306 const ruleChainId = this.ruleChain.id ? this.ruleChain.id.id : null;
1307 this.enableHotKeys = false; 1307 this.enableHotKeys = false;
  1308 + const ruleChainType = this.ruleChainType;
1308 this.dialog.open<AddRuleNodeDialogComponent, AddRuleNodeDialogData, 1309 this.dialog.open<AddRuleNodeDialogComponent, AddRuleNodeDialogData,
1309 FcRuleNode>(AddRuleNodeDialogComponent, { 1310 FcRuleNode>(AddRuleNodeDialogComponent, {
1310 disableClose: true, 1311 disableClose: true,
1311 panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], 1312 panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
1312 data: { 1313 data: {
1313 ruleNode, 1314 ruleNode,
1314 - ruleChainId 1315 + ruleChainId,
  1316 + ruleChainType
1315 } 1317 }
1316 }).afterClosed().subscribe( 1318 }).afterClosed().subscribe(
1317 (addedRuleNode) => { 1319 (addedRuleNode) => {
@@ -1510,6 +1512,7 @@ export class AddRuleNodeLinkDialogComponent extends DialogComponent<AddRuleNodeL @@ -1510,6 +1512,7 @@ export class AddRuleNodeLinkDialogComponent extends DialogComponent<AddRuleNodeL
1510 export interface AddRuleNodeDialogData { 1512 export interface AddRuleNodeDialogData {
1511 ruleNode: FcRuleNode; 1513 ruleNode: FcRuleNode;
1512 ruleChainId: string; 1514 ruleChainId: string;
  1515 + ruleChainType: string;
1513 } 1516 }
1514 1517
1515 @Component({ 1518 @Component({
@@ -1525,6 +1528,7 @@ export class AddRuleNodeDialogComponent extends DialogComponent<AddRuleNodeDialo @@ -1525,6 +1528,7 @@ export class AddRuleNodeDialogComponent extends DialogComponent<AddRuleNodeDialo
1525 1528
1526 ruleNode: FcRuleNode; 1529 ruleNode: FcRuleNode;
1527 ruleChainId: string; 1530 ruleChainId: string;
  1531 + ruleChainType: string;
1528 1532
1529 submitted = false; 1533 submitted = false;
1530 1534
@@ -1537,6 +1541,7 @@ export class AddRuleNodeDialogComponent extends DialogComponent<AddRuleNodeDialo @@ -1537,6 +1541,7 @@ export class AddRuleNodeDialogComponent extends DialogComponent<AddRuleNodeDialo
1537 1541
1538 this.ruleNode = this.data.ruleNode; 1542 this.ruleNode = this.data.ruleNode;
1539 this.ruleChainId = this.data.ruleChainId; 1543 this.ruleChainId = this.data.ruleChainId;
  1544 + this.ruleChainType = this.data.ruleChainType;
1540 } 1545 }
1541 1546
1542 ngOnInit(): void { 1547 ngOnInit(): void {
@@ -216,38 +216,38 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -216,38 +216,38 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
216 onAction: ($event, entity) => this.exportRuleChain($event, entity) 216 onAction: ($event, entity) => this.exportRuleChain($event, entity)
217 } 217 }
218 ) 218 )
219 - }  
220 - if (ruleChainScope === 'tenant') {  
221 - actions.push(  
222 - {  
223 - name: this.translate.instant('rulechain.set-root'),  
224 - icon: 'flag',  
225 - isEnabled: (entity) => this.isNonRootRuleChain(entity),  
226 - onAction: ($event, entity) => this.setRootRuleChain($event, entity)  
227 - }  
228 - )  
229 - }  
230 - if (ruleChainScope === 'edges') {  
231 - actions.push(  
232 - {  
233 - name: this.translate.instant('rulechain.set-edge-template-root-rulechain'),  
234 - icon: 'flag',  
235 - isEnabled: (entity) => this.isNonRootRuleChain(entity),  
236 - onAction: ($event, entity) => this.setEdgeTemplateRootRuleChain($event, entity)  
237 - },  
238 - {  
239 - name: this.translate.instant('rulechain.set-auto-assign-to-edge'),  
240 - icon: 'bookmark_outline',  
241 - isEnabled: (entity) => this.isNotAutoAssignToEdgeRuleChain(entity),  
242 - onAction: ($event, entity) => this.setAutoAssignToEdgeRuleChain($event, entity)  
243 - },  
244 - {  
245 - name: this.translate.instant('rulechain.unset-auto-assign-to-edge'),  
246 - icon: 'bookmark',  
247 - isEnabled: (entity) => this.isAutoAssignToEdgeRuleChain(entity),  
248 - onAction: ($event, entity) => this.unsetAutoAssignToEdgeRuleChain($event, entity)  
249 - }  
250 - ) 219 + if (ruleChainScope === 'tenant') {
  220 + actions.push(
  221 + {
  222 + name: this.translate.instant('rulechain.set-root'),
  223 + icon: 'flag',
  224 + isEnabled: (entity) => this.isNonRootRuleChain(entity),
  225 + onAction: ($event, entity) => this.setRootRuleChain($event, entity)
  226 + }
  227 + )
  228 + }
  229 + if (ruleChainScope === 'edges') {
  230 + actions.push(
  231 + {
  232 + name: this.translate.instant('rulechain.set-edge-template-root-rulechain'),
  233 + icon: 'flag',
  234 + isEnabled: (entity) => this.isNonRootRuleChain(entity),
  235 + onAction: ($event, entity) => this.setEdgeTemplateRootRuleChain($event, entity)
  236 + },
  237 + {
  238 + name: this.translate.instant('rulechain.set-auto-assign-to-edge'),
  239 + icon: 'bookmark_outline',
  240 + isEnabled: (entity) => this.isNotAutoAssignToEdgeRuleChain(entity),
  241 + onAction: ($event, entity) => this.setAutoAssignToEdgeRuleChain($event, entity)
  242 + },
  243 + {
  244 + name: this.translate.instant('rulechain.unset-auto-assign-to-edge'),
  245 + icon: 'bookmark',
  246 + isEnabled: (entity) => this.isAutoAssignToEdgeRuleChain(entity),
  247 + onAction: ($event, entity) => this.unsetAutoAssignToEdgeRuleChain($event, entity)
  248 + }
  249 + )
  250 + }
251 } 251 }
252 if (ruleChainScope === 'edge') { 252 if (ruleChainScope === 'edge') {
253 actions.push( 253 actions.push(
@@ -276,7 +276,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -276,7 +276,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
276 this.importExport.importRuleChain(expectedRuleChainType).subscribe((ruleChainImport) => { 276 this.importExport.importRuleChain(expectedRuleChainType).subscribe((ruleChainImport) => {
277 if (ruleChainImport) { 277 if (ruleChainImport) {
278 this.itembuffer.storeRuleChainImport(ruleChainImport); 278 this.itembuffer.storeRuleChainImport(ruleChainImport);
279 - this.router.navigateByUrl(`${this.router.routerState.snapshot.url}/ruleChain/import`); 279 + if (this.config.componentsData.ruleChainScope === 'edges') {
  280 + this.router.navigateByUrl(`edges/ruleChains/ruleChain/import`);
  281 + } else {
  282 + this.router.navigateByUrl(`ruleChains/ruleChain/import`);
  283 + }
280 } 284 }
281 }); 285 });
282 } 286 }
@@ -285,7 +289,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -285,7 +289,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
285 if ($event) { 289 if ($event) {
286 $event.stopPropagation(); 290 $event.stopPropagation();
287 } 291 }
288 - this.router.navigateByUrl(`${this.router.routerState.snapshot.url}/${ruleChain.id.id}`); 292 + if (this.config.componentsData.ruleChainScope === 'edges') {
  293 + this.router.navigateByUrl(`edges/ruleChains/${ruleChain.id.id}`);
  294 + } else {
  295 + this.router.navigateByUrl(`ruleChains/${ruleChain.id.id}`);
  296 + }
289 } 297 }
290 298
291 saveRuleChain(ruleChain: RuleChain) { 299 saveRuleChain(ruleChain: RuleChain) {
@@ -294,6 +302,9 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< @@ -294,6 +302,9 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
294 ruleChain.type = ruleChainType.core; 302 ruleChain.type = ruleChainType.core;
295 } else if (this.config.componentsData.ruleChainScope == 'edges') { 303 } else if (this.config.componentsData.ruleChainScope == 'edges') {
296 ruleChain.type = ruleChainType.edge; 304 ruleChain.type = ruleChainType.edge;
  305 + } else {
  306 + // safe fallback to default core type
  307 + ruleChain.type = ruleChainType.core;
297 } 308 }
298 } 309 }
299 return this.ruleChainService.saveRuleChain(ruleChain); 310 return this.ruleChainService.saveRuleChain(ruleChain);