1 import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
3 import { Subscription } from 'rxjs';
5 import { Icons } from '~/app/shared/enum/icons.enum';
6 import { Permissions } from '~/app/shared/models/permissions';
7 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
11 } from '~/app/shared/services/feature-toggles.service';
12 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
13 import { SummaryService } from '~/app/shared/services/summary.service';
14 import { TelemetryNotificationService } from '~/app/shared/services/telemetry-notification.service';
17 selector: 'cd-navigation',
18 templateUrl: './navigation.component.html',
19 styleUrls: ['./navigation.component.scss']
21 export class NavigationComponent implements OnInit, OnDestroy {
22 notifications: string[] = [];
23 @HostBinding('class') get class(): string {
24 return 'top-notification-' + this.notifications.length;
27 permissions: Permissions;
28 enabledFeature$: FeatureTogglesMap$;
32 rightSidebarOpen = false; // rightSidebar only opens when width is less than 768px
33 showMenuSidebar = true;
34 displayedSubMenu = '';
39 private subs = new Subscription();
42 private authStorageService: AuthStorageService,
43 private summaryService: SummaryService,
44 private featureToggles: FeatureTogglesService,
45 private telemetryNotificationService: TelemetryNotificationService,
46 public prometheusAlertService: PrometheusAlertService
48 this.permissions = this.authStorageService.getPermissions();
49 this.enabledFeature$ = this.featureToggles.get();
54 this.summaryService.subscribe((summary) => {
55 this.summaryData = summary;
59 Note: If you're going to add more top notifications please do not forget to increase
60 the number of generated css-classes in section topNotification settings in the scss
64 this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
65 this.showTopNotification('isPwdDisplayed', isDisplayed);
69 this.telemetryNotificationService.update.subscribe((visible: boolean) => {
70 this.showTopNotification('telemetryNotificationEnabled', visible);
76 this.subs.unsubscribe();
80 if (this.summaryData && this.summaryData.rbd_mirroring) {
81 if (this.summaryData.rbd_mirroring.errors > 0) {
82 return { color: '#d9534f' };
83 } else if (this.summaryData.rbd_mirroring.warnings > 0) {
84 return { color: '#f0ad4e' };
91 toggleSubMenu(menu: string) {
92 if (this.displayedSubMenu === menu) {
93 this.displayedSubMenu = '';
95 this.displayedSubMenu = menu;
99 toggleRightSidebar() {
100 this.rightSidebarOpen = !this.rightSidebarOpen;
103 showTopNotification(name: string, isDisplayed: boolean) {
105 if (!this.notifications.includes(name)) {
106 this.notifications.push(name);
109 const index = this.notifications.indexOf(name);
111 this.notifications.splice(index, 1);