]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/error/error.component.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / error / error.component.ts
CommitLineData
2a845540 1import { HttpClient } from '@angular/common/http';
f67539c2
TL
2import { Component, HostListener, OnDestroy, OnInit } from '@angular/core';
3import { NavigationEnd, Router, RouterEvent } from '@angular/router';
4
5import { Subscription } from 'rxjs';
6import { filter } from 'rxjs/operators';
7
2a845540 8import { NotificationType } from '~/app/shared/enum/notification-type.enum';
f67539c2 9import { DocService } from '~/app/shared/services/doc.service';
2a845540 10import { NotificationService } from '~/app/shared/services/notification.service';
f67539c2
TL
11
12@Component({
13 selector: 'cd-error',
14 templateUrl: './error.component.html',
15 styleUrls: ['./error.component.scss']
16})
17export class ErrorComponent implements OnDestroy, OnInit {
18 header: string;
19 message: string;
20 section: string;
21 section_info: string;
2a845540
TL
22 button_name: string;
23 button_route: string;
f67539c2
TL
24 icon: string;
25 docUrl: string;
26 source: string;
27 routerSubscription: Subscription;
2a845540
TL
28 uiConfig: string;
29 uiApiPath: string;
30 buttonRoute: string;
31 buttonName: string;
32 buttonTitle: string;
33 component: string;
f67539c2 34
2a845540
TL
35 constructor(
36 private router: Router,
37 private docService: DocService,
38 private http: HttpClient,
39 private notificationService: NotificationService
40 ) {}
f67539c2
TL
41
42 ngOnInit() {
43 this.fetchData();
44 this.routerSubscription = this.router.events
45 .pipe(filter((event: RouterEvent) => event instanceof NavigationEnd))
46 .subscribe(() => {
47 this.fetchData();
48 });
49 }
50
2a845540
TL
51 doConfigure() {
52 this.http.post(`ui-api/${this.uiApiPath}/configure`, {}).subscribe({
53 next: () => {
54 this.notificationService.show(NotificationType.info, `Configuring ${this.component}`);
55 },
56 error: (error: any) => {
57 this.notificationService.show(NotificationType.error, error);
58 },
59 complete: () => {
60 setTimeout(() => {
61 this.router.navigate([this.uiApiPath]);
62 this.notificationService.show(NotificationType.success, `Configured ${this.component}`);
63 }, 3000);
64 }
65 });
66 }
67
f67539c2
TL
68 @HostListener('window:beforeunload', ['$event']) unloadHandler(event: Event) {
69 event.returnValue = false;
70 }
71
72 fetchData() {
73 try {
74 this.router.onSameUrlNavigation = 'reload';
75 this.message = history.state.message;
76 this.header = history.state.header;
77 this.section = history.state.section;
78 this.section_info = history.state.section_info;
2a845540
TL
79 this.button_name = history.state.button_name;
80 this.button_route = history.state.button_route;
f67539c2
TL
81 this.icon = history.state.icon;
82 this.source = history.state.source;
2a845540
TL
83 this.uiConfig = history.state.uiConfig;
84 this.uiApiPath = history.state.uiApiPath;
85 this.buttonRoute = history.state.button_route;
86 this.buttonName = history.state.button_name;
87 this.buttonTitle = history.state.button_title;
88 this.component = history.state.component;
f67539c2
TL
89 this.docUrl = this.docService.urlGenerator(this.section);
90 } catch (error) {
91 this.router.navigate(['/error']);
92 }
93 }
94
95 ngOnDestroy() {
96 if (this.routerSubscription) {
97 this.routerSubscription.unsubscribe();
98 }
99 }
100}