1 import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
4 import { Subscription } from 'rxjs';
5 import { MultiClusterService } from '~/app/shared/api/multi-cluster.service';
6 import { Permissions } from '~/app/shared/models/permissions';
7 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
9 import { FaviconService } from '~/app/shared/services/favicon.service';
10 import { SummaryService } from '~/app/shared/services/summary.service';
11 import { TaskManagerService } from '~/app/shared/services/task-manager.service';
12 import { TelemetryNotificationService } from '../../../shared/services/telemetry-notification.service';
13 import { MotdNotificationService } from '~/app/shared/services/motd-notification.service';
14 import _ from 'lodash';
17 selector: 'cd-workbench-layout',
18 templateUrl: './workbench-layout.component.html',
19 styleUrls: ['./workbench-layout.component.scss'],
20 providers: [FaviconService],
23 export class WorkbenchLayoutComponent implements OnInit, OnDestroy {
24 notifications: string[] = [];
25 private subs = new Subscription();
26 permissions: Permissions;
27 @HostBinding('class') get class(): string {
28 return 'top-notification-' + this.notifications.length;
32 public router: Router,
33 private summaryService: SummaryService,
34 private taskManagerService: TaskManagerService,
35 private multiClusterService: MultiClusterService,
36 private faviconService: FaviconService,
37 private authStorageService: AuthStorageService,
38 private telemetryNotificationService: TelemetryNotificationService,
39 private motdNotificationService: MotdNotificationService
41 this.permissions = this.authStorageService.getPermissions();
45 if (this.permissions.configOpt.read) {
46 this.subs.add(this.multiClusterService.startPolling());
47 this.subs.add(this.multiClusterService.startClusterTokenStatusPolling());
49 this.subs.add(this.summaryService.startPolling());
50 this.subs.add(this.taskManagerService.init(this.summaryService));
53 this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
54 this.showTopNotification('isPwdDisplayed', isDisplayed);
58 this.telemetryNotificationService.update.subscribe((visible: boolean) => {
59 this.showTopNotification('telemetryNotificationEnabled', visible);
63 this.motdNotificationService.motd$.subscribe((motd: any) => {
64 this.showTopNotification('motdNotificationEnabled', _.isPlainObject(motd));
67 this.faviconService.init();
69 showTopNotification(name: string, isDisplayed: boolean) {
71 if (!this.notifications.includes(name)) {
72 this.notifications.push(name);
75 const index = this.notifications.indexOf(name);
77 this.notifications.splice(index, 1);
83 this.subs.unsubscribe();