Skip to content
Snippets Groups Projects
Select Git revision
  • 4c8af8a98b91f603d73e16979f048e1d14587eff
  • master default
2 results

matrix_server.cpp

Blame
  • error-dialog.component.ts 1.35 KiB
    import { Component, OnInit, ViewChild } from '@angular/core';
    import { ErrorModel } from '../../models/error.model';
    import { ErrorService } from '../../services/error.service';
    import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
    import { Router } from '@angular/router';
    
    /**
     * Component that opens a new dialog if the errorService is updated
     */
    @Component({
      selector: 'app-error-dialog',
      templateUrl: './error-dialog.component.html',
      styleUrls: ['./error-dialog.component.css'],
    })
    export class ErrorDialogComponent implements OnInit {
      /**
       * Error that will be displayed
       */
      error: ErrorModel;
      /**
       * Get the modal from template
       */
      @ViewChild('modalData') modalData: any;
    
      constructor(private errorService: ErrorService, private modalService: NgbModal, private router: Router) {}
    
      /**
       * Subscribe to the ErrorService and trigger the modal on change
       */
      ngOnInit(): void {
        this.errorService.errorData$.subscribe((e) => {
          if (e) {
            this.error = e;
            this.triggerModal();
          }
        });
      }
    
      /**
       * Open the modal
       */
      triggerModal(): void {
        this.modalService.open(this.modalData, { ariaLabelledBy: 'modal-basic-title' });
      }
    
      /**
       * Redirect to the given route in the error
       */
      redirectToHome(): void {
        if (this.error.navigate) {
          this.router.navigate(this.error.navigate);
        }
      }
    }