mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-01-20 03:36:46 +00:00
Update project-map-guard.ts
This commit is contained in:
parent
0beff5f418
commit
54c2af8896
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user