]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
ce3e97fd516c4058e21e449af9257b5014c5112f
[ceph.git] /
1 import { Component, OnDestroy, OnInit } from '@angular/core';
2
3 import { UserFormModel } from '../../../core/auth/user-form/user-form.model';
4 import { MgrModuleService } from '../../api/mgr-module.service';
5 import { UserService } from '../../api/user.service';
6 import { NotificationType } from '../../enum/notification-type.enum';
7 import { AuthStorageService } from '../../services/auth-storage.service';
8 import { NotificationService } from '../../services/notification.service';
9 import { TelemetryNotificationService } from '../../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 })
16 export class TelemetryNotificationComponent implements OnInit, OnDestroy {
17   displayNotification = false;
18
19   constructor(
20     private mgrModuleService: MgrModuleService,
21     private authStorageService: AuthStorageService,
22     private userService: UserService,
23     private notificationService: NotificationService,
24     private telemetryNotificationService: TelemetryNotificationService
25   ) {}
26
27   ngOnInit() {
28     this.telemetryNotificationService.update.subscribe((visible: boolean) => {
29       this.displayNotification = visible;
30     });
31
32     if (!this.isNotificationHidden()) {
33       const username = this.authStorageService.getUsername();
34       this.userService.get(username).subscribe((user: UserFormModel) => {
35         if (user.roles.includes('administrator')) {
36           this.mgrModuleService.getConfig('telemetry').subscribe((options) => {
37             if (!options['enabled']) {
38               this.telemetryNotificationService.setVisibility(true);
39             }
40           });
41         }
42       });
43     }
44   }
45
46   ngOnDestroy() {
47     this.telemetryNotificationService.setVisibility(false);
48   }
49
50   isNotificationHidden(): boolean {
51     return localStorage.getItem('telemetry_notification_hidden') === 'true';
52   }
53
54   close() {
55     this.telemetryNotificationService.setVisibility(false);
56     localStorage.setItem('telemetry_notification_hidden', 'true');
57     this.notificationService.show(
58       NotificationType.success,
59       $localize`Telemetry activation reminder muted`,
60       $localize`You can activate the module on the Telemetry configuration \
61 page (<b>Dashboard Settings</b> -> <b>Telemetry configuration</b>) at any time.`
62     );
63   }
64 }