Initial implementation added

This commit is contained in:
Piotr Pekala 2019-11-18 04:25:54 -08:00
parent ed9ca9ed03
commit 01d2fc2d43
4 changed files with 33 additions and 8 deletions

View File

@ -1,4 +1,10 @@
<button mat-menu-item (click)="importConfig()">
<input
type="file"
accept=".txt, .vpc"
class="non-visible"
#file
(change)="importConfig($event)"/>
<button mat-menu-item (click)="file.click()">
<mat-icon>call_received</mat-icon>
<span>Import config</span>
</button>

View File

@ -0,0 +1,3 @@
.non-visible {
display: none;
}

View File

@ -2,18 +2,34 @@ import { Component, Input } from '@angular/core';
import { Node } from '../../../../../cartography/models/node';
import { NodeService } from '../../../../../services/node.service';
import { Server } from '../../../../../models/server';
import { ToasterService } from '../../../../../services/toaster.service';
@Component({
selector: 'app-import-config-action',
templateUrl: './import-config-action.component.html'
templateUrl: './import-config-action.component.html',
styleUrls: ['./import-config-action.component.scss']
})
export class ImportConfigActionComponent {
@Input() server: Server;
@Input() node: Node;
constructor() {}
constructor(
private nodeService: NodeService,
private toasterService: ToasterService
) {}
importConfig() {
//needs implementation
importConfig(event) {
let file: File = event.target.files[0];
let fileReader: FileReader = new FileReader();
fileReader.onload = (e) => {
let content: string | ArrayBuffer = fileReader.result;
if (typeof content !== 'string'){
content = content.toString();
}
this.nodeService.saveConfiguration(this.server, this.node, content).subscribe(() => {
this.toasterService.success(`Configuration for node ${this.node.name} imported.`);
});
};
fileReader.readAsText(file);
}
}

View File

@ -59,14 +59,14 @@
[project]="project"
[node]="nodes[0]"
></app-edit-config-action>
<app-export-config-action *ngIf="nodes.length===1 && nodes[0].node_type==='vpcs'"
<app-export-config-action *ngIf="nodes.length===1 && (nodes[0].node_type==='vpcs' || nodes[0].node_type==='iou' || nodes[0].node_type==='dynamips')"
[server]="server"
[node]="nodes[0]"
></app-export-config-action>
<!-- <app-import-config-action *ngIf="nodes.length===1"
<app-import-config-action *ngIf="nodes.length===1 && (nodes[0].node_type==='vpcs' || nodes[0].node_type==='iou' || nodes[0].node_type==='dynamips')"
[server]="server"
[node]="nodes[0]"
></app-import-config-action> -->
></app-import-config-action>
<app-move-layer-up-action
*ngIf="!projectService.isReadOnly(project) && (drawings.length || nodes.length)"
[server]="server"