Console connect to all nodes added

This commit is contained in:
Piotr Pekala 2019-09-24 07:12:26 -07:00
parent 03b88da9f6
commit 5832d3f36e
4 changed files with 55 additions and 4 deletions

View File

@ -1,3 +1,11 @@
<button
matTooltip="Console connect to all nodes"
mat-icon-button
(click)="startConsoleForAllNodes()"
class="menu-button"
>
<mat-icon>web_asset</mat-icon>
</button>
<button
matTooltip="Start/Resume all nodes"
mat-icon-button

View File

@ -1,7 +1,7 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NodesMenuComponent } from './nodes-menu.component';
import { MockedToasterService } from '../../../services/toaster.service.spec';
import { MockedNodeService } from '../project-map.component.spec';
import { MockedNodeService, MockedNodesDataSource } from '../project-map.component.spec';
import { MatButtonModule, MatIconModule } from '@angular/material';
import { CommonModule } from '@angular/common';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@ -9,19 +9,28 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { NodeService } from '../../../services/node.service';
import { ToasterService } from '../../../services/toaster.service';
import { of } from 'rxjs';
import { NodesDataSource } from '../../../cartography/datasources/nodes-datasource';
import { ServerService } from '../../../services/server.service';
import { SettingsService } from '../../../services/settings.service';
import { ElectronService } from 'ngx-electron';
describe('NodesMenuComponent', () => {
let component: NodesMenuComponent;
let fixture: ComponentFixture<NodesMenuComponent>;
let mockedToasterService: MockedToasterService = new MockedToasterService();
let mockedNodeService: MockedNodeService = new MockedNodeService();
let mockedNodesDataSource: MockedNodesDataSource = new MockedNodesDataSource();
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatButtonModule, MatIconModule, CommonModule, NoopAnimationsModule],
providers: [
{ provide: NodeService, useValue: mockedNodeService },
{ provide: ToasterService, useValue: mockedToasterService }
{ provide: ToasterService, useValue: mockedToasterService },
{ provide: NodesDataSource, useValue: mockedNodesDataSource },
{ provide: ServerService },
{ provide: SettingsService },
{ provide: ElectronService }
],
declarations: [
NodesMenuComponent,

View File

@ -3,6 +3,10 @@ import { Project } from '../../../models/project';
import { Server } from '../../../models/server';
import { NodeService } from '../../../services/node.service';
import { ToasterService } from '../../../services/toaster.service';
import { NodesDataSource } from '../../../cartography/datasources/nodes-datasource';
import { ElectronService } from 'ngx-electron';
import { SettingsService } from '../../../services/settings.service';
import { ServerService } from '../../../services/server.service';
@Component({
selector: 'app-nodes-menu',
@ -15,9 +19,39 @@ export class NodesMenuComponent {
constructor(
private nodeService: NodeService,
private toasterService: ToasterService
private nodesDataSource: NodesDataSource,
private toasterService: ToasterService,
private serverService: ServerService,
private settingsService: SettingsService,
private electronService: ElectronService
) {}
async startConsoleForAllNodes() {
if (this.electronService.isElectronApp) {
let consoleCommand = this.settingsService.get<string>('console_command');
if(consoleCommand === undefined) {
consoleCommand = `putty.exe -telnet \%h \%p -wt \"\%d\" -gns3 5 -skin 4`;
}
let nodes = this.nodesDataSource.getItems();
for(var node of nodes) {
const request = {
command: consoleCommand,
type: node.console_type,
host: node.console_host,
port: node.console,
name: node.name,
project_id: node.project_id,
node_id: node.node_id,
server_url: this.serverService.getServerUrl(this.server)
};
await this.electronService.remote.require('./console-executor.js').openConsole(request);
}
} else {
this.toasterService.error("Starting all nodes available only in Electron app.");
}
}
startNodes() {
this.nodeService.startAll(this.server, this.project).subscribe(() => {
this.toasterService.success('All nodes successfully started');

View File

@ -80,7 +80,7 @@ g.node:hover {
}
.extended {
width: 770px !important;
width: 830px !important;
height: 100%;
overflow: hidden;
}