]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
852189020031bd5566361e4e3fdd69fcbb9dfd55
[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 })
16 export class TelemetryNotificationComponent implements OnInit, OnDestroy {
17   displayNotification = false;
18
19   constructor(
20     private mgrModuleService: MgrModuleService,
21     private authStorageService: AuthStorageService,
22     private notificationService: NotificationService,
23     private telemetryNotificationService: TelemetryNotificationService
24   ) {}
25
26   ngOnInit() {
27     this.telemetryNotificationService.update.subscribe((visible: boolean) => {
28       this.displayNotification = visible;
29     });
30
31     if (!this.isNotificationHidden()) {
32       const configOptPermissions = this.authStorageService.getPermissions().configOpt;
33       if (_.every(Object.values(configOptPermissions))) {
34         this.mgrModuleService.getConfig('telemetry').subscribe((options) => {
35           if (!options['enabled']) {
36             this.telemetryNotificationService.setVisibility(true);
37           }
38         });
39       }
40     }
41   }
42
43   ngOnDestroy() {
44     this.telemetryNotificationService.setVisibility(false);
45   }
46
47   isNotificationHidden(): boolean {
48     return localStorage.getItem('telemetry_notification_hidden') === 'true';
49   }
50
51   close() {
52     this.telemetryNotificationService.setVisibility(false);
53     localStorage.setItem('telemetry_notification_hidden', 'true');
54     this.notificationService.show(
55       NotificationType.success,
56       $localize`Telemetry activation reminder muted`,
57       $localize`You can activate the module on the Telemetry configuration \
58 page (<b>Dashboard Settings</b> -> <b>Telemetry configuration</b>) at any time.`
59     );
60   }
61 }