Continue new list building for results

This commit is contained in:
Stephan Porada
2020-02-03 12:58:40 +01:00
parent e95cc42a22
commit 21371efde6
4 changed files with 65 additions and 66 deletions

View File

@ -93,66 +93,55 @@ RessourceList.options = {
class ResultList extends List {
createResultRowElement(item, chunk) {
let values, cpos, matchRowElement, lcCellElement, lcTokenElement, token;
let values, cpos, token, matchRowElement, lcCellElement, hitCellElement, rcCellElement, textTitlesCellElement;
// gather values from item
values = item.values();
console.log("CHONK");
console.log(chunk);
// get infos for full match row
matchRowElement = document.createElement("tr");
for (cpos of values["lc"]) {
console.log(cpos);
lcCellElement = document.createElement("td");
lcTokenElement = document.createElement("span");
lcTokenElement.classList.add("token");
lcTokenElement.dataset.cpos = cpos;
token = chunk["cpos_lookup"][cpos];
lcTokenElement.innerText = token["word"];
lcCellElement.appendChild(lcTokenElement);
// let hit_tokens = "";
}
matchRowElement.setAttribute("data-index", values["index"])
lcCellElement = document.createElement("td");
lcCellElement.classList.add("left-context");
matchRowElement.appendChild(lcCellElement);
// // get infos of match
// let textTitles = new Set();
// for (cpos of match["hit"]) {
// tokenElement = document.createElement("span");
// tokenElement.classList.add("token");
// tokenElement.dataset.cpos = cpos;
// token = chunk["cpos_lookup"][cpos];
// tokenElement.innerText = token["word"];
// hit_tokens += " " + tokenElement.outerHTML;
// // get text titles of every hit cpos token
// textTitles.add(chunk["text_lookup"][token["text"]]["title"]);
// }
// // add button to trigger more context to every match td
// var inspectBtn = document.createElement("a");
// inspectBtn.setAttribute("class", "btn-floating btn-flat waves-effect waves-light grey right inspect");
// inspectBtn.onclick = function() {inspect()};
// inspectBtn.innerHTML = '<i class="material-icons">search</i>';
// hit_tokens += "<p>" + inspectBtn.outerHTML + "</p>";
// // get infos for right context of match
// let rc_tokens = "";
// for (cpos of match["rc"]) {
// tokenElement = document.createElement("span");
// tokenElement.classList.add("token");
// tokenElement.dataset.cpos = cpos;
// token = chunk["cpos_lookup"][cpos];
// tokenElement.innerText = token["word"];
// rc_tokens += " " + tokenElement.outerHTML;
// }
// // put all infos into an javascribt object
// textTitleElement = document.createElement("span");
// textTitleElement.classList.add("text-titles");
// textTitles = [...textTitles].join(",");
// textTitleElement.innerText = textTitles;
//
// matchRowElement.appendChild(textTitleElement);
// // matchRowElement.appendChild(lc_tokens);
// // matchRowElement.appendChild(hit_tokens);
// // matchRowElement.appendChild(rc_tokens);
// // matchRowElement.appendChild(index);
// }
console.log(matchRowElement.outerHTML);
for (cpos of values["lc"]) {
token = chunk["cpos_lookup"][cpos];
lcCellElement.insertAdjacentHTML("beforeend", `<span class="token" data-cpos="${cpos}">${token["word"]} </span>`);
}
// get infos for hit of match
let textTitles = new Set();
hitCellElement = document.createElement("td");
hitCellElement.classList.add("match-hit");
textTitlesCellElement = document.createElement("td");
textTitlesCellElement.classList.add("titles");
matchRowElement.appendChild(hitCellElement);
for (cpos of values["hit"]) {
token = chunk["cpos_lookup"][cpos];
hitCellElement.insertAdjacentHTML("beforeend", `<span class="token" data-cpos="${cpos}">${token["word"]} </span>`);
// get text titles of every hit cpos token
textTitles.add(chunk["text_lookup"][token["text"]]["title"]);
// add button to trigger more context to every match td
var inspectBtn = document.createElement("a");
inspectBtn.setAttribute("class", "btn-floating btn-flat waves-effect waves-light grey right inspect");
inspectBtn.innerHTML = '<i class="material-icons">search</i>';
inspectBtn.onclick = function () {inspect(values["index"])};
}
// add text titles at front as first td of one row
hitCellElement.appendChild(inspectBtn);
textTitlesCellElement.innerText = [...textTitles].join(", ");
matchRowElement.insertAdjacentHTML("afterbegin", textTitlesCellElement.outerHTML);
// get infos for right context of match
rcCellElement = document.createElement("td");
rcCellElement.classList.add("right-context");
matchRowElement.appendChild(rcCellElement);
for (cpos of values["rc"]) {
token = chunk["cpos_lookup"][cpos];
rcCellElement.insertAdjacentHTML("beforeend", `<span class="token" data-cpos="${cpos}">${token["word"]} </span>`);
}
console.log(matchRowElement);
return matchRowElement
}
}