diff --git a/app/static/js/nopaque.CorpusAnalysisClient.js b/app/static/js/nopaque.CorpusAnalysisClient.js index 1c99c0f7..c14cc3cc 100644 --- a/app/static/js/nopaque.CorpusAnalysisClient.js +++ b/app/static/js/nopaque.CorpusAnalysisClient.js @@ -47,13 +47,24 @@ class CorpusAnalysisClient { this.socket.emit("pj_corpus_analysis_init", this.corpusId); } - query(query) { + query(queryStr) { if (this.displays.query.errorContainer != undefined) {this.displays.query.errorContainer.innerHTML == "";} if (this.displays.query != undefined) {this.displays.query.setVisibilityByStatus("waiting");} - nopaque.socket.emit("pj_corpus_analysis_query", query); + nopaque.socket.emit("pj_corpus_analysis_query", queryStr); + } + + getQueryStr(queryFormElement) { + // gets query + let queryFormData; + let queryStr; + queryFormData = new FormData(queryFormElement); + queryStr = queryFormData.get("query-form-query"); + return queryStr } setCallback(type, callback) { + // saves callback functions into an object. Key is function type, callback + // is the callback function this.callbacks[type] = callback; } diff --git a/app/static/js/nopaque.callbacks.js b/app/static/js/nopaque.callbacks.js new file mode 100644 index 00000000..71875278 --- /dev/null +++ b/app/static/js/nopaque.callbacks.js @@ -0,0 +1,31 @@ +function querySetup(payload) { + // This is called when a query was successfull + console.log("Query setup."); + console.log(payload); + queryResultsDeterminateElement.style.width = "0%"; + receivedMatchNumElement.innerText = "0"; + textLookupNumElement.innerText = "0"; + matchNumElement.innerText = payload.num_matches; + results = {}; + results["matches"] = []; // list of all c with lc and rc + results["cpos_lookup"] = {}; // object contains all cpos as key value pair + results["text_lookup"] = {}; // same as above for all text ids + results[] +} + +function queryRenderResults(payload) { + // This is called when results are transmitted. + console.log("CHUNK:", payload.chunk); + console.log("RESULTS:", results); + if (payload.progress === 100) { + queryResultsProgressElement.classList.add("hide"); + } + queryResultsDeterminateElement.style.width = `${payload.progress}%`; + results.matches.push(...payload.chunk.matches); + receivedMatchNumElement.innerText = `${results.matches.length}`; + // incorporating new chunk results into full results + Object.assign(results.cpos_lookup, payload.chunk.cpos_lookup); + Object.assign(results.text_lookup, payload.chunk.text_lookup); + + textLookupNumElement.innerText = `${Object.keys(results.text_lookup).length}`; +} \ No newline at end of file diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index 7f95bbe9..545111d1 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -247,7 +247,7 @@ server side --> var queryResultsDeterminateElement; // progress bar for recieved query status var queryResultsTableElement; // table element displaying the query results var queryLoadingElement; // shows progress bar until first results are in - var queryFormElement; // the quer form + var queryFormElement; // the query form var hitsPerPageInputElement; // value of hits per page (part of query form) var contextPerItemElement; // value of contex per match (part of query form) var paginationElements; // top and button pagination elements diff --git a/app/templates/corpora/pj_analyse_corpus.html.j2 b/app/templates/corpora/pj_analyse_corpus.html.j2 index 3c389bbf..c5912fcc 100644 --- a/app/templates/corpora/pj_analyse_corpus.html.j2 +++ b/app/templates/corpora/pj_analyse_corpus.html.j2 @@ -5,11 +5,17 @@ {% block page_content %}