998 lines
26 KiB
TypeScript
Raw Normal View History

///
2023-01-31 10:43:56 +02:00
/// Copyright © 2016-2023 The Thingsboard Authors
///
/// 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 { select, Store } from '@ngrx/store';
import { AppState } from '../core.state';
import { getCurrentOpenedMenuSections, selectAuth, selectIsAuthenticated } from '../auth/auth.selectors';
2023-04-17 19:09:23 +03:00
import { filter, map, 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 { AuthState } from '@core/auth/auth.models';
2023-02-13 19:09:05 +02:00
import { NavigationEnd, Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class MenuService {
2023-02-13 19:09:05 +02:00
currentMenuSections: Array<MenuSection>;
menuSections$: Subject<Array<MenuSection>> = new BehaviorSubject<Array<MenuSection>>([]);
homeSections$: Subject<Array<HomeSection>> = new BehaviorSubject<Array<HomeSection>>([]);
2023-04-17 19:09:23 +03:00
availableMenuLinks$ = this.menuSections$.pipe(
map((items) => this.allMenuLinks(items))
);
constructor(private store: Store<AppState>,
private router: Router) {
this.store.pipe(select(selectIsAuthenticated)).subscribe(
(authenticated: boolean) => {
if (authenticated) {
this.buildMenu();
}
}
);
2023-02-13 19:09:05 +02:00
this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(
() => {
this.updateOpenedMenuSections();
}
);
}
private buildMenu() {
this.store.pipe(select(selectAuth), take(1)).subscribe(
(authState: AuthState) => {
if (authState.authUser) {
let homeSections: Array<HomeSection>;
switch (authState.authUser.authority) {
case Authority.SYS_ADMIN:
this.currentMenuSections = this.buildSysAdminMenu();
homeSections = this.buildSysAdminHome();
break;
case Authority.TENANT_ADMIN:
2023-02-13 19:09:05 +02:00
this.currentMenuSections = this.buildTenantAdminMenu(authState);
homeSections = this.buildTenantAdminHome(authState);
break;
case Authority.CUSTOMER_USER:
2023-02-13 19:09:05 +02:00
this.currentMenuSections = this.buildCustomerUserMenu(authState);
homeSections = this.buildCustomerUserHome(authState);
break;
}
2023-02-13 19:09:05 +02:00
this.updateOpenedMenuSections();
this.menuSections$.next(this.currentMenuSections);
this.homeSections$.next(homeSections);
}
}
);
}
2023-02-13 19:09:05 +02:00
private updateOpenedMenuSections() {
const url = this.router.url;
const openedMenuSections = getCurrentOpenedMenuSections(this.store);
this.currentMenuSections.filter(section => section.type === 'toggle' &&
(url.startsWith(section.path) || openedMenuSections.includes(section.path))).forEach(
section => section.opened = true
);
}
private buildSysAdminMenu(): Array<MenuSection> {
const sections: Array<MenuSection> = [];
sections.push(
{
2023-04-17 19:09:23 +03:00
id: 'home',
name: 'home.home',
type: 'link',
path: '/home',
icon: 'home'
},
{
2023-04-17 19:09:23 +03:00
id: 'tenants',
name: 'tenant.tenants',
type: 'link',
path: '/tenants',
icon: 'supervisor_account'
},
{
2023-04-18 13:45:47 +03:00
id: 'tenant_profiles',
2020-08-27 19:32:15 +03:00
name: 'tenant-profile.tenant-profiles',
type: 'link',
path: '/tenantProfiles',
icon: 'mdi:alpha-t-box',
isMdiIcon: true
},
{
2023-04-17 19:09:23 +03:00
id: 'resources',
name: 'admin.resources',
type: 'toggle',
path: '/resources',
icon: 'folder',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'widget_library',
name: 'widget.widget-library',
type: 'link',
path: '/resources/widgets-bundles',
icon: 'now_widgets'
},
{
2023-04-18 13:45:47 +03:00
id: 'resources_library',
name: 'resource.resources-library',
type: 'link',
path: '/resources/resources-library',
icon: 'mdi:rhombus-split',
isMdiIcon: true
}
]
},
{
2023-04-18 13:45:47 +03:00
id: 'notifications_center',
name: 'notification.notification-center',
type: 'link',
2023-03-21 17:56:12 +02:00
path: '/notification',
icon: 'mdi:message-badge',
isMdiIcon: true,
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'notification_inbox',
2023-03-21 17:56:12 +02:00
name: 'notification.inbox',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-inbox',
2023-03-21 17:56:12 +02:00
type: 'link',
path: '/notification/inbox',
icon: 'inbox'
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_sent',
2023-03-21 17:56:12 +02:00
name: 'notification.sent',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-sent',
2023-03-21 17:56:12 +02:00
type: 'link',
path: '/notification/sent',
icon: 'outbox'
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_recipients',
name: 'notification.recipients',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-recipients',
2023-03-21 17:56:12 +02:00
type: 'link',
path: '/notification/recipients',
icon: 'contacts'
2023-03-21 17:56:12 +02:00
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_templates',
name: 'notification.templates',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-templates',
2023-03-21 17:56:12 +02:00
type: 'link',
path: '/notification/templates',
icon: 'mdi:message-draw',
isMdiIcon: true
2023-03-21 17:56:12 +02:00
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_rules',
2023-03-21 17:56:12 +02:00
name: 'notification.rules',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-rules',
2023-03-21 17:56:12 +02:00
type: 'link',
path: '/notification/rules',
icon: 'mdi:message-cog',
isMdiIcon: true
}
]
},
{
2023-04-17 19:09:23 +03:00
id: 'settings',
2023-02-13 19:09:05 +02:00
name: 'admin.settings',
type: 'link',
path: '/settings',
icon: 'settings',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'general',
name: 'admin.general',
2023-04-24 19:05:59 +03:00
fullName: 'admin.general-settings',
type: 'link',
path: '/settings/general',
icon: 'settings_applications'
},
{
2023-04-18 13:45:47 +03:00
id: 'mail_server',
name: 'admin.outgoing-mail',
type: 'link',
path: '/settings/outgoing-mail',
icon: 'mail'
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_settings',
name: 'admin.notifications',
2023-04-24 19:05:59 +03:00
fullName: 'admin.notifications-settings',
type: 'link',
path: '/settings/notifications',
icon: 'mdi:message-badge',
isMdiIcon: true
},
{
2023-04-18 13:45:47 +03:00
id: 'queues',
name: 'admin.queues',
type: 'link',
path: '/settings/queues',
icon: 'swap_calls'
2020-07-09 13:47:35 +03:00
},
]
},
{
2023-04-18 13:45:47 +03:00
id: 'security_settings',
name: 'security.security',
2023-03-21 12:19:37 +02:00
type: 'toggle',
path: '/security-settings',
icon: 'security',
pages: [
2020-07-09 13:47:35 +03:00
{
2023-04-18 13:45:47 +03:00
id: 'security_settings_general',
name: 'admin.general',
2023-04-24 19:05:59 +03:00
fullName: 'security.general-settings',
2020-07-09 13:47:35 +03:00
type: 'link',
path: '/security-settings/general',
icon: 'settings_applications'
},
2022-04-28 23:03:37 +03:00
{
2023-04-18 13:45:47 +03:00
id: '2fa',
2022-04-28 23:03:37 +03:00
name: 'admin.2fa.2fa',
type: 'link',
2023-02-14 16:59:04 +02:00
path: '/security-settings/2fa',
2022-04-28 23:03:37 +03:00
icon: 'mdi:two-factor-authentication',
isMdiIcon: true
},
{
2023-04-18 13:45:47 +03:00
id: 'oauth2',
2023-02-14 16:59:04 +02:00
name: 'admin.oauth2.oauth2',
2022-02-18 16:41:24 +02:00
type: 'link',
2023-02-14 16:59:04 +02:00
path: '/security-settings/oauth2',
icon: 'mdi:shield-account',
isMdiIcon: true
}
]
}
);
return sections;
}
private buildSysAdminHome(): Array<HomeSection> {
const homeSections: Array<HomeSection> = [];
homeSections.push(
{
name: 'tenant.management',
places: [
{
name: 'tenant.tenants',
icon: 'supervisor_account',
path: '/tenants'
2020-08-27 19:32:15 +03:00
},
{
name: 'tenant-profile.tenant-profiles',
icon: 'mdi:alpha-t-box',
isMdiIcon: true,
path: '/tenantProfiles'
},
]
},
{
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.sms-provider',
icon: 'sms',
path: '/settings/sms-provider'
},
{
name: 'admin.security-settings',
icon: 'security',
path: '/settings/security-settings'
},
{
name: 'admin.oauth2.oauth2',
icon: 'security',
path: '/settings/oauth2'
},
2022-04-28 23:03:37 +03:00
{
name: 'admin.2fa.2fa',
icon: 'mdi:two-factor-authentication',
isMdiIcon: true,
path: '/settings/2fa'
},
{
name: 'resource.resources-library',
icon: 'folder',
path: '/settings/resources-library'
2022-02-18 16:41:24 +02:00
},
{
name: 'admin.queues',
icon: 'swap_calls',
path: '/settings/queues'
},
]
}
);
return homeSections;
}
private buildTenantAdminMenu(authState: AuthState): Array<MenuSection> {
const sections: Array<MenuSection> = [];
sections.push(
{
2023-04-17 19:09:23 +03:00
id: 'home',
name: 'home.home',
type: 'link',
path: '/home',
icon: 'home'
},
{
2023-04-17 19:09:23 +03:00
id: 'alarms',
2023-02-13 19:09:05 +02:00
name: 'alarm.alarms',
type: 'link',
path: '/alarms',
2023-05-02 11:14:11 +03:00
icon: 'mdi:alert-outline',
isMdiIcon: true
},
{
2023-04-17 19:09:23 +03:00
id: 'dashboards',
2023-02-13 19:09:05 +02:00
name: 'dashboard.dashboards',
type: 'link',
2023-02-13 19:09:05 +02:00
path: '/dashboards',
icon: 'dashboards'
},
{
2023-04-17 19:09:23 +03:00
id: 'entities',
2023-02-13 19:09:05 +02:00
name: 'entity.entities',
type: 'toggle',
path: '/entities',
icon: 'category',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'devices',
2023-02-13 19:09:05 +02:00
name: 'device.devices',
type: 'link',
path: '/entities/devices',
icon: 'devices_other'
},
{
2023-04-18 13:45:47 +03:00
id: 'assets',
2023-02-13 19:09:05 +02:00
name: 'asset.assets',
type: 'link',
path: '/entities/assets',
icon: 'domain'
},
{
2023-04-18 13:45:47 +03:00
id: 'entity_views',
2023-02-13 19:09:05 +02:00
name: 'entity-view.entity-views',
type: 'link',
path: '/entities/entityViews',
icon: 'view_quilt'
}
]
},
{
2023-04-17 19:09:23 +03:00
id: 'profiles',
2022-09-26 18:10:12 +03:00
name: 'profiles.profiles',
type: 'toggle',
path: '/profiles',
icon: 'badge',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'device_profiles',
2022-09-26 18:10:12 +03:00
name: 'device-profile.device-profiles',
type: 'link',
path: '/profiles/deviceProfiles',
icon: 'mdi:alpha-d-box',
isMdiIcon: true
},
{
2023-04-18 13:45:47 +03:00
id: 'asset_profiles',
2022-09-26 18:10:12 +03:00
name: 'asset-profile.asset-profiles',
type: 'link',
path: '/profiles/assetProfiles',
icon: 'mdi:alpha-a-box',
isMdiIcon: true
}
]
2020-09-02 18:32:57 +03:00
},
2021-04-12 16:56:00 +03:00
{
2023-04-17 19:09:23 +03:00
id: 'customers',
2023-02-13 19:09:05 +02:00
name: 'customer.customers',
type: 'link',
2023-02-13 19:09:05 +02:00
path: '/customers',
icon: 'supervisor_account'
},
{
2023-04-18 13:45:47 +03:00
id: 'rule_chains',
name: 'rulechain.rulechains',
type: 'link',
path: '/ruleChains',
icon: 'settings_ethernet'
2020-12-18 16:29:12 +02:00
}
);
if (authState.edgesSupportEnabled) {
2020-12-18 16:29:12 +02:00
sections.push(
{
2023-04-18 13:45:47 +03:00
id: 'edge_management',
2020-12-18 16:29:12 +02:00
name: 'edge.management',
type: 'toggle',
2021-05-26 21:02:35 +03:00
path: '/edgeManagement',
icon: 'settings_input_antenna',
2020-12-18 16:29:12 +02:00
pages: [
2023-02-13 19:09:05 +02:00
{
2023-04-18 13:45:47 +03:00
id: 'edges',
2023-02-13 19:09:05 +02:00
name: 'edge.instances',
2023-04-24 19:05:59 +03:00
fullName: 'edge.edge-instances',
2023-02-13 19:09:05 +02:00
type: 'link',
path: '/edgeManagement/instances',
icon: 'router'
},
2020-12-18 16:29:12 +02:00
{
2023-04-18 13:45:47 +03:00
id: 'rulechain_templates',
name: 'edge.rulechain-templates',
2023-04-24 19:05:59 +03:00
fullName: 'edge.edge-rulechain-templates',
2020-12-18 16:29:12 +02:00
type: 'link',
2021-05-26 21:02:35 +03:00
path: '/edgeManagement/ruleChains',
2020-12-18 16:29:12 +02:00
icon: 'settings_ethernet'
}
]
}
);
}
sections.push(
{
2023-04-17 19:09:23 +03:00
id: 'features',
2023-02-13 19:09:05 +02:00
name: 'feature.advanced-features',
type: 'toggle',
path: '/features',
icon: 'construction',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'otaUpdates',
2023-02-13 19:09:05 +02:00
name: 'ota-update.ota-updates',
type: 'link',
path: '/features/otaUpdates',
icon: 'memory'
},
{
2023-04-18 13:45:47 +03:00
id: 'version_control',
2023-02-13 19:09:05 +02:00
name: 'version-control.version-control',
type: 'link',
path: '/features/vc',
icon: 'history'
}
]
},
2022-05-25 12:26:23 +03:00
{
2023-04-17 19:09:23 +03:00
id: 'resources',
2023-02-13 19:09:05 +02:00
name: 'admin.resources',
type: 'toggle',
path: '/resources',
icon: 'folder',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'widget_library',
2023-02-13 19:09:05 +02:00
name: 'widget.widget-library',
type: 'link',
path: '/resources/widgets-bundles',
icon: 'now_widgets'
},
{
2023-04-18 13:45:47 +03:00
id: 'resources_library',
2023-02-13 19:09:05 +02:00
name: 'resource.resources-library',
type: 'link',
path: '/resources/resources-library',
icon: 'mdi:rhombus-split',
isMdiIcon: true
}
]
2022-05-25 12:26:23 +03:00
},
{
2023-04-18 13:45:47 +03:00
id: 'notifications_center',
2023-02-13 19:09:05 +02:00
name: 'notification.notification-center',
type: 'link',
2023-02-13 19:09:05 +02:00
path: '/notification',
icon: 'mdi:message-badge',
isMdiIcon: true,
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'notification_inbox',
2023-02-13 19:09:05 +02:00
name: 'notification.inbox',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-inbox',
2023-02-13 19:09:05 +02:00
type: 'link',
path: '/notification/inbox',
icon: 'inbox'
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_sent',
2023-02-13 19:09:05 +02:00
name: 'notification.sent',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-sent',
2023-02-13 19:09:05 +02:00
type: 'link',
path: '/notification/sent',
icon: 'outbox'
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_recipients',
name: 'notification.recipients',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-recipients',
2023-02-13 19:09:05 +02:00
type: 'link',
path: '/notification/recipients',
icon: 'contacts'
2023-02-13 19:09:05 +02:00
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_templates',
name: 'notification.templates',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-templates',
2023-02-13 19:09:05 +02:00
type: 'link',
path: '/notification/templates',
icon: 'mdi:message-draw',
isMdiIcon: true
2023-02-13 19:09:05 +02:00
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_rules',
2023-02-13 19:09:05 +02:00
name: 'notification.rules',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-rules',
2023-02-13 19:09:05 +02:00
type: 'link',
path: '/notification/rules',
icon: 'mdi:message-cog',
isMdiIcon: true
}
]
},
{
2023-04-18 13:45:47 +03:00
id: 'api_usage',
name: 'api-usage.api-usage',
type: 'link',
path: '/usage',
2022-01-18 11:31:40 +02:00
icon: 'insert_chart'
},
{
2023-04-17 19:09:23 +03:00
id: 'settings',
2023-02-13 19:09:05 +02:00
name: 'admin.settings',
type: 'link',
path: '/settings',
icon: 'settings',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'home_settings',
2023-02-13 19:09:05 +02:00
name: 'admin.home',
2023-04-24 19:05:59 +03:00
fullName: 'admin.home-settings',
type: 'link',
path: '/settings/home',
icon: 'settings_applications'
},
{
2023-04-18 13:45:47 +03:00
id: 'notification_settings',
name: 'admin.notifications',
2023-04-24 19:05:59 +03:00
fullName: 'admin.notifications-settings',
type: 'link',
path: '/settings/notifications',
icon: 'mdi:message-badge',
isMdiIcon: true
},
{
2023-04-18 13:45:47 +03:00
id: 'repository_settings',
2023-02-13 19:09:05 +02:00
name: 'admin.repository',
2023-04-24 19:05:59 +03:00
fullName: 'admin.repository-settings',
2022-05-20 15:02:30 +03:00
type: 'link',
path: '/settings/repository',
2022-05-20 15:02:30 +03:00
icon: 'manage_history'
2022-05-31 18:42:33 +03:00
},
{
2023-04-18 13:45:47 +03:00
id: 'auto_commit_settings',
2023-02-13 19:09:05 +02:00
name: 'admin.auto-commit',
2023-04-24 19:05:59 +03:00
fullName: 'admin.auto-commit-settings',
2022-05-31 18:42:33 +03:00
type: 'link',
path: '/settings/auto-commit',
icon: 'settings_backup_restore'
}
]
2023-02-13 19:09:05 +02:00
},
{
2023-04-18 13:45:47 +03:00
id: 'security_settings',
2023-02-13 19:09:05 +02:00
name: 'security.security',
2023-03-21 12:19:37 +02:00
type: 'toggle',
2023-02-13 19:09:05 +02:00
path: '/security-settings',
icon: 'security',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'audit_log',
2023-02-13 19:09:05 +02:00
name: 'audit-log.audit-logs',
type: 'link',
2023-02-14 11:31:34 +02:00
path: '/security-settings/auditLogs',
2023-02-13 19:09:05 +02:00
icon: 'track_changes'
}
]
}
);
return sections;
}
private buildTenantAdminHome(authState: AuthState): Array<HomeSection> {
const homeSections: Array<HomeSection> = [];
homeSections.push(
{
name: 'rulechain.management',
places: [
{
name: 'rulechain.rulechains',
icon: 'settings_ethernet',
path: '/ruleChains'
}
]
},
{
name: 'customer.management',
places: [
{
name: 'customer.customers',
icon: 'supervisor_account',
path: '/customers'
}
]
},
{
name: 'asset.management',
places: [
{
name: 'asset.assets',
icon: 'domain',
path: '/assets'
2022-09-26 18:10:12 +03:00
},
{
name: 'asset-profile.asset-profiles',
icon: 'mdi:alpha-a-box',
isMdiIcon: true,
path: '/profiles/assetProfiles'
}
]
},
{
name: 'device.management',
places: [
{
name: 'device.devices',
icon: 'devices_other',
path: '/devices'
2020-09-02 18:32:57 +03:00
},
{
name: 'device-profile.device-profiles',
icon: 'mdi:alpha-d-box',
isMdiIcon: true,
2022-09-26 18:10:12 +03:00
path: '/profiles/deviceProfiles'
2021-04-12 16:56:00 +03:00
},
{
2021-05-31 18:15:31 +03:00
name: 'ota-update.ota-updates',
2021-04-12 16:56:00 +03:00
icon: 'memory',
2021-05-31 18:15:31 +03:00
path: '/otaUpdates'
}
]
},
{
name: 'entity-view.management',
places: [
{
name: 'entity-view.entity-views',
icon: 'view_quilt',
path: '/entityViews'
}
]
2020-12-18 16:29:12 +02:00
}
);
if (authState.edgesSupportEnabled) {
2020-12-18 16:29:12 +02:00
homeSections.push(
{
name: 'edge.management',
places: [
{
name: 'edge.edge-instances',
2020-12-18 16:29:12 +02:00
icon: 'router',
2021-05-26 21:02:35 +03:00
path: '/edgeInstances'
2020-12-18 16:29:12 +02:00
},
{
name: 'edge.rulechain-templates',
2020-12-18 16:29:12 +02:00
icon: 'settings_ethernet',
2021-05-26 21:02:35 +03:00
path: '/edgeManagement/ruleChains'
2020-12-18 16:29:12 +02:00
}
]
}
);
}
homeSections.push(
{
name: 'dashboard.management',
places: [
{
name: 'widget.widget-library',
icon: 'now_widgets',
path: '/widgets-bundles'
},
{
name: 'dashboard.dashboards',
icon: 'dashboard',
path: '/dashboards'
}
]
},
2022-05-25 12:26:23 +03:00
{
name: 'version-control.management',
places: [
{
name: 'version-control.version-control',
icon: 'history',
path: '/vc'
}
]
},
{
name: 'audit-log.audit',
places: [
{
name: 'audit-log.audit-logs',
icon: 'track_changes',
path: '/auditLogs'
},
{
name: 'api-usage.api-usage',
icon: 'insert_chart',
path: '/usage'
}
]
},
{
name: 'admin.system-settings',
places: [
{
name: 'admin.home-settings',
icon: 'settings_applications',
path: '/settings/home'
},
{
name: 'resource.resources-library',
icon: 'folder',
path: '/settings/resources-library'
2022-05-20 15:02:30 +03:00
},
{
name: 'admin.repository-settings',
2022-05-20 15:02:30 +03:00
icon: 'manage_history',
path: '/settings/repository',
2022-05-31 18:42:33 +03:00
},
{
name: 'admin.auto-commit-settings',
icon: 'settings_backup_restore',
path: '/settings/auto-commit'
}
]
}
);
return homeSections;
}
private buildCustomerUserMenu(authState: AuthState): Array<MenuSection> {
const sections: Array<MenuSection> = [];
sections.push(
{
2023-04-17 19:09:23 +03:00
id: 'home',
name: 'home.home',
type: 'link',
path: '/home',
icon: 'home'
2019-08-12 19:34:23 +03:00
},
{
2023-04-17 19:09:23 +03:00
id: 'alarms',
2023-02-13 19:09:05 +02:00
name: 'alarm.alarms',
2019-08-12 19:34:23 +03:00
type: 'link',
2023-02-13 19:09:05 +02:00
path: '/alarms',
2023-05-02 11:14:11 +03:00
icon: 'mdi:alert-outline',
isMdiIcon: true
2019-08-12 19:34:23 +03:00
},
{
2023-04-17 19:09:23 +03:00
id: 'dashboards',
2023-02-13 19:09:05 +02:00
name: 'dashboard.dashboards',
2019-08-12 19:34:23 +03:00
type: 'link',
2023-02-13 19:09:05 +02:00
path: '/dashboards',
icon: 'dashboards'
2019-08-12 19:34:23 +03:00
},
{
2023-04-17 19:09:23 +03:00
id: 'entities',
2023-02-13 19:09:05 +02:00
name: 'entity.entities',
type: 'toggle',
path: '/entities',
icon: 'category',
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'devices',
2023-02-13 19:09:05 +02:00
name: 'device.devices',
type: 'link',
path: '/entities/devices',
icon: 'devices_other'
},
{
2023-04-18 13:45:47 +03:00
id: 'assets',
2023-02-13 19:09:05 +02:00
name: 'asset.assets',
type: 'link',
path: '/entities/assets',
icon: 'domain'
},
{
2023-04-18 13:45:47 +03:00
id: 'entity_views',
2023-02-13 19:09:05 +02:00
name: 'entity-view.entity-views',
type: 'link',
path: '/entities/entityViews',
icon: 'view_quilt'
}
]
}
);
if (authState.edgesSupportEnabled) {
sections.push(
{
2023-04-18 13:45:47 +03:00
id: 'edges',
name: 'edge.edge-instances',
2023-04-24 19:05:59 +03:00
fullName: 'edge.edge-instances',
type: 'link',
2023-02-13 19:09:05 +02:00
path: '/edgeManagement/instances',
icon: 'router'
}
);
}
2023-03-21 17:56:12 +02:00
sections.push(
{
2023-04-18 13:45:47 +03:00
id: 'notifications_center',
2023-03-21 17:56:12 +02:00
name: 'notification.notification-center',
type: 'link',
path: '/notification',
icon: 'mdi:message-badge',
isMdiIcon: true,
pages: [
{
2023-04-18 13:45:47 +03:00
id: 'notification_inbox',
2023-03-21 17:56:12 +02:00
name: 'notification.inbox',
2023-04-24 19:05:59 +03:00
fullName: 'notification.notification-inbox',
2023-03-21 17:56:12 +02:00
type: 'link',
path: '/notification/inbox',
icon: 'inbox'
}
]
}
);
return sections;
}
private buildCustomerUserHome(authState: AuthState): Array<HomeSection> {
const homeSections: Array<HomeSection> = [];
homeSections.push(
2019-08-12 19:34:23 +03:00
{
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'
}
]
}
);
if (authState.edgesSupportEnabled) {
homeSections.push(
{
name: 'edge.management',
places: [
{
name: 'edge.edge-instances',
2021-05-26 21:02:35 +03:00
icon: 'settings_input_antenna',
path: '/edgeInstances'
}
]
}
);
}
homeSections.push(
2019-08-12 19:34:23 +03:00
{
name: 'dashboard.view-dashboards',
places: [
{
name: 'dashboard.dashboards',
icon: 'dashboard',
path: '/dashboards'
}
]
}
);
return homeSections;
}
2023-04-17 19:09:23 +03:00
private allMenuLinks(sections: Array<MenuSection>): Array<MenuSection> {
const result: Array<MenuSection> = [];
for (const section of sections) {
if (section.type === 'link') {
result.push(section);
}
if (section.pages && section.pages.length) {
result.push(...this.allMenuLinks(section.pages));
}
}
return result;
}
public menuSections(): Observable<Array<MenuSection>> {
return this.menuSections$;
}
public homeSections(): Observable<Array<HomeSection>> {
return this.homeSections$;
}
2023-04-17 19:09:23 +03:00
public availableMenuLinks(): Observable<Array<MenuSection>> {
return this.availableMenuLinks$;
}
2023-04-17 19:09:23 +03:00
public menuLinkById(id: string): Observable<MenuSection | undefined> {
return this.availableMenuLinks$.pipe(
map((links) => links.find(link => link.id === id))
);
}
public menuLinksByIds(ids: string[]): Observable<Array<MenuSection>> {
return this.availableMenuLinks$.pipe(
2023-04-18 13:45:47 +03:00
map((links) => links.filter(link => ids.includes(link.id)).sort((a, b) => {
const i1 = ids.indexOf(a.id);
const i2 = ids.indexOf(b.id);
return i1 - i2;
}))
2023-04-17 19:09:23 +03:00
);
}
}