diff --git a/app/static/js/nopaque.Results.js b/app/static/js/nopaque.Results.js index f265728f..2afbc917 100644 --- a/app/static/js/nopaque.Results.js +++ b/app/static/js/nopaque.Results.js @@ -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") } diff --git a/app/static/js/nopaque.lists.js b/app/static/js/nopaque.lists.js index 0f53e0e6..d62a11d3 100644 --- a/app/static/js/nopaque.lists.js +++ b/app/static/js/nopaque.lists.js @@ -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"); diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index 0838244a..8cbf4df8 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -260,7 +260,10 @@ @@ -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); + }; {% endblock %}