Commit 09deae39 authored by ext.sopra.ncastejon's avatar ext.sopra.ncastejon
Browse files

Rollback the download button to the preivous version.

parent 89037124
This diff is collapsed.
......@@ -82,10 +82,11 @@
height: 3.5rem;
flex-grow: 1;
margin-top: 0.5rem;
border-color: $grey-super-light-color;
@media screen and (min-width: $tablet) {
height: 2.5rem;
width: 2.5rem;
height: 2.75rem;
width: 2.75rem;
margin-top: 0;
flex-grow: 0;
}
......
import { Component, HostListener, Input, OnInit } from '@angular/core';
import { geosource } from '../../../../i18n/traductions';
import { saveAs } from 'file-saver';
import { geosource, notificationMessages } from '../../../../i18n/traductions';
import { NotificationService } from '../../../core/services';
@Component({
selector: 'app-download-button',
......@@ -29,37 +31,50 @@ export class DownloadButtonComponent implements OnInit {
abortMessage: string = geosource.downloads.abort;
downloadMessage: string = geosource.downloads.download;
constructor() { }
constructor(
private _notificationService: NotificationService,
) { }
ngOnInit() {
this.controller = new AbortController();
this.signal = this.controller.signal;
}
// Temporary: put back the old download method before we can use a proxy to pass credentials
download() {
this.loading = true;
fetch(this.url, { signal: this.signal }).then((response) => {
// To allow the download, get the repsons as a blob
return response.blob();
})
.then((blob) => {
// Create a temporary link and click on it to launch the blob download
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.rel = 'noopener';
a.download = this.fileName;
document.body.appendChild(a); // append the element to the dom -> otherwise it will not work in firefox
a.click();
a.remove();
this.loading = false;
clearTimeout(this.timeOut); // If the download is under 2000ms, we clear the ongoing timeout
})
.catch((err) => {
console.log('The fetch could not succeeded', err.message);
});
saveAs(this.url, this.fileName);
this._notificationService.notify(
{
type: 'success',
message: notificationMessages.general.startDownload,
},
);
}
// download() {
// this.loading = true;
// fetch(this.url, { signal: this.signal }).then((response) => {
// // To allow the download, get the repsons as a blob
// return response.blob();
// })
// .then((blob) => {
// // Create a temporary link and click on it to launch the blob download
// const url = window.URL.createObjectURL(blob);
// const a = document.createElement('a');
// a.href = url;
// a.rel = 'noopener';
// a.download = this.fileName;
// document.body.appendChild(a); // append the element to the dom -> otherwise it will not work in firefox
// a.click();
// a.remove();
// this.loading = false;
// clearTimeout(this.timeOut); // If the download is under 2000ms, we clear the ongoing timeout
// })
// .catch((err) => {
// console.log('The fetch could not succeeded', err.message);
// });
// }
abortDownload() {
this.controller.abort();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment