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) {
this.isDirtyValue = 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 {
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 {
ResolvedRuleChainMetaData,
RuleChain,
RuleChainType,
ruleChainType,
} from '@shared/models/rule-chain.models';
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>> {
const ruleChainType: RuleChainType = route.data.type;
return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType);
return this.ruleChainService.getRuleNodeComponents(this.modulesMap, route.data.ruleChainType);
}
}
@ -151,8 +149,7 @@ const routes: Routes = [
data: {
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechains',
ruleChainsType: 'tenant',
type: ruleChainType.core
ruleChainsType: 'tenant'
},
resolve: {
entitiesTableConfig: RuleChainsTableConfigResolver
@ -170,7 +167,7 @@ const routes: Routes = [
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain',
import: false,
type: ruleChainType.core
ruleChainType: ruleChainType.core
},
resolve: {
ruleChain: RuleChainResolver,
@ -190,7 +187,8 @@ const routes: Routes = [
} as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain',
import: true
import: true,
ruleChainType: ruleChainType.core
},
resolve: {
ruleNodeComponents: RuleNodeComponentsResolver
@ -204,8 +202,7 @@ const routes: Routes = [
breadcrumb: {
label: 'rulechain.edge-rulechains',
icon: 'settings_ethernet'
},
type: 'edge'
}
},
children: [
{
@ -214,48 +211,48 @@ const routes: Routes = [
data: {
auth: [Authority.TENANT_ADMIN],
title: 'edge.rulechains',
ruleChainsType: 'edges',
type: ruleChainType.edge
ruleChainsType: 'edges'
},
resolve: {
entitiesTableConfig: RuleChainsTableConfigResolver
}
},
{
path: 'ruleChain/import',
path: ':ruleChainId',
component: RuleChainPageComponent,
canActivate: [RuleChainImportGuard],
canDeactivate: [ConfirmOnExitGuard],
data: {
breadcrumb: {
labelFunction: importRuleChainBreadcumbLabelFunction,
labelFunction: ruleChainBreadcumbLabelFunction,
icon: 'settings_ethernet'
} as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain',
import: true
title: 'edge.rulechain',
import: false,
ruleChainType: ruleChainType.edge
},
resolve: {
ruleChain: RuleChainResolver,
ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
ruleNodeComponents: RuleNodeComponentsResolver
}
},
{
path: ':ruleChainId',
path: 'ruleChain/import',
component: RuleChainPageComponent,
canActivate: [RuleChainImportGuard],
canDeactivate: [ConfirmOnExitGuard],
data: {
breadcrumb: {
labelFunction: ruleChainBreadcumbLabelFunction,
labelFunction: importRuleChainBreadcumbLabelFunction,
icon: 'settings_ethernet'
} as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain',
import: false,
type: ruleChainType.edge
title: 'edge.rulechain',
import: true,
ruleChainType: ruleChainType.edge
},
resolve: {
ruleChain: RuleChainResolver,
ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
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>('root', 'rulechain.root', '60px',
entity => {
if (isDefined(this.config.componentsData.edgeId)) {
if (this.config.componentsData.edgeId) {
return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id));
} else {
return checkBoxCell(entity.root);
@ -90,23 +90,25 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.saveEntity = ruleChain => this.saveRuleChain(ruleChain);
this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id);
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> {
const routeParams = route.params;
this.config.componentsData = {
ruleChainScope: route.data.ruleChainsType,
type: route.data.type,
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.config.groupActionDescriptors = this.configureGroupActions(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.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink);
} 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);
}
}
@ -297,7 +292,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
true
).subscribe((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(
(edge) => {
this.edge = edge;
@ -469,7 +464,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
}
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(ruleChain)) && !ruleChain.root;
@ -489,21 +484,16 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
fetchEdgeRuleChains(pageLink: PageLink) {
let defaultEdgeRuleChainIds: Array<string> = [];
this.ruleChainService.getDefaultEdgeRuleChains().pipe(
map(ruleChains =>
ruleChains.map(ruleChain =>
defaultEdgeRuleChainIds.push(ruleChain.id.id)
)
)
).subscribe();
this.ruleChainService.getDefaultEdgeRuleChains().subscribe(ruleChains => {
ruleChains.map(ruleChain => defaultEdgeRuleChainIds.push(ruleChain.id.id))
});
return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe(
map((response) => {
map(response => {
response.data.map(ruleChain =>
ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id))
);
return response;
return response;
})
);
}
}

Loading…
Cancel
Save