Commit 9cd0c45950932ffd7e08423cf5f118d1718c988f

Authored by Artem Babak
1 parent e393f3b5

Fixed defaulEdgeRuleChains

... ... @@ -323,9 +323,8 @@ export class RuleChainService {
323 323 return this.http.delete<RuleChain>(`/api/ruleChain/${ruleChainId}/defaultEdge`, defaultHttpOptionsFromConfig(config));
324 324 }
325 325
326   - public getDefaultEdgeRuleChains(config?: RequestConfig): Observable<PageData<RuleChain>> {
327   - return this.http.get<PageData<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains`,
328   - defaultHttpOptionsFromConfig(config));
  326 + public getDefaultEdgeRuleChains(config?: RequestConfig): Observable<Array<RuleChain>> {
  327 + return this.http.get<Array<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains`, defaultHttpOptionsFromConfig(config));
329 328 }
330 329
331 330 }
... ...
... ... @@ -29,7 +29,7 @@ import { TranslateService } from '@ngx-translate/core';
29 29 import { DatePipe } from '@angular/common';
30 30 import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
31 31 import { EntityAction } from '@home/models/entity/entity-component.models';
32   -import {RuleChain, RuleChainType, ruleChainType} from '@shared/models/rule-chain.models';
  32 +import { RuleChain, ruleChainType} from '@shared/models/rule-chain.models';
33 33 import { RuleChainService } from '@core/http/rule-chain.service';
34 34 import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
35 35 import { DialogService } from '@core/services/dialog.service';
... ... @@ -141,7 +141,6 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
141 141 this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope);
142 142 this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope);
143 143 this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.ruleChainScope);
144   -
145 144 return this.config;
146 145 }
147 146
... ... @@ -179,10 +178,10 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
179 178 configureEntityFunctions(ruleChainScope: string): void {
180 179 if (ruleChainScope === 'tenant') {
181 180 this.config.tableTitle = this.translate.instant('rulechain.core-rulechains');
182   - this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink, ruleChainType.core);
  181 + this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink);
183 182 } else if (ruleChainScope === 'edges') {
184 183 this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains');
185   - this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink, ruleChainType.edge);
  184 + this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink);
186 185 } else if (ruleChainScope === 'edge') {
187 186 if (this.edgeId) {
188 187 this.edgeService.getEdge(this.edgeId)
... ... @@ -238,13 +237,13 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
238 237 {
239 238 name: this.translate.instant('rulechain.set-default-edge'),
240 239 icon: 'bookmark_outline',
241   - isEnabled: () => true,
  240 + isEnabled: (entity) => this.isNonDefaultEdgeRuleChain(entity),
242 241 onAction: ($event, entity) => this.setDefaultEdgeRuleChain($event, entity)
243 242 },
244 243 {
245 244 name: this.translate.instant('rulechain.remove-default-edge'),
246 245 icon: 'bookmark',
247   - isEnabled: () => true,
  246 + isEnabled: (entity) => this.isDefaultEdgeRuleChain(entity),
248 247 onAction: ($event, entity) => this.removeDefaultEdgeRuleChain($event, entity)
249 248 }
250 249 )
... ... @@ -481,8 +480,32 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
481 480 return (isDefined(ruleChain)) && !ruleChain.root && !ruleChain.isDefault;
482 481 }
483 482
484   - fetchRuleChains(pageLink: PageLink, type: string) {
485   - return this.ruleChainService.getRuleChains(pageLink, type);
  483 + isDefaultEdgeRuleChain(ruleChain) {
  484 + return (isDefined(ruleChain)) && !ruleChain.root && ruleChain.isDefault;
  485 + }
  486 +
  487 + isNonDefaultEdgeRuleChain(ruleChain) {
  488 + return (isDefined(ruleChain)) && !ruleChain.root && !ruleChain.isDefault;
  489 + }
  490 +
  491 + fetchRuleChains(pageLink: PageLink) {
  492 + return this.ruleChainService.getRuleChains(pageLink, ruleChainType.core);
  493 + }
  494 +
  495 + fetchEdgeRuleChains(pageLink: PageLink) {
  496 + let defaultEdgeRuleChainIds: Array<string> = [];
  497 + this.ruleChainService.getDefaultEdgeRuleChains().pipe(
  498 + map(ruleChains =>
  499 + ruleChains.map(ruleChain =>
  500 + defaultEdgeRuleChainIds.push(ruleChain.id.id)))
  501 + ).subscribe();
  502 + return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe(
  503 + map((response) => {
  504 + response.data.map(ruleChain =>
  505 + ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id)));
  506 + return response;
  507 + })
  508 + )
486 509 }
487 510
488 511 }
... ...