From ecce86aaf75c7b428dc4b74fce27e822fe52df72 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Mon, 9 Sep 2019 06:57:42 -0700 Subject: [PATCH 01/30] Dialog for VPCS added --- src/app/app.module.ts | 9 ++- src/app/cartography/models/node.ts | 1 + .../config-action.component.html | 4 ++ .../config-action.component.spec.ts | 0 .../config-action/config-action.component.ts | 58 +++++++++++++++++++ .../context-menu/context-menu.component.html | 4 ++ .../configurator/configurator.component.scss | 7 +++ .../vpcs/configurator-vpcs.component.html | 39 +++++++++++++ .../vpcs/configurator-vpcs.component.ts | 58 +++++++++++++++++++ src/app/services/node.service.ts | 11 ++++ 10 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 src/app/components/project-map/context-menu/actions/config-action/config-action.component.html create mode 100644 src/app/components/project-map/context-menu/actions/config-action/config-action.component.spec.ts create mode 100644 src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts create mode 100644 src/app/components/project-map/node-editors/configurator/configurator.component.scss create mode 100644 src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.html create mode 100644 src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3edba25a..fbcdc4ff 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -211,6 +211,8 @@ import { ProjectsFilter } from './filters/projectsFilter.pipe'; import { ComputeService } from './services/compute.service'; import { ReloadNodeActionComponent } from './components/project-map/context-menu/actions/reload-node-action/reload-node-action.component'; import { SuspendNodeActionComponent } from './components/project-map/context-menu/actions/suspend-node-action/suspend-node-action.component'; +import { ConfigActionComponent } from './components/project-map/context-menu/actions/config-action/config-action.component'; +import { ConfiguratorDialogVpcsComponent } from './components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -349,7 +351,9 @@ if (environment.production) { ChangeSymbolActionComponent, EditProjectDialogComponent, ReloadNodeActionComponent, - SuspendNodeActionComponent + SuspendNodeActionComponent, + ConfigActionComponent, + ConfiguratorDialogVpcsComponent ], imports: [ BrowserModule, @@ -449,7 +453,8 @@ if (environment.production) { SaveProjectDialogComponent, InfoDialogComponent, ChangeSymbolDialogComponent, - EditProjectDialogComponent + EditProjectDialogComponent, + ConfiguratorDialogVpcsComponent ], bootstrap: [AppComponent] }) diff --git a/src/app/cartography/models/node.ts b/src/app/cartography/models/node.ts index 5caf995f..3478617f 100644 --- a/src/app/cartography/models/node.ts +++ b/src/app/cartography/models/node.ts @@ -5,6 +5,7 @@ export class Node { command_line: string; compute_id: string; console: number; + console_auto_start: boolean; console_host: string; console_type: string; first_port_name: string; diff --git a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.html b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.html new file mode 100644 index 00000000..3290ba3a --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.html @@ -0,0 +1,4 @@ + diff --git a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.spec.ts b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts new file mode 100644 index 00000000..5d9d0974 --- /dev/null +++ b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts @@ -0,0 +1,58 @@ +import { Component, Input, OnInit, OnChanges } from '@angular/core'; +import { Server } from '../../../../../models/server'; +import { Node } from '../../../../../cartography/models/node'; +import { MatDialog, MatDialogRef } from '@angular/material'; +import { ConfiguratorDialogVpcsComponent } from '../../../node-editors/configurator/vpcs/configurator-vpcs.component'; + + +@Component({ + selector: 'app-config-node-action', + templateUrl: './config-action.component.html' +}) +export class ConfigActionComponent { + @Input() server: Server; + @Input() node: Node; + private conf = { + width: '600px', + autoFocus: false + }; + dialogRef; + + constructor(private dialog: MatDialog) {} + + configureNode() { + if (this.node.node_type === 'vpcs') { + this.dialogRef = this.dialog.open(ConfiguratorDialogVpcsComponent, this.conf); + } else if (this.node.node_type === 'ethernet_hub') { + + } else if (this.node.node_type === 'ethernet_switch') { + + } else if (this.node.node_type === 'cloud') { + + } else if (this.node.node_type === 'dynamips') { + + } else if (this.node.node_type === 'iou') { + + } else if (this.node.node_type === 'qemu') { + + } else if (this.node.node_type === 'virtualbox') { + + } else if (this.node.node_type === 'vmware') { + + } else if (this.node.node_type === 'docker') { + + } else if (this.node.node_type === 'nat') { + + } else if (this.node.node_type === 'frame_relay_switch') { + + } else if (this.node.node_type === 'atm_switch') { + + } else if (this.node.node_type === 'traceng') { + + } + + let instance = this.dialogRef.componentInstance; + instance.server = this.server; + instance.node = this.node; + } +} diff --git a/src/app/components/project-map/context-menu/context-menu.component.html b/src/app/components/project-map/context-menu/context-menu.component.html index 091a6fcf..177d607d 100644 --- a/src/app/components/project-map/context-menu/context-menu.component.html +++ b/src/app/components/project-map/context-menu/context-menu.component.html @@ -5,6 +5,10 @@ [server]="server" [node]="nodes[0]" > + diff --git a/src/app/components/project-map/node-editors/configurator/configurator.component.scss b/src/app/components/project-map/node-editors/configurator/configurator.component.scss new file mode 100644 index 00000000..ae93f5c6 --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/configurator.component.scss @@ -0,0 +1,7 @@ +.form-field { + width: 100%; +} + +.select { + width: 100%; +} diff --git a/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.html b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.html new file mode 100644 index 00000000..e4edc149 --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.html @@ -0,0 +1,39 @@ +

