mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add specific page for download
This commit is contained in:
parent
8e9b94898f
commit
bf12046afa
@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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 ]
|
@ -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
|
||||
|
||||
|
85
Resources/views/Export/download.html.twig
Normal file
85
Resources/views/Export/download.html.twig
Normal 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 %}
|
Loading…
x
Reference in New Issue
Block a user