mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-20 17:52:46 +00:00
Dialog for im porting private config added
This commit is contained in:
parent
8ca4eabe22
commit
ff5d79f38f
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user