Some fixes and enhancements befor javascript rework

This commit is contained in:
Stephan Porada
2020-08-06 10:42:35 +02:00
parent a390fbb0ce
commit 301b090fc0
5 changed files with 82 additions and 38 deletions

View File

@ -520,7 +520,7 @@ class ResultsList extends List {
helperActivateBtn(btn) {
btn.classList.remove("grey");
btn.classList.add("green");
btn.innerText = "check";
btn.textContent = "check";
}
// Used in addToSubResults and inspect to toggle the design of the check
@ -528,7 +528,7 @@ class ResultsList extends List {
helperDeactivateBtn(btn) {
btn.classList.remove("green");
btn.classList.add("grey");
btn.innerText = "add";
btn.textContent = "add";
}
// Either adds or removes a match to the sub-results. For this it checks
@ -544,16 +544,16 @@ class ResultsList extends List {
this.helperActivateBtn(event.target);
this.addToSubResultsStatus[dataIndex] = true; // sets status to true
this.addToSubResultsIdsToShow.add(dataIndex + 1); // + 1 because user does not see zero indexd data indexes
textarea.innerText = [...this.addToSubResultsIdsToShow].sort(function(a, b){return a-b}).join(", "); // automaticalle sorts ids into the textarea in ascending order
textarea.textContent = [...this.addToSubResultsIdsToShow].sort(function(a, b){return a-b}).join(", "); // automaticalle sorts ids into the textarea in ascending order
M.textareaAutoResize(textarea); // after an insert textarea has to be resized manually
nrMarkedMatches.innerText = [...this.addToSubResultsIdsToShow].length;
nrMarkedMatches.textContent = [...this.addToSubResultsIdsToShow].length;
} else if (this.addToSubResultsStatus[dataIndex]) {
// add button is deactivated because status is true
this.helperDeactivateBtn(event.target);
this.addToSubResultsStatus[dataIndex] = false; // sets status to false
this.addToSubResultsIdsToShow.delete(dataIndex + 1); // + 1 because user does not see zero indexd data indexes
textarea.innerText = [...this.addToSubResultsIdsToShow].sort(function(a, b){return a-b}).join(", "); // automaticalle sorts ids into the textarea in ascending order
nrMarkedMatches.innerText = [...this.addToSubResultsIdsToShow].length;
textarea.textContent = [...this.addToSubResultsIdsToShow].sort(function(a, b){return a-b}).join(", "); // automaticalle sorts ids into the textarea in ascending order
nrMarkedMatches.textContent = [...this.addToSubResultsIdsToShow].length;
M.textareaAutoResize(textarea); // after an insert textarea has to be resized manually
}
// Toggles the create button according to the number of ids in addToSubResultsIdsToShow
@ -633,6 +633,9 @@ class ResultsList extends List {
// results to be able to inspect matches.
createFakeResponse() {
contextModal.open();
// match nr for user to display derived from data_index
let contextMatchNrElement = document.getElementById("context-match-nr");
contextMatchNrElement.textContent = this.contextId + 1;
let cpos_lookup;
let fake_response = {};
let contextResultsElement;
@ -640,6 +643,7 @@ class ResultsList extends List {
// that is passed into the results.jsList.showMatchContext() function
fake_response["payload"] = {};
let dataIndex = event.target.closest("tr").dataset.index;
this.contextId = dataIndex;
fake_response.payload["matches"] = [results.data.matches[dataIndex]];
contextResultsElement = document.getElementById("context-results");
contextResultsElement.innerHTML = "";
@ -667,16 +671,15 @@ class ResultsList extends List {
// gets result cpos infos for one dataIndex (list of length 1) to send back to
// the server
inspect(dataIndex, type) {
let contextMatchNrElement;
let contextResultsElement;
// get result infos from server and show them in context modal
this.contextId = dataIndex[0];
// match nr for user to display derived from data_index
contextMatchNrElement = document.getElementById("context-match-nr");
contextMatchNrElement.innerText = this.contextId + 1;
contextResultsElement = document.getElementById("context-results");
contextResultsElement.innerHTML = ""; // clear it from old inspects
this.getMatchWithContext(dataIndex, type);
// match nr for user to display derived from data_index
let contextMatchNrElement = document.getElementById("context-match-nr");
contextMatchNrElement.textContent = this.contextId + 1;
contextModal.open();
// add a button to add this match to sub results with onclick event
let classes = `btn-floating btn waves-effect` +
@ -1046,18 +1049,6 @@ class ResultsList extends List {
values = item.values();
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)
@ -1099,28 +1090,19 @@ class ResultsList extends List {
inspectBtn.setAttribute("style", css);
inspectBtn.setAttribute("class", classes + ` disabled inspect`
);
inspectBtn.innerHTML = '<i class="material-icons">search</i>';
if (imported) {
inspectBtn.onclick = () => {
fakeResponse = this.createFakeResponse();
this.showMatchContext(fakeResponse);
};
} else {
inspectBtn.onclick = () => {this.inspect([values.index], "inspect")};
}
inspectBtn.innerHTML = '<i class="material-icons inspect-btn">search</i>';
// # add btn to add matches to sub-results. hidden per default
addToSubResultsBtn = document.createElement("a");
addToSubResultsBtn.setAttribute("style", css);
addToSubResultsBtn.setAttribute("class", classes + ` hide add`
);
addToSubResultsBtn.innerHTML = '<i class="material-icons">add</i>';
addToSubResultsBtn.onclick = (event) => {this.addToSubResults(values.index)}
addToSubResultsBtn.innerHTML = '<i class="material-icons add-btn">add</i>';
aCellElement.appendChild(inspectBtn);
aCellElement.appendChild(addToSubResultsBtn);
// add text titles at front as first td of one row
textTitlesCellElement.innerText = [...textTitles].join(", ");
textTitlesCellElement.textContent = [...textTitles].join(", ");
matchRowElement.insertAdjacentHTML("afterbegin", textTitlesCellElement.outerHTML);
matchNrElement.innerText = values.index + 1;
matchNrElement.textContent = values.index + 1;
matchRowElement.insertAdjacentHTML("afterbegin", matchNrElement.outerHTML);
// get infos for right context of match