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