From e9eaa49826e95424f92876220a10d962844dca5c Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Tue, 14 Jul 2020 10:59:02 +0200 Subject: [PATCH 1/2] Removed redundant range functions and create one class method for its purpose. --- web/app/static/js/nopaque.lists.js | 90 +++++++++++++----------------- 1 file changed, 38 insertions(+), 52 deletions(-) diff --git a/web/app/static/js/nopaque.lists.js b/web/app/static/js/nopaque.lists.js index f20004a7..013290e5 100644 --- a/web/app/static/js/nopaque.lists.js +++ b/web/app/static/js/nopaque.lists.js @@ -402,6 +402,26 @@ class ResultsList extends List { this.addToSubResultsIdsToShow = new Set(); // If check button is pressed its corresponding data_index is saved in this set. The set is shown to the user. } + helperCreateCpos(cpos_ranges, cpos_values) { + console.log(cpos_values); + let lc; + let c; + let rc; + if (cpos_ranges) { + // python range like function from MDN + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Sequence_generator_(range) + const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step)); + lc = range(cpos_values.lc[0], cpos_values.lc[1], 1) + c = range(cpos_values.c[0], cpos_values.c[1], 1) + rc = range(cpos_values.rc[0], cpos_values.rc[1], 1) + } else { + lc = cpos_values.lc; + c = cpos_values.c; + rc = cpos_values.rc; + } + return {lc: lc, c: c, rc: rc}; + } + // handels interactionElements during a pagination navigation // loops over interactionElements and executes callback functions accordingly pageChangeEventInteractionHandler(interactionElements) { @@ -564,9 +584,6 @@ class ResultsList extends List { // results to be able to inspect matches. createFakeResponse() { contextModal.open(); - let lc; - let c; - let rc; let cpos_lookup; let fake_response = {}; let contextResultsElement; @@ -577,24 +594,8 @@ class ResultsList extends List { fake_response.payload["matches"] = [results.data.matches[dataIndex]]; contextResultsElement = document.getElementById("context-results"); contextResultsElement.innerHTML = ""; - if (results.data.cpos_ranges) { - // python range like function from MDN - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Sequence_generator_(range) - const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step)); - lc = range(fake_response.payload.matches[0].lc[0], - fake_response.payload.matches[0].lc[1], - 1); - c = range(fake_response.payload.matches[0].c[0], - fake_response.payload.matches[0].c[1], - 1) - rc = range(fake_response.payload.matches[0].rc[0], - fake_response.payload.matches[0].rc[1], - 1); - } else { - lc = fake_response.payload.matches[0].lc; - c = fake_response.payload.matches[0].c; - rc = fake_response.payload.matches[0].rc; - } + let {lc, c, rc} = this.helperCreateCpos(results.data.cpos_ranges, + fake_response.payload.matches[0]); cpos_lookup = {}; for (let cpos of lc) { cpos_lookup[cpos] = results.data.cpos_lookup[cpos]; @@ -662,18 +663,15 @@ class ResultsList extends List { // has been used. showMatchContext(response) { this.contextData; - let c; let contextModalLoading; let contextModalReady; let contextResultsElement; let highlightSentencesSwitchElement; let htmlTokenStr; - let lc; let modalExpertModeSwitchElement; let modalTokenElements; let nrOfContextSentences; let partElement; - let rc; let token; let tokenHTMLArray; let tokenHTMlElement; @@ -694,19 +692,8 @@ class ResultsList extends List { nrOfContextSentences = document.getElementById("context-sentences"); uniqueS = new Set(); uniqueContextS = new Set(); - // check if cpos ranges are used or not - if (this.contextData.cpos_ranges == true) { - // python range like function from MDN - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Sequence_generator_(range) - const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step)); - lc = range(this.contextData.matches[0].lc[0], this.contextData.matches[0].lc[1], 1) - c = range(this.contextData.matches[0].c[0], this.contextData.matches[0].c[1], 1) - rc = range(this.contextData.matches[0].rc[0], this.contextData.matches[0].rc[1], 1) - } else { - lc = this.contextData.matches[0].lc; - c = this.contextData.matches[0].c; - rc = this.contextData.matches[0].rc; - } + let {lc, c, rc} = this.helperCreateCpos(this.contextData.cpos_ranges, + this.contextData.matches[0]) // create sentence strings as tokens tokenHTMLArray = []; for (let cpos of lc) { @@ -994,16 +981,13 @@ class ResultsList extends List { createResultRowElement(item, chunk, imported=false) { let aCellElement; let addToSubResultsBtn; - let c; let cCellElement; let cpos; let fakeResponse; // used if imported results are being created; let inspectBtn - let lc; let lcCellElement; let matchNrElement; let matchRowElement; - let rc; let rcCellElement; let textTitles; let textTitlesCellElement; @@ -1011,18 +995,20 @@ class ResultsList extends List { let values; // gather values from item values = item.values(); - if (chunk.cpos_ranges == true) { - // python range like function from MDN - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Sequence_generator_(range) - const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step)); - lc = range(values.lc[0], values.lc[1], 1) - c = range(values.c[0], values.c[1], 1) - rc = range(values.rc[0], values.rc[1], 1) - } else { - lc = values.lc; - c = values.c; - rc = values.rc; - } + let {lc, c, rc} = this.helperCreateCpos(chunk.cpos_ranges, + values) + // if (chunk.cpos_ranges == true) { + // // python range like function from MDN + // // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Sequence_generator_(range) + // const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step)); + // lc = range(values.lc[0], values.lc[1], 1) + // c = range(values.c[0], values.c[1], 1) + // rc = range(values.rc[0], values.rc[1], 1) + // } else { + // lc = values.lc; + // c = values.c; + // rc = values.rc; + // } // get infos for full match row matchRowElement = document.createElement("tr"); matchRowElement.setAttribute("data-index", values.index) From 13a6ef95c345f621ab364797a789ffd0b16addcb Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Tue, 14 Jul 2020 15:51:02 +0200 Subject: [PATCH 2/2] Fix rseults only showing after page navigation in import viewer --- web/app/static/js/nopaque.callbacks.js | 49 +++++++++++++++----------- web/app/static/js/nopaque.lists.js | 1 - 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/web/app/static/js/nopaque.callbacks.js b/web/app/static/js/nopaque.callbacks.js index 43a62e05..15a021b1 100644 --- a/web/app/static/js/nopaque.callbacks.js +++ b/web/app/static/js/nopaque.callbacks.js @@ -85,15 +85,42 @@ function queryRenderResults(payload, imported=false) { for (let item of items) { item.elm = results.jsList.createResultRowElement(item, payload.chunk); } + helperQueryRenderResults(payload); + if (progress === 100) { + queryResultsProgressElement.classList.add("hide"); + queryResultsUserFeedbackElement.classList.add("hide"); + queryResultsExportElement.classList.remove("disabled"); + addToSubResultsElement.removeAttribute("disabled"); + // inital expert mode check and sub results activation + results.jsList.activateInspect(); + if (addToSubResultsElement.checked) { + results.jsList.activateAddToSubResults(); + } + if (expertModeSwitchElement.checked) { + results.jsList.expertModeOn("query-display"); + } + } }); - } else { + } else if (imported) { results.jsList.add(resultItems, (items) => { for (let item of items) { item.elm = results.jsList.createResultRowElement(item, payload.chunk, true); } + helperQueryRenderResults(payload); + progress = 100; + console.log(progress); + results.jsList.activateInspect(); + if (expertModeSwitchElement.checked) { + results.jsList.expertModeOn("query-display"); + } }); } +} + +function helperQueryRenderResults (payload) { + // updating table on finished item creation callback via createResultRowElement + results.jsList.update(); results.jsList.changeContext(); // sets lr context on first result load // incorporating new chunk results into full results results.data.matches.push(...payload.chunk.matches); @@ -110,24 +137,4 @@ function queryRenderResults(payload, imported=false) { console.log("Results recieved:", results.data); // upate progress status progress = payload.progress; // global declaration - if (progress === 100 && !imported) { - queryResultsProgressElement.classList.add("hide"); - queryResultsUserFeedbackElement.classList.add("hide"); - queryResultsExportElement.classList.remove("disabled"); - addToSubResultsElement.removeAttribute("disabled"); - // inital expert mode check and sub results activation - results.jsList.activateInspect(); - if (addToSubResultsElement.checked) { - results.jsList.activateAddToSubResults(); - } - if (expertModeSwitchElement.checked) { - results.jsList.expertModeOn("query-display"); - } - } else if (imported) { - progress = 100; - results.jsList.activateInspect(); - if (expertModeSwitchElement.checked) { - results.jsList.expertModeOn("query-display"); - } - } } \ No newline at end of file diff --git a/web/app/static/js/nopaque.lists.js b/web/app/static/js/nopaque.lists.js index 013290e5..924ec8e2 100644 --- a/web/app/static/js/nopaque.lists.js +++ b/web/app/static/js/nopaque.lists.js @@ -403,7 +403,6 @@ class ResultsList extends List { } helperCreateCpos(cpos_ranges, cpos_values) { - console.log(cpos_values); let lc; let c; let rc;