2019-08-20 20:42:48 +03:00
|
|
|
///
|
2020-02-20 10:26:43 +02:00
|
|
|
/// Copyright © 2016-2020 The Thingsboard Authors
|
2019-08-20 20:42:48 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
2020-08-17 16:11:01 +03:00
|
|
|
import { Inject, Injectable, NgModule, Optional } from '@angular/core';
|
2020-01-22 20:05:30 +02:00
|
|
|
import {
|
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
|
CanActivate,
|
2020-04-27 09:27:14 +03:00
|
|
|
Resolve,
|
|
|
|
|
Router,
|
2020-01-22 20:05:30 +02:00
|
|
|
RouterModule,
|
|
|
|
|
RouterStateSnapshot,
|
2020-04-27 09:27:14 +03:00
|
|
|
Routes,
|
|
|
|
|
UrlTree
|
2020-01-22 20:05:30 +02:00
|
|
|
} from '@angular/router';
|
2019-08-20 20:42:48 +03:00
|
|
|
|
2020-01-14 16:57:42 +02:00
|
|
|
import { EntitiesTableComponent } from '../../components/entity/entities-table.component';
|
|
|
|
|
import { Authority } from '@shared/models/authority.enum';
|
|
|
|
|
import { RuleChainsTableConfigResolver } from '@modules/home/pages/rulechain/rulechains-table-config.resolver';
|
2019-11-15 16:12:24 +02:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb';
|
2020-10-27 09:19:42 +02:00
|
|
|
import {
|
|
|
|
|
ResolvedRuleChainMetaData,
|
|
|
|
|
RuleChain,
|
|
|
|
|
RuleChainType,
|
|
|
|
|
ruleChainType,
|
|
|
|
|
} from '@shared/models/rule-chain.models';
|
2019-11-15 16:12:24 +02:00
|
|
|
import { RuleChainService } from '@core/http/rule-chain.service';
|
|
|
|
|
import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component';
|
2019-11-22 17:58:13 +02:00
|
|
|
import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models';
|
|
|
|
|
import { ConfirmOnExitGuard } from '@core/guards/confirm-on-exit.guard';
|
2020-04-27 09:27:14 +03:00
|
|
|
import { ItemBufferService } from '@core/public-api';
|
2020-08-17 16:11:01 +03:00
|
|
|
import { MODULES_MAP } from '@shared/public-api';
|
2019-12-23 14:36:44 +02:00
|
|
|
|
2019-11-15 16:12:24 +02:00
|
|
|
@Injectable()
|
|
|
|
|
export class RuleChainResolver implements Resolve<RuleChain> {
|
|
|
|
|
|
|
|
|
|
constructor(private ruleChainService: RuleChainService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<RuleChain> {
|
|
|
|
|
const ruleChainId = route.params.ruleChainId;
|
|
|
|
|
return this.ruleChainService.getRuleChain(ruleChainId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 17:58:13 +02:00
|
|
|
@Injectable()
|
|
|
|
|
export class ResolvedRuleChainMetaDataResolver implements Resolve<ResolvedRuleChainMetaData> {
|
|
|
|
|
|
|
|
|
|
constructor(private ruleChainService: RuleChainService) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<ResolvedRuleChainMetaData> {
|
|
|
|
|
const ruleChainId = route.params.ruleChainId;
|
|
|
|
|
return this.ruleChainService.getResolvedRuleChainMetadata(ruleChainId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeComponentDescriptor>> {
|
|
|
|
|
|
2020-08-17 16:11:01 +03:00
|
|
|
constructor(private ruleChainService: RuleChainService,
|
|
|
|
|
@Optional() @Inject(MODULES_MAP) private modulesMap: {[key: string]: any}) {
|
2019-11-22 17:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> {
|
2020-10-27 09:19:42 +02:00
|
|
|
const ruleChainType: RuleChainType = route.data.type;
|
2020-10-26 20:16:44 +02:00
|
|
|
return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType);
|
2019-11-22 17:58:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 20:05:30 +02:00
|
|
|
@Injectable()
|
|
|
|
|
export class RuleChainImportGuard implements CanActivate {
|
|
|
|
|
|
|
|
|
|
constructor(private itembuffer: ItemBufferService,
|
|
|
|
|
private router: Router) {
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 15:14:17 +02:00
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
|
|
|
|
|
Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
2020-01-22 20:05:30 +02:00
|
|
|
if (this.itembuffer.hasRuleChainImport()) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return this.router.parseUrl('ruleChains');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-07 17:06:04 +03:00
|
|
|
export const ruleChainBreadcumbLabelFunction: BreadCrumbLabelFunction<RuleChainPageComponent>
|
|
|
|
|
= ((route, translate, component) => {
|
2019-11-15 16:12:24 +02:00
|
|
|
let label: string = component.ruleChain.name;
|
|
|
|
|
if (component.ruleChain.root) {
|
|
|
|
|
label += ` (${translate.instant('rulechain.root')})`;
|
|
|
|
|
}
|
|
|
|
|
return label;
|
|
|
|
|
});
|
2019-08-20 20:42:48 +03:00
|
|
|
|
2020-04-07 17:06:04 +03:00
|
|
|
export const importRuleChainBreadcumbLabelFunction: BreadCrumbLabelFunction<RuleChainPageComponent> =
|
|
|
|
|
((route, translate, component) => {
|
2019-11-22 17:58:13 +02:00
|
|
|
return `${translate.instant('rulechain.import')}: ${component.ruleChain.name}`;
|
|
|
|
|
});
|
|
|
|
|
|
2019-08-20 20:42:48 +03:00
|
|
|
const routes: Routes = [
|
|
|
|
|
{
|
|
|
|
|
path: 'ruleChains',
|
|
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
label: 'rulechain.rulechains',
|
|
|
|
|
icon: 'settings_ethernet'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
2020-06-23 00:34:47 +03:00
|
|
|
redirectTo: '/ruleChains/core',
|
|
|
|
|
pathMatch: 'full',
|
2019-08-20 20:42:48 +03:00
|
|
|
component: EntitiesTableComponent,
|
|
|
|
|
data: {
|
|
|
|
|
auth: [Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'rulechain.rulechains'
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
entitiesTableConfig: RuleChainsTableConfigResolver
|
|
|
|
|
}
|
2019-11-15 16:12:24 +02:00
|
|
|
},
|
|
|
|
|
{
|
2020-06-23 00:34:47 +03:00
|
|
|
path: 'core',
|
2019-11-15 16:12:24 +02:00
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
2020-06-23 00:34:47 +03:00
|
|
|
label: 'rulechain.core-rulechains',
|
2019-11-15 16:12:24 +02:00
|
|
|
icon: 'settings_ethernet'
|
2020-06-23 00:34:47 +03:00
|
|
|
}
|
2019-11-15 16:12:24 +02:00
|
|
|
},
|
2020-06-23 00:34:47 +03:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
|
|
|
|
component: EntitiesTableComponent,
|
|
|
|
|
data: {
|
|
|
|
|
auth: [Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'rulechain.rulechains',
|
|
|
|
|
ruleChainScope: 'tenant',
|
|
|
|
|
type: ruleChainType.core
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
entitiesTableConfig: RuleChainsTableConfigResolver
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: ':ruleChainId',
|
|
|
|
|
component: RuleChainPageComponent,
|
|
|
|
|
canDeactivate: [ConfirmOnExitGuard],
|
|
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
labelFunction: ruleChainBreadcumbLabelFunction,
|
|
|
|
|
icon: 'settings_ethernet'
|
|
|
|
|
} as BreadCrumbConfig<RuleChainPageComponent>,
|
|
|
|
|
auth: [Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'rulechain.rulechain',
|
2020-10-18 11:15:11 +03:00
|
|
|
import: false,
|
|
|
|
|
type: ruleChainType.core
|
2020-06-23 00:34:47 +03:00
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
ruleChain: RuleChainResolver,
|
|
|
|
|
ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
|
|
|
|
|
ruleNodeComponents: RuleNodeComponentsResolver
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'ruleChain/import',
|
|
|
|
|
component: RuleChainPageComponent,
|
|
|
|
|
canActivate: [RuleChainImportGuard],
|
|
|
|
|
canDeactivate: [ConfirmOnExitGuard],
|
|
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
labelFunction: importRuleChainBreadcumbLabelFunction,
|
|
|
|
|
icon: 'settings_ethernet'
|
|
|
|
|
} as BreadCrumbConfig<RuleChainPageComponent>,
|
|
|
|
|
auth: [Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'rulechain.rulechain',
|
|
|
|
|
import: true
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
ruleNodeComponents: RuleNodeComponentsResolver
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2019-11-22 17:58:13 +02:00
|
|
|
},
|
|
|
|
|
{
|
2020-06-23 00:34:47 +03:00
|
|
|
path: 'edge',
|
2019-11-22 17:58:13 +02:00
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
2020-06-23 00:34:47 +03:00
|
|
|
label: 'rulechain.edge-rulechains',
|
2019-11-22 17:58:13 +02:00
|
|
|
icon: 'settings_ethernet'
|
2020-06-23 00:34:47 +03:00
|
|
|
},
|
|
|
|
|
type: 'edge'
|
2019-11-22 17:58:13 +02:00
|
|
|
},
|
2020-06-23 00:34:47 +03:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
|
|
|
|
component: EntitiesTableComponent,
|
|
|
|
|
data: {
|
|
|
|
|
auth: [Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'edge.rulechains',
|
|
|
|
|
ruleChainScope: 'edges',
|
|
|
|
|
type: ruleChainType.edge
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
entitiesTableConfig: RuleChainsTableConfigResolver
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'ruleChain/import',
|
|
|
|
|
component: RuleChainPageComponent,
|
|
|
|
|
canActivate: [RuleChainImportGuard],
|
|
|
|
|
canDeactivate: [ConfirmOnExitGuard],
|
|
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
labelFunction: importRuleChainBreadcumbLabelFunction,
|
|
|
|
|
icon: 'settings_ethernet'
|
|
|
|
|
} as BreadCrumbConfig<RuleChainPageComponent>,
|
|
|
|
|
auth: [Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'rulechain.rulechain',
|
2020-10-27 09:19:42 +02:00
|
|
|
import: true
|
2020-06-23 00:34:47 +03:00
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
ruleNodeComponents: RuleNodeComponentsResolver
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: ':ruleChainId',
|
|
|
|
|
component: RuleChainPageComponent,
|
|
|
|
|
canDeactivate: [ConfirmOnExitGuard],
|
|
|
|
|
data: {
|
|
|
|
|
breadcrumb: {
|
|
|
|
|
labelFunction: ruleChainBreadcumbLabelFunction,
|
|
|
|
|
icon: 'settings_ethernet'
|
|
|
|
|
} as BreadCrumbConfig<RuleChainPageComponent>,
|
|
|
|
|
auth: [Authority.TENANT_ADMIN],
|
|
|
|
|
title: 'rulechain.rulechain',
|
|
|
|
|
import: false,
|
|
|
|
|
type: ruleChainType.edge
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
ruleChain: RuleChainResolver,
|
|
|
|
|
ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
|
|
|
|
|
ruleNodeComponents: RuleNodeComponentsResolver
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2019-08-20 20:42:48 +03:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2019-12-23 14:36:44 +02:00
|
|
|
// @dynamic
|
2019-08-20 20:42:48 +03:00
|
|
|
@NgModule({
|
|
|
|
|
imports: [RouterModule.forChild(routes)],
|
|
|
|
|
exports: [RouterModule],
|
|
|
|
|
providers: [
|
2019-11-15 16:12:24 +02:00
|
|
|
RuleChainsTableConfigResolver,
|
2019-11-22 17:58:13 +02:00
|
|
|
RuleChainResolver,
|
|
|
|
|
ResolvedRuleChainMetaDataResolver,
|
|
|
|
|
RuleNodeComponentsResolver,
|
2020-01-22 20:05:30 +02:00
|
|
|
RuleChainImportGuard
|
2019-08-20 20:42:48 +03:00
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
export class RuleChainRoutingModule { }
|