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 c18d7862..ac0b2178 100644 --- a/web/app/static/js/nopaque.lists.js +++ b/web/app/static/js/nopaque.lists.js @@ -355,6 +355,25 @@ 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) { + 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) { @@ -517,9 +536,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; @@ -530,24 +546,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]; @@ -615,18 +615,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; @@ -647,19 +644,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) { @@ -947,16 +933,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; @@ -964,18 +947,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)