Browse Source

Fixed defaulEdgeRuleChains

pull/3811/head
Artem Babak 6 years ago
parent
commit
9cd0c45950
  1. 5
      ui-ngx/src/app/core/http/rule-chain.service.ts
  2. 39
      ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts

5
ui-ngx/src/app/core/http/rule-chain.service.ts

@ -323,9 +323,8 @@ export class RuleChainService {
return this.http.delete<RuleChain>(`/api/ruleChain/${ruleChainId}/defaultEdge`, defaultHttpOptionsFromConfig(config)); return this.http.delete<RuleChain>(`/api/ruleChain/${ruleChainId}/defaultEdge`, defaultHttpOptionsFromConfig(config));
} }
public getDefaultEdgeRuleChains(config?: RequestConfig): Observable<PageData<RuleChain>> { public getDefaultEdgeRuleChains(config?: RequestConfig): Observable<Array<RuleChain>> {
return this.http.get<PageData<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains`, return this.http.get<Array<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains`, defaultHttpOptionsFromConfig(config));
defaultHttpOptionsFromConfig(config));
} }
} }

39
ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts

@ -29,7 +29,7 @@ import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '@angular/common'; import { DatePipe } from '@angular/common';
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models'; import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
import { EntityAction } from '@home/models/entity/entity-component.models'; import { EntityAction } from '@home/models/entity/entity-component.models';
import {RuleChain, RuleChainType, ruleChainType} from '@shared/models/rule-chain.models'; import { RuleChain, ruleChainType} from '@shared/models/rule-chain.models';
import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainService } from '@core/http/rule-chain.service';
import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component'; import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
@ -141,7 +141,6 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope); this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope);
this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope); this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope);
this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.ruleChainScope); this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.ruleChainScope);
return this.config; return this.config;
} }
@ -179,10 +178,10 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
configureEntityFunctions(ruleChainScope: string): void { configureEntityFunctions(ruleChainScope: string): void {
if (ruleChainScope === 'tenant') { if (ruleChainScope === 'tenant') {
this.config.tableTitle = this.translate.instant('rulechain.core-rulechains'); this.config.tableTitle = this.translate.instant('rulechain.core-rulechains');
this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink, ruleChainType.core); this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink);
} else if (ruleChainScope === 'edges') { } else if (ruleChainScope === 'edges') {
this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains');
this.config.entitiesFetchFunction = pageLink => this.fetchRuleChains(pageLink, ruleChainType.edge); this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink);
} else if (ruleChainScope === 'edge') { } else if (ruleChainScope === 'edge') {
if (this.edgeId) { if (this.edgeId) {
this.edgeService.getEdge(this.edgeId) this.edgeService.getEdge(this.edgeId)
@ -238,13 +237,13 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
{ {
name: this.translate.instant('rulechain.set-default-edge'), name: this.translate.instant('rulechain.set-default-edge'),
icon: 'bookmark_outline', icon: 'bookmark_outline',
isEnabled: () => true, isEnabled: (entity) => this.isNonDefaultEdgeRuleChain(entity),
onAction: ($event, entity) => this.setDefaultEdgeRuleChain($event, entity) onAction: ($event, entity) => this.setDefaultEdgeRuleChain($event, entity)
}, },
{ {
name: this.translate.instant('rulechain.remove-default-edge'), name: this.translate.instant('rulechain.remove-default-edge'),
icon: 'bookmark', icon: 'bookmark',
isEnabled: () => true, isEnabled: (entity) => this.isDefaultEdgeRuleChain(entity),
onAction: ($event, entity) => this.removeDefaultEdgeRuleChain($event, entity) onAction: ($event, entity) => this.removeDefaultEdgeRuleChain($event, entity)
} }
) )
@ -481,8 +480,32 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
return (isDefined(ruleChain)) && !ruleChain.root && !ruleChain.isDefault; return (isDefined(ruleChain)) && !ruleChain.root && !ruleChain.isDefault;
} }
fetchRuleChains(pageLink: PageLink, type: string) { isDefaultEdgeRuleChain(ruleChain) {
return this.ruleChainService.getRuleChains(pageLink, type); return (isDefined(ruleChain)) && !ruleChain.root && ruleChain.isDefault;
}
isNonDefaultEdgeRuleChain(ruleChain) {
return (isDefined(ruleChain)) && !ruleChain.root && !ruleChain.isDefault;
}
fetchRuleChains(pageLink: PageLink) {
return this.ruleChainService.getRuleChains(pageLink, ruleChainType.core);
}
fetchEdgeRuleChains(pageLink: PageLink) {
let defaultEdgeRuleChainIds: Array<string> = [];
this.ruleChainService.getDefaultEdgeRuleChains().pipe(
map(ruleChains =>
ruleChains.map(ruleChain =>
defaultEdgeRuleChainIds.push(ruleChain.id.id)))
).subscribe();
return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe(
map((response) => {
response.data.map(ruleChain =>
ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id)));
return response;
})
)
} }
} }

Loading…
Cancel
Save