]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/telemetry-notification/telemetry-notification.component.ts
import quincy beta 17.1.0
[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 _ 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 notificationSeverity = 'warning';
19
20 constructor(
21 private mgrModuleService: MgrModuleService,
22 private authStorageService: AuthStorageService,
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 configOptPermissions = this.authStorageService.getPermissions().configOpt;
34 if (_.every(Object.values(configOptPermissions))) {
35 this.mgrModuleService.getConfig('telemetry').subscribe((options) => {
36 if (!options['enabled']) {
37 this.telemetryNotificationService.setVisibility(true);
38 }
39 });
40 }
41 }
42 }
43
44 ngOnDestroy() {
45 this.telemetryNotificationService.setVisibility(false);
46 }
47
48 isNotificationHidden(): boolean {
49 return localStorage.getItem('telemetry_notification_hidden') === 'true';
50 }
51
52 onDismissed(): void {
53 this.telemetryNotificationService.setVisibility(false);
54 localStorage.setItem('telemetry_notification_hidden', 'true');
55 this.notificationService.show(
56 NotificationType.success,
57 $localize`Telemetry activation reminder muted`,
58 $localize`You can activate the module on the Telemetry configuration \
59 page (<b>Dashboard Settings</b> -> <b>Telemetry configuration</b>) at any time.`
60 );
61 }
62 }