Configurator for node {{node.name}}

+ + + +
+ + +
diff --git a/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts new file mode 100644 index 00000000..c2073860 --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts @@ -0,0 +1,58 @@ +import { Component, OnInit, Input } from "@angular/core"; +import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; +import { VpcsConfigurationService } from '../../../../../services/vpcs-configuration.service'; +import { Node } from '../../../../../cartography/models/node'; +import { Server } from '../../../../../models/server'; +import { NodeService } from '../../../../../services/node.service'; +import { ToasterService } from '../../../../../services/toaster.service'; +import { MatDialogRef } from '@angular/material'; + + +@Component({ + selector: 'app-configurator-vpcs', + templateUrl: './configurator-vpcs.component.html', + styleUrls: ['../configurator.component.scss'] +}) +export class ConfiguratorDialogVpcsComponent implements OnInit { + server: Server; + node: Node; + + inputForm: FormGroup; + consoleTypes: string[] = []; + categories = []; + + constructor( + public dialogRef: MatDialogRef, + public nodeService: NodeService, + private toasterService: ToasterService, + private formBuilder: FormBuilder, + private vpcsConfigurationService: VpcsConfigurationService + ) { + this.inputForm = this.formBuilder.group({ + name: new FormControl('', Validators.required) + }); + } + + ngOnInit() { + this.nodeService.getNode(this.server, this.node).subscribe((node: Node) => { + this.node = node; + this.getConfiguration(); + }) + } + + getConfiguration() { + this.consoleTypes = this.vpcsConfigurationService.getConsoleTypes(); + this.categories = this.vpcsConfigurationService.getCategories(); + } + + onSaveClick() { + this.nodeService.updateNode(this.server, this.node).subscribe(() => { + this.toasterService.success(`Node ${this.node.name} updated.`); + this.onCancelClick(); + }); + } + + onCancelClick() { + this.dialogRef.close(); + } +} diff --git a/src/app/services/node.service.ts b/src/app/services/node.service.ts index 111b5106..9beb0d6f 100644 --- a/src/app/services/node.service.ts +++ b/src/app/services/node.service.ts @@ -86,6 +86,13 @@ export class NodeService { }); } + updateNode(server: Server, node: Node): Observable { + return this.httpServer.put(server, `/projects/${node.project_id}/nodes/${node.node_id}`, { + console_type: node.console_type, + name: node.name + }); + } + delete(server: Server, node: Node) { return this.httpServer.delete(server, `/projects/${node.project_id}/nodes/${node.node_id}`); } @@ -99,6 +106,10 @@ export class NodeService { }); } + getNode(server: Server, node: Node) { + return this.httpServer.get(server, `/projects/${node.project_id}/nodes/${node.node_id}`) + } + getConfiguration(server: Server, node: Node) { let urlPath: string = `/projects/${node.project_id}/nodes/${node.node_id}` From 96e297ff6a1f68910180f8b24b2819e18d5db1cf Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Mon, 9 Sep 2019 08:56:14 -0700 Subject: [PATCH 02/30] Validation added --- .../config-action/config-action.component.ts | 9 +- .../configurator-ethernet-hub.component.html | 31 +++++++ .../configurator-ethernet-hub.component.ts | 83 +++++++++++++++++++ .../vpcs/configurator-vpcs.component.ts | 12 ++- 4 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.html create mode 100644 src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts diff --git a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts index 5d9d0974..43cd50cd 100644 --- a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts +++ b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts @@ -3,6 +3,7 @@ import { Server } from '../../../../../models/server'; import { Node } from '../../../../../cartography/models/node'; import { MatDialog, MatDialogRef } from '@angular/material'; import { ConfiguratorDialogVpcsComponent } from '../../../node-editors/configurator/vpcs/configurator-vpcs.component'; +import { ConfiguratorDialogEthernetHubComponent } from '../../../node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component'; @Component({ @@ -24,7 +25,7 @@ export class ConfigActionComponent { if (this.node.node_type === 'vpcs') { this.dialogRef = this.dialog.open(ConfiguratorDialogVpcsComponent, this.conf); } else if (this.node.node_type === 'ethernet_hub') { - + this.dialogRef = this.dialog.open(ConfiguratorDialogEthernetHubComponent, this.conf); } else if (this.node.node_type === 'ethernet_switch') { } else if (this.node.node_type === 'cloud') { @@ -43,11 +44,11 @@ export class ConfigActionComponent { } else if (this.node.node_type === 'nat') { - } else if (this.node.node_type === 'frame_relay_switch') { + } else if (this.node.node_type === 'frame_relay_switch') { - } else if (this.node.node_type === 'atm_switch') { + } else if (this.node.node_type === 'atm_switch') { - } else if (this.node.node_type === 'traceng') { + } else if (this.node.node_type === 'traceng') { } diff --git a/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.html b/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.html new file mode 100644 index 00000000..c60a7f67 --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.html @@ -0,0 +1,31 @@ +

Configurator for node {{node.name}}

+ + + +
+ + +
diff --git a/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts b/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts new file mode 100644 index 00000000..05966da7 --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts @@ -0,0 +1,83 @@ +import { Component, OnInit, Input } from "@angular/core"; +import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; +import { VpcsConfigurationService } from '../../../../../services/vpcs-configuration.service'; +import { Node } from '../../../../../cartography/models/node'; +import { Server } from '../../../../../models/server'; +import { NodeService } from '../../../../../services/node.service'; +import { ToasterService } from '../../../../../services/toaster.service'; +import { MatDialogRef } from '@angular/material'; + + +@Component({ + selector: 'app-configurator-ethernet-hub', + templateUrl: './configurator-ethernet-hub.component.html', + styleUrls: ['../configurator.component.scss'] +}) +export class ConfiguratorDialogEthernetHubComponent implements OnInit { + server: Server; + node: Node; + numberOfPorts: number; + inputForm: FormGroup; + consoleTypes: string[] = []; + categories = []; + + constructor( + public dialogRef: MatDialogRef, + public nodeService: NodeService, + private toasterService: ToasterService, + private formBuilder: FormBuilder, + private vpcsConfigurationService: VpcsConfigurationService + ) { + this.inputForm = this.formBuilder.group({ + name: new FormControl('', Validators.required) + }); + } + + ngOnInit() { + this.nodeService.getNode(this.server, this.node).subscribe((node: Node) => { + this.node = node; + this.getConfiguration(); + }) + } + + getConfiguration() { + this.consoleTypes = this.vpcsConfigurationService.getConsoleTypes(); + this.categories = this.vpcsConfigurationService.getCategories(); + } + + onSaveClick() { + if (this.inputForm.valid) { + for(let i=0; i { + this.toasterService.success(`Node ${this.node.name} updated.`); + this.onCancelClick(); + }); + } else { + this.toasterService.error(`Fill all required fields.`) + } + } + + onCancelClick() { + this.dialogRef.close(); + } +} diff --git a/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts index c2073860..042e60fd 100644 --- a/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts +++ b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts @@ -46,10 +46,14 @@ export class ConfiguratorDialogVpcsComponent implements OnInit { } onSaveClick() { - this.nodeService.updateNode(this.server, this.node).subscribe(() => { - this.toasterService.success(`Node ${this.node.name} updated.`); - this.onCancelClick(); - }); + if (this.inputForm.valid) { + this.nodeService.updateNode(this.server, this.node).subscribe(() => { + this.toasterService.success(`Node ${this.node.name} updated.`); + this.onCancelClick(); + }); + } else { + this.toasterService.error(`Fill all required fields.`); + } } onCancelClick() { From 0fe44b2235f801325d57e5b12917a66a00c02a8d Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Mon, 9 Sep 2019 09:33:10 -0700 Subject: [PATCH 03/30] Dialog for ethernet hubs added --- src/app/app.module.ts | 7 +++++-- src/app/cartography/models/node.ts | 10 ++++++++++ .../configurator-ethernet-hub.component.ts | 20 ++++--------------- src/app/services/node.service.ts | 3 ++- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index fbcdc4ff..dc540c2f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -213,6 +213,7 @@ import { ReloadNodeActionComponent } from './components/project-map/context-menu import { SuspendNodeActionComponent } from './components/project-map/context-menu/actions/suspend-node-action/suspend-node-action.component'; import { ConfigActionComponent } from './components/project-map/context-menu/actions/config-action/config-action.component'; import { ConfiguratorDialogVpcsComponent } from './components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component'; +import { ConfiguratorDialogEthernetHubComponent } from './components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -353,7 +354,8 @@ if (environment.production) { ReloadNodeActionComponent, SuspendNodeActionComponent, ConfigActionComponent, - ConfiguratorDialogVpcsComponent + ConfiguratorDialogVpcsComponent, + ConfiguratorDialogEthernetHubComponent ], imports: [ BrowserModule, @@ -454,7 +456,8 @@ if (environment.production) { InfoDialogComponent, ChangeSymbolDialogComponent, EditProjectDialogComponent, - ConfiguratorDialogVpcsComponent + ConfiguratorDialogVpcsComponent, + ConfiguratorDialogEthernetHubComponent ], bootstrap: [AppComponent] }) diff --git a/src/app/cartography/models/node.ts b/src/app/cartography/models/node.ts index 3478617f..358a1dcc 100644 --- a/src/app/cartography/models/node.ts +++ b/src/app/cartography/models/node.ts @@ -1,6 +1,15 @@ import { Label } from './label'; import { Port } from '../../models/port'; +export class PortsMapping { + name: string; + port_number: number; +} + +export class Properties { + ports_mapping: PortsMapping[]; +} + export class Node { command_line: string; compute_id: string; @@ -19,6 +28,7 @@ export class Node { port_segment_size: number; ports: Port[]; project_id: string; + properties: Properties; status: string; symbol: string; symbol_url: string; // @TODO: full URL to symbol, move to MapNode once converters are moved to app module diff --git a/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts b/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts index 05966da7..ebc74b47 100644 --- a/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts +++ b/src/app/components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component.ts @@ -36,6 +36,7 @@ export class ConfiguratorDialogEthernetHubComponent implements OnInit { ngOnInit() { this.nodeService.getNode(this.server, this.node).subscribe((node: Node) => { this.node = node; + this.numberOfPorts = this.node.ports.length; this.getConfiguration(); }) } @@ -47,27 +48,14 @@ export class ConfiguratorDialogEthernetHubComponent implements OnInit { onSaveClick() { if (this.inputForm.valid) { + this.node.properties.ports_mapping = []; for(let i=0; i { this.toasterService.success(`Node ${this.node.name} updated.`); this.onCancelClick(); diff --git a/src/app/services/node.service.ts b/src/app/services/node.service.ts index 9beb0d6f..c94bd3c5 100644 --- a/src/app/services/node.service.ts +++ b/src/app/services/node.service.ts @@ -89,7 +89,8 @@ export class NodeService { updateNode(server: Server, node: Node): Observable { return this.httpServer.put(server, `/projects/${node.project_id}/nodes/${node.node_id}`, { console_type: node.console_type, - name: node.name + name: node.name, + properties: node.properties }); } From bdf8e89dfa2f25bac215d7e0af1db3bf919fa360 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Tue, 10 Sep 2019 03:05:54 -0700 Subject: [PATCH 04/30] Support for ethernet switches --- src/app/app.module.ts | 9 ++- ...t-switches-template-details.component.html | 60 +---------------- ...net-switches-template-details.component.ts | 33 ++-------- .../common/ports/ports.component.html | 66 +++++++++++++++++++ .../common/ports/ports.component.scss | 0 .../common/ports/ports.component.spec.ts | 0 .../common/ports/ports.component.ts | 48 ++++++++++++++ .../config-action/config-action.component.ts | 3 +- .../configurator/configurator.component.scss | 20 ++++++ ...onfigurator-ethernet-switch.component.html | 35 ++++++++++ .../configurator-ethernet-switch.component.ts | 63 ++++++++++++++++++ .../vpcs/configurator-vpcs.component.ts | 2 - 12 files changed, 247 insertions(+), 92 deletions(-) create mode 100644 src/app/components/preferences/common/ports/ports.component.html create mode 100644 src/app/components/preferences/common/ports/ports.component.scss create mode 100644 src/app/components/preferences/common/ports/ports.component.spec.ts create mode 100644 src/app/components/preferences/common/ports/ports.component.ts create mode 100644 src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html create mode 100644 src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index dc540c2f..a094098b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -214,6 +214,8 @@ import { SuspendNodeActionComponent } from './components/project-map/context-men import { ConfigActionComponent } from './components/project-map/context-menu/actions/config-action/config-action.component'; import { ConfiguratorDialogVpcsComponent } from './components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component'; import { ConfiguratorDialogEthernetHubComponent } from './components/project-map/node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component'; +import { ConfiguratorDialogEthernetSwitchComponent } from './components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component'; +import { PortsComponent } from './components/preferences/common/ports/ports.component'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -355,7 +357,9 @@ if (environment.production) { SuspendNodeActionComponent, ConfigActionComponent, ConfiguratorDialogVpcsComponent, - ConfiguratorDialogEthernetHubComponent + ConfiguratorDialogEthernetHubComponent, + ConfiguratorDialogEthernetSwitchComponent, + PortsComponent ], imports: [ BrowserModule, @@ -457,7 +461,8 @@ if (environment.production) { ChangeSymbolDialogComponent, EditProjectDialogComponent, ConfiguratorDialogVpcsComponent, - ConfiguratorDialogEthernetHubComponent + ConfiguratorDialogEthernetHubComponent, + ConfiguratorDialogEthernetSwitchComponent ], bootstrap: [AppComponent] }) diff --git a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.html b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.html index f798570b..8089383b 100644 --- a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.html +++ b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.html @@ -57,69 +57,13 @@ - + Port settings - - - - - - - - - - - - - - - - - - - - - - - -
Port number {{element.port_number}} VLAN {{element.vlan}} Type {{element.type}} EtherType {{element.ethertype}}

- - - - - - - - - - {{type}} - - - - - - - {{type}} - - - - +
diff --git a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.ts b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.ts index f3a33a97..6ffd3415 100644 --- a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.ts +++ b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, OnInit, ViewChild } from "@angular/core"; import { ActivatedRoute, Router } from '@angular/router'; import { ServerService } from '../../../../../services/server.service'; import { Server } from '../../../../../models/server'; @@ -6,8 +6,8 @@ import { ToasterService } from '../../../../../services/toaster.service'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { BuiltInTemplatesService } from '../../../../../services/built-in-templates.service'; import { EthernetSwitchTemplate } from '../../../../../models/templates/ethernet-switch-template'; -import { PortsMappingEntity } from '../../../../../models/ethernetHub/ports-mapping-enity'; import { BuiltInTemplatesConfigurationService } from '../../../../../services/built-in-templates-configuration.service'; +import { PortsComponent } from '../../../common/ports/ports.component'; @Component({ @@ -16,20 +16,13 @@ import { BuiltInTemplatesConfigurationService } from '../../../../../services/bu styleUrls: ['./ethernet-switches-template-details.component.scss', '../../../preferences.component.scss'] }) export class EthernetSwitchesTemplateDetailsComponent implements OnInit { + @ViewChild(PortsComponent, {static: false}) portsComponent: PortsComponent; server: Server; ethernetSwitchTemplate: EthernetSwitchTemplate; inputForm: FormGroup; - ethernetPorts: PortsMappingEntity[] = []; - dataSource: PortsMappingEntity[] = []; - newPort: PortsMappingEntity; - isSymbolSelectionOpened: boolean = false; - categories = []; consoleTypes: string[] = []; - portTypes: string[] = []; - etherTypes: string[] = []; - displayedColumns: string[] = ['port_number', 'vlan', 'type', 'ethertype']; constructor( private route: ActivatedRoute, @@ -45,11 +38,6 @@ export class EthernetSwitchesTemplateDetailsComponent implements OnInit { defaultName: new FormControl('', Validators.required), symbol: new FormControl('', Validators.required) }); - - this.newPort = { - name: '', - port_number: 0, - }; } ngOnInit() { @@ -61,8 +49,6 @@ export class EthernetSwitchesTemplateDetailsComponent implements OnInit { this.getConfiguration(); this.builtInTemplatesService.getTemplate(this.server, template_id).subscribe((ethernetSwitchTemplate: EthernetSwitchTemplate) => { this.ethernetSwitchTemplate = ethernetSwitchTemplate; - this.ethernetPorts = this.ethernetSwitchTemplate.ports_mapping; - this.dataSource = this.ethernetSwitchTemplate.ports_mapping; }); }); } @@ -70,18 +56,6 @@ export class EthernetSwitchesTemplateDetailsComponent implements OnInit { getConfiguration() { this.categories = this.builtInTemplatesConfigurationService.getCategoriesForEthernetSwitches(); this.consoleTypes = this.builtInTemplatesConfigurationService.getConsoleTypesForEthernetSwitches(); - this.portTypes = this.builtInTemplatesConfigurationService.getPortTypesForEthernetSwitches(); - this.etherTypes = this.builtInTemplatesConfigurationService.getEtherTypesForEthernetSwitches(); - } - - onAdd() { - this.ethernetPorts.push(this.newPort); - this.dataSource = [...this.ethernetPorts]; - - this.newPort = { - name: '', - port_number: 0, - }; } goBack() { @@ -92,6 +66,7 @@ export class EthernetSwitchesTemplateDetailsComponent implements OnInit { if (this.inputForm.invalid) { this.toasterService.error(`Fill all required fields`); } else { + this.ethernetSwitchTemplate.ports_mapping = this.portsComponent.ethernetPorts; this.builtInTemplatesService.saveTemplate(this.server, this.ethernetSwitchTemplate).subscribe((ethernetSwitchTemplate: EthernetSwitchTemplate) => { this.toasterService.success("Changes saved"); }); diff --git a/src/app/components/preferences/common/ports/ports.component.html b/src/app/components/preferences/common/ports/ports.component.html new file mode 100644 index 00000000..2fcc2f00 --- /dev/null +++ b/src/app/components/preferences/common/ports/ports.component.html @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Port number {{element.port_number}} VLAN {{element.vlan}} Type {{element.type}} EtherType {{element.ethertype}} Actions + +

+ + + + + + + + + + {{type}} + + + + + + + {{type}} + + + + diff --git a/src/app/components/preferences/common/ports/ports.component.scss b/src/app/components/preferences/common/ports/ports.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/components/preferences/common/ports/ports.component.spec.ts b/src/app/components/preferences/common/ports/ports.component.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/app/components/preferences/common/ports/ports.component.ts b/src/app/components/preferences/common/ports/ports.component.ts new file mode 100644 index 00000000..efc2d393 --- /dev/null +++ b/src/app/components/preferences/common/ports/ports.component.ts @@ -0,0 +1,48 @@ +import { Component, OnInit, Input, Output, EventEmitter } from "@angular/core"; +import { Server } from '../../../../models/server'; +import { PortsMappingEntity } from '../../../../models/ethernetHub/ports-mapping-enity'; +import { BuiltInTemplatesConfigurationService } from '../../../../services/built-in-templates-configuration.service'; + + +@Component({ + selector: 'app-ports', + templateUrl: './ports.component.html', + styleUrls: ['../../preferences.component.scss'] +}) +export class PortsComponent implements OnInit { + @Input() ethernetPorts: PortsMappingEntity[] = []; + newPort: PortsMappingEntity = { + name: '', + port_number: 0, + }; + + portTypes: string[] = []; + etherTypes: string[] = []; + displayedColumns: string[] = ['port_number', 'vlan', 'type', 'ethertype', 'action']; + + constructor( + private builtInTemplatesConfigurationService: BuiltInTemplatesConfigurationService + ) {} + + ngOnInit() { + this.getConfiguration(); + } + + getConfiguration() { + this.etherTypes = this.builtInTemplatesConfigurationService.getEtherTypesForEthernetSwitches(); + this.portTypes = this.builtInTemplatesConfigurationService.getPortTypesForEthernetSwitches(); + } + + onAdd() { + this.ethernetPorts.push(this.newPort); + + this.newPort = { + name: '', + port_number: 0, + }; + } + + delete(port: PortsMappingEntity) { + this.ethernetPorts = this.ethernetPorts.filter(n => n !== port); + } +} diff --git a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts index 43cd50cd..c1bccc72 100644 --- a/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts +++ b/src/app/components/project-map/context-menu/actions/config-action/config-action.component.ts @@ -4,6 +4,7 @@ import { Node } from '../../../../../cartography/models/node'; import { MatDialog, MatDialogRef } from '@angular/material'; import { ConfiguratorDialogVpcsComponent } from '../../../node-editors/configurator/vpcs/configurator-vpcs.component'; import { ConfiguratorDialogEthernetHubComponent } from '../../../node-editors/configurator/ethernet_hub/configurator-ethernet-hub.component'; +import { ConfiguratorDialogEthernetSwitchComponent } from '../../../node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component'; @Component({ @@ -27,7 +28,7 @@ export class ConfigActionComponent { } else if (this.node.node_type === 'ethernet_hub') { this.dialogRef = this.dialog.open(ConfiguratorDialogEthernetHubComponent, this.conf); } else if (this.node.node_type === 'ethernet_switch') { - + this.dialogRef = this.dialog.open(ConfiguratorDialogEthernetSwitchComponent, this.conf); } else if (this.node.node_type === 'cloud') { } else if (this.node.node_type === 'dynamips') { diff --git a/src/app/components/project-map/node-editors/configurator/configurator.component.scss b/src/app/components/project-map/node-editors/configurator/configurator.component.scss index ae93f5c6..d914988c 100644 --- a/src/app/components/project-map/node-editors/configurator/configurator.component.scss +++ b/src/app/components/project-map/node-editors/configurator/configurator.component.scss @@ -5,3 +5,23 @@ .select { width: 100%; } + +.default-content { + max-height: 400px; + overflow-y: scroll; + scrollbar-color: darkgrey #263238; + scrollbar-width: thin; +} + +::-webkit-scrollbar { + width: 0.5em; +} + +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +::-webkit-scrollbar-thumb { + background-color: darkgrey; + outline: 1px solid #263238; +} diff --git a/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html b/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html new file mode 100644 index 00000000..900d1abd --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html @@ -0,0 +1,35 @@ +

Configurator for node {{node.name}}

+ + + +
+ + +
diff --git a/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.ts b/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.ts new file mode 100644 index 00000000..41e27483 --- /dev/null +++ b/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.ts @@ -0,0 +1,63 @@ +import { Component, OnInit, Input, ViewChild } from "@angular/core"; +import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; +import { Node } from '../../../../../cartography/models/node'; +import { Server } from '../../../../../models/server'; +import { NodeService } from '../../../../../services/node.service'; +import { ToasterService } from '../../../../../services/toaster.service'; +import { MatDialogRef } from '@angular/material'; +import { BuiltInTemplatesConfigurationService } from '../../../../../services/built-in-templates-configuration.service'; +import { PortsComponent } from '../../../../../components/preferences/common/ports/ports.component'; + + +@Component({ + selector: 'app-configurator-ethernet-switch', + templateUrl: './configurator-ethernet-switch.component.html', + styleUrls: ['../configurator.component.scss'] +}) +export class ConfiguratorDialogEthernetSwitchComponent implements OnInit { + @ViewChild(PortsComponent, {static: false}) portsComponent: PortsComponent; + server: Server; + node: Node; + + inputForm: FormGroup; + consoleTypes: string[] = []; + + constructor( + public dialogRef: MatDialogRef, + public nodeService: NodeService, + private toasterService: ToasterService, + private formBuilder: FormBuilder, + private ethernetSwitchesConfigurationService: BuiltInTemplatesConfigurationService + ) { + this.inputForm = this.formBuilder.group({ + name: new FormControl('', Validators.required) + }); + } + + ngOnInit() { + this.nodeService.getNode(this.server, this.node).subscribe((node: Node) => { + this.node = node; + this.getConfiguration(); + }) + } + + getConfiguration() { + this.consoleTypes = this.ethernetSwitchesConfigurationService.getConsoleTypesForEthernetSwitches(); + } + + onSaveClick() { + if (this.inputForm.valid) { + this.node.properties.ports_mapping = this.portsComponent.ethernetPorts; + this.nodeService.updateNode(this.server, this.node).subscribe(() => { + this.toasterService.success(`Node ${this.node.name} updated.`); + this.onCancelClick(); + }); + } else { + this.toasterService.error(`Fill all required fields.`); + } + } + + onCancelClick() { + this.dialogRef.close(); + } +} diff --git a/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts index 042e60fd..0ff0526b 100644 --- a/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts +++ b/src/app/components/project-map/node-editors/configurator/vpcs/configurator-vpcs.component.ts @@ -19,7 +19,6 @@ export class ConfiguratorDialogVpcsComponent implements OnInit { inputForm: FormGroup; consoleTypes: string[] = []; - categories = []; constructor( public dialogRef: MatDialogRef, @@ -42,7 +41,6 @@ export class ConfiguratorDialogVpcsComponent implements OnInit { getConfiguration() { this.consoleTypes = this.vpcsConfigurationService.getConsoleTypes(); - this.categories = this.vpcsConfigurationService.getCategories(); } onSaveClick() { From 32dc9e3c0750343ce9b78f9111c8865e9fde8958 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Tue, 10 Sep 2019 03:57:46 -0700 Subject: [PATCH 05/30] Update ethernet-switches-template-details.component.spec.ts --- .../ethernet-switches-template-details.component.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.spec.ts b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.spec.ts index 108d2f91..3eeef4f5 100644 --- a/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.spec.ts +++ b/src/app/components/preferences/built-in/ethernet-switches/ethernet-switches-template-details/ethernet-switches-template-details.component.spec.ts @@ -17,6 +17,7 @@ import { BuiltInTemplatesService } from '../../../../../services/built-in-templa import { EthernetSwitchTemplate } from '../../../../../models/templates/ethernet-switch-template'; import { EthernetSwitchesTemplateDetailsComponent } from './ethernet-switches-template-details.component'; import { BuiltInTemplatesConfigurationService } from '../../../../../services/built-in-templates-configuration.service'; +import { PortsComponent } from '../../../common/ports/ports.component'; export class MockedBuiltInTemplatesService { public getTemplate(server: Server, template_id: string) { @@ -68,6 +69,7 @@ describe('EthernetSwitchesTemplateDetailsComponent', () => { it('should call save template', () => { spyOn(mockedBuiltInTemplatesService, 'saveTemplate').and.returnValue(of({} as EthernetSwitchTemplate)); + component.portsComponent = {ethernetPorts: []} as PortsComponent; component.inputForm.controls['templateName'].setValue('template name'); component.inputForm.controls['defaultName'].setValue('default name'); component.inputForm.controls['symbol'].setValue('symbol'); @@ -102,7 +104,7 @@ describe('EthernetSwitchesTemplateDetailsComponent', () => { expect(mockedBuiltInTemplatesService.saveTemplate).not.toHaveBeenCalled(); }); - it('should call save template when symbol path is empty', () => { + it('should not call save template when symbol path is empty', () => { spyOn(mockedBuiltInTemplatesService, 'saveTemplate').and.returnValue(of({} as EthernetSwitchTemplate)); component.inputForm.controls['templateName'].setValue('template name'); component.inputForm.controls['defaultName'].setValue('default name'); From 9ab7616d891cf4f7941510abfe0ed1df355f5ab0 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Tue, 10 Sep 2019 04:07:08 -0700 Subject: [PATCH 06/30] Fix for configurator name --- .../configurator-ethernet-switch.component.html | 2 +- .../ethernet-switch/configurator-ethernet-switch.component.ts | 3 ++- .../ethernet_hub/configurator-ethernet-hub.component.html | 2 +- .../ethernet_hub/configurator-ethernet-hub.component.ts | 2 ++ .../configurator/vpcs/configurator-vpcs.component.html | 2 +- .../configurator/vpcs/configurator-vpcs.component.ts | 3 ++- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html b/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html index 900d1abd..826a0154 100644 --- a/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html +++ b/src/app/components/project-map/node-editors/configurator/ethernet-switch/configurator-ethernet-switch.component.html @@ -1,4 +1,4 @@ -

Configurator for node {{node.name}}

+

Configurator for node {{name}}