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> <mat-icon>call_received</mat-icon>
<span>Import config</span> <span>Import config</span>
</button> </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 { Node } from '../../../../../cartography/models/node';
import { NodeService } from '../../../../../services/node.service'; import { NodeService } from '../../../../../services/node.service';
import { Server } from '../../../../../models/server'; import { Server } from '../../../../../models/server';
import { ToasterService } from '../../../../../services/toaster.service';
@Component({ @Component({
selector: 'app-import-config-action', 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 { export class ImportConfigActionComponent {
@Input() server: Server; @Input() server: Server;
@Input() node: Node; @Input() node: Node;
constructor() {} constructor(
private nodeService: NodeService,
private toasterService: ToasterService
) {}
importConfig() { importConfig(event) {
//needs implementation 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" [project]="project"
[node]="nodes[0]" [node]="nodes[0]"
></app-edit-config-action> ></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" [server]="server"
[node]="nodes[0]" [node]="nodes[0]"
></app-export-config-action> ></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" [server]="server"
[node]="nodes[0]" [node]="nodes[0]"
></app-import-config-action> --> ></app-import-config-action>
<app-move-layer-up-action <app-move-layer-up-action
*ngIf="!projectService.isReadOnly(project) && (drawings.length || nodes.length)" *ngIf="!projectService.isReadOnly(project) && (drawings.length || nodes.length)"
[server]="server" [server]="server"