]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/error/error.component.ts
1f2cf57c5088780a25fcf11c4bcc8cb69ac2e855
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / error / error.component.ts
1 import { Component, HostListener, OnDestroy, OnInit } from '@angular/core';
2 import { NavigationEnd, Router, RouterEvent } from '@angular/router';
3
4 import { Subscription } from 'rxjs';
5 import { filter } from 'rxjs/operators';
6
7 import { DocService } from '~/app/shared/services/doc.service';
8
9 @Component({
10 selector: 'cd-error',
11 templateUrl: './error.component.html',
12 styleUrls: ['./error.component.scss']
13 })
14 export class ErrorComponent implements OnDestroy, OnInit {
15 header: string;
16 message: string;
17 section: string;
18 section_info: string;
19 icon: string;
20 docUrl: string;
21 source: string;
22 routerSubscription: Subscription;
23
24 constructor(private router: Router, private docService: DocService) {}
25
26 ngOnInit() {
27 this.fetchData();
28 this.routerSubscription = this.router.events
29 .pipe(filter((event: RouterEvent) => event instanceof NavigationEnd))
30 .subscribe(() => {
31 this.fetchData();
32 });
33 }
34
35 @HostListener('window:beforeunload', ['$event']) unloadHandler(event: Event) {
36 event.returnValue = false;
37 }
38
39 fetchData() {
40 try {
41 this.router.onSameUrlNavigation = 'reload';
42 this.message = history.state.message;
43 this.header = history.state.header;
44 this.section = history.state.section;
45 this.section_info = history.state.section_info;
46 this.icon = history.state.icon;
47 this.source = history.state.source;
48 this.docUrl = this.docService.urlGenerator(this.section);
49 } catch (error) {
50 this.router.navigate(['/error']);
51 }
52 }
53
54 ngOnDestroy() {
55 if (this.routerSubscription) {
56 this.routerSubscription.unsubscribe();
57 }
58 }
59 }