add specific page for download

This commit is contained in:
Julien Fastré 2017-04-19 00:30:36 +02:00
parent 8e9b94898f
commit bf12046afa
4 changed files with 103 additions and 1 deletions

View File

@ -374,7 +374,7 @@ class ExportController extends Controller
);
unset($redirectParameters['_token']);
return $this->redirectToRoute('chill_main_export_generate',
return $this->redirectToRoute('chill_main_export_download',
$redirectParameters);
}
@ -410,4 +410,11 @@ class ExportController extends Controller
return $r;
}
public function downloadResultAction(Request $request, $alias)
{
return $this->render("ChillMainBundle:Export:download.html.twig", [
'alias' => $alias
]);
}
}

View File

@ -16,3 +16,8 @@ chill_main_export_generate:
path: /generate/{alias}
defaults: { _controller: ChillMainBundle:Export:generate }
methods: [GET]
chill_main_export_download:
path: /download/{alias}
defaults: { _controller: ChillMainBundle:Export:downloadResult }
methods: [ GET ]

View File

@ -142,6 +142,11 @@ Go to formatter options: Vers les options de mise en forme
Generate the report: Générer le rapport
No options availables. Your report is fully configured.: Pas d'options disponibles. Votre rapport est déjà configuré.
#export download
Download export: Téléchargement du rapport
Waiting for your report: En attente de votre rapport
Download your report: Télécharger votre rapport
Problem during download: Problème durant le téléchargement
# sans valeur
without data: sans valeur

View File

@ -0,0 +1,85 @@
{#
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
<info@champs-libres.coop> / <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "ChillMainBundle::layoutWithVerticalMenu.html.twig" %}
{% block title "Download export"|trans %}
{% block js %}
<script type="text/javascript">
window.addEventListener("DOMContentLoaded", function(e) {
var url = "{{ path('chill_main_export_generate', { 'alias' : alias } ) }}",
query = window.location.search,
container = document.querySelector("#download_container"),
header_content_type
;
window.fetch(url+query, { credentials: 'same-origin' })
.then(function(response) {
if (!response.ok) {
throw Error(response.statusText);
}
header_content_type = response.headers.get("Content-Type");
return response.blob();
}).then(function(blob) {
var content = URL.createObjectURL(blob),
link = document.createElement("a"),
suffix_file;
switch (header_content_type) {
case 'application/vnd.oasis.opendocument.spreadsheet':
suffix_file = '.ods';
break;
case 'text/csv':
suffix_file = '.csv';
break;
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
suffix_file = '.xlsx';
break;
default:
suffix_file = '';
}
link.appendChild(document.createTextNode("{{ "Download your report"|trans }}"));
link.classList.add("sc-button", "btn-action");
link.href = content;
link.download = "{{ alias }}"+suffix_file;
let waiting_text = container.querySelector("#waiting_text");
container.removeChild(waiting_text);
container.appendChild(link);
}).catch(function(error) {
var problem_text =
document.createTextNode("{{ "Problem during download"|trans }}");
container
.replaceChild(problem_text, container.firstChild);
})
;
});
</script>
{% endblock %}
{% block layout_wvm_content %}
<h1>{{ "Download export"|trans }}</h1>
<div id="download_container"><span id="waiting_text">{{ "Waiting for your report"|trans }}...</span></div>
{% endblock %}