]>
Commit | Line | Data |
---|---|---|
f6b5b4d7 TL |
1 | import { Component, OnDestroy, OnInit } from '@angular/core'; |
2 | ||
f67539c2 | 3 | import _ from 'lodash'; |
f6b5b4d7 | 4 | |
f67539c2 TL |
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'; | |
f6b5b4d7 TL |
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; | |
20effc67 | 18 | notificationSeverity = 'warning'; |
f6b5b4d7 TL |
19 | |
20 | constructor( | |
21 | private mgrModuleService: MgrModuleService, | |
22 | private authStorageService: AuthStorageService, | |
f6b5b4d7 | 23 | private notificationService: NotificationService, |
f67539c2 | 24 | private telemetryNotificationService: TelemetryNotificationService |
f6b5b4d7 TL |
25 | ) {} |
26 | ||
27 | ngOnInit() { | |
28 | this.telemetryNotificationService.update.subscribe((visible: boolean) => { | |
29 | this.displayNotification = visible; | |
30 | }); | |
31 | ||
32 | if (!this.isNotificationHidden()) { | |
f91f0fd5 TL |
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 | } | |
f6b5b4d7 TL |
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 | ||
20effc67 | 52 | onDismissed(): void { |
f6b5b4d7 TL |
53 | this.telemetryNotificationService.setVisibility(false); |
54 | localStorage.setItem('telemetry_notification_hidden', 'true'); | |
55 | this.notificationService.show( | |
56 | NotificationType.success, | |
f67539c2 TL |
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.` | |
f6b5b4d7 TL |
60 | ); |
61 | } | |
62 | } |