compatibility fixes and add reimplementations

This commit is contained in:
Patrick Jentsch
2020-03-28 19:29:19 +01:00
parent 970d7024e0
commit e3fde2d5c9
12 changed files with 499 additions and 44 deletions

View File

@ -0,0 +1,101 @@
class CorpusAnalysisClient {
constructor(corpusId, socket) {
this.callbacks = {};
this.corpusId = corpusId;
this.displays = {};
this.socket = socket;
socket.on("corpus_analysis_init", (response) => {
if (response.code === 200) {
console.log(`corpus_analysis_init: ${response.code} - ${response.msg}`);
if (this.callbacks.init) {this.callbacks.init(response.msg);}
if (this.displays.init) {this.displays.init.setVisibilityByStatus("success");}
} else {
if (this.displays.init) {
this.displays.init.errorContainer.innerHTML = `<p class="red-text"><i class="material-icons tiny">error</i> Error ${response.code}: ${response.msg}</p>`;
this.displays.init.setVisibilityByStatus("error");
}
console.error(`corpus_analysis_init: ${response.code} - ${response.msg}`);
}
});
socket.on("corpus_analysis_query", (response) => {
if (response.code === 200) {
console.log(`corpus_analysis_query: ${response.code} - ${response.msg}`);
if (this.callbacks.query) {this.callbacks.query(response.data);}
if (this.displays.query) {this.displays.query.setVisibilityByStatus("success");}
} else {
nopaque.flash("error", `Error ${response.code}: ${response.msg}`);
this.displays.query.errorContainer.innerHTML = `<p class="red-text"><i class="material-icons tiny">error</i> Error ${response.code}: ${response.msg}</p>`;
if (this.displays.query) {this.displays.query.setVisibilityByStatus("error");}
console.error(`corpus_analysis_query: ${response.code} - ${response.msg}`)
}
});
socket.on("corpus_analysis_query_results", (response) => {
console.log("corpus_analysis_query_results:")
console.log(response);
if (this.callbacks.query_results) {this.callbacks.query_results(response);}
});
}
init() {
if (this.displays.init) {
this.displays.init.errorContainer.innerHTML == "";
this.displays.init.setVisibilityByStatus("waiting");
}
this.socket.emit("corpus_analysis_init", this.corpusId);
}
query(query) {
if (this.displays.query) {
this.displays.query.errorContainer.innerHTML == "";
this.displays.query.setVisibilityByStatus("waiting");
}
nopaque.socket.emit("corpus_analysis_query", query);
}
setCallback(type, callback) {
this.callbacks[type] = callback;
}
setDisplay(type, display) {
this.displays[type] = display;
}
}
class CorpusAnalysisDisplay {
constructor(element) {
this.element = element;
this.errorContainer = element.querySelector(".error-container");
this.showOnError = element.querySelectorAll(".show-on-error");
this.showOnSuccess = element.querySelectorAll(".show-on-success");
this.showWhileWaiting = element.querySelectorAll(".show-while-waiting");
}
setVisibilityByStatus(status) {
switch (status) {
case "error":
for (let element of this.showOnError) {element.classList.remove("hide");}
for (let element of this.showOnSuccess) {element.classList.add("hide");}
for (let element of this.showWhileWaiting) {element.classList.add("hide");}
break;
case "success":
for (let element of this.showOnError) {element.classList.add("hide");}
for (let element of this.showOnSuccess) {element.classList.remove("hide");}
for (let element of this.showWhileWaiting) {element.classList.add("hide");}
break;
case "waiting":
for (let element of this.showOnError) {element.classList.add("hide");}
for (let element of this.showOnSuccess) {element.classList.add("hide");}
for (let element of this.showWhileWaiting) {element.classList.remove("hide");}
break;
default:
// Hide all
for (let element of this.showOnError) {element.classList.add("hide");}
for (let element of this.showOnSuccess) {element.classList.add("hide");}
for (let element of this.showWhileWaiting) {element.classList.add("hide");}
}
}
}

View File

@ -56,7 +56,7 @@ async function sendQuery(event) {
queryData = getQueryData(queryFormElement);
if (analysisStatus === "idle") {
nopaque.toast("Query has been sent!");
nopaque.flash("Query has been sent!");
nopaque.socket.emit("corpus_analysis_query", queryData.query);
helperSendQuery(queryData);
analysisStatus = checkAnalysisStatus(sessionId);
@ -100,7 +100,7 @@ function helperSendQuery(queryData) {
innerWindow: 8,
outerWindow: 1
}],
valueNames: ["titles", "lc", "hit", "rc", {data: ["index"]}],
valueNames: ["titles", "lc", "c", "rc", {data: ["index"]}],
item: `<span class="hidden"></span>`};
resultList = new ResultList('result-list', resultListOptions);
resultList.clear(); // empty list for new query
@ -132,7 +132,7 @@ function recieveResults(response) {
} else if (response["code"] === 1) {
queryResultsTableElement.classList.add("hide");
queryLoadingElement.classList.add("hide");
nopaque.toast("error", "Invalid query entered!");
nopaque.flash("error", "Invalid query entered!");
console.log("[ERROR] corpus_analysis_init");
console.log("Code:" + response["code"]);
return; // no further code execution of this code block
@ -173,7 +173,7 @@ function recieveResults(response) {
// check if query has any results
if (chunk["matches"].length === 0) {
queryResultsTableElement.classList.add("hide");
nopaque.toast("No results for this query!");
nopaque.flash("No results for this query!");
return;
}
@ -234,9 +234,9 @@ function activateInspect() {
//gets result cpos infos for one dataIndex to send back to the server
function inspect(dataIndex) {
console.log("Inspect!");
console.log(result["matches"][dataIndex]["hit"]);
console.log(result["matches"][dataIndex]["c"]);
contextModal.open();
nopaque.socket.emit("inspect_match", {"cpos": result["matches"][dataIndex]["hit"]});
nopaque.socket.emit("inspect_match", {"cpos": result["matches"][dataIndex]["c"]});
}
function showMatchContext(message) {
@ -282,7 +282,7 @@ function changeHitsPerPage(event) {
try {
resultList.page = event.target.value;
resultList.update();
nopaque.toast("Updated matches per page.")
nopaque.flash("Updated matches per page.")
} catch (e) {
console.log("resultList has no results right now. Live update of items per page is useless for now.");
}
@ -296,7 +296,7 @@ function changeContext(event) {
let array;
try {
if (event.type === "change") {
nopaque.toast("Updated context per match!");
nopaque.flash("Updated context per match!");
}
} catch (e) {
console.log(e);

View File

@ -145,7 +145,7 @@ class ResultList extends List {
matchNrElement = document.createElement("td");
matchNrElement.classList.add("match-nr");
matchRowElement.appendChild(hitCellElement);
for (cpos of values["hit"]) {
for (cpos of values["c"]) {
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