]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
3cc7faf0eb633b49c6fde98597ac24a0f99e824c
[ceph.git] /
1 import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
2 import { ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router';
3
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';
9
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';
16
17 @Component({
18   selector: 'cd-workbench-layout',
19   templateUrl: './workbench-layout.component.html',
20   styleUrls: ['./workbench-layout.component.scss'],
21   providers: [FaviconService],
22   standalone: false
23 })
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;
30
31   @HostBinding('class') get class(): string {
32     return 'top-notification-' + this.notifications.length;
33   }
34
35   constructor(
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
44   ) {
45     this.permissions = this.authStorageService.getPermissions();
46   }
47
48   ngOnInit() {
49     if (this.permissions.configOpt.read) {
50       this.subs.add(this.multiClusterService.startPolling());
51       this.subs.add(this.multiClusterService.startClusterTokenStatusPolling());
52     }
53     this.subs.add(this.summaryService.startPolling());
54     this.subs.add(this.taskManagerService.init(this.summaryService));
55
56     this.subs.add(
57       this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
58         this.showTopNotification('isPwdDisplayed', isDisplayed);
59       })
60     );
61     this.subs.add(
62       this.telemetryNotificationService.update.subscribe((visible: boolean) => {
63         this.showTopNotification('telemetryNotificationEnabled', visible);
64       })
65     );
66     this.subs.add(
67       this.motdNotificationService.motd$.subscribe((motd: any) => {
68         this.showTopNotification('motdNotificationEnabled', _.isPlainObject(motd));
69       })
70     );
71     this.faviconService.init();
72
73     this.updatePageHeaderFromRoute();
74     this.subs.add(
75       this.router.events
76         .pipe(filter((e) => e instanceof NavigationEnd))
77         .subscribe(() => this.updatePageHeaderFromRoute())
78     );
79   }
80
81   private updatePageHeaderFromRoute(): void {
82     let route: ActivatedRouteSnapshot | null = this.router.routerState.snapshot.root;
83     while (route?.firstChild) {
84       route = route.firstChild;
85     }
86     const pageHeader = route?.routeConfig?.data?.['pageHeader'] as
87       | { title?: string; description?: string }
88       | undefined;
89     this.pageHeaderTitle = pageHeader?.title ?? null;
90     this.pageHeaderDescription = pageHeader?.description ?? null;
91   }
92
93   showTopNotification(name: string, isDisplayed: boolean) {
94     if (isDisplayed) {
95       if (!this.notifications.includes(name)) {
96         this.notifications.push(name);
97       }
98     } else {
99       const index = this.notifications.indexOf(name);
100       if (index >= 0) {
101         this.notifications.splice(index, 1);
102       }
103     }
104   }
105
106   ngOnDestroy() {
107     this.subs.unsubscribe();
108   }
109 }