1 import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
2 import { ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router';
4 import { Subscription } from 'rxjs';
5 import { filter } from 'rxjs/operators';
6 import { MultiClusterService } from '~/app/shared/api/multi-cluster.service';
7 import { Permissions } from '~/app/shared/models/permissions';
8 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
10 import { FaviconService } from '~/app/shared/services/favicon.service';
11 import { SummaryService } from '~/app/shared/services/summary.service';
12 import { TaskManagerService } from '~/app/shared/services/task-manager.service';
13 import { TelemetryNotificationService } from '../../../shared/services/telemetry-notification.service';
14 import { MotdNotificationService } from '~/app/shared/services/motd-notification.service';
15 import _ from 'lodash';
18 selector: 'cd-workbench-layout',
19 templateUrl: './workbench-layout.component.html',
20 styleUrls: ['./workbench-layout.component.scss'],
21 providers: [FaviconService],
24 export class WorkbenchLayoutComponent implements OnInit, OnDestroy {
25 notifications: string[] = [];
26 private subs = new Subscription();
27 permissions: Permissions;
28 pageHeaderTitle: string | null = null;
29 pageHeaderDescription: string | null = null;
31 @HostBinding('class') get class(): string {
32 return 'top-notification-' + this.notifications.length;
36 public router: Router,
37 private summaryService: SummaryService,
38 private taskManagerService: TaskManagerService,
39 private multiClusterService: MultiClusterService,
40 private faviconService: FaviconService,
41 private authStorageService: AuthStorageService,
42 private telemetryNotificationService: TelemetryNotificationService,
43 private motdNotificationService: MotdNotificationService
45 this.permissions = this.authStorageService.getPermissions();
49 if (this.permissions.configOpt.read) {
50 this.subs.add(this.multiClusterService.startPolling());
51 this.subs.add(this.multiClusterService.startClusterTokenStatusPolling());
53 this.subs.add(this.summaryService.startPolling());
54 this.subs.add(this.taskManagerService.init(this.summaryService));
57 this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
58 this.showTopNotification('isPwdDisplayed', isDisplayed);
62 this.telemetryNotificationService.update.subscribe((visible: boolean) => {
63 this.showTopNotification('telemetryNotificationEnabled', visible);
67 this.motdNotificationService.motd$.subscribe((motd: any) => {
68 this.showTopNotification('motdNotificationEnabled', _.isPlainObject(motd));
71 this.faviconService.init();
73 this.updatePageHeaderFromRoute();
76 .pipe(filter((e) => e instanceof NavigationEnd))
77 .subscribe(() => this.updatePageHeaderFromRoute())
81 private updatePageHeaderFromRoute(): void {
82 let route: ActivatedRouteSnapshot | null = this.router.routerState.snapshot.root;
83 while (route?.firstChild) {
84 route = route.firstChild;
86 const pageHeader = route?.routeConfig?.data?.['pageHeader'] as
87 | { title?: string; description?: string }
89 this.pageHeaderTitle = pageHeader?.title ?? null;
90 this.pageHeaderDescription = pageHeader?.description ?? null;
93 showTopNotification(name: string, isDisplayed: boolean) {
95 if (!this.notifications.includes(name)) {
96 this.notifications.push(name);
99 const index = this.notifications.indexOf(name);
101 this.notifications.splice(index, 1);
107 this.subs.unsubscribe();