Commit 0e7ad39b authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat(csv export): Add a button to export the query result as CSV content

parent 1ab132c64d8a
......@@ -92,6 +92,7 @@
</div>
</div>
<div class="row justify-content-center">
<button class="btn btn-primary" id="csv-export-button" disabled>Télécharger en CSV</button>
<div class="col-md-11">
<div id="yasr"></div>
</div>
......@@ -316,12 +317,19 @@
.replace(/>/g, "&gt;")
);
yasqe.setValue(queryString);
if(queryString.length === 0) {
$("#csv-export-button").prop("disabled", true);
} else {
$("#csv-export-button").prop("disabled", false);
}
yasqe.query();
},
});
});
var yasqe = YASQE.fromTextArea(document.getElementById("yasqe"), {
persistencyExpire: 0,
sparql: {
showQueryButton: true,
endpoint: $("#endpoint").text(),
......@@ -339,6 +347,15 @@
// link yasqe and yasr
yasqe.options.sparql.callbacks.complete = yasr.setResponse;
document.getElementById("csv-export-button").onclick = () => {
const query = yasqe.getValue().replace("LIMIT 5000", "");
const endpoint = $("#endpoint").text();
const url = endpoint + "?query=" + encodeURIComponent(query) + "&format=text/csv";
var win = window.open(url, '_blank');
win.focus();
};
</script>
</body>
</html>
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