Browse Source

Partial fix Edge Rule Chain page

pull/3811/head
deaflynx 7 years ago
parent
commit
bc28406594
  1. 7
      ui-ngx/src/app/core/http/entity.service.ts
  2. 6
      ui-ngx/src/app/core/services/menu.service.ts
  3. 6
      ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts
  4. 142
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-routing.module.ts
  5. 320
      ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts
  6. 4
      ui-ngx/src/assets/locale/locale.constant-en_US.json

7
ui-ngx/src/app/core/http/entity.service.ts

@ -310,12 +310,7 @@ export class EntityService {
break;
case EntityType.RULE_CHAIN:
pageLink.sortOrder.property = 'name';
entitiesObservable = this.ruleChainService.getRuleChains(pageLink, ruleChainType.core, config);
// TODO: deaflynx: change solution
// console.log("route.routerState.snapshot.url", this.route.routerState.snapshot.url);
// if (this.route.url.includes('edges')) {
// entitiesObservable = this.ruleChainService.getRuleChains(pageLink, edgeRuleChainType, config);
// } else { entitiesObservable = this.ruleChainService.getRuleChains(pageLink, subType, config); }
entitiesObservable = this.ruleChainService.getRuleChains(pageLink, subType, config);
break;
case EntityType.DASHBOARD:
pageLink.sortOrder.property = 'title';

6
ui-ngx/src/app/core/services/menu.service.ts

@ -186,15 +186,15 @@ export class MenuService {
icon: 'settings_ethernet',
pages: [
{
name: 'rulechain.rulechains',
name: 'rulechain.core-rulechains',
type: 'link',
path: '/ruleChains',
path: '/ruleChains/core',
icon: 'settings_ethernet'
},
{
name: 'rulechain.edge-rulechains',
type: 'link',
path: '/edgesRuleChains',
path: '/ruleChains/edge',
icon: 'router'
}
]

6
ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts

@ -40,7 +40,6 @@ const routes: Routes = [
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
title: 'edge.edges',
edgeScope: 'tenant'
},
resolve: {
@ -52,7 +51,6 @@ const routes: Routes = [
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
title: 'edge.rulechains',
ruleChainScope: 'edge',
breadcrumb: {
label: 'edge.rulechains',
@ -68,7 +66,6 @@ const routes: Routes = [
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
title: 'edge.assets',
assetsType: 'edge',
breadcrumb: {
label: 'edge.assets',
@ -84,7 +81,6 @@ const routes: Routes = [
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
title: 'edge.devices',
devicesType: 'edge',
breadcrumb: {
label: 'edge.devices',
@ -100,7 +96,6 @@ const routes: Routes = [
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
title: 'edge.entity-views',
entityViewsType: 'edge',
breadcrumb: {
label: 'edge.entity-views',
@ -116,7 +111,6 @@ const routes: Routes = [
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER],
title: 'edge.dashboards',
dashboardsType: 'edge',
breadcrumb: {
label: 'edge.dashboards',

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

@ -35,7 +35,7 @@ import * as RxJs from 'rxjs';
import { Observable } from 'rxjs';
import * as RxJsOperators from 'rxjs/operators';
import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb';
import { ResolvedRuleChainMetaData, RuleChain } from '@shared/models/rule-chain.models';
import {ResolvedRuleChainMetaData, RuleChain, ruleChainType} from '@shared/models/rule-chain.models';
import { RuleChainService } from '@core/http/rule-chain.service';
import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component';
import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models';
@ -158,6 +158,8 @@ const routes: Routes = [
children: [
{
path: '',
redirectTo: '/ruleChains/core',
pathMatch: 'full',
component: EntitiesTableComponent,
data: {
auth: [Authority.TENANT_ADMIN],
@ -168,41 +170,129 @@ const routes: Routes = [
}
},
{
path: ':ruleChainId',
component: RuleChainPageComponent,
canDeactivate: [ConfirmOnExitGuard],
path: 'core',
data: {
breadcrumb: {
labelFunction: ruleChainBreadcumbLabelFunction,
label: 'rulechain.core-rulechains',
icon: 'settings_ethernet'
} as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain',
import: false
}
},
resolve: {
ruleChain: RuleChainResolver,
ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
ruleNodeComponents: RuleNodeComponentsResolver
}
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',
import: false
},
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
}
}
]
},
{
path: 'ruleChain/import',
component: RuleChainPageComponent,
canActivate: [RuleChainImportGuard],
canDeactivate: [ConfirmOnExitGuard],
path: 'edge',
data: {
breadcrumb: {
labelFunction: importRuleChainBreadcumbLabelFunction,
label: 'rulechain.edge-rulechains',
icon: 'settings_ethernet'
} as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain',
import: true
},
type: 'edge'
},
resolve: {
ruleNodeComponents: RuleNodeComponentsResolver
}
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',
import: true,
type: ruleChainType.edge
},
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
}
}
]
}
]
}

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

@ -16,34 +16,48 @@
import { Injectable } from '@angular/core';
import { Resolve, Router } from '@angular/router';
import {ActivatedRouteSnapshot, Resolve, Router} from '@angular/router';
import {
CellActionDescriptor,
checkBoxCell,
DateEntityTableColumn,
EntityTableColumn,
EntityTableConfig
EntityTableConfig,
GroupActionDescriptor, HeaderActionDescriptor
} from '@home/models/entity/entities-table-config.models';
import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '@angular/common';
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
import { EntityAction } from '@home/models/entity/entity-component.models';
import {RuleChain, 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 { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
import { DialogService } from '@core/services/dialog.service';
import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component';
import { ImportExportService } from '@home/components/import-export/import-export.service';
import { ItemBufferService } from '@core/services/item-buffer.service';
import { EdgeService } from "@core/http/edge.service";
import { map } from "rxjs/operators";
import { forkJoin, Observable } from "rxjs";
import {
AddEntitiesToEdgeDialogComponent,
AddEntitiesToEdgeDialogData
} from "@home/dialogs/add-entities-to-edge-dialog.component";
import { MatDialog } from "@angular/material/dialog";
import {isUndefined} from "@core/utils";
@Injectable()
export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> {
private readonly config: EntityTableConfig<RuleChain> = new EntityTableConfig<RuleChain>();
private edgeId: string;
constructor(private ruleChainService: RuleChainService,
private dialogService: DialogService,
private dialog: MatDialog,
private importExport: ImportExportService,
private itembuffer: ItemBufferService,
private edgeService: EdgeService,
private translate: TranslateService,
private datePipe: DatePipe,
private router: Router) {
@ -63,41 +77,41 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
}),
);
this.config.addActionDescriptors.push(
{
name: this.translate.instant('rulechain.create-new-rulechain'),
icon: 'insert_drive_file',
isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event)
},
{
name: this.translate.instant('rulechain.import'),
icon: 'file_upload',
isEnabled: () => true,
onAction: ($event) => this.importRuleChain($event)
}
);
// this.config.addActionDescriptors.push(
// {
// name: this.translate.instant('rulechain.create-new-rulechain'),
// icon: 'insert_drive_file',
// isEnabled: () => true,
// onAction: ($event) => this.config.table.addEntity($event)
// },
// {
// name: this.translate.instant('rulechain.import'),
// icon: 'file_upload',
// isEnabled: () => true,
// onAction: ($event) => this.importRuleChain($event)
// }
// );
this.config.cellActionDescriptors.push(
{
name: this.translate.instant('rulechain.open-rulechain'),
icon: 'settings_ethernet',
isEnabled: () => true,
onAction: ($event, entity) => this.openRuleChain($event, entity)
},
{
name: this.translate.instant('rulechain.export'),
icon: 'file_download',
isEnabled: () => true,
onAction: ($event, entity) => this.exportRuleChain($event, entity)
},
{
name: this.translate.instant('rulechain.set-root'),
icon: 'flag',
isEnabled: (ruleChain) => !ruleChain.root,
onAction: ($event, entity) => this.setRootRuleChain($event, entity)
}
);
// this.config.cellActionDescriptors.push(
// {
// name: this.translate.instant('rulechain.open-rulechain'),
// icon: 'settings_ethernet',
// isEnabled: () => true,
// onAction: ($event, entity) => this.openRuleChain($event, entity)
// },
// {
// name: this.translate.instant('rulechain.export'),
// icon: 'file_download',
// isEnabled: () => true,
// onAction: ($event, entity) => this.exportRuleChain($event, entity)
// },
// {
// name: this.translate.instant('rulechain.set-root'),
// icon: 'flag',
// isEnabled: (ruleChain) => !ruleChain.root,
// onAction: ($event, entity) => this.setRootRuleChain($event, entity)
// }
// );
this.config.deleteEntityTitle = ruleChain => this.translate.instant('rulechain.delete-rulechain-title',
{ ruleChainName: ruleChain.name });
@ -105,21 +119,142 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.deleteEntitiesTitle = count => this.translate.instant('rulechain.delete-rulechains-title', {count});
this.config.deleteEntitiesContent = () => this.translate.instant('rulechain.delete-rulechains-text');
this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.core);
// this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge);
this.config.loadEntity = id => this.ruleChainService.getRuleChain(id.id);
this.config.saveEntity = ruleChain => this.ruleChainService.saveRuleChain(ruleChain);
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.entitySelectionEnabled = (ruleChain) => ruleChain && !ruleChain.root;
}
resolve(): EntityTableConfig<RuleChain> {
this.config.tableTitle = this.translate.instant('rulechain.rulechains');
resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> {
// this.config.tableTitle = this.translate.instant('rulechain.rulechains');
const routeParams = route.params;
this.config.componentsData = {
ruleChainScope: route.data.ruleChainScope,
type: route.data.type
};
this.edgeId = routeParams.edgeId;
this.configureEntityFunctions(this.config.componentsData.ruleChainScope);
this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope);
this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope);
this.config.cellActionDescriptors = this.configureCellActions(this.config.componentsData.ruleChainScope);
return this.config;
}
configureAddActions(ruleChainScope: string): Array<HeaderActionDescriptor> {
const actions: Array<HeaderActionDescriptor> = [];
if (ruleChainScope === 'tenant' || ruleChainScope === 'edges') {
actions.push(
{
name: this.translate.instant('rulechain.create-new-rulechain'),
icon: 'insert_drive_file',
isEnabled: () => true,
onAction: ($event) => this.config.table.addEntity($event)
},
{
name: this.translate.instant('rulechain.import'),
icon: 'file_upload',
isEnabled: () => true,
onAction: ($event) => this.importRuleChain($event)
}
)
}
if (ruleChainScope === 'edge') {
actions.push(
{
name: this.translate.instant('rulechain.assign-new-rulechain'),
icon: 'add',
isEnabled: () => true,
onAction: ($event) => this.addRuleChainsToEdge($event)
}
)
}
return actions;
}
configureEntityFunctions(ruleChainScope: string): void {
if (ruleChainScope === 'tenant') {
this.config.tableTitle = this.translate.instant('rulechain.core-rulechains');
this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.core);
} else if (ruleChainScope === 'edges') {
this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains');
this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge);
} else if (ruleChainScope === 'edge') {
if (this.edgeId) {
this.edgeService.getEdge(this.edgeId)
.pipe(map(edge => this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains')))
.subscribe();
}
this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.edgeId, pageLink);
this.config.deleteEnabled = () => false;
}
}
configureGroupActions(ruleChainScope: string): Array<GroupActionDescriptor<RuleChain>> {
const actions: Array<GroupActionDescriptor<RuleChain>> = [];
if (ruleChainScope === 'edge') {
actions.push(
{
name: this.translate.instant('rulechain.unassign-rulechains-from-edge'),
icon: 'portable_wifi_off',
isEnabled: true,
onAction: ($event, entities) => this.unassignRuleChainsFromEdge($event, entities)
}
)
}
return actions;
}
configureCellActions(ruleChainScope: string): Array<CellActionDescriptor<RuleChain>> {
const actions: Array<CellActionDescriptor<RuleChain>> = [];
if (ruleChainScope === 'tenant' || ruleChainScope === 'edges') {
actions.push(
{
name: this.translate.instant('rulechain.open-rulechain'),
icon: 'settings_ethernet',
isEnabled: () => true,
onAction: ($event, entity) => this.openRuleChain($event, entity)
},
{
name: this.translate.instant('rulechain.export'),
icon: 'file_download',
isEnabled: () => true,
onAction: ($event, entity) => this.exportRuleChain($event, entity)
},
{
name: this.translate.instant('rulechain.set-root'),
icon: 'flag',
isEnabled: (ruleChain) => !ruleChain.root,
onAction: ($event, entity) => this.setRootRuleChain($event, entity)
}
)
}
if (ruleChainScope === 'edges') {
actions.push(
{
name: this.translate.instant('rulechain.make-default!!!'),
icon: 'flag',
isEnabled: () => true,
onAction: ($event, entity) => this.setDefaultRootEdgeRuleChain($event, entity)
}
)
}
if (ruleChainScope === 'edge') {
actions.push(
{
name: this.translate.instant('edge.unassign-from-edge'),
icon: 'portable_wifi_off',
isEnabled: () => true,
onAction: ($event, entity) => this.unassignFromEdge($event, entity)
}
)
}
return actions;
}
importRuleChain($event: Event) {
if ($event) {
$event.stopPropagation();
@ -139,6 +274,17 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
this.router.navigateByUrl(`ruleChains/${ruleChain.id.id}`);
}
saveRuleChain(ruleChain: RuleChain) {
if (isUndefined(ruleChain.type)) {
if (this.config.componentsData.ruleChainScope == 'tenant') {
ruleChain.type = ruleChainType.core;
} else if (this.config.componentsData.ruleChainScope == 'edges') {
ruleChain.type = ruleChainType.edge;
}
}
return this.ruleChainService.saveRuleChain(ruleChain);
}
exportRuleChain($event: Event, ruleChain: RuleChain) {
if ($event) {
$event.stopPropagation();
@ -183,4 +329,96 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
return false;
}
setDefaultRootEdgeRuleChain($event: Event, ruleChain: RuleChain) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('rulechain.set-default-root-edge-rulechain-title', {ruleChainName: ruleChain.name}),
this.translate.instant('rulechain.set-default-root-edge-rulechain-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
if (res) {
this.ruleChainService.setDefaultRootEdgeRuleChain(ruleChain.id.id).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
addRuleChainsToEdge($event: Event) {
if ($event) {
$event.stopPropagation();
}
this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData,
boolean>(AddEntitiesToEdgeDialogComponent, {
disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
edgeId: this.edgeId,
entityType: EntityType.RULE_CHAIN
}
}).afterClosed()
.subscribe((res) => {
if (res) {
this.config.table.updateData();
}
});
}
unassignFromEdge($event: Event, ruleChain: RuleChain) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('rulechain.unassign-from-edges'),
this.translate.instant('rulechain.unassign-from-edges-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
if (res) {
this.ruleChainService.unassignRuleChainFromEdge(this.config.componentsData.edgeId, ruleChain.id.id).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
unassignRuleChainsFromEdge($event: Event, ruleChains: Array<RuleChain>) {
if ($event) {
$event.stopPropagation();
}
this.dialogService.confirm(
this.translate.instant('rulechain.unassign-rulechains-from-edge-title', {count: ruleChains.length}),
this.translate.instant('rulechain.unassign-rulechains-from-edge-text'),
this.translate.instant('action.no'),
this.translate.instant('action.yes'),
true
).subscribe((res) => {
if (res) {
const tasks: Observable<any>[] = [];
ruleChains.forEach(
(ruleChain) => {
tasks.push(this.ruleChainService.unassignRuleChainFromEdge(this.config.componentsData.edgeId, ruleChain.id.id));
}
);
forkJoin(tasks).subscribe(
() => {
this.config.table.updateData();
}
);
}
}
);
}
}

4
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -1513,7 +1513,11 @@
"no-relations-text": "No relations found"
},
"rulechain": {
"assign-new-rulechain": "Assign new rulechain",
"assign-rulechain-to-edge-title": "Assign Rule Chain(s) To Edge",
"assign-rulechain-to-edge-text": "Please select the rulechains to assign to the edge",
"edge-rulechains": "Edge Rule chains",
"core-rulechains": "Core Rule chains",
"rulechain": "Rule chain",
"rulechains": "Rule chains",
"root": "Root",

Loading…
Cancel
Save