mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Add download for context data.
This commit is contained in:
		@@ -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");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user