mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-22 10:20:48 +00:00
CanDeactivate project map component when console is open
This commit is contained in:
parent
c3ebdd6498
commit
8da4407109
@ -64,6 +64,7 @@ import { SystemStatusComponent } from './components/system-status/system-status.
|
||||
import { ServerResolve } from './resolvers/server-resolve';
|
||||
import { ProjectMapGuard } from './guards/project-map-guard';
|
||||
import { WebConsoleFullWindowComponent } from './components/web-console-full-window/web-console-full-window.component';
|
||||
import { ConsoleGuard } from './guards/console-guard';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
@ -153,7 +154,8 @@ const routes: Routes = [
|
||||
{
|
||||
path: 'server/:server_id/project/:project_id',
|
||||
component: ProjectMapComponent,
|
||||
canActivate: [ProjectMapGuard]
|
||||
canActivate: [ProjectMapGuard],
|
||||
canDeactivate: [ConsoleGuard]
|
||||
},
|
||||
{
|
||||
path: 'server/:server_id/project/:project_id/nodes/:node_id',
|
||||
|
@ -274,6 +274,7 @@ import { ConsoleWrapperComponent } from './components/project-map/console-wrappe
|
||||
import { NodeConsoleService } from './services/nodeConsole.service';
|
||||
import { HttpConsoleNewTabActionComponent } from './components/project-map/context-menu/actions/http-console-new-tab/http-console-new-tab-action.component';
|
||||
import { WebConsoleFullWindowComponent } from './components/web-console-full-window/web-console-full-window.component';
|
||||
import { ConsoleGuard } from './guards/console-guard';
|
||||
|
||||
if (environment.production) {
|
||||
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
|
||||
@ -555,6 +556,7 @@ if (environment.production) {
|
||||
NodeConsoleService,
|
||||
ServerResolve,
|
||||
ProjectMapGuard,
|
||||
ConsoleGuard,
|
||||
Title
|
||||
],
|
||||
entryComponents: [
|
||||
|
@ -68,10 +68,13 @@ export class ConsoleWrapperComponent implements OnInit {
|
||||
if (selectAfterAdding) {
|
||||
this.selected.setValue(this.nodes.length);
|
||||
}
|
||||
|
||||
this.consoleService.openConsoles++;
|
||||
}
|
||||
|
||||
removeTab(index: number) {
|
||||
this.nodes.splice(index, 1);
|
||||
this.consoleService.openConsoles--;
|
||||
}
|
||||
|
||||
toggleDragging(value: boolean) {
|
||||
|
29
src/app/guards/console-guard.ts
Normal file
29
src/app/guards/console-guard.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { CanDeactivate } from '@angular/router';
|
||||
import { NodeConsoleService } from '../services/nodeConsole.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { MatBottomSheet } from '@angular/material';
|
||||
import { ConfirmationBottomSheetComponent } from '../components/projects/confirmation-bottomsheet/confirmation-bottomsheet.component';
|
||||
|
||||
export interface CanComponentDeactivate {
|
||||
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ConsoleGuard implements CanDeactivate<CanComponentDeactivate> {
|
||||
constructor(
|
||||
private consoleService: NodeConsoleService,
|
||||
private bottomSheet: MatBottomSheet
|
||||
) {}
|
||||
|
||||
canDeactivate() {
|
||||
if (this.consoleService.openConsoles > 0) {
|
||||
this.bottomSheet.open(ConfirmationBottomSheetComponent);
|
||||
let bottomSheetRef = this.bottomSheet._openedBottomSheetRef;
|
||||
bottomSheetRef.instance.message = 'Exiting the project will close open consoles, do you want to continue?';
|
||||
return bottomSheetRef.afterDismissed();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ export class NodeConsoleService {
|
||||
public nodeConsoleTrigger = new EventEmitter<Node>();
|
||||
public closeNodeConsoleTrigger = new Subject<Node>();
|
||||
public consoleResized = new Subject<ConsoleResizedEvent>();
|
||||
public openConsoles: number = 0;
|
||||
|
||||
public readonly defaultConsoleWidth = 720;
|
||||
public readonly defaultConsoleHeight = 408;
|
||||
|
Loading…
x
Reference in New Issue
Block a user