mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-23 08:55:32 +00:00
Import/export buttons added
This commit is contained in:
@ -40,11 +40,19 @@
|
|||||||
<mat-menu #mainMenu="matMenu" [overlapTrigger]="false">
|
<mat-menu #mainMenu="matMenu" [overlapTrigger]="false">
|
||||||
<button mat-menu-item [routerLink]="['/server', server.id, 'projects']">
|
<button mat-menu-item [routerLink]="['/server', server.id, 'projects']">
|
||||||
<mat-icon>work</mat-icon>
|
<mat-icon>work</mat-icon>
|
||||||
<span>Projects</span>
|
<span>Go to projects</span>
|
||||||
</button>
|
</button>
|
||||||
<button mat-menu-item [routerLink]="['/servers']">
|
<button mat-menu-item [routerLink]="['/servers']">
|
||||||
<mat-icon>developer_board</mat-icon>
|
<mat-icon>developer_board</mat-icon>
|
||||||
<span>Servers</span>
|
<span>Go to servers</span>
|
||||||
|
</button>
|
||||||
|
<button mat-menu-item (click)="exportProject()">
|
||||||
|
<mat-icon>call_made</mat-icon>
|
||||||
|
<span>Export portable project</span>
|
||||||
|
</button>
|
||||||
|
<button mat-menu-item (click)="importProject()">
|
||||||
|
<mat-icon>call_received</mat-icon>
|
||||||
|
<span>Import portable project</span>
|
||||||
</button>
|
</button>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
||||||
|
|
||||||
import { Observable, Subject, Subscription, from } from 'rxjs';
|
import { Observable, Subject, Subscription, from } from 'rxjs';
|
||||||
import { webSocket } from 'rxjs/webSocket';
|
import { webSocket } from 'rxjs/webSocket';
|
||||||
@ -51,6 +51,8 @@ import { LabelWidget } from '../../cartography/widgets/label';
|
|||||||
import { MapLinkNodeToLinkNodeConverter } from '../../cartography/converters/map/map-link-node-to-link-node-converter';
|
import { MapLinkNodeToLinkNodeConverter } from '../../cartography/converters/map/map-link-node-to-link-node-converter';
|
||||||
import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.component';
|
import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.component';
|
||||||
import { ToasterService } from '../../services/toaster.service';
|
import { ToasterService } from '../../services/toaster.service';
|
||||||
|
import { ImportProjectDialogComponent } from '../projects/import-project-dialog/import-project-dialog.component';
|
||||||
|
import { MatDialog } from '@angular/material';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -115,7 +117,9 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
private movingEventSource: MovingEventSource,
|
private movingEventSource: MovingEventSource,
|
||||||
private mapScaleService: MapScaleService,
|
private mapScaleService: MapScaleService,
|
||||||
private nodeCreatedLabelStylesFixer: NodeCreatedLabelStylesFixer,
|
private nodeCreatedLabelStylesFixer: NodeCreatedLabelStylesFixer,
|
||||||
private toasterService: ToasterService
|
private toasterService: ToasterService,
|
||||||
|
private dialog: MatDialog,
|
||||||
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -387,6 +391,30 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
this.mapScaleService.resetToDefault();
|
this.mapScaleService.resetToDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importProject() {
|
||||||
|
let uuid: string = '';
|
||||||
|
const dialogRef = this.dialog.open(ImportProjectDialogComponent, {
|
||||||
|
width: '400px',
|
||||||
|
autoFocus: false
|
||||||
|
});
|
||||||
|
let instance = dialogRef.componentInstance;
|
||||||
|
instance.server = this.server;
|
||||||
|
const subscription = dialogRef.componentInstance.onImportProject.subscribe((projectId: string) => {
|
||||||
|
uuid = projectId;
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogRef.afterClosed().subscribe(() => {
|
||||||
|
subscription.unsubscribe();
|
||||||
|
this.projectService.open(this.server, uuid).subscribe(() => {
|
||||||
|
this.router.navigate(['/server', this.server.id, 'project', uuid]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exportProject() {
|
||||||
|
window.location.href = `http://${this.server.host}:${this.server.port}/v2/projects/${this.project.project_id}/export`;
|
||||||
|
}
|
||||||
|
|
||||||
public uploadImageFile(event) {
|
public uploadImageFile(event) {
|
||||||
this.readImageFile(event.target);
|
this.readImageFile(event.target);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit, Inject } from '@angular/core';
|
import { Component, OnInit, Inject, EventEmitter } from '@angular/core';
|
||||||
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material';
|
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material';
|
||||||
import { FileUploader, ParsedResponseHeaders, FileItem } from 'ng2-file-upload';
|
import { FileUploader, ParsedResponseHeaders, FileItem } from 'ng2-file-upload';
|
||||||
import { Server } from '../../../models/server';
|
import { Server } from '../../../models/server';
|
||||||
@ -26,6 +26,8 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
projectNameForm: FormGroup;
|
projectNameForm: FormGroup;
|
||||||
submitted: boolean = false;
|
submitted: boolean = false;
|
||||||
isFirstStepCompleted: boolean = false;
|
isFirstStepCompleted: boolean = false;
|
||||||
|
uuid: string;
|
||||||
|
onImportProject = new EventEmitter<string>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
@ -58,6 +60,7 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
status: number,
|
status: number,
|
||||||
headers: ParsedResponseHeaders
|
headers: ParsedResponseHeaders
|
||||||
) => {
|
) => {
|
||||||
|
this.onImportProject.emit(this.uuid);
|
||||||
this.resultMessage = 'Project was imported succesfully!';
|
this.resultMessage = 'Project was imported succesfully!';
|
||||||
this.isFinishEnabled = true;
|
this.isFinishEnabled = true;
|
||||||
};
|
};
|
||||||
@ -138,7 +141,8 @@ export class ImportProjectDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepareUploadPath(): string {
|
prepareUploadPath(): string {
|
||||||
|
this.uuid = uuid();
|
||||||
const projectName = this.projectNameForm.controls['projectName'].value;
|
const projectName = this.projectNameForm.controls['projectName'].value;
|
||||||
return `http://${this.server.host}:${this.server.port}/v2/projects/${uuid()}/import?name=${projectName}`;
|
return `http://${this.server.host}:${this.server.port}/v2/projects/${this.uuid}/import?name=${projectName}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,10 @@ export class ProjectService {
|
|||||||
return this.httpServer.delete(server, `/projects/${project_id}`);
|
return this.httpServer.delete(server, `/projects/${project_id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export(server: Server, project_id: string): Observable<any> {
|
||||||
|
return this.httpServer.get(server, `/projects/${project_id}/export`)
|
||||||
|
}
|
||||||
|
|
||||||
notificationsPath(server: Server, project_id: string): string {
|
notificationsPath(server: Server, project_id: string): string {
|
||||||
return `ws://${server.host}:${server.port}/v2/projects/${project_id}/notifications/ws`;
|
return `ws://${server.host}:${server.port}/v2/projects/${project_id}/notifications/ws`;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user