Some fixes and clean up

This commit is contained in:
Stephan Porada
2020-04-09 10:17:04 +02:00
parent 24cc8975a9
commit ca333e29ee
6 changed files with 36 additions and 32 deletions

View File

@ -57,6 +57,10 @@ class CorpusAnalysisClient {
socket.on("corpus_analysis_query_results", (response) => {
if (this.callbacks.query_results != undefined) {this.callbacks.query_results(response.payload);}
});
// TODO: set callback for this
// get context of one match if inspected via socket.io
socket.on("corpus_analysis_match_context", (response) => { results.resultsList.showMatchContext(response)});
}
init() {

View File

@ -4,7 +4,7 @@ class Results {
this.resultsList = resultsList;
}
clear_all() {
clearAll() {
this.resultsList.clear();
this.resultsList.update();
this.resultsJSON.init();

View File

@ -1,6 +1,6 @@
function querySetup(payload) {
// This is called when a query was successfull
// some hiding
// some hiding and resetting
queryResultsExportElement.classList.add("disabled");
queryResultsDeterminateElement.style.width = "0%";
queryResultsProgressElement.classList.remove("hide");
@ -11,7 +11,7 @@ function querySetup(payload) {
matchCountElement.innerText = payload.match_count;
// always re initializes results to delete old results from it
// this has to be done here again because the last chunk from old results was still being recieved
results.clear_all()
results.clearAll()
// Get query string again
results.resultsJSON.getQueryStr(queryFormElement);
}

View File

@ -163,7 +163,8 @@ class ResultsList extends List {
contextResultsElement.innerHTML = ""; // clear it from old inspects
contextModal.open();
nopaque.socket.emit("corpus_analysis_inspect_match",
{payload: {
{
payload: {
first_cpos: results.resultsJSON.matches[dataIndex].c[0],
last_cpos: results.resultsJSON.matches[dataIndex].c[1]
}
@ -203,22 +204,22 @@ class ResultsList extends List {
// create sentence strings as tokens
partElement = document.createElement("p");
for (let cpos of lc) {
token = contextData["cpos_lookup"][cpos];
token = contextData.cpos_lookup[cpos];
partElement.insertAdjacentHTML("beforeend",
`<span class="token" data-cpos="${cpos}">${token["word"]} </span>`);
`<span class="token" data-cpos="${cpos}">${token.word} </span>`);
contextResultsElement.append(partElement);
}
for (let cpos of c) {
token = contextData["cpos_lookup"][cpos];
token = contextData.cpos_lookup[cpos];
partElement.insertAdjacentHTML("beforeend",
`<span class="token bold light-green" data-cpos="${cpos}"` +
`style="text-decoration-line: underline;">${token["word"]} </span>`);
`style="text-decoration-line: underline;">${token.word} </span>`);
contextResultsElement.append(partElement);
}
for (let cpos of rc) {
token = contextData["cpos_lookup"][cpos];
token = contextData.cpos_lookup[cpos];
partElement.insertAdjacentHTML("beforeend",
`<span class="token" data-cpos="${cpos}">${token["word"]} </span>`);
`<span class="token" data-cpos="${cpos}">${token.word} </span>`);
contextResultsElement.append(partElement);
}
if (expertModeSwitchElement.checked) {
@ -294,15 +295,14 @@ class ResultsList extends List {
}
// function to apply extra information and animation to every token
expertModeOn(tokenElements, results) {
expertModeOn(tokenElements) {
let token;
for (let tokenElement of tokenElements) {
tokenElement.classList.add("chip");
tokenElement.classList.add("hoverable");
tokenElement.classList.add("expert-view");
token = results.cpos_lookup[tokenElement.dataset.cpos];
tokenElement.addEventListener("mouseover", (event) => {
token = results.cpos_lookup[event.target.dataset.cpos];
token = results.resultsJSON.cpos_lookup[event.target.dataset.cpos];
this.addToolTipToTokenElement(event.target, token);
});
}
@ -345,6 +345,7 @@ class ResultsList extends List {
tokenElement.classList.remove("hoverable");
tokenElement.classList.remove("expert-view");
tokenElement.outerHTML = tokenElement.outerHTML; // this is actually a workaround, but it works pretty fast
// TODO: use M.Tooltip.destroy()
}
}
@ -379,7 +380,7 @@ class ResultsList extends List {
}
// get infos for full match row
matchRowElement = document.createElement("tr");
matchRowElement.setAttribute("data-index", values["index"])
matchRowElement.setAttribute("data-index", values.index)
lcCellElement = document.createElement("td");
lcCellElement.classList.add("left-context");
matchRowElement.appendChild(lcCellElement);
@ -424,7 +425,7 @@ class ResultsList extends List {
rcCellElement.classList.add("right-context");
matchRowElement.appendChild(rcCellElement);
for (cpos of rc) {
token = chunk["cpos_lookup"][cpos];
token = chunk.cpos_lookup[cpos];
rcCellElement.insertAdjacentHTML("beforeend",
`<span class="token" data-cpos="${cpos}">${token.word} </span>`);
}