Support for editing VPCS config files

This commit is contained in:
Piotr Pekala 2019-07-30 07:21:55 -07:00
parent d2271f0421
commit 753649a321
8 changed files with 121 additions and 2 deletions

View File

@ -191,6 +191,8 @@ import { DuplicateActionComponent } from './components/project-map/context-menu/
import { MapSettingService } from './services/mapsettings.service';
import { ProjectMapMenuComponent } from './components/project-map/project-map-menu/project-map-menu.component';
import { HelpComponent } from './components/help/help.component';
import { ConfigEditorDialogComponent } from './components/project-map/node-editors/config-editor/config-editor.component';
import { EditConfigActionComponent } from './components/project-map/context-menu/actions/edit-config/edit-config-action.component';
if (environment.production) {
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
@ -312,7 +314,9 @@ if (environment.production) {
ConsoleComponent,
NodesMenuComponent,
ProjectMapMenuComponent,
HelpComponent
HelpComponent,
ConfigEditorDialogComponent,
EditConfigActionComponent
],
imports: [
BrowserModule,
@ -404,7 +408,8 @@ if (environment.production) {
SymbolsComponent,
DeleteConfirmationDialogComponent,
HelpDialogComponent,
StartCaptureDialogComponent
StartCaptureDialogComponent,
ConfigEditorDialogComponent
],
bootstrap: [AppComponent]
})

View File

@ -0,0 +1,4 @@
<button mat-menu-item (click)="editConfig()">
<mat-icon>settings</mat-icon>
<span>Edit config</span>
</button>

View File

@ -0,0 +1,30 @@
import { Component, Input } from '@angular/core';
import { Node } from '../../../../../cartography/models/node';
import { Project } from '../../../../../models/project';
import { Server } from '../../../../../models/server';
import { ConfigEditorDialogComponent } from '../../../node-editors/config-editor/config-editor.component';
import { MatDialog } from '@angular/material';
@Component({
selector: 'app-edit-config-action',
templateUrl: './edit-config-action.component.html'
})
export class EditConfigActionComponent {
@Input() server: Server;
@Input() project: Project;
@Input() node: Node;
constructor(private dialog: MatDialog) {}
editConfig() {
const dialogRef = this.dialog.open(ConfigEditorDialogComponent, {
width: '600px',
height: '500px',
autoFocus: false
});
let instance = dialogRef.componentInstance;
instance.server = this.server;
instance.project = this.project;
instance.node = this.node;
}
}

View File

@ -32,6 +32,11 @@
[link]="links[0]"
[linkNode]="linkNodes[0]"
></app-edit-text-action>
<app-edit-config-action *ngIf="nodes.length === 1"
[server]="server"
[project]="project"
[node]="nodes[0]"
></app-edit-config-action>
<app-move-layer-up-action
*ngIf="!projectService.isReadOnly(project) && (drawings.length || nodes.length) && labels.length===0"
[server]="server"

View File

@ -0,0 +1,10 @@
<h1 mat-dialog-title>Configuration for node {{node.name}}</h1>
<div class="modal-form-container">
<textarea #textArea id="textArea" class="textArea" [(ngModel)]="config"></textarea>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onCancelClick()" color="accent">Cancel</button>
<button mat-button (click)="onSaveClick()" tabindex="2" mat-raised-button color="primary">Apply</button>
</div>

View File

@ -0,0 +1,4 @@
.textArea {
width: 100%;
height: 350px;
}

View File

@ -0,0 +1,43 @@
import { Component, OnInit } from '@angular/core';
import { Node } from '../../../../cartography/models/node';
import { Project } from '../../../../models/project';
import { Server } from '../../../../models/server';
import { MatDialogRef } from '@angular/material';
import { NodeService } from '../../../../services/node.service';
import { ToasterService } from '../../../../services/toaster.service';
@Component({
selector: 'app-config-editor',
templateUrl: './config-editor.component.html',
styleUrls: ['./config-editor.component.scss']
})
export class ConfigEditorDialogComponent implements OnInit {
server: Server;
project: Project;
node: Node;
config: any;
constructor(
public dialogRef: MatDialogRef<ConfigEditorDialogComponent>,
public nodeService: NodeService,
private toasterService: ToasterService
) {}
ngOnInit() {
this.nodeService.getConfiguration(this.server, this.node).subscribe((config: any) => {
this.config = config;
});
}
onSaveClick() {
this.nodeService.saveConfiguration(this.server, this.node, this.config).subscribe((response) => {
this.dialogRef.close();
this.toasterService.success(`Configuration for node ${this.node.name} saved.`);
});
}
onCancelClick() {
this.dialogRef.close();
}
}

View File

@ -84,4 +84,22 @@ export class NodeService {
"z": node.z
});
}
getConfiguration(server: Server, node: Node) {
let urlPath: string = `/projects/${node.project_id}/nodes/${node.node_id}`
if (node.node_type === 'vpcs') {
urlPath += '/files/startup.vpc';
return this.httpServer.get(server, urlPath, { responseType: 'text' as 'json'});
}
}
saveConfiguration(server: Server, node: Node, configuration: string) {
let urlPath: string = `/projects/${node.project_id}/nodes/${node.node_id}`
if (node.node_type === 'vpcs') {
urlPath += '/files/startup.vpc';
return this.httpServer.post(server, urlPath, configuration);
}
}
}