From c0472eb6c50cb1ea1db9719e5ecc5bae271d907a Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Tue, 15 Sep 2020 17:18:22 +0200 Subject: [PATCH] Add switch to download full context results or not. --- .../modules/corpus_analysis/client/Client.js | 61 +++++++++++++++++++ .../corpus_analysis/client/callbacks.js | 11 +++- .../corpus_analysis/client/listeners.js | 3 +- .../templates/corpora/analyse_corpus.html.j2 | 36 +++++++++-- web/app/templates/interactions/export.html.j2 | 20 ++++++ 5 files changed, 123 insertions(+), 8 deletions(-) diff --git a/web/app/static/js/modules/corpus_analysis/client/Client.js b/web/app/static/js/modules/corpus_analysis/client/Client.js index bd4f92bc..57148af1 100644 --- a/web/app/static/js/modules/corpus_analysis/client/Client.js +++ b/web/app/static/js/modules/corpus_analysis/client/Client.js @@ -114,6 +114,8 @@ class Client { * Requests results data either for, 'full-results', 'sub-results' or * 'inspect-results' (resultsType). * 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) { let tmp_first_cpos = []; @@ -129,6 +131,65 @@ class Client { 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}); + } + } diff --git a/web/app/static/js/modules/corpus_analysis/client/callbacks.js b/web/app/static/js/modules/corpus_analysis/client/callbacks.js index 4db0c200..a2cc29f2 100644 --- a/web/app/static/js/modules/corpus_analysis/client/callbacks.js +++ b/web/app/static/js/modules/corpus_analysis/client/callbacks.js @@ -71,10 +71,16 @@ function saveQueryData() { } function getResultsData() { - let [resultsType, dataIndexes, client, results, rest] = arguments; + let [resultsType, dataIndexes, resultsList, client, results, rest] = arguments; client.isBusy = true; 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() { @@ -100,6 +106,7 @@ function saveResultsData() { results[objectKey].corpus_type = type; results[objectKey].match_count = [...payload.matches].length; results[objectKey].cpos_ranges = payload.cpos_ranges; + results[objectKey].fullContext = true; console.info('Results data has been saved.', results); client.isBusy = false; client.notifyView('results-data-recieved', {type: type, diff --git a/web/app/static/js/modules/corpus_analysis/client/listeners.js b/web/app/static/js/modules/corpus_analysis/client/listeners.js index ceae01ba..883c639e 100644 --- a/web/app/static/js/modules/corpus_analysis/client/listeners.js +++ b/web/app/static/js/modules/corpus_analysis/client/listeners.js @@ -179,7 +179,8 @@ function recieveViewNotification(type, client) { console.info('Client getting full results for export.'); // execute callback or functions client.eventListeners[type].executeCallback([event.detail.resultsType, - event.detail.dataIndexes], + event.detail.dataIndexes, + event.detail.resultsList], caseIdentifier); break default: diff --git a/web/app/templates/corpora/analyse_corpus.html.j2 b/web/app/templates/corpora/analyse_corpus.html.j2 index f0a5e312..36f271da 100644 --- a/web/app/templates/corpora/analyse_corpus.html.j2 +++ b/web/app/templates/corpora/analyse_corpus.html.j2 @@ -245,6 +245,7 @@ document.addEventListener("DOMContentLoaded", () => { '#show-meta-data', '#sub-results-create', '#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. * 1. Create full-results @@ -338,7 +352,9 @@ document.addEventListener("DOMContentLoaded", () => { loadingSpinnerHTML); let dataIndexes = [...Array(results.data.match_count).keys()]; resultsList.notifyClient('get-results', { resultsType: 'full-results', - dataIndexes: dataIndexes}); + dataIndexes: dataIndexes, + resultsList: resultsList, + }); } // 2. Add events for sub-results create resultsList.subResultsCreate.onclick = (event) => { @@ -351,14 +367,20 @@ document.addEventListener("DOMContentLoaded", () => { resultsList.subResultsCreate.insertAdjacentHTML('afterbegin', loadingSpinnerHTML); resultsList.notifyClient('get-results', { resultsType: 'sub-results', - dataIndexes: dataIndexes}); + dataIndexes: dataIndexes, + resultsList: resultsList, + }); } // 3. Open download modal when full results export button is pressed resultsList.fullResultsExport.onclick = (event) => { resultsList.queryResultsDownloadModal.open(); // add onclick to download JSON button and download the file 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.downloadJSONRessource(filename, results.fullResultsData, @@ -369,7 +391,11 @@ document.addEventListener("DOMContentLoaded", () => { resultsList.queryResultsDownloadModal.open(); // add onclick to download JSON button and download the file 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.downloadJSONRessource(filename, results.subResultsData, @@ -380,7 +406,7 @@ document.addEventListener("DOMContentLoaded", () => { resultsList.queryResultsDownloadModal.open(); // add onclick to download JSON button and download the file 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.downloadJSONRessource(filename, results.inspectResultsData, diff --git a/web/app/templates/interactions/export.html.j2 b/web/app/templates/interactions/export.html.j2 index 7e2b3c04..3c819498 100644 --- a/web/app/templates/interactions/export.html.j2 +++ b/web/app/templates/interactions/export.html.j2 @@ -5,6 +5,26 @@ the selected sub results.-->
Export
+
+
+ Full context + + info_outline + +
+
+
+ +
+
+