1 import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
3 import * as _ from 'lodash';
4 import { Subscription } from 'rxjs';
6 import { Icons } from '~/app/shared/enum/icons.enum';
7 import { Permissions } from '~/app/shared/models/permissions';
8 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
12 } from '~/app/shared/services/feature-toggles.service';
13 import { MotdNotificationService } from '~/app/shared/services/motd-notification.service';
14 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
15 import { SummaryService } from '~/app/shared/services/summary.service';
16 import { TelemetryNotificationService } from '~/app/shared/services/telemetry-notification.service';
19 selector: 'cd-navigation',
20 templateUrl: './navigation.component.html',
21 styleUrls: ['./navigation.component.scss']
23 export class NavigationComponent implements OnInit, OnDestroy {
24 notifications: string[] = [];
25 @HostBinding('class') get class(): string {
26 return 'top-notification-' + this.notifications.length;
29 permissions: Permissions;
30 enabledFeature$: FeatureTogglesMap$;
34 rightSidebarOpen = false; // rightSidebar only opens when width is less than 768px
35 showMenuSidebar = true;
36 displayedSubMenu = '';
41 private subs = new Subscription();
44 private authStorageService: AuthStorageService,
45 private summaryService: SummaryService,
46 private featureToggles: FeatureTogglesService,
47 private telemetryNotificationService: TelemetryNotificationService,
48 public prometheusAlertService: PrometheusAlertService,
49 private motdNotificationService: MotdNotificationService
51 this.permissions = this.authStorageService.getPermissions();
52 this.enabledFeature$ = this.featureToggles.get();
57 this.summaryService.subscribe((summary) => {
58 this.summaryData = summary;
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
67 this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
68 this.showTopNotification('isPwdDisplayed', isDisplayed);
72 this.telemetryNotificationService.update.subscribe((visible: boolean) => {
73 this.showTopNotification('telemetryNotificationEnabled', visible);
77 this.motdNotificationService.motd$.subscribe((motd: any) => {
78 this.showTopNotification('motdNotificationEnabled', _.isPlainObject(motd));
84 this.subs.unsubscribe();
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' };
99 toggleSubMenu(menu: string) {
100 if (this.displayedSubMenu === menu) {
101 this.displayedSubMenu = '';
103 this.displayedSubMenu = menu;
107 toggleRightSidebar() {
108 this.rightSidebarOpen = !this.rightSidebarOpen;
111 showTopNotification(name: string, isDisplayed: boolean) {
113 if (!this.notifications.includes(name)) {
114 this.notifications.push(name);
117 const index = this.notifications.indexOf(name);
119 this.notifications.splice(index, 1);