2019-08-09 19:13:18 +03:00
|
|
|
///
|
2020-02-20 10:26:43 +02:00
|
|
|
/// Copyright © 2016-2020 The Thingsboard Authors
|
2019-08-09 19:13:18 +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.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { AuthService } from '../auth/auth.service';
|
|
|
|
|
import { select, Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '../core.state';
|
|
|
|
|
import { 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';
|
2020-04-27 09:27:14 +03:00
|
|
|
import { AuthUser } from '@shared/models/user.model';
|
2019-08-09 19:13:18 +03:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class MenuService {
|
|
|
|
|
|
|
|
|
|
menuSections$: Subject<Array<MenuSection>> = new BehaviorSubject<Array<MenuSection>>([]);
|
|
|
|
|
homeSections$: Subject<Array<HomeSection>> = new BehaviorSubject<Array<HomeSection>>([]);
|
|
|
|
|
|
|
|
|
|
constructor(private store: Store<AppState>, private authService: AuthService) {
|
|
|
|
|
this.store.pipe(select(selectIsAuthenticated)).subscribe(
|
|
|
|
|
(authenticated: boolean) => {
|
|
|
|
|
if (authenticated) {
|
|
|
|
|
this.buildMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildMenu() {
|
|
|
|
|
this.store.pipe(select(selectAuthUser), take(1)).subscribe(
|
|
|
|
|
(authUser: AuthUser) => {
|
|
|
|
|
if (authUser) {
|
|
|
|
|
let menuSections: Array<MenuSection>;
|
|
|
|
|
let homeSections: Array<HomeSection>;
|
|
|
|
|
switch (authUser.authority) {
|
|
|
|
|
case Authority.SYS_ADMIN:
|
|
|
|
|
menuSections = this.buildSysAdminMenu(authUser);
|
|
|
|
|
homeSections = this.buildSysAdminHome(authUser);
|
|
|
|
|
break;
|
|
|
|
|
case Authority.TENANT_ADMIN:
|
|
|
|
|
menuSections = this.buildTenantAdminMenu(authUser);
|
|
|
|
|
homeSections = this.buildTenantAdminHome(authUser);
|
|
|
|
|
break;
|
|
|
|
|
case Authority.CUSTOMER_USER:
|
|
|
|
|
menuSections = this.buildCustomerUserMenu(authUser);
|
|
|
|
|
homeSections = this.buildCustomerUserHome(authUser);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
this.menuSections$.next(menuSections);
|
|
|
|
|
this.homeSections$.next(homeSections);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildSysAdminMenu(authUser: any): Array<MenuSection> {
|
|
|
|
|
const sections: Array<MenuSection> = [];
|
|
|
|
|
sections.push(
|
|
|
|
|
{
|
|
|
|
|
name: 'home.home',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/home',
|
|
|
|
|
icon: 'home'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'tenant.tenants',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/tenants',
|
|
|
|
|
icon: 'supervisor_account'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'widget.widget-library',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/widgets-bundles',
|
|
|
|
|
icon: 'now_widgets'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.system-settings',
|
|
|
|
|
type: 'toggle',
|
|
|
|
|
path: '/settings',
|
|
|
|
|
height: '120px',
|
|
|
|
|
icon: 'settings',
|
|
|
|
|
pages: [
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.general',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/settings/general',
|
|
|
|
|
icon: 'settings_applications'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.outgoing-mail',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/settings/outgoing-mail',
|
|
|
|
|
icon: 'mail'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.security-settings',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/settings/security-settings',
|
|
|
|
|
icon: 'security'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return sections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildSysAdminHome(authUser: any): Array<HomeSection> {
|
|
|
|
|
const homeSections: Array<HomeSection> = [];
|
|
|
|
|
homeSections.push(
|
|
|
|
|
{
|
|
|
|
|
name: 'tenant.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'tenant.tenants',
|
|
|
|
|
icon: 'supervisor_account',
|
|
|
|
|
path: '/tenants'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'widget.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'widget.widget-library',
|
|
|
|
|
icon: 'now_widgets',
|
|
|
|
|
path: '/widgets-bundles'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.system-settings',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.general',
|
|
|
|
|
icon: 'settings_applications',
|
|
|
|
|
path: '/settings/general'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.outgoing-mail',
|
|
|
|
|
icon: 'mail',
|
|
|
|
|
path: '/settings/outgoing-mail'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'admin.security-settings',
|
|
|
|
|
icon: 'security',
|
|
|
|
|
path: '/settings/security-settings'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return homeSections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildTenantAdminMenu(authUser: any): Array<MenuSection> {
|
|
|
|
|
const sections: Array<MenuSection> = [];
|
|
|
|
|
sections.push(
|
|
|
|
|
{
|
|
|
|
|
name: 'home.home',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/home',
|
|
|
|
|
icon: 'home'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'rulechain.rulechains',
|
2020-06-21 20:38:43 +03:00
|
|
|
type: 'toggle',
|
2019-08-09 19:13:18 +03:00
|
|
|
path: '/ruleChains',
|
2020-06-21 20:38:43 +03:00
|
|
|
height: '80px',
|
|
|
|
|
icon: 'settings_ethernet',
|
|
|
|
|
pages: [
|
|
|
|
|
{
|
2020-06-23 00:34:47 +03:00
|
|
|
name: 'rulechain.core-rulechains',
|
2020-06-21 20:38:43 +03:00
|
|
|
type: 'link',
|
2020-06-23 00:34:47 +03:00
|
|
|
path: '/ruleChains/core',
|
2020-06-21 20:38:43 +03:00
|
|
|
icon: 'settings_ethernet'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'rulechain.edge-rulechains',
|
|
|
|
|
type: 'link',
|
2020-06-23 00:34:47 +03:00
|
|
|
path: '/ruleChains/edge',
|
2020-06-21 20:38:43 +03:00
|
|
|
icon: 'router'
|
|
|
|
|
}
|
|
|
|
|
]
|
2019-08-09 19:13:18 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'customer.customers',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/customers',
|
|
|
|
|
icon: 'supervisor_account'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'asset.assets',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/assets',
|
|
|
|
|
icon: 'domain'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'device.devices',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/devices',
|
|
|
|
|
icon: 'devices_other'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'entity-view.entity-views',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/entityViews',
|
|
|
|
|
icon: 'view_quilt'
|
|
|
|
|
},
|
2020-06-21 20:38:43 +03:00
|
|
|
{
|
|
|
|
|
name: 'edge.edges',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/edges',
|
|
|
|
|
icon: 'router'
|
|
|
|
|
},
|
2019-08-09 19:13:18 +03:00
|
|
|
{
|
|
|
|
|
name: 'widget.widget-library',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/widgets-bundles',
|
|
|
|
|
icon: 'now_widgets'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'dashboard.dashboards',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/dashboards',
|
|
|
|
|
icon: 'dashboards'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'audit-log.audit-logs',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/auditLogs',
|
|
|
|
|
icon: 'track_changes'
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return sections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildTenantAdminHome(authUser: any): Array<HomeSection> {
|
|
|
|
|
const homeSections: Array<HomeSection> = [];
|
|
|
|
|
homeSections.push(
|
|
|
|
|
{
|
|
|
|
|
name: 'rulechain.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'rulechain.rulechains',
|
|
|
|
|
icon: 'settings_ethernet',
|
|
|
|
|
path: '/ruleChains'
|
2020-06-21 20:38:43 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'rulechain.edge-rulechains',
|
|
|
|
|
icon: 'router',
|
|
|
|
|
path: '/edgesRuleChains'
|
2019-08-09 19:13:18 +03:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'customer.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'customer.customers',
|
|
|
|
|
icon: 'supervisor_account',
|
|
|
|
|
path: '/customers'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'asset.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'asset.assets',
|
|
|
|
|
icon: 'domain',
|
|
|
|
|
path: '/assets'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'device.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'device.devices',
|
|
|
|
|
icon: 'devices_other',
|
|
|
|
|
path: '/devices'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'entity-view.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'entity-view.entity-views',
|
|
|
|
|
icon: 'view_quilt',
|
|
|
|
|
path: '/entityViews'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
2020-06-21 20:38:43 +03:00
|
|
|
{
|
|
|
|
|
name: 'edge.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'edge.edges',
|
|
|
|
|
icon: 'router',
|
|
|
|
|
path: '/edges'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
2019-08-09 19:13:18 +03:00
|
|
|
{
|
|
|
|
|
name: 'dashboard.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'widget.widget-library',
|
|
|
|
|
icon: 'now_widgets',
|
|
|
|
|
path: '/widgets-bundles'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'dashboard.dashboards',
|
|
|
|
|
icon: 'dashboard',
|
|
|
|
|
path: '/dashboards'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'audit-log.audit',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'audit-log.audit-logs',
|
|
|
|
|
icon: 'track_changes',
|
|
|
|
|
path: '/auditLogs'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return homeSections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildCustomerUserMenu(authUser: any): Array<MenuSection> {
|
|
|
|
|
const sections: Array<MenuSection> = [];
|
|
|
|
|
sections.push(
|
|
|
|
|
{
|
|
|
|
|
name: 'home.home',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/home',
|
|
|
|
|
icon: 'home'
|
2019-08-12 19:34:23 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'asset.assets',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/assets',
|
|
|
|
|
icon: 'domain'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'device.devices',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/devices',
|
|
|
|
|
icon: 'devices_other'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'entity-view.entity-views',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/entityViews',
|
|
|
|
|
icon: 'view_quilt'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'dashboard.dashboards',
|
|
|
|
|
type: 'link',
|
|
|
|
|
path: '/dashboards',
|
|
|
|
|
icon: 'dashboard'
|
2019-08-09 19:13:18 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return sections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildCustomerUserHome(authUser: any): Array<HomeSection> {
|
2019-08-12 19:34:23 +03:00
|
|
|
const homeSections: Array<HomeSection> = [
|
|
|
|
|
{
|
|
|
|
|
name: 'asset.view-assets',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'asset.assets',
|
|
|
|
|
icon: 'domain',
|
|
|
|
|
path: '/assets'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'device.view-devices',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'device.devices',
|
|
|
|
|
icon: 'devices_other',
|
|
|
|
|
path: '/devices'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'entity-view.management',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'entity-view.entity-views',
|
|
|
|
|
icon: 'view_quilt',
|
|
|
|
|
path: '/entityViews'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'dashboard.view-dashboards',
|
|
|
|
|
places: [
|
|
|
|
|
{
|
|
|
|
|
name: 'dashboard.dashboards',
|
|
|
|
|
icon: 'dashboard',
|
|
|
|
|
path: '/dashboards'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
];
|
2019-08-09 19:13:18 +03:00
|
|
|
return homeSections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public menuSections(): Observable<Array<MenuSection>> {
|
|
|
|
|
return this.menuSections$;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public homeSections(): Observable<Array<HomeSection>> {
|
|
|
|
|
return this.homeSections$;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|