mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 12:22:47 +00:00 
			
		
		
		
	Add switch to download full context results or not.
This commit is contained in:
		@@ -114,6 +114,8 @@ class Client {
 | 
				
			|||||||
   * Requests results data either for, 'full-results', 'sub-results' or
 | 
					   * Requests results data either for, 'full-results', 'sub-results' or
 | 
				
			||||||
   * 'inspect-results' (resultsType).
 | 
					   * 'inspect-results' (resultsType).
 | 
				
			||||||
   * Gets full results for evere provided dataIndex (one match).
 | 
					   * Gets full results for evere provided dataIndex (one match).
 | 
				
			||||||
 | 
					   * Full results means with full context. So the Client has to request all
 | 
				
			||||||
 | 
					   * matches from the server again!
 | 
				
			||||||
   **/
 | 
					   **/
 | 
				
			||||||
  getResultsData(resultsType, dataIndexes, results) {
 | 
					  getResultsData(resultsType, dataIndexes, results) {
 | 
				
			||||||
    let tmp_first_cpos = [];
 | 
					    let tmp_first_cpos = [];
 | 
				
			||||||
@@ -129,6 +131,65 @@ class Client {
 | 
				
			|||||||
                         last_cpos: tmp_last_cpos,});
 | 
					                         last_cpos: tmp_last_cpos,});
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  getResultsDataWithoutContext(resultsType, dataIndexes, results, resultsList) {
 | 
				
			||||||
 | 
					    let objectKey = '';
 | 
				
			||||||
 | 
					    if (resultsType === 'full-results') {
 | 
				
			||||||
 | 
					      console.info('Saving full-results data without full context.');
 | 
				
			||||||
 | 
					      objectKey = 'fullResultsData';
 | 
				
			||||||
 | 
					    } else if (resultsType === 'sub-results') {
 | 
				
			||||||
 | 
					      console.info('Saving sub-results data without full context.');
 | 
				
			||||||
 | 
					      objectKey = 'subResultsData';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // Get matches from results.data.
 | 
				
			||||||
 | 
					    let matches = [];
 | 
				
			||||||
 | 
					    let cpos = [];
 | 
				
			||||||
 | 
					    let match;
 | 
				
			||||||
 | 
					    for (let index of dataIndexes) {
 | 
				
			||||||
 | 
					      match = results.data.matches[index]
 | 
				
			||||||
 | 
					      matches.push(match)
 | 
				
			||||||
 | 
					      // Get cpos from match.
 | 
				
			||||||
 | 
					      let {lc, c, rc} = resultsList.helperCreateCpos(results.data.cpos_ranges,
 | 
				
			||||||
 | 
					                                                     match);
 | 
				
			||||||
 | 
					      cpos.push(...lc);
 | 
				
			||||||
 | 
					      cpos.push(...c);
 | 
				
			||||||
 | 
					      cpos.push(...rc);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // Get cpos_lookups from cposes.
 | 
				
			||||||
 | 
					    let cpos_lookup = {};
 | 
				
			||||||
 | 
					    let single_lookup = {};
 | 
				
			||||||
 | 
					    let textIds = new Set;
 | 
				
			||||||
 | 
					    for (let single_cpos of cpos) {
 | 
				
			||||||
 | 
					      single_lookup[single_cpos] = results.data.cpos_lookup[single_cpos];
 | 
				
			||||||
 | 
					      textIds.add(single_lookup[single_cpos].text);
 | 
				
			||||||
 | 
					      Object.assign(cpos_lookup, single_lookup);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let text = {};
 | 
				
			||||||
 | 
					    let text_lookup = {};
 | 
				
			||||||
 | 
					    for (let id of textIds) {
 | 
				
			||||||
 | 
					      text[id] = results.data.text_lookup[id];
 | 
				
			||||||
 | 
					      Object.assign(text_lookup, text);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Save the data from results.dat either in results.fullResultsData or
 | 
				
			||||||
 | 
					     * results.subResultsData.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    results[objectKey].init();
 | 
				
			||||||
 | 
					    results[objectKey].matches.push(...matches);
 | 
				
			||||||
 | 
					    results[objectKey].addData(cpos_lookup, "cpos_lookup");
 | 
				
			||||||
 | 
					    results[objectKey].addData(text_lookup, "text_lookup");
 | 
				
			||||||
 | 
					    results[objectKey].addData(results.metaData);
 | 
				
			||||||
 | 
					    results[objectKey].query = results.data.query;
 | 
				
			||||||
 | 
					    results[objectKey].corpus_type = resultsType;
 | 
				
			||||||
 | 
					    results[objectKey].match_count = matches.length;
 | 
				
			||||||
 | 
					    results[objectKey].cpos_ranges = results.data.cpos_ranges;
 | 
				
			||||||
 | 
					    results[objectKey].fullContext = false;
 | 
				
			||||||
 | 
					    console.info('Results data without context has been saved.', results);
 | 
				
			||||||
 | 
					    this.isBusy = false;
 | 
				
			||||||
 | 
					    this.notifyView('results-data-recieved', {type: resultsType,
 | 
				
			||||||
 | 
					                                                results: results});
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,10 +71,16 @@ function saveQueryData() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getResultsData() {
 | 
					function getResultsData() {
 | 
				
			||||||
  let [resultsType, dataIndexes, client, results, rest] = arguments;
 | 
					  let [resultsType, dataIndexes, resultsList, client, results, rest] = arguments;
 | 
				
			||||||
  client.isBusy = true;
 | 
					  client.isBusy = true;
 | 
				
			||||||
  client.notifyView('results-data-recieving');
 | 
					  client.notifyView('results-data-recieving');
 | 
				
			||||||
  client.getResultsData(resultsType, dataIndexes, results);
 | 
					  if (resultsList.exportFullInspectContext.checked) {
 | 
				
			||||||
 | 
					    console.log('Get with full context');
 | 
				
			||||||
 | 
					    client.getResultsData(resultsType, dataIndexes, results);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    client.getResultsDataWithoutContext(resultsType, dataIndexes, results,
 | 
				
			||||||
 | 
					                                        resultsList);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function saveResultsData() {
 | 
					function saveResultsData() {
 | 
				
			||||||
@@ -100,6 +106,7 @@ function saveResultsData() {
 | 
				
			|||||||
  results[objectKey].corpus_type = type;
 | 
					  results[objectKey].corpus_type = type;
 | 
				
			||||||
  results[objectKey].match_count = [...payload.matches].length;
 | 
					  results[objectKey].match_count = [...payload.matches].length;
 | 
				
			||||||
  results[objectKey].cpos_ranges = payload.cpos_ranges;
 | 
					  results[objectKey].cpos_ranges = payload.cpos_ranges;
 | 
				
			||||||
 | 
					  results[objectKey].fullContext = true;
 | 
				
			||||||
  console.info('Results data has been saved.', results);
 | 
					  console.info('Results data has been saved.', results);
 | 
				
			||||||
  client.isBusy = false;
 | 
					  client.isBusy = false;
 | 
				
			||||||
  client.notifyView('results-data-recieved', {type: type,
 | 
					  client.notifyView('results-data-recieved', {type: type,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -179,7 +179,8 @@ function recieveViewNotification(type, client) {
 | 
				
			|||||||
        console.info('Client getting full results for export.');
 | 
					        console.info('Client getting full results for export.');
 | 
				
			||||||
        // execute callback or functions
 | 
					        // execute callback or functions
 | 
				
			||||||
        client.eventListeners[type].executeCallback([event.detail.resultsType,
 | 
					        client.eventListeners[type].executeCallback([event.detail.resultsType,
 | 
				
			||||||
                                                     event.detail.dataIndexes],
 | 
					                                                     event.detail.dataIndexes,
 | 
				
			||||||
 | 
					                                                     event.detail.resultsList],
 | 
				
			||||||
                                                     caseIdentifier);
 | 
					                                                     caseIdentifier);
 | 
				
			||||||
        break
 | 
					        break
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -245,6 +245,7 @@ document.addEventListener("DOMContentLoaded", () => {
 | 
				
			|||||||
    '#show-meta-data',
 | 
					    '#show-meta-data',
 | 
				
			||||||
    '#sub-results-create',
 | 
					    '#sub-results-create',
 | 
				
			||||||
    '#sub-results-export',
 | 
					    '#sub-results-export',
 | 
				
			||||||
 | 
					    '#export-full-inspect-context',
 | 
				
			||||||
  ]);
 | 
					  ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
@@ -322,6 +323,19 @@ document.addEventListener("DOMContentLoaded", () => {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Checks if resultsList.exportFullInspectContext switch is changed.#
 | 
				
			||||||
 | 
					   * If it has been changed reset all Download buttons.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  resultsList.exportFullInspectContext.onchange = (event) => {
 | 
				
			||||||
 | 
					    // Hide all download buttons.
 | 
				
			||||||
 | 
					    resultsList.fullResultsExport.classList.toggle('hide', true);
 | 
				
			||||||
 | 
					    resultsList.subResultsExport.classList.toggle('hide', true);
 | 
				
			||||||
 | 
					    // Show result create buttons.
 | 
				
			||||||
 | 
					    resultsList.fullResultsCreate.classList.toggle('hide', false);
 | 
				
			||||||
 | 
					    resultsList.subResultsCreate.classList.toggle('hide', false);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * The following event listeners are handeling the data export.
 | 
					   * The following event listeners are handeling the data export.
 | 
				
			||||||
   * 1. Create full-results
 | 
					   * 1. Create full-results
 | 
				
			||||||
@@ -338,7 +352,9 @@ document.addEventListener("DOMContentLoaded", () => {
 | 
				
			|||||||
                                                      loadingSpinnerHTML);
 | 
					                                                      loadingSpinnerHTML);
 | 
				
			||||||
    let dataIndexes = [...Array(results.data.match_count).keys()];
 | 
					    let dataIndexes = [...Array(results.data.match_count).keys()];
 | 
				
			||||||
    resultsList.notifyClient('get-results', { resultsType: 'full-results',
 | 
					    resultsList.notifyClient('get-results', { resultsType: 'full-results',
 | 
				
			||||||
                                              dataIndexes: dataIndexes});
 | 
					                                              dataIndexes: dataIndexes,
 | 
				
			||||||
 | 
					                                              resultsList: resultsList,
 | 
				
			||||||
 | 
					                                            });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  // 2. Add events for sub-results create
 | 
					  // 2. Add events for sub-results create
 | 
				
			||||||
  resultsList.subResultsCreate.onclick = (event) => {
 | 
					  resultsList.subResultsCreate.onclick = (event) => {
 | 
				
			||||||
@@ -351,14 +367,20 @@ document.addEventListener("DOMContentLoaded", () => {
 | 
				
			|||||||
    resultsList.subResultsCreate.insertAdjacentHTML('afterbegin',
 | 
					    resultsList.subResultsCreate.insertAdjacentHTML('afterbegin',
 | 
				
			||||||
    loadingSpinnerHTML);
 | 
					    loadingSpinnerHTML);
 | 
				
			||||||
    resultsList.notifyClient('get-results', { resultsType: 'sub-results',
 | 
					    resultsList.notifyClient('get-results', { resultsType: 'sub-results',
 | 
				
			||||||
                                              dataIndexes: dataIndexes});
 | 
					                                              dataIndexes: dataIndexes,
 | 
				
			||||||
 | 
					                                              resultsList: resultsList,
 | 
				
			||||||
 | 
					                                            });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  // 3. Open download modal when full results export button is pressed
 | 
					  // 3. Open download modal when full results export button is pressed
 | 
				
			||||||
  resultsList.fullResultsExport.onclick = (event) => {
 | 
					  resultsList.fullResultsExport.onclick = (event) => {
 | 
				
			||||||
    resultsList.queryResultsDownloadModal.open();
 | 
					    resultsList.queryResultsDownloadModal.open();
 | 
				
			||||||
    // add onclick to download JSON button and download the file
 | 
					    // add onclick to download JSON button and download the file
 | 
				
			||||||
    resultsList.downloadResultsJson.onclick = (event) => {
 | 
					    resultsList.downloadResultsJson.onclick = (event) => {
 | 
				
			||||||
      let filename = results.fullResultsData.createDownloadFilename('full-results');
 | 
					      let suffix = 'full-results'
 | 
				
			||||||
 | 
					      if (resultsList.exportFullInspectContext.checked) {
 | 
				
			||||||
 | 
					        suffix += '_full-context';
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      let filename = results.fullResultsData.createDownloadFilename(suffix);
 | 
				
			||||||
      results.fullResultsData.addData(results.metaData);
 | 
					      results.fullResultsData.addData(results.metaData);
 | 
				
			||||||
      results.fullResultsData.downloadJSONRessource(filename,
 | 
					      results.fullResultsData.downloadJSONRessource(filename,
 | 
				
			||||||
                                                    results.fullResultsData,
 | 
					                                                    results.fullResultsData,
 | 
				
			||||||
@@ -369,7 +391,11 @@ document.addEventListener("DOMContentLoaded", () => {
 | 
				
			|||||||
    resultsList.queryResultsDownloadModal.open();
 | 
					    resultsList.queryResultsDownloadModal.open();
 | 
				
			||||||
    // add onclick to download JSON button and download the file
 | 
					    // add onclick to download JSON button and download the file
 | 
				
			||||||
    resultsList.downloadResultsJson.onclick = (event) => {
 | 
					    resultsList.downloadResultsJson.onclick = (event) => {
 | 
				
			||||||
      let filename = results.subResultsData.createDownloadFilename('sub-results');
 | 
					      let suffix = 'sub-results'
 | 
				
			||||||
 | 
					      if (resultsList.exportFullInspectContext.checked) {
 | 
				
			||||||
 | 
					        suffix += '_full-context';
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      let filename = results.subResultsData.createDownloadFilename(suffix);
 | 
				
			||||||
      results.subResultsData.addData(results.metaData);
 | 
					      results.subResultsData.addData(results.metaData);
 | 
				
			||||||
      results.subResultsData.downloadJSONRessource(filename,
 | 
					      results.subResultsData.downloadJSONRessource(filename,
 | 
				
			||||||
                                                   results.subResultsData,
 | 
					                                                   results.subResultsData,
 | 
				
			||||||
@@ -380,7 +406,7 @@ document.addEventListener("DOMContentLoaded", () => {
 | 
				
			|||||||
    resultsList.queryResultsDownloadModal.open();
 | 
					    resultsList.queryResultsDownloadModal.open();
 | 
				
			||||||
    // add onclick to download JSON button and download the file
 | 
					    // add onclick to download JSON button and download the file
 | 
				
			||||||
    resultsList.downloadResultsJson.onclick = (event) => {
 | 
					    resultsList.downloadResultsJson.onclick = (event) => {
 | 
				
			||||||
      let filename = results.subResultsData.createDownloadFilename('inspect-results');
 | 
					      let filename = results.subResultsData.createDownloadFilename('inspect-results_full-context');
 | 
				
			||||||
      results.subResultsData.addData(results.metaData);
 | 
					      results.subResultsData.addData(results.metaData);
 | 
				
			||||||
      results.subResultsData.downloadJSONRessource(filename,
 | 
					      results.subResultsData.downloadJSONRessource(filename,
 | 
				
			||||||
                                                   results.inspectResultsData,
 | 
					                                                   results.inspectResultsData,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,26 @@ the selected sub results.-->
 | 
				
			|||||||
  <h6 style="margin-top: 0px;">Export</h6>
 | 
					  <h6 style="margin-top: 0px;">Export</h6>
 | 
				
			||||||
  <div class="divider" style="margin-bottom: 10px;"></div>
 | 
					  <div class="divider" style="margin-bottom: 10px;"></div>
 | 
				
			||||||
  <div class="row">
 | 
					  <div class="row">
 | 
				
			||||||
 | 
					    <div class="col s12" style="line-height: 38px;">
 | 
				
			||||||
 | 
					        <div class="col s8">
 | 
				
			||||||
 | 
					          Full context
 | 
				
			||||||
 | 
					          <a class="tooltipped black-text" data-tooltip="Check this switch to
 | 
				
			||||||
 | 
					            create results for the download with full context. Creating
 | 
				
			||||||
 | 
					            results like this will take much longer but you will be able to
 | 
				
			||||||
 | 
					            inspect your matches in detail when you import them into the query
 | 
				
			||||||
 | 
					            results viewer.">
 | 
				
			||||||
 | 
					            <i class="material-icons tiny">info_outline</i>
 | 
				
			||||||
 | 
					          </a>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <div class="class col s4">
 | 
				
			||||||
 | 
					          <div class="switch">
 | 
				
			||||||
 | 
					            <label style="margin-left: -20px;">
 | 
				
			||||||
 | 
					              <input type="checkbox" id="export-full-inspect-context">
 | 
				
			||||||
 | 
					              <span class="lever"></span>
 | 
				
			||||||
 | 
					            </label>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
    <div class="col s12">
 | 
					    <div class="col s12">
 | 
				
			||||||
      <button class="waves-effect
 | 
					      <button class="waves-effect
 | 
				
			||||||
              waves-light
 | 
					              waves-light
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user