]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
a162e5f067d76d398c618a5f4372d81cd1d8babc
[ceph.git] /
1 import { Component, HostBinding, OnDestroy, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
3
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';
8
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';
15
16 @Component({
17   selector: 'cd-workbench-layout',
18   templateUrl: './workbench-layout.component.html',
19   styleUrls: ['./workbench-layout.component.scss'],
20   providers: [FaviconService],
21   standalone: false
22 })
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;
29   }
30
31   constructor(
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
40   ) {
41     this.permissions = this.authStorageService.getPermissions();
42   }
43
44   ngOnInit() {
45     if (this.permissions.configOpt.read) {
46       this.subs.add(this.multiClusterService.startPolling());
47       this.subs.add(this.multiClusterService.startClusterTokenStatusPolling());
48     }
49     this.subs.add(this.summaryService.startPolling());
50     this.subs.add(this.taskManagerService.init(this.summaryService));
51
52     this.subs.add(
53       this.authStorageService.isPwdDisplayed$.subscribe((isDisplayed) => {
54         this.showTopNotification('isPwdDisplayed', isDisplayed);
55       })
56     );
57     this.subs.add(
58       this.telemetryNotificationService.update.subscribe((visible: boolean) => {
59         this.showTopNotification('telemetryNotificationEnabled', visible);
60       })
61     );
62     this.subs.add(
63       this.motdNotificationService.motd$.subscribe((motd: any) => {
64         this.showTopNotification('motdNotificationEnabled', _.isPlainObject(motd));
65       })
66     );
67     this.faviconService.init();
68   }
69   showTopNotification(name: string, isDisplayed: boolean) {
70     if (isDisplayed) {
71       if (!this.notifications.includes(name)) {
72         this.notifications.push(name);
73       }
74     } else {
75       const index = this.notifications.indexOf(name);
76       if (index >= 0) {
77         this.notifications.splice(index, 1);
78       }
79     }
80   }
81
82   ngOnDestroy() {
83     this.subs.unsubscribe();
84   }
85 }