Console setting edition

This commit is contained in:
ziajka 2019-04-17 11:16:35 +02:00
parent f6b50526f4
commit b6ed486ce0
14 changed files with 155 additions and 22 deletions

View File

@ -180,6 +180,8 @@ import { StartCaptureDialogComponent } from './components/project-map/packet-cap
import { SuspendLinkActionComponent } from './components/project-map/context-menu/actions/suspend-link/suspend-link-action.component';
import { ResumeLinkActionComponent } from './components/project-map/context-menu/actions/resume-link-action/resume-link-action.component';
import { StopCaptureActionComponent } from './components/project-map/context-menu/actions/stop-capture/stop-capture-action.component';
import { ConsoleService } from './services/settings/console.service';
import { DefaultConsoleService } from './services/settings/default-console.service';
if (environment.production) {
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
@ -365,7 +367,9 @@ if (environment.production) {
IouService,
IouConfigurationService,
RecentlyOpenedProjectService,
ServerManagementService
ServerManagementService,
ConsoleService,
DefaultConsoleService
],
entryComponents: [
AddServerDialogComponent,

View File

@ -4,6 +4,8 @@ import { Server } from '../../../../../models/server';
import { ElectronService } from 'ngx-electron';
import { Project } from '../../../../../models/project';
import { ServerService } from '../../../../../services/server.service';
import { SettingsService } from '../../../../../services/settings.service';
import { ToasterService } from '../../../../../services/toaster.service';
@Component({
selector: 'app-console-device-action',
@ -16,15 +18,36 @@ export class ConsoleDeviceActionComponent implements OnInit {
constructor(
private electronService: ElectronService,
private serverService: ServerService
private serverService: ServerService,
private settingsService: SettingsService,
private toasterService: ToasterService
) { }
ngOnInit() {
}
async console() {
const consoleCommand = this.settingsService.get<string>('console_command');
if(consoleCommand === undefined) {
this.toasterService.error('Console command is not defined. Please change it in the Settings.');
return;
}
const startedNodes = this.nodes.filter(node => node.status === 'started');
if(startedNodes.length === 0) {
this.toasterService.error('Device needs to be started in order to console to it.');
return;
}
for(var node of this.nodes) {
if(node.status !== 'started') {
continue;
}
const consoleRequest = {
command: consoleCommand,
type: node.console_type,
host: node.console_host,
port: node.console,

View File

@ -7,20 +7,22 @@
<div class="default-content">
<mat-card>
<form [formGroup]="consoleForm">
<mat-form-field class="form-field">
<input
matInput type="text"
formControlName="runner"
placeholder="Predefined command">
</mat-form-field>
<mat-form-field class="form-field">
<mat-form-field class="form-field full-width-field">
<textarea matInput formControlName="command" placeholder="Command"></textarea>
</mat-form-field>
<div class="help">The following variables are replaced by GNS3:<br />
%h: console IP or hostname<br />
%p: console port<br />
%s: path of the serial connection<br />
%d: title of the console<br />
%i: Project UUID<br />
%c: server URL (http://user:password@server:port)
</div>
</form>
</mat-card>
<div class="buttons-bar">
<button class="cancel-button" (click)="goBack()" mat-button>Cancel</button>
<button mat-raised-button color="primary" (click)="onSave()">Save</button><br/>
<button mat-raised-button color="primary" (click)="save()">Save</button><br/>
</div>
</div>
</div>

View File

@ -0,0 +1,3 @@
.help {
font-size: 14px;
}

View File

@ -1,5 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { ConsoleService } from '../../../services/settings/console.service';
import { ToasterService } from '../../../services/toaster.service';
@Component({
selector: 'app-console',
@ -9,13 +12,29 @@ import { FormGroup, FormControl, Validators } from '@angular/forms';
export class ConsoleComponent implements OnInit {
consoleForm = new FormGroup({
'runner': new FormControl('', [ Validators.required ]),
'command': new FormControl(''),
});
constructor() { }
constructor(
private router: Router,
private consoleService: ConsoleService,
private toasterService: ToasterService
) { }
ngOnInit() {
const commandControl = this.consoleForm.get('command');
commandControl.setValue(this.consoleService.command);
}
goBack() {
this.router.navigate(['/settings']);
}
save() {
const formValue = this.consoleForm.value;
this.consoleService.command = formValue.command;
this.toasterService.success("Console command has been updated.");
this.goBack();
}
}

View File

@ -28,15 +28,15 @@
</div> -->
</mat-expansion-panel>
<mat-expansion-panel [expanded]="true">
<mat-expansion-panel [expanded]="false">
<mat-expansion-panel-header>
<mat-panel-title> Console settings </mat-panel-title>
<mat-panel-description> Customize console settings </mat-panel-description>
</mat-expansion-panel-header>
<div>
<mat-form-field class="example-full-width">
<input matInput placeholder="console">
<mat-form-field class="full-width-field">
<input matInput placeholder="console" [value]="consoleCommand" readonly="true">
<a mat-icon-button matSuffix routerLink="/settings/console"><mat-icon>mode_edit</mat-icon></a>
</mat-form-field>
</div>

View File

@ -1,4 +0,0 @@
.example-full-width {
width: 100%;
}

View File

@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { SettingsService } from '../../services/settings.service';
import { ToasterService } from '../../services/toaster.service';
import { ConsoleService } from '../../services/settings/console.service';
@Component({
selector: 'app-settings',
@ -9,11 +10,16 @@ import { ToasterService } from '../../services/toaster.service';
})
export class SettingsComponent implements OnInit {
settings = { ...SettingsService.DEFAULTS };
consoleCommand: string;
constructor(private settingsService: SettingsService, private toaster: ToasterService) {}
constructor(
private settingsService: SettingsService,
private toaster: ToasterService,
private consoleService: ConsoleService) {}
ngOnInit() {
this.settings = this.settingsService.getAll();
this.consoleCommand = this.consoleService.command;
}
save() {

View File

@ -6,6 +6,7 @@ export interface Settings {
crash_reports: boolean;
experimental_features: boolean;
angular_map: boolean;
console_command: string;
}
@Injectable()
@ -13,7 +14,8 @@ export class SettingsService {
static DEFAULTS: Settings = {
crash_reports: true,
experimental_features: false,
angular_map: false
angular_map: false,
console_command: undefined
};
private settingsSubject: BehaviorSubject<Settings>;

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { ConsoleService } from './console.service';
describe('ConsoleService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: ConsoleService = TestBed.get(ConsoleService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';
import { DefaultConsoleService } from './default-console.service';
import { SettingsService } from '../settings.service';
@Injectable()
export class ConsoleService {
constructor(
private defaultConsoleService: DefaultConsoleService,
private settingsService: SettingsService
) { }
get command(): string {
const command = this.settingsService.get<string>('console_command');
if(command === undefined) {
return this.defaultConsoleService.get();
}
return command;
}
set command(command: string) {
this.settingsService.set<string>('console_command', command);
}
}

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { DefaultConsoleService } from './default-console.service';
describe('DefaultConsoleService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: DefaultConsoleService = TestBed.get(DefaultConsoleService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,26 @@
import { Injectable } from '@angular/core';
import { ElectronService } from 'ngx-electron';
@Injectable()
export class DefaultConsoleService {
constructor(
private electronService: ElectronService
) { }
get() {
if(!this.electronService.isElectronApp) {
return undefined;
}
if(this.electronService.isLinux) {
return 'xfce4-terminal --tab -T "%d" -e "telnet %h %p"'
}
if(this.electronService.isWindows) {
return 'putty.exe -telnet %h %p -loghost "%d"'
}
return undefined;
}
}

View File

@ -26,6 +26,10 @@ a.table-link {
}
}
.full-width-field {
width: 100%;
}
app-root {
width: 100%;
}