mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Add download for context data.
This commit is contained in:
parent
76e7d65017
commit
5dfaf51793
@ -33,7 +33,7 @@ class ResultsJSON {
|
||||
}
|
||||
|
||||
// function creates a unique and safe filename for the download
|
||||
createDownloadFilename() {
|
||||
createDownloadFilename(suffix) {
|
||||
let today;
|
||||
let currentDate;
|
||||
let currentTime;
|
||||
@ -48,36 +48,28 @@ class ResultsJSON {
|
||||
`${today.getUTCMinutes()}m` +
|
||||
`${today.getUTCSeconds()}s`;
|
||||
safeFilename = this.query.replace(/[^a-z0-9_-]/gi, "_");
|
||||
resultFilename = `UTC-${currentDate}_${currentTime}_${safeFilename}`;
|
||||
resultFilename = `UTC-${currentDate}_${currentTime}_${safeFilename}_${suffix}`;
|
||||
return resultFilename
|
||||
}
|
||||
|
||||
// Function to download data as Blob created from string
|
||||
// should be private but that is not yet a feature of javascript 08.04.2020
|
||||
download(downloadElem, dataStr, filename, type, filenameSlug) {
|
||||
let file;
|
||||
download(downloadElement, dataStr, filename, type, filenameSlug) {
|
||||
console.log("Start Download!");
|
||||
let file;
|
||||
filename += filenameSlug;
|
||||
file = new Blob([dataStr], {type: type});
|
||||
if (window.navigator.msSaveOrOpenBlob) {// IE10+
|
||||
window.navigator.msSaveOrOpenBlob(file, filename);
|
||||
}
|
||||
else { // Others
|
||||
var url = URL.createObjectURL(file);
|
||||
downloadElem.href = url;
|
||||
downloadElem.download = filename;
|
||||
}
|
||||
downloadElement.href = url;
|
||||
downloadElement.download = filename;
|
||||
}
|
||||
|
||||
// function to download the results as JSON
|
||||
downloadJSONRessource(resultFilename) {
|
||||
downloadJSONRessource(resultFilename, downloadData, downloadElement) {
|
||||
let dataStr;
|
||||
let downloadElement;
|
||||
// stringify JSON object for json download
|
||||
// use tabs to save some space
|
||||
dataStr = JSON.stringify(results.resultsJSON, undefined, "\t");
|
||||
// get downloadResultsElement
|
||||
downloadElement = document.getElementById("download-results-json");
|
||||
dataStr = JSON.stringify(downloadData, undefined, "\t");
|
||||
// start actual download
|
||||
this.download(downloadElement, dataStr, resultFilename, "text/json", ".json")
|
||||
}
|
||||
|
@ -210,6 +210,7 @@ class ResultsList extends List {
|
||||
let uniqueS;
|
||||
|
||||
this.contextData = response.payload;
|
||||
this.contextData["query"] = results.resultsJSON.query;
|
||||
contextResultsElement = document.getElementById("context-results");
|
||||
modalExpertModeSwitchElement = document.getElementById("inspect-display-options-form-expert_mode_inspect");
|
||||
highlightSentencesSwitchElement = document.getElementById("inspect-display-options-form-highlight_sentences");
|
||||
|
@ -260,7 +260,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#!" class="left waves-effect waves-light btn disabled">Export</a>
|
||||
<a id="inspect-download-context" class="left waves-effect waves-light btn">
|
||||
Export Context
|
||||
<i class="material-icons right">file_download</i>
|
||||
</a>
|
||||
<a href="#!" class="modal-close waves-effect waves-light red btn">Close</a>
|
||||
</div>
|
||||
</div>
|
||||
@ -300,6 +303,7 @@
|
||||
let displayOptionsData; // Getting form data from display options
|
||||
let displayOptionsFormElement; // Form holding the display informations
|
||||
let downloadResultsJSONElement; // button for downloading results as JSON
|
||||
let downloadInspectContextElement; // button for downloading inspect context
|
||||
let exportModal; // Download options modal
|
||||
let firstPageElement; // first page element of resultsList pagination
|
||||
let hitsPerPageInputElement;
|
||||
@ -444,11 +448,19 @@
|
||||
queryResultsExportElement.onclick = () => {
|
||||
exportModal.open();
|
||||
}
|
||||
|
||||
// add onclick to download JSON button and download the file
|
||||
downloadResultsJSONElement = document.getElementById("download-results-json")
|
||||
downloadResultsJSONElement.onclick = () => {
|
||||
let filename = results.resultsJSON.createDownloadFilename();
|
||||
results.resultsJSON.downloadJSONRessource(filename)};
|
||||
let filename = results.resultsJSON.createDownloadFilename("matches");
|
||||
results.resultsJSON.downloadJSONRessource(filename, results.resultsJSON, downloadResultsJSONElement
|
||||
)};
|
||||
|
||||
// add onclick to download JSON button and download the file
|
||||
downloadInspectContextElement = document.getElementById("inspect-download-context")
|
||||
downloadInspectContextElement.onclick = () => {
|
||||
let filename = results.resultsJSON.createDownloadFilename("context");
|
||||
console.log(filename);
|
||||
results.resultsJSON.downloadJSONRessource(filename, results.resultsList.contextData, downloadInspectContextElement);
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user