]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/telemetry-notification/telemetry-notification.component.ts
974f625e1c6aa3341e058d2b085ba9e0067e605e
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / telemetry-notification / telemetry-notification.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4
5 import { UserFormModel } from '../../../core/auth/user-form/user-form.model';
6 import { MgrModuleService } from '../../api/mgr-module.service';
7 import { UserService } from '../../api/user.service';
8 import { NotificationType } from '../../enum/notification-type.enum';
9 import { AuthStorageService } from '../../services/auth-storage.service';
10 import { NotificationService } from '../../services/notification.service';
11 import { TelemetryNotificationService } from '../../services/telemetry-notification.service';
12
13 @Component({
14 selector: 'cd-telemetry-notification',
15 templateUrl: './telemetry-notification.component.html',
16 styleUrls: ['./telemetry-notification.component.scss']
17 })
18 export class TelemetryNotificationComponent implements OnInit, OnDestroy {
19 displayNotification = false;
20
21 constructor(
22 private mgrModuleService: MgrModuleService,
23 private authStorageService: AuthStorageService,
24 private userService: UserService,
25 private notificationService: NotificationService,
26 private telemetryNotificationService: TelemetryNotificationService,
27 private i18n: I18n
28 ) {}
29
30 ngOnInit() {
31 this.telemetryNotificationService.update.subscribe((visible: boolean) => {
32 this.displayNotification = visible;
33 });
34
35 if (!this.isNotificationHidden()) {
36 const username = this.authStorageService.getUsername();
37 this.userService.get(username).subscribe((user: UserFormModel) => {
38 if (user.roles.includes('administrator')) {
39 this.mgrModuleService.getConfig('telemetry').subscribe((options) => {
40 if (!options['enabled']) {
41 this.telemetryNotificationService.setVisibility(true);
42 }
43 });
44 }
45 });
46 }
47 }
48
49 ngOnDestroy() {
50 this.telemetryNotificationService.setVisibility(false);
51 }
52
53 isNotificationHidden(): boolean {
54 return localStorage.getItem('telemetry_notification_hidden') === 'true';
55 }
56
57 close() {
58 this.telemetryNotificationService.setVisibility(false);
59 localStorage.setItem('telemetry_notification_hidden', 'true');
60 this.notificationService.show(
61 NotificationType.success,
62 this.i18n('Telemetry activation reminder muted'),
63 this.i18n(
64 'You can activate the module on the Telemetry configuration ' +
65 'page (<b>Dashboard Settings</b> -> <b>Telemetry configuration</b>) at any time.'
66 )
67 );
68 }
69 }