Browse Source

Rule Chains routing refactored, fixed import edge save

pull/3811/head
Artem Babak 6 years ago
parent
commit
0336906bf2
  1. 2
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts
  2. 43
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-routing.module.ts
  3. 48
      ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts

2
ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts

@ -1281,7 +1281,7 @@ export class RuleChainPageComponent extends PageComponent
if (this.isImport) { if (this.isImport) {
this.isDirtyValue = false; this.isDirtyValue = false;
this.isImport = false; this.isImport = false;
this.router.navigateByUrl(`ruleChains/${this.ruleChain.id.id}`); this.router.navigateByUrl(`ruleChains/${this.route.snapshot.data.ruleChainType.toLowerCase()}/${this.ruleChain.id.id}`);
} else { } else {
this.createRuleChainModel(); this.createRuleChainModel();
} }

43
ui-ngx/src/app/modules/home/pages/rulechain/rulechain-routing.module.ts

@ -34,7 +34,6 @@ import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/br
import { import {
ResolvedRuleChainMetaData, ResolvedRuleChainMetaData,
RuleChain, RuleChain,
RuleChainType,
ruleChainType, ruleChainType,
} from '@shared/models/rule-chain.models'; } from '@shared/models/rule-chain.models';
import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainService } from '@core/http/rule-chain.service';
@ -76,8 +75,7 @@ export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeCompone
} }
resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> { resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> {
const ruleChainType: RuleChainType = route.data.type; return this.ruleChainService.getRuleNodeComponents(this.modulesMap, route.data.ruleChainType);
return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType);
} }
} }
@ -151,8 +149,7 @@ const routes: Routes = [
data: { data: {
auth: [Authority.TENANT_ADMIN], auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechains', title: 'rulechain.rulechains',
ruleChainsType: 'tenant', ruleChainsType: 'tenant'
type: ruleChainType.core
}, },
resolve: { resolve: {
entitiesTableConfig: RuleChainsTableConfigResolver entitiesTableConfig: RuleChainsTableConfigResolver
@ -170,7 +167,7 @@ const routes: Routes = [
auth: [Authority.TENANT_ADMIN], auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain', title: 'rulechain.rulechain',
import: false, import: false,
type: ruleChainType.core ruleChainType: ruleChainType.core
}, },
resolve: { resolve: {
ruleChain: RuleChainResolver, ruleChain: RuleChainResolver,
@ -190,7 +187,8 @@ const routes: Routes = [
} as BreadCrumbConfig<RuleChainPageComponent>, } as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN], auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain', title: 'rulechain.rulechain',
import: true import: true,
ruleChainType: ruleChainType.core
}, },
resolve: { resolve: {
ruleNodeComponents: RuleNodeComponentsResolver ruleNodeComponents: RuleNodeComponentsResolver
@ -204,8 +202,7 @@ const routes: Routes = [
breadcrumb: { breadcrumb: {
label: 'rulechain.edge-rulechains', label: 'rulechain.edge-rulechains',
icon: 'settings_ethernet' icon: 'settings_ethernet'
}, }
type: 'edge'
}, },
children: [ children: [
{ {
@ -214,48 +211,48 @@ const routes: Routes = [
data: { data: {
auth: [Authority.TENANT_ADMIN], auth: [Authority.TENANT_ADMIN],
title: 'edge.rulechains', title: 'edge.rulechains',
ruleChainsType: 'edges', ruleChainsType: 'edges'
type: ruleChainType.edge
}, },
resolve: { resolve: {
entitiesTableConfig: RuleChainsTableConfigResolver entitiesTableConfig: RuleChainsTableConfigResolver
} }
}, },
{ {
path: 'ruleChain/import', path: ':ruleChainId',
component: RuleChainPageComponent, component: RuleChainPageComponent,
canActivate: [RuleChainImportGuard],
canDeactivate: [ConfirmOnExitGuard], canDeactivate: [ConfirmOnExitGuard],
data: { data: {
breadcrumb: { breadcrumb: {
labelFunction: importRuleChainBreadcumbLabelFunction, labelFunction: ruleChainBreadcumbLabelFunction,
icon: 'settings_ethernet' icon: 'settings_ethernet'
} as BreadCrumbConfig<RuleChainPageComponent>, } as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN], auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain', title: 'edge.rulechain',
import: true import: false,
ruleChainType: ruleChainType.edge
}, },
resolve: { resolve: {
ruleChain: RuleChainResolver,
ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
ruleNodeComponents: RuleNodeComponentsResolver ruleNodeComponents: RuleNodeComponentsResolver
} }
}, },
{ {
path: ':ruleChainId', path: 'ruleChain/import',
component: RuleChainPageComponent, component: RuleChainPageComponent,
canActivate: [RuleChainImportGuard],
canDeactivate: [ConfirmOnExitGuard], canDeactivate: [ConfirmOnExitGuard],
data: { data: {
breadcrumb: { breadcrumb: {
labelFunction: ruleChainBreadcumbLabelFunction, labelFunction: importRuleChainBreadcumbLabelFunction,
icon: 'settings_ethernet' icon: 'settings_ethernet'
} as BreadCrumbConfig<RuleChainPageComponent>, } as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN], auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain', title: 'edge.rulechain',
import: false, import: true,
type: ruleChainType.edge ruleChainType: ruleChainType.edge
}, },
resolve: { resolve: {
ruleChain: RuleChainResolver,
ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
ruleNodeComponents: RuleNodeComponentsResolver ruleNodeComponents: RuleNodeComponentsResolver
} }
} }

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

@ -74,7 +74,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'), new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'),
new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px', new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px',
entity => { entity => {
if (isDefined(this.config.componentsData.edgeId)) { if (this.config.componentsData.edgeId) {
return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id)); return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id));
} else { } else {
return checkBoxCell(entity.root); return checkBoxCell(entity.root);
@ -90,23 +90,25 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.saveEntity = ruleChain => this.saveRuleChain(ruleChain); this.config.saveEntity = ruleChain => this.saveRuleChain(ruleChain);
this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id); this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id);
this.config.onEntityAction = action => this.onRuleChainAction(action); this.config.onEntityAction = action => this.onRuleChainAction(action);
this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root && !this.config.componentsData.edgeId;
this.config.entitySelectionEnabled = (ruleChain) => {
if (isDefined(this.config.componentsData.edgeId)) {
return this.edge.rootRuleChainId.id != ruleChain.id.id;
} else {
return ruleChain && !ruleChain.root;
}
}
} }
resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> { resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> {
const routeParams = route.params; const routeParams = route.params;
this.config.componentsData = { this.config.componentsData = {
ruleChainScope: route.data.ruleChainsType, ruleChainScope: route.data.ruleChainsType,
type: route.data.type,
edgeId: routeParams.edgeId edgeId: routeParams.edgeId
}; };
if (this.config.componentsData.edgeId) {
this.config.entitySelectionEnabled = ruleChain => this.edge.rootRuleChainId.id != ruleChain.id.id;
this.config.deleteEnabled = () => false;
this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe(edge => {
this.edge = edge;
this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains')
});
} else {
this.config.entitySelectionEnabled = ruleChain => ruleChain && !ruleChain.root;
this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root;
}
this.configureEntityFunctions(this.config.componentsData.ruleChainScope); this.configureEntityFunctions(this.config.componentsData.ruleChainScope);
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);
@ -153,13 +155,6 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains');
this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink); this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink);
} else if (ruleChainScope === 'edge') { } else if (ruleChainScope === 'edge') {
if (isDefined(this.config.componentsData.edgeId)) {
this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe(
edge => {
this.edge = edge;
this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains')
});
}
this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.config.componentsData.edgeId, pageLink); this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.config.componentsData.edgeId, pageLink);
} }
} }
@ -297,7 +292,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
true true
).subscribe((res) => { ).subscribe((res) => {
if (res) { if (res) {
if (isDefined(this.config.componentsData.edgeId)) { if (this.config.componentsData.edgeId) {
this.edgeService.setRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( this.edgeService.setRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe(
(edge) => { (edge) => {
this.edge = edge; this.edge = edge;
@ -469,7 +464,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
} }
isNonRootRuleChain(ruleChain: RuleChain) { isNonRootRuleChain(ruleChain: RuleChain) {
if (isDefined(this.config.componentsData.edgeId)) { if (this.config.componentsData.edgeId) {
return (isDefined(this.edge.rootRuleChainId) && this.edge.rootRuleChainId != null && this.edge.rootRuleChainId.id != ruleChain.id.id); return (isDefined(this.edge.rootRuleChainId) && this.edge.rootRuleChainId != null && this.edge.rootRuleChainId.id != ruleChain.id.id);
} }
return (isDefined(ruleChain)) && !ruleChain.root; return (isDefined(ruleChain)) && !ruleChain.root;
@ -489,21 +484,16 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
fetchEdgeRuleChains(pageLink: PageLink) { fetchEdgeRuleChains(pageLink: PageLink) {
let defaultEdgeRuleChainIds: Array<string> = []; let defaultEdgeRuleChainIds: Array<string> = [];
this.ruleChainService.getDefaultEdgeRuleChains().pipe( this.ruleChainService.getDefaultEdgeRuleChains().subscribe(ruleChains => {
map(ruleChains => ruleChains.map(ruleChain => defaultEdgeRuleChainIds.push(ruleChain.id.id))
ruleChains.map(ruleChain => });
defaultEdgeRuleChainIds.push(ruleChain.id.id)
)
)
).subscribe();
return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe( return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe(
map((response) => { map(response => {
response.data.map(ruleChain => response.data.map(ruleChain =>
ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id)) ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id))
); );
return response; return response;
}) })
); );
} }
} }

Loading…
Cancel
Save