1 import { HttpClient } from '@angular/common/http';
2 import { Component, HostListener, OnDestroy, OnInit } from '@angular/core';
3 import { NavigationEnd, Router, RouterEvent } from '@angular/router';
5 import { Subscription } from 'rxjs';
6 import { filter } from 'rxjs/operators';
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';
14 templateUrl: './error.component.html',
15 styleUrls: ['./error.component.scss']
17 export class ErrorComponent implements OnDestroy, OnInit {
25 routerSubscription: Subscription;
31 secondaryButtonRoute: string;
32 secondaryButtonName: string;
33 secondaryButtonTitle: string;
37 private router: Router,
38 private docService: DocService,
39 private http: HttpClient,
40 private notificationService: NotificationService
45 this.routerSubscription = this.router.events
46 .pipe(filter((event: RouterEvent) => event instanceof NavigationEnd))
53 this.http.post(`ui-api/${this.uiApiPath}/configure`, {}).subscribe({
55 this.notificationService.show(NotificationType.info, `Configuring ${this.component}`);
57 error: (error: any) => {
58 this.notificationService.show(NotificationType.error, error);
62 this.router.navigate([this.uiApiPath]);
63 this.notificationService.show(NotificationType.success, `Configured ${this.component}`);
69 @HostListener('window:beforeunload', ['$event']) unloadHandler(event: Event) {
70 event.returnValue = false;
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);
93 this.router.navigate(['/error']);
98 if (this.routerSubscription) {
99 this.routerSubscription.unsubscribe();