]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
57730b3431320242cc9ad7fb6f1ffaaf75aa60b6
[ceph.git] /
1 import { Component, OnDestroy, OnInit } from '@angular/core';
2
3 import _ from 'lodash';
4
5 import { MgrModuleService } from '~/app/shared/api/mgr-module.service';
6 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
7 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
8 import { NotificationService } from '~/app/shared/services/notification.service';
9 import { TelemetryNotificationService } from '~/app/shared/services/telemetry-notification.service';
10
11 @Component({
12   selector: 'cd-telemetry-notification',
13   templateUrl: './telemetry-notification.component.html',
14   styleUrls: ['./telemetry-notification.component.scss'],
15   standalone: false
16 })
17 export class TelemetryNotificationComponent implements OnInit, OnDestroy {
18   displayNotification = false;
19   notificationSeverity = 'warning';
20
21   constructor(
22     private mgrModuleService: MgrModuleService,
23     private authStorageService: AuthStorageService,
24     private notificationService: NotificationService,
25     private telemetryNotificationService: TelemetryNotificationService
26   ) {}
27
28   ngOnInit() {
29     this.telemetryNotificationService.update.subscribe((visible: boolean) => {
30       this.displayNotification = visible;
31     });
32
33     if (!this.isNotificationHidden()) {
34       const configOptPermissions = this.authStorageService.getPermissions().configOpt;
35       if (_.every(Object.values(configOptPermissions))) {
36         this.mgrModuleService.getConfig('telemetry').subscribe((options) => {
37           if (!options['enabled']) {
38             this.telemetryNotificationService.setVisibility(true);
39           }
40         });
41       }
42     }
43   }
44
45   ngOnDestroy() {
46     this.telemetryNotificationService.setVisibility(false);
47   }
48
49   isNotificationHidden(): boolean {
50     return localStorage.getItem('telemetry_notification_hidden') === 'true';
51   }
52
53   onDismissed(): void {
54     this.telemetryNotificationService.setVisibility(false);
55     localStorage.setItem('telemetry_notification_hidden', 'true');
56     this.notificationService.show(
57       NotificationType.success,
58       $localize`Telemetry activation reminder muted`,
59       $localize`You can activate the module on the Telemetry configuration \
60 page (<b>Dashboard Settings</b> -> <b>Telemetry configuration</b>) at any time.`
61     );
62   }
63 }