Dialog for im porting private config added

This commit is contained in:
Piotr Pekala 2019-11-18 07:21:17 -08:00
parent 8ca4eabe22
commit ff5d79f38f
2 changed files with 36 additions and 7 deletions

View File

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

View File

@ -1,8 +1,10 @@
import { Component, Input } from '@angular/core';
import { Component, Input, ViewChild, ElementRef } 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';
import { MatDialog } from '@angular/material';
import { ConfigDialogComponent } from '../../dialogs/config-dialog/config-dialog.component';
@Component({
selector: 'app-import-config-action',
@ -12,12 +14,32 @@ import { ToasterService } from '../../../../../services/toaster.service';
export class ImportConfigActionComponent {
@Input() server: Server;
@Input() node: Node;
@ViewChild('fileInput', {static: false}) fileInput: ElementRef;
configType: string;
constructor(
private nodeService: NodeService,
private toasterService: ToasterService
private toasterService: ToasterService,
private dialog: MatDialog
) {}
triggerClick() {
if (this.node.node_type !== 'vpcs') {
const dialogRef = this.dialog.open(ConfigDialogComponent, {
width: '500px',
autoFocus: false
});
let instance = dialogRef.componentInstance;
dialogRef.afterClosed().subscribe((configType: string) => {
this.configType = configType;
this.fileInput.nativeElement.click();
});
} else {
this.configType = 'startup-config';
this.fileInput.nativeElement.click();
}
}
importConfig(event) {
let file: File = event.target.files[0];
let fileReader: FileReader = new FileReader();
@ -26,9 +48,16 @@ export class ImportConfigActionComponent {
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.`);
});
if (this.configType === 'startup-config') {
this.nodeService.saveConfiguration(this.server, this.node, content).subscribe(() => {
this.toasterService.success(`Configuration for node ${this.node.name} imported.`);
});
} else if (this.configType === 'private-config') {
this.nodeService.savePrivateConfiguration(this.server, this.node, content).subscribe(() => {
this.toasterService.success(`Configuration for node ${this.node.name} imported.`);
});
}
};
fileReader.readAsText(file);
}