mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-01-18 14:00:33 +00:00
Removed redundant range functions and create one class method for its purpose.
This commit is contained in:
parent
82c26a02bb
commit
e9eaa49826
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user