diff --git a/ui-ngx/src/app/core/http/component-descriptor.service.ts b/ui-ngx/src/app/core/http/component-descriptor.service.ts index 3ec35cad81..3d77d39d75 100644 --- a/ui-ngx/src/app/core/http/component-descriptor.service.ts +++ b/ui-ngx/src/app/core/http/component-descriptor.service.ts @@ -28,8 +28,8 @@ import { RuleChainType } from "@shared/models/rule-chain.models"; }) export class ComponentDescriptorService { - private componentsByType: Map> = - new Map>(); + private componentsByTypeByRuleChainType: Map>> = + new Map>>(); private componentsByClazz: Map = new Map(); constructor( @@ -37,14 +37,17 @@ export class ComponentDescriptorService { ) { } - public getComponentDescriptorsByType(componentType: ComponentType, config?: RequestConfig): Observable> { - const existing = this.componentsByType.get(componentType); + public getComponentDescriptorsByType(componentType: ComponentType, ruleChainType: RuleChainType, config?: RequestConfig): Observable> { + if (!this.componentsByTypeByRuleChainType.get(ruleChainType)) { + this.componentsByTypeByRuleChainType.set(ruleChainType, new Map>()); + } + const existing = this.componentsByTypeByRuleChainType.get(ruleChainType).get(componentType); if (existing) { return of(existing); } else { - return this.http.get>(`/api/components/${componentType}`, defaultHttpOptionsFromConfig(config)).pipe( + return this.http.get>(`/api/components/${componentType}&ruleChainType=${ruleChainType}`, defaultHttpOptionsFromConfig(config)).pipe( map((componentDescriptors) => { - this.componentsByType.set(componentType, componentDescriptors); + this.componentsByTypeByRuleChainType.get(ruleChainType).set(componentType, componentDescriptors); componentDescriptors.forEach((componentDescriptor) => { this.componentsByClazz.set(componentDescriptor.clazz, componentDescriptor); }); @@ -55,10 +58,13 @@ export class ComponentDescriptorService { } public getComponentDescriptorsByTypes(componentTypes: Array, ruleChainType: RuleChainType, config?: RequestConfig): Observable> { + if (!this.componentsByTypeByRuleChainType.get(ruleChainType)) { + this.componentsByTypeByRuleChainType.set(ruleChainType, new Map>()); + } let result: ComponentDescriptor[] = []; for (let i = componentTypes.length - 1; i >= 0; i--) { const componentType = componentTypes[i]; - const componentDescriptors = this.componentsByType.get(componentType); + const componentDescriptors = this.componentsByTypeByRuleChainType.get(ruleChainType).get(componentType); if (componentDescriptors) { result = result.concat(componentDescriptors); componentTypes.splice(i, 1); @@ -71,10 +77,10 @@ export class ComponentDescriptorService { defaultHttpOptionsFromConfig(config)).pipe( map((componentDescriptors) => { componentDescriptors.forEach((componentDescriptor) => { - let componentsList = this.componentsByType.get(componentDescriptor.type); + let componentsList = this.componentsByTypeByRuleChainType.get(ruleChainType).get(componentDescriptor.type); if (!componentsList) { componentsList = new Array(); - this.componentsByType.set(componentDescriptor.type, componentsList); + this.componentsByTypeByRuleChainType.get(ruleChainType).set(componentDescriptor.type, componentsList); } componentsList.push(componentDescriptor); this.componentsByClazz.set(componentDescriptor.clazz, componentDescriptor); diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 929bef9409..e0b1fc04bc 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -28,7 +28,7 @@ import { UserService } from './user.service'; import { DashboardService } from '@core/http/dashboard.service'; import { Direction } from '@shared/models/page/sort-order'; import { PageData } from '@shared/models/page/page-data'; -import { getCurrentAuthUser } from '@core/auth/auth.selectors'; +import { getCurrentAuthState, getCurrentAuthUser } from '@core/auth/auth.selectors'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { Authority } from '@shared/models/authority.enum'; @@ -579,16 +579,18 @@ export class EntityService { public prepareAllowedEntityTypesList(allowedEntityTypes: Array, useAliasEntityTypes?: boolean): Array { - const authUser = getCurrentAuthUser(this.store); + const authState = getCurrentAuthState(this.store); const entityTypes: Array = []; - switch (authUser.authority) { + switch (authState.authUser.authority) { case Authority.SYS_ADMIN: entityTypes.push(EntityType.TENANT); break; case Authority.TENANT_ADMIN: entityTypes.push(EntityType.DEVICE); entityTypes.push(EntityType.ASSET); - entityTypes.push(EntityType.EDGE); + if (authState.edgesSupportEnabled) { + entityTypes.push(EntityType.EDGE); + } entityTypes.push(EntityType.ENTITY_VIEW); entityTypes.push(EntityType.TENANT); entityTypes.push(EntityType.CUSTOMER); @@ -602,7 +604,9 @@ export class EntityService { case Authority.CUSTOMER_USER: entityTypes.push(EntityType.DEVICE); entityTypes.push(EntityType.ASSET); - entityTypes.push(EntityType.EDGE); + if (authState.edgesSupportEnabled) { + entityTypes.push(EntityType.EDGE); + } entityTypes.push(EntityType.ENTITY_VIEW); entityTypes.push(EntityType.CUSTOMER); entityTypes.push(EntityType.USER); @@ -614,7 +618,7 @@ export class EntityService { } if (useAliasEntityTypes) { entityTypes.push(AliasEntityType.CURRENT_USER); - if (authUser.authority !== Authority.SYS_ADMIN) { + if (authState.authUser.authority !== Authority.SYS_ADMIN) { entityTypes.push(AliasEntityType.CURRENT_USER_OWNER); } } diff --git a/ui-ngx/src/app/core/http/rule-chain.service.ts b/ui-ngx/src/app/core/http/rule-chain.service.ts index e4e5015577..9db728f105 100644 --- a/ui-ngx/src/app/core/http/rule-chain.service.ts +++ b/ui-ngx/src/app/core/http/rule-chain.service.ts @@ -51,7 +51,8 @@ import { Edge } from "@shared/models/edge.models"; }) export class RuleChainService { - private ruleNodeComponents: Array; + private ruleNodeComponentsMap: Map> = + new Map>(); private ruleNodeConfigFactories: {[directive: string]: ComponentFactory} = {}; constructor( @@ -120,16 +121,16 @@ export class RuleChainService { public getRuleNodeComponents(ruleNodeConfigResourcesModulesMap: {[key: string]: any}, ruleChainType: RuleChainType, config?: RequestConfig): Observable> { - if (this.ruleNodeComponents) { - return of(this.ruleNodeComponents); + if (this.ruleNodeComponentsMap.get(ruleChainType)) { + return of(this.ruleNodeComponentsMap.get(ruleChainType)); } else { return this.loadRuleNodeComponents(ruleChainType, config).pipe( mergeMap((components) => { return this.resolveRuleNodeComponentsUiResources(components, ruleNodeConfigResourcesModulesMap).pipe( map((ruleNodeComponents) => { - this.ruleNodeComponents = ruleNodeComponents; - this.ruleNodeComponents.push(ruleChainNodeComponent); - this.ruleNodeComponents.sort( + this.ruleNodeComponentsMap.set(ruleChainType, ruleNodeComponents); + this.ruleNodeComponentsMap.get(ruleChainType).push(ruleChainNodeComponent); + this.ruleNodeComponentsMap.get(ruleChainType).sort( (comp1, comp2) => { let result = comp1.type.toString().localeCompare(comp2.type.toString()); if (result === 0) { @@ -138,7 +139,7 @@ export class RuleChainService { return result; } ); - return this.ruleNodeComponents; + return this.ruleNodeComponentsMap.get(ruleChainType); }) ); }) @@ -151,7 +152,11 @@ export class RuleChainService { } public getRuleNodeComponentByClazz(clazz: string): RuleNodeComponentDescriptor { - const found = this.ruleNodeComponents.filter((component) => component.clazz === clazz); + let mergedRuleNodeComponents: RuleNodeComponentDescriptor[] = []; + this.ruleNodeComponentsMap.forEach((value: Array, key: RuleChainType) => { + mergedRuleNodeComponents = mergedRuleNodeComponents.concat(value); + }); + const found = mergedRuleNodeComponents.filter((component) => component.clazz === clazz); if (found && found.length) { return found[0]; } else { diff --git a/ui-ngx/src/app/core/services/menu.service.ts b/ui-ngx/src/app/core/services/menu.service.ts index 0fbc5fdcab..7aef4a862b 100644 --- a/ui-ngx/src/app/core/services/menu.service.ts +++ b/ui-ngx/src/app/core/services/menu.service.ts @@ -18,14 +18,13 @@ import { Injectable } from '@angular/core'; import { AuthService } from '../auth/auth.service'; import { select, Store } from '@ngrx/store'; import { AppState } from '../core.state'; -import {selectAuth, selectAuthUser, selectIsAuthenticated} from '../auth/auth.selectors'; +import { selectAuth, selectAuthUser, selectIsAuthenticated } from '../auth/auth.selectors'; import { take } from 'rxjs/operators'; import { HomeSection, MenuSection } from '@core/services/menu.models'; import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { Authority } from '@shared/models/authority.enum'; -import { AuthUser } from '@shared/models/user.model'; import { guid } from '@core/utils'; -import {AuthState} from "@core/auth/auth.models"; +import { AuthState } from "@core/auth/auth.models"; @Injectable({ providedIn: 'root' @@ -282,14 +281,14 @@ export class MenuService { pages: [ { id: guid(), - name: 'edge.edges', + name: 'edge.edge-instances', type: 'link', path: '/edges', icon: 'router' }, { id: guid(), - name: 'rulechain.edge-rulechains', + name: 'edge.rulechain-templates', type: 'link', path: '/edges/ruleChains', icon: 'settings_ethernet' @@ -398,12 +397,12 @@ export class MenuService { name: 'edge.management', places: [ { - name: 'edge.edges', + name: 'edge.edge-instances', icon: 'router', path: '/edges' }, { - name: 'rulechain.edge-rulechains', + name: 'edge.rulechain-templates', icon: 'settings_ethernet', path: '/edges/ruleChains' } @@ -476,7 +475,20 @@ export class MenuService { type: 'link', path: '/entityViews', icon: 'view_quilt' - }, + } + ); + if (authState.edgesSupportEnabled) { + sections.push( + { + id: guid(), + name: 'edge.edge-instances', + type: 'link', + path: '/edges', + icon: 'router' + } + ); + } + sections.push( { id: guid(), name: 'dashboard.dashboards', @@ -489,7 +501,8 @@ export class MenuService { } private buildCustomerUserHome(authState: AuthState): Array { - const homeSections: Array = [ + const homeSections: Array = []; + homeSections.push( { name: 'asset.view-assets', places: [ @@ -519,7 +532,23 @@ export class MenuService { path: '/entityViews' } ] - }, + } + ); + if (authState.edgesSupportEnabled) { + homeSections.push( + { + name: 'edge.management', + places: [ + { + name: 'edge.edge-instances', + icon: 'router', + path: '/edges' + } + ] + } + ); + } + homeSections.push( { name: 'dashboard.view-dashboards', places: [ @@ -530,7 +559,7 @@ export class MenuService { } ] } - ]; + ); return homeSections; } diff --git a/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts b/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts index dfa52843e3..55506c7cc2 100644 --- a/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts @@ -250,7 +250,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI resetSortAndFilter(update: boolean = true) { const entityType = this.entityIdValue.entityType; - if (entityType === EntityType.DEVICE || entityType === EntityType.ENTITY_VIEW || entityType === EntityType.EDGE) { + if (entityType === EntityType.DEVICE || entityType === EntityType.ENTITY_VIEW) { this.attributeScopes = Object.keys(AttributeScope); this.attributeScopeSelectionReadonly = false; } else { diff --git a/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts index 6a30cc68ac..4b2a73602d 100644 --- a/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts @@ -239,7 +239,7 @@ export class AssetsTableConfigResolver implements Resolve true, onAction: ($event, entity) => this.unassignFromEdge($event, entity) } @@ -274,7 +274,7 @@ export class AssetsTableConfigResolver implements Resolve this.unassignAssetsFromEdge($event, entities) } diff --git a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts index afda43e54c..8c73ca7420 100644 --- a/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts @@ -257,7 +257,7 @@ export class DashboardsTableConfigResolver implements Resolve true, onAction: ($event, entity) => this.unassignFromEdge($event, entity) } @@ -301,7 +301,7 @@ export class DashboardsTableConfigResolver implements Resolve this.unassignDashboardsFromEdge($event, entities) } diff --git a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts index 7b6d14d97d..6abd204962 100644 --- a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts @@ -281,7 +281,7 @@ export class DevicesTableConfigResolver implements Resolve true, onAction: ($event, entity) => this.unassignFromEdge($event, entity) } @@ -315,10 +315,10 @@ export class DevicesTableConfigResolver implements Resolve this.unassignDevicesFromCustomer($event, entities) + onAction: ($event, entities) => this.unassignDevicesFromEdge($event, entities) } ); } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts b/ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts index 53ba2902d8..cf7014d601 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts @@ -42,7 +42,7 @@ const routes: Routes = [ path: 'edges', data: { breadcrumb: { - label: 'edge.edges', + label: 'edge.edge-instances', icon: 'router' } }, @@ -65,7 +65,7 @@ const routes: Routes = [ auth: [Authority.TENANT_ADMIN], ruleChainsType: 'edge', breadcrumb: { - label: 'rulechain.edge-rulechains', + label: 'edge.rulechain-templates', icon: 'settings_ethernet' }, }, @@ -131,7 +131,7 @@ const routes: Routes = [ path: '', component: EntitiesTableComponent, data: { - auth: [Authority.TENANT_ADMIN], + auth: [Authority.TENANT_ADMIN, Authority.CUSTOMER_USER], dashboardsType: 'edge' }, resolve: { @@ -160,7 +160,7 @@ const routes: Routes = [ path: 'ruleChains', data: { breadcrumb: { - label: 'rulechain.edge-rulechains', + label: 'edge.rulechain-templates', icon: 'settings_ethernet' } }, @@ -170,7 +170,7 @@ const routes: Routes = [ component: EntitiesTableComponent, data: { auth: [Authority.TENANT_ADMIN], - title: 'rulechain.edge-rulechains', + title: 'edge.rulechain-templates', ruleChainsType: 'edges' }, resolve: { diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html index ec894a6319..dc892aadbe 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html @@ -17,7 +17,7 @@ --> - diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html index dca66eab64..6fe5d4d87c 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html @@ -34,42 +34,44 @@ [fxShow]="!isEdit && (edgeScope === 'customer' || edgeScope === 'tenant') && isAssignedToCustomer(entity)"> {{ (entity?.customerIsPublic ? 'edge.make-private' : 'edge.unassign-from-customer') | translate }} - - - - - +
+ + + + + +
-
@@ -123,18 +124,6 @@ [required]="true" [entityType]="entityType.EDGE"> - - edge.label - - - -
- - edge.description - - -
-
@@ -163,7 +152,7 @@ edge.edge-key -
+
@@ -173,5 +162,16 @@
+ + edge.label + + +
+ + edge.description + + +
+
diff --git a/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts index 9fe8c9b77e..f54cfdc0e1 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts @@ -122,10 +122,10 @@ export class EdgesTableConfigResolver implements Resolve this.edgeService.unassignEdgeFromCustomer(id.id); } + if (edgeScope === 'customer_user') { + this.config.entitiesFetchFunction = pageLink => + this.edgeService.getCustomerEdgeInfos(this.customerId, pageLink); + this.config.deleteEntity = id => this.edgeService.unassignEdgeFromCustomer(id.id); + } } configureCellActions(edgeScope: string): Array> { diff --git a/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts index 216acc80d5..10f235e312 100644 --- a/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts @@ -239,7 +239,7 @@ export class EntityViewsTableConfigResolver implements Resolve true, onAction: ($event, entity) => this.unassignFromEdge($event, entity) } @@ -274,7 +274,7 @@ export class EntityViewsTableConfigResolver implements Resolve this.unassignEntityViewsFromEdge($event, entities) } diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts index c37659fbc4..6e0f592b5e 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts @@ -101,7 +101,7 @@ export class RuleChainsTableConfigResolver implements Resolve this.config.componentsData.edge.rootRuleChainId.id != ruleChain.id.id; this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe(edge => { this.config.componentsData.edge = edge; - this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains'); + this.config.tableTitle = edge.name + ': ' + this.translate.instant('edge.rulechain-templates'); }); this.config.entitiesDeleteEnabled = false; } @@ -128,7 +128,7 @@ export class RuleChainsTableConfigResolver implements Resolve('createdTime', 'common.created-time', this.datePipe, '150px'), new EntityTableColumn('name', 'rulechain.name', '100%'), - new EntityTableColumn('root', 'rulechain.default-root', '60px', + new EntityTableColumn('root', 'rulechain.root', '60px', entity => { return checkBoxCell(entity.root); }) @@ -173,7 +173,7 @@ export class RuleChainsTableConfigResolver implements Resolve this.fetchRuleChains(pageLink); } else if (ruleChainScope === 'edges') { - this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); + this.config.tableTitle = this.translate.instant('edge.rulechain-templates'); this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink); } else if (ruleChainScope === 'edge') { this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.config.componentsData.edgeId, pageLink); @@ -186,7 +186,7 @@ export class RuleChainsTableConfigResolver implements Resolve this.unassignRuleChainsFromEdge($event, entities) } @@ -232,7 +232,7 @@ export class RuleChainsTableConfigResolver implements Resolve this.setDefaultRootEdgeRuleChain($event, entity) }, { - name: this.translate.instant('rulechain.set-default-edge'), + name: this.translate.instant('rulechain.set-auto-assign-to-edge'), icon: 'bookmark_outline', isEnabled: (entity) => this.isNonDefaultEdgeRuleChain(entity), onAction: ($event, entity) => this.setDefaultEdgeRuleChain($event, entity) @@ -255,7 +255,7 @@ export class RuleChainsTableConfigResolver implements Resolve entity.id.id != this.config.componentsData.edge.rootRuleChainId.id, onAction: ($event, entity) => this.unassignFromEdge($event, entity) } @@ -449,8 +449,8 @@ export class RuleChainsTableConfigResolver implements Resolve