mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-31 06:20:59 +00:00
Merge branch 'master' into angular-resolvers
This commit is contained in:
commit
5c37f4dfa6
@ -62,6 +62,7 @@ import { Gns3vmComponent } from './components/preferences/gns3vm/gns3vm.componen
|
|||||||
import { DirectLinkComponent } from './components/direct-link/direct-link.component';
|
import { DirectLinkComponent } from './components/direct-link/direct-link.component';
|
||||||
import { SystemStatusComponent } from './components/system-status/system-status.component';
|
import { SystemStatusComponent } from './components/system-status/system-status.component';
|
||||||
import { ServerResolve } from './resolvers/server-resolve';
|
import { ServerResolve } from './resolvers/server-resolve';
|
||||||
|
import { ProjectMapGuard } from './guards/project-map-guard';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
@ -149,7 +150,9 @@ const routes: Routes = [
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'server/:server_id/project/:project_id', component: ProjectMapComponent,
|
path: 'server/:server_id/project/:project_id',
|
||||||
|
component: ProjectMapComponent,
|
||||||
|
canActivate: [ProjectMapGuard]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '**',
|
path: '**',
|
||||||
|
@ -267,6 +267,7 @@ import { NgCircleProgressModule } from 'ng-circle-progress';
|
|||||||
import { OpenFileExplorerActionComponent } from './components/project-map/context-menu/actions/open-file-explorer/open-file-explorer-action.component';
|
import { OpenFileExplorerActionComponent } from './components/project-map/context-menu/actions/open-file-explorer/open-file-explorer-action.component';
|
||||||
import { NgxChildProcessModule } from 'ngx-childprocess';
|
import { NgxChildProcessModule } from 'ngx-childprocess';
|
||||||
import { ServerResolve } from './resolvers/server-resolve';
|
import { ServerResolve } from './resolvers/server-resolve';
|
||||||
|
import { ProjectMapGuard } from './guards/project-map-guard';
|
||||||
|
|
||||||
if (environment.production) {
|
if (environment.production) {
|
||||||
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
|
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
|
||||||
@ -541,6 +542,7 @@ if (environment.production) {
|
|||||||
ThemeService,
|
ThemeService,
|
||||||
GoogleAnalyticsService,
|
GoogleAnalyticsService,
|
||||||
ServerResolve,
|
ServerResolve,
|
||||||
|
ProjectMapGuard,
|
||||||
Title
|
Title
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
|
@ -61,6 +61,8 @@ export class ProjectsComponent implements OnInit {
|
|||||||
this.dataSource = new ProjectDataSource(this.projectDatabase, this.sort);
|
this.dataSource = new ProjectDataSource(this.projectDatabase, this.sort);
|
||||||
this.settings = this.settingsService.getAll();
|
this.settings = this.settingsService.getAll();
|
||||||
|
|
||||||
|
this.projectService.projectListSubject.subscribe(() => this.refresh());
|
||||||
|
|
||||||
let gns3vmConfig = localStorage.getItem('gns3vmConfig');
|
let gns3vmConfig = localStorage.getItem('gns3vmConfig');
|
||||||
if (this.electronService.isElectronApp && gns3vmConfig!=='configured') {
|
if (this.electronService.isElectronApp && gns3vmConfig!=='configured') {
|
||||||
const dialogRef = this.dialog.open(ConfigureGns3VMDialogComponent, {
|
const dialogRef = this.dialog.open(ConfigureGns3VMDialogComponent, {
|
||||||
|
35
src/app/guards/project-map-guard.ts
Normal file
35
src/app/guards/project-map-guard.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
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';
|
||||||
|
import { Server } from '../models/server';
|
||||||
|
import { ServerService } from '../services/server.service';
|
||||||
|
import { switchMap, map } from 'rxjs/operators';
|
||||||
|
import { ToasterService } from '../services/toaster.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ProjectMapGuard implements CanActivate {
|
||||||
|
constructor(
|
||||||
|
private projectService: ProjectService,
|
||||||
|
private serverService: ServerService,
|
||||||
|
private toasterService: ToasterService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
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)),
|
||||||
|
map(response => {
|
||||||
|
let projectToOpen = response.find(n => n.project_id === project_id);
|
||||||
|
if (projectToOpen) return true;
|
||||||
|
|
||||||
|
this.toasterService.error('Project could not be opened');
|
||||||
|
this.projectService.projectListUpdated();
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Project } from '../models/project';
|
import { Project } from '../models/project';
|
||||||
import { Node } from '../cartography/models/node';
|
import { Node } from '../cartography/models/node';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable, Subject } from 'rxjs';
|
||||||
import { Link } from '../models/link';
|
import { Link } from '../models/link';
|
||||||
import { Server } from '../models/server';
|
import { Server } from '../models/server';
|
||||||
import { HttpServer } from './http-server.service';
|
import { HttpServer } from './http-server.service';
|
||||||
@ -10,8 +10,14 @@ import { SettingsService } from './settings.service';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProjectService {
|
export class ProjectService {
|
||||||
|
public projectListSubject = new Subject<boolean>();
|
||||||
|
|
||||||
constructor(private httpServer: HttpServer, private settingsService: SettingsService) {}
|
constructor(private httpServer: HttpServer, private settingsService: SettingsService) {}
|
||||||
|
|
||||||
|
projectListUpdated() {
|
||||||
|
this.projectListSubject.next(true);
|
||||||
|
}
|
||||||
|
|
||||||
get(server: Server, project_id: string) {
|
get(server: Server, project_id: string) {
|
||||||
return this.httpServer.get<Project>(server, `/projects/${project_id}`);
|
return this.httpServer.get<Project>(server, `/projects/${project_id}`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user