mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-20 21:43:06 +00:00
Add window.location.assign() for file downloading.
This commit is contained in:
parent
7398c07c6b
commit
5cc45a39ca
@ -7,7 +7,7 @@
|
||||
<h1 mat-dialog-title>Export Project</h1>
|
||||
</div>
|
||||
<div class="col-md-2 txt-align">
|
||||
<button mat-button class="close-btn" (click)="dialogRef.close()">
|
||||
<button mat-button type="button" class="close-btn" (click)="dialogRef.close()">
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
@ -1,12 +1,9 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { of } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Project } from '../../models/project';
|
||||
import { Server } from '../../models/server';
|
||||
import { ProjectService } from '../../services/project.service';
|
||||
import { ToasterService } from '../../services/toaster.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-export-portable-project',
|
||||
@ -28,7 +25,6 @@ export class ExportPortableProjectComponent implements OnInit {
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<ExportPortableProjectComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private toasterService: ToasterService,
|
||||
private projectService: ProjectService,
|
||||
private _fb: FormBuilder
|
||||
) {}
|
||||
@ -69,22 +65,7 @@ export class ExportPortableProjectComponent implements OnInit {
|
||||
exportPortableProject() {
|
||||
this.isExport = true;
|
||||
this.export_project_form.value.compression = this.export_project_form.value.compression.value ?? 'zstd';
|
||||
const object = this.projectService
|
||||
.exportPortableProject(this.server, this.project.project_id, this.export_project_form.value)
|
||||
.pipe(catchError((error) => of(error)));
|
||||
object.subscribe((res) => {
|
||||
const url = window.URL.createObjectURL(new Blob([res]));
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', this.fileName);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
console.log(document.cookie.search(this.fileName));
|
||||
this.isExport = false;
|
||||
setTimeout(() => {
|
||||
window.location.assign(this.projectService.getexportPortableProjectPath(this.server, this.project.project_id, this.export_project_form.value))
|
||||
this.dialogRef.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -136,18 +136,12 @@ export class ProjectService {
|
||||
return this.compression_level_default_value;
|
||||
};
|
||||
|
||||
exportPortableProject(server:Server, project_id: string,formData:any={}) {
|
||||
if (formData.compression_level != null && formData.compression_level !='') {
|
||||
return this.httpServer.getBlob(server,`/projects/${project_id}/export?include_snapshots=${formData.include_snapshots}&include_images=${formData.include_base_image}&reset_mac_addresses=${formData.reset_mac_address}&compression=${formData.compression}&compression_level=${formData.compression_level}`)
|
||||
} else {
|
||||
return this.httpServer.getBlob(server,`/projects/${project_id}/export?include_snapshots=${formData.include_snapshots}&include_images=${formData.include_base_image}&reset_mac_addresses=${formData.reset_mac_address}&compression=${formData.compression}`)
|
||||
}
|
||||
}
|
||||
|
||||
getexportPortableProjectPath(server:Server, project_id: string,formData:any={}) {
|
||||
if (formData.compression_level != null && formData.compression_level !='') {
|
||||
return `${server.protocol}//${server.host}:${server.port}/${environment.current_version}/projects/${project_id}/export?include_snapshots=${formData.include_snapshots}&include_images=${formData.include_base_image}&reset_mac_addresses=${formData.reset_mac_address}&compression=${formData.compression}&compression_level=${formData.compression_level}`;
|
||||
return `${server.protocol}//${server.host}:${server.port}/${environment.current_version}/projects/${project_id}/export?include_snapshots=${formData.include_snapshots}&include_images=${formData.include_base_image}&reset_mac_addresses=${formData.reset_mac_address}&compression=${formData.compression}&compression_level=${formData.compression_level}&token=${server.authToken}`;
|
||||
} else {
|
||||
return `${server.protocol}//${server.host}:${server.port}/${environment.current_version}/projects/${project_id}/export?include_snapshots=${formData.include_snapshots}&include_images=${formData.include_base_image}&reset_mac_addresses=${formData.reset_mac_address}&compression=${formData.compression}`;
|
||||
return `${server.protocol}//${server.host}:${server.port}/${environment.current_version}/projects/${project_id}/export?include_snapshots=${formData.include_snapshots}&include_images=${formData.include_base_image}&reset_mac_addresses=${formData.reset_mac_address}&compression=${formData.compression}&token=${server.authToken}`;
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user