Commit 685e89ea87d72b5e9139a040708902e97335ac43

Authored by Volodymyr Babak
1 parent 90fb9a5f

Code review fixes

... ... @@ -45,7 +45,6 @@ import { ActionNotificationShow } from '@core/notification/notification.actions'
45 45 import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
46 46 import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component';
47 47 import { OAuth2ClientInfo } from '@shared/models/oauth2.models';
48   -import { EdgeService } from "@core/http/edge.service";
49 48
50 49 @Injectable({
51 50 providedIn: 'root'
... ...
... ... @@ -70,7 +70,6 @@ import {
70 70 import { alarmFields } from '@shared/models/alarm.models';
71 71 import { EdgeService } from "@core/http/edge.service";
72 72 import { ruleChainType } from "@shared/models/rule-chain.models";
73   -import { Router } from "@angular/router";
74 73
75 74 @Injectable({
76 75 providedIn: 'root'
... ... @@ -91,8 +90,7 @@ export class EntityService {
91 90 private dashboardService: DashboardService,
92 91 private entityRelationService: EntityRelationService,
93 92 private attributeService: AttributeService,
94   - private utils: UtilsService,
95   - private router: Router
  93 + private utils: UtilsService
96 94 ) { }
97 95
98 96 private getEntityObservable(entityType: EntityType, entityId: string,
... ... @@ -322,9 +320,10 @@ export class EntityService {
322 320 break;
323 321 case EntityType.RULE_CHAIN:
324 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 325 } else {
  326 + // safe fallback to default core type
328 327 entitiesObservable = this.ruleChainService.getRuleChains(pageLink, ruleChainType.core, config);
329 328 }
330 329 break;
... ...
... ... @@ -230,7 +230,7 @@ export class MenuService {
230 230 name: 'rulechain.rulechains',
231 231 type: 'link',
232 232 path: '/ruleChains',
233   - icon: 'settings_ethernet',
  233 + icon: 'settings_ethernet'
234 234 },
235 235 {
236 236 id: guid(),
... ...
... ... @@ -17,14 +17,13 @@
17 17 import { BaseData, HasId } from '@shared/models/base-data';
18 18 import { FormBuilder, FormGroup } from '@angular/forms';
19 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 21 import { Store } from '@ngrx/store';
22 22 import { AppState } from '@core/core.state';
23 23 import { EntityAction } from '@home/models/entity/entity-component.models';
24 24 import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
25 25 import { PageLink } from '@shared/models/page/page-link';
26 26 import { deepTrim } from '@core/utils';
27   -import { WINDOW } from "@core/services/window.service";
28 27
29 28 // @dynamic
30 29 @Directive()
... ...
... ... @@ -24,16 +24,16 @@ import { DebugEventType, Event, EventType } from '@shared/models/event.models';
24 24 import { TimePageLink } from '@shared/models/page/page-link';
25 25 import { TranslateService } from '@ngx-translate/core';
26 26 import { DatePipe } from '@angular/common';
27   -import { MatDialog } from '@angular/material/dialog';
  27 +import { MatDialog } from '@angular/material/dialog';
28 28 import { EntityId } from '@shared/models/id/entity-id';
29 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 31 import { EntityTypeResource } from '@shared/models/entity-type.models';
32 32 import { Observable } from 'rxjs';
33 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 37 import {
38 38 EventContentDialogComponent,
39 39 EventContentDialogData
... ...
... ... @@ -29,6 +29,7 @@ import { EntityService } from '@core/http/entity.service';
29 29 import { TruncatePipe } from '@shared/pipe/truncate.pipe';
30 30 import { RuleChainService } from '@core/http/rule-chain.service';
31 31 import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
  32 +import { ruleChainType } from '@app/shared/models/rule-chain.models';
32 33
33 34 @Component({
34 35 selector: 'tb-rule-chain-autocomplete',
... ... @@ -187,8 +188,9 @@ export class RuleChainAutocompleteComponent implements ControlValueAccessor, OnI
187 188
188 189 fetchRuleChain(searchText?: string): Observable<Array<BaseData<EntityId>>> {
189 190 this.searchText = searchText;
  191 + // voba: at the moment device profiles are not supported by edge, so 'core' hardcoded
190 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 196 clear() {
... ...
... ... @@ -33,6 +33,7 @@
33 33 <tb-rule-node #tbRuleNode
34 34 [ruleNode]="ruleNode"
35 35 [ruleChainId]="ruleChainId"
  36 + [ruleChainType]="ruleChainType"
36 37 [isEdit]="true"
37 38 [isAdd]="true"
38 39 [isReadOnly]="false">
... ...
... ... @@ -53,6 +53,7 @@
53 53 <tb-entity-autocomplete required
54 54 [excludeEntityIds]="[ruleChainId]"
55 55 [entityType]="entityType.RULE_CHAIN"
  56 + [entitySubtype]="ruleChainType"
56 57 formControlName="targetRuleChainId">
57 58 </tb-entity-autocomplete>
58 59 <div formGroupName="additionalInfo" fxLayout="column">
... ...
... ... @@ -25,6 +25,7 @@ import { Subscription } from 'rxjs';
25 25 import { RuleChainService } from '@core/http/rule-chain.service';
26 26 import { RuleNodeConfigComponent } from './rule-node-config.component';
27 27 import { Router } from '@angular/router';
  28 +import { ruleChainType } from '@app/shared/models/rule-chain.models';
28 29
29 30 @Component({
30 31 selector: 'tb-rule-node',
... ... @@ -42,6 +43,9 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
42 43 ruleChainId: string;
43 44
44 45 @Input()
  46 + ruleChainType: string;
  47 +
  48 + @Input()
45 49 isEdit: boolean;
46 50
47 51 @Input()
... ... @@ -147,7 +151,11 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
147 151 $event.stopPropagation();
148 152 }
149 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 116 <tb-rule-node #tbRuleNode
117 117 [ruleNode]="editingRuleNode"
118 118 [ruleChainId]="ruleChain.id?.id"
  119 + [ruleChainType]="ruleChainType"
119 120 [isEdit]="true"
120 121 [isReadOnly]="false">
121 122 </tb-rule-node>
... ...
... ... @@ -1305,13 +1305,15 @@ export class RuleChainPageComponent extends PageComponent
1305 1305 ruleNode.configuration = deepClone(ruleNode.component.configurationDescriptor.nodeDefinition.defaultConfiguration);
1306 1306 const ruleChainId = this.ruleChain.id ? this.ruleChain.id.id : null;
1307 1307 this.enableHotKeys = false;
  1308 + const ruleChainType = this.ruleChainType;
1308 1309 this.dialog.open<AddRuleNodeDialogComponent, AddRuleNodeDialogData,
1309 1310 FcRuleNode>(AddRuleNodeDialogComponent, {
1310 1311 disableClose: true,
1311 1312 panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
1312 1313 data: {
1313 1314 ruleNode,
1314   - ruleChainId
  1315 + ruleChainId,
  1316 + ruleChainType
1315 1317 }
1316 1318 }).afterClosed().subscribe(
1317 1319 (addedRuleNode) => {
... ... @@ -1510,6 +1512,7 @@ export class AddRuleNodeLinkDialogComponent extends DialogComponent<AddRuleNodeL
1510 1512 export interface AddRuleNodeDialogData {
1511 1513 ruleNode: FcRuleNode;
1512 1514 ruleChainId: string;
  1515 + ruleChainType: string;
1513 1516 }
1514 1517
1515 1518 @Component({
... ... @@ -1525,6 +1528,7 @@ export class AddRuleNodeDialogComponent extends DialogComponent<AddRuleNodeDialo
1525 1528
1526 1529 ruleNode: FcRuleNode;
1527 1530 ruleChainId: string;
  1531 + ruleChainType: string;
1528 1532
1529 1533 submitted = false;
1530 1534
... ... @@ -1537,6 +1541,7 @@ export class AddRuleNodeDialogComponent extends DialogComponent<AddRuleNodeDialo
1537 1541
1538 1542 this.ruleNode = this.data.ruleNode;
1539 1543 this.ruleChainId = this.data.ruleChainId;
  1544 + this.ruleChainType = this.data.ruleChainType;
1540 1545 }
1541 1546
1542 1547 ngOnInit(): void {
... ...
... ... @@ -216,38 +216,38 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
216 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 252 if (ruleChainScope === 'edge') {
253 253 actions.push(
... ... @@ -276,7 +276,11 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
276 276 this.importExport.importRuleChain(expectedRuleChainType).subscribe((ruleChainImport) => {
277 277 if (ruleChainImport) {
278 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 289 if ($event) {
286 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 299 saveRuleChain(ruleChain: RuleChain) {
... ... @@ -294,6 +302,9 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
294 302 ruleChain.type = ruleChainType.core;
295 303 } else if (this.config.componentsData.ruleChainScope == 'edges') {
296 304 ruleChain.type = ruleChainType.edge;
  305 + } else {
  306 + // safe fallback to default core type
  307 + ruleChain.type = ruleChainType.core;
297 308 }
298 309 }
299 310 return this.ruleChainService.saveRuleChain(ruleChain);
... ...