Update project-map-guard.ts

This commit is contained in:
piotrpekala7 2020-02-28 12:33:09 +01:00
parent 0beff5f418
commit 54c2af8896

View File

@ -1,5 +1,5 @@
import { Injectable } from "@angular/core";
import { CanDeactivate } from '@angular/router';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { ProjectMapComponent } from '../components/project-map/project-map.component';
import { Observable, pipe, timer, from } from 'rxjs';
import { ProjectService } from '../services/project.service';
@ -8,20 +8,15 @@ import { ServerService } from '../services/server.service';
import { switchMap, map } from 'rxjs/operators';
@Injectable()
export class ProjectMapGuard implements CanDeactivate<ProjectMapComponent> {
export class ProjectMapGuard implements CanActivate {
constructor(
private projectService: ProjectService,
private serverService: ServerService
) {}
) {}
canDeactivate(
component: ProjectMapComponent,
currentRoute: import("@angular/router").ActivatedRouteSnapshot,
currentState: import("@angular/router").RouterStateSnapshot,
nextState?: import("@angular/router").RouterStateSnapshot): Observable<boolean>
{
const server_id = currentRoute.paramMap.get("server_id");
const project_id = currentRoute.paramMap.get("project_id");
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
const server_id = route.paramMap.get("server_id");
const project_id = route.paramMap.get("project_id");
return from(this.serverService.get(parseInt(server_id, 10))).pipe(
switchMap(response => this.projectService.list(response as Server)),