]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts
import ceph 15.2.14
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / navigation / navigation / navigation.component.ts
CommitLineData
1911f103
TL
1import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
2
6d8e3169 3import * as _ from 'lodash';
1911f103 4import { Subscription } from 'rxjs';
11fdf7f2 5
9f95a23c 6import { Icons } from '../../../shared/enum/icons.enum';
11fdf7f2
TL
7import { Permissions } from '../../../shared/models/permissions';
8import { AuthStorageService } from '../../../shared/services/auth-storage.service';
9import {
10 FeatureTogglesMap$,
11 FeatureTogglesService
12} from '../../../shared/services/feature-toggles.service';
6d8e3169 13import { MotdNotificationService } from '../../../shared/services/motd-notification.service';
e306af50 14import { PrometheusAlertService } from '../../../shared/services/prometheus-alert.service';
11fdf7f2 15import { SummaryService } from '../../../shared/services/summary.service';
f6b5b4d7 16import { TelemetryNotificationService } from '../../../shared/services/telemetry-notification.service';
11fdf7f2
TL
17
18@Component({
19 selector: 'cd-navigation',
20 templateUrl: './navigation.component.html',
21 styleUrls: ['./navigation.component.scss']
22})
1911f103 23export class NavigationComponent implements OnInit, OnDestroy {
f6b5b4d7
TL
24 notifications: string[] = [];
25 @HostBinding('class') get class(): string {
26 return 'top-notification-' + this.notifications.length;
27 }
9f95a23c 28
11fdf7f2 29 permissions: Permissions;
9f95a23c 30 enabledFeature$: FeatureTogglesMap$;
11fdf7f2 31 summaryData: any;
9f95a23c 32 icons = Icons;
11fdf7f2 33
6d8e3169 34 rightSidebarOpen = false; // rightSidebar only opens when width is less than 768px
9f95a23c
TL
35 showMenuSidebar = true;
36 displayedSubMenu = '';
37
38 simplebar = {
39 autoHide: false
40 };
1911f103 41 private subs = new Subscription();
11fdf7f2
TL
42
43 constructor(
44 private authStorageService: AuthStorageService,
11fdf7f2 45 private summaryService: SummaryService,
e306af50 46 private featureToggles: FeatureTogglesService,
f6b5b4d7 47 private telemetryNotificationService: TelemetryNotificationService,
6d8e3169
FG
48 public prometheusAlertService: PrometheusAlertService,
49 private motdNotificationService: MotdNotificationService
11fdf7f2
TL
50 ) {
51 this.permissions = this.authStorageService.getPermissions();
52 this.enabledFeature$ = this.featureToggles.get();
53 }
54
55 ngOnInit() {
1911f103 56 this.subs.add(
f6b5b4d7
TL
57 this.summaryService.subscribe((summary) => {
58 this.summaryData = summary;
1911f103
TL
59 })
60 );
f6b5b4d7
TL
61 /*
62 Note: If you're going to add more top notifications please do not forget to increase
63 the number of generated css-classes in section topNotification settings in the scss
64 file.
65 */
1911f103
TL
66 this.subs.add(
67 this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
f6b5b4d7
TL
68 this.showTopNotification('isPwdDisplayed', isDisplayed);
69 })
70 );
71 this.subs.add(
72 this.telemetryNotificationService.update.subscribe((visible: boolean) => {
73 this.showTopNotification('telemetryNotificationEnabled', visible);
1911f103
TL
74 })
75 );
6d8e3169
FG
76 this.subs.add(
77 this.motdNotificationService.motd$.subscribe((motd: any) => {
78 this.showTopNotification('motdNotificationEnabled', _.isPlainObject(motd));
79 })
80 );
1911f103
TL
81 }
82
83 ngOnDestroy(): void {
84 this.subs.unsubscribe();
11fdf7f2
TL
85 }
86
87 blockHealthColor() {
88 if (this.summaryData && this.summaryData.rbd_mirroring) {
89 if (this.summaryData.rbd_mirroring.errors > 0) {
90 return { color: '#d9534f' };
91 } else if (this.summaryData.rbd_mirroring.warnings > 0) {
92 return { color: '#f0ad4e' };
93 }
94 }
9f95a23c
TL
95
96 return undefined;
97 }
98
99 toggleSubMenu(menu: string) {
100 if (this.displayedSubMenu === menu) {
101 this.displayedSubMenu = '';
102 } else {
103 this.displayedSubMenu = menu;
104 }
11fdf7f2 105 }
f6b5b4d7 106
6d8e3169
FG
107 toggleRightSidebar() {
108 this.rightSidebarOpen = !this.rightSidebarOpen;
109 }
110
f6b5b4d7
TL
111 showTopNotification(name: string, isDisplayed: boolean) {
112 if (isDisplayed) {
113 if (!this.notifications.includes(name)) {
114 this.notifications.push(name);
115 }
116 } else {
117 const index = this.notifications.indexOf(name);
118 if (index >= 0) {
119 this.notifications.splice(index, 1);
120 }
121 }
122 }
11fdf7f2 123}