2020-03-28 18:29:19 +00:00
|
|
|
class CorpusAnalysisClient {
|
|
|
|
constructor(corpusId, socket) {
|
|
|
|
this.callbacks = {};
|
|
|
|
this.corpusId = corpusId;
|
|
|
|
this.displays = {};
|
|
|
|
this.socket = socket;
|
|
|
|
|
2020-03-28 19:45:33 +00:00
|
|
|
socket.on("pj_corpus_analysis_init", (response) => {
|
2020-03-28 18:29:19 +00:00
|
|
|
if (response.code === 200) {
|
2020-03-28 19:45:33 +00:00
|
|
|
console.log(`pj_corpus_analysis_init: ${response.code} - ${response.msg}`);
|
|
|
|
if (this.callbacks.init != undefined) {this.callbacks.init(response.msg);}
|
|
|
|
if (this.displays.init != undefined) {this.displays.init.setVisibilityByStatus("success");}
|
2020-03-28 18:29:19 +00:00
|
|
|
} else {
|
2020-03-28 19:45:33 +00:00
|
|
|
if (this.displays.init != undefined) {
|
|
|
|
if (this.displays.init.errorContainer != undefined) {this.displays.init.errorContainer.innerHTML = `<p class="red-text"><i class="material-icons tiny">error</i> Error ${response.code}: ${response.msg}</p>`;}
|
2020-03-28 18:29:19 +00:00
|
|
|
this.displays.init.setVisibilityByStatus("error");
|
|
|
|
}
|
2020-03-28 19:45:33 +00:00
|
|
|
console.error(`pj_corpus_analysis_init: ${response.code} - ${response.msg}`);
|
2020-03-28 18:29:19 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-28 19:45:33 +00:00
|
|
|
socket.on("pj_corpus_analysis_query", (response) => {
|
2020-03-28 18:29:19 +00:00
|
|
|
if (response.code === 200) {
|
2020-03-28 19:45:33 +00:00
|
|
|
console.log(`pj_corpus_analysis_query: ${response.code} - ${response.msg}`);
|
|
|
|
if (this.callbacks.query != undefined) {this.callbacks.query(response.data);}
|
|
|
|
if (this.displays.query != undefined) {this.displays.query.setVisibilityByStatus("success");}
|
2020-03-28 18:29:19 +00:00
|
|
|
} else {
|
|
|
|
nopaque.flash("error", `Error ${response.code}: ${response.msg}`);
|
2020-03-28 19:45:33 +00:00
|
|
|
if (this.displays.query.errorContainer != undefined) {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 != undefined) {this.displays.query.setVisibilityByStatus("error");}
|
|
|
|
console.error(`pj_corpus_analysis_query: ${response.code} - ${response.msg}`)
|
2020-03-28 18:29:19 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-28 19:45:33 +00:00
|
|
|
socket.on("pj_corpus_analysis_query_results", (response) => {
|
|
|
|
if (this.callbacks.query_results != undefined) {this.callbacks.query_results(response);}
|
2020-03-28 18:29:19 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
if (this.displays.init) {
|
2020-03-28 19:45:33 +00:00
|
|
|
if (this.displays.init.errorContainer != undefined) {this.displays.init.errorContainer.innerHTML == "";}
|
2020-03-28 18:29:19 +00:00
|
|
|
this.displays.init.setVisibilityByStatus("waiting");
|
|
|
|
}
|
2020-03-28 19:45:33 +00:00
|
|
|
this.socket.emit("pj_corpus_analysis_init", this.corpusId);
|
2020-03-28 18:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
query(query) {
|
|
|
|
if (this.displays.query) {
|
2020-03-28 19:45:33 +00:00
|
|
|
if (this.displays.query.errorContainer != undefined) {this.displays.query.errorContainer.innerHTML == "";}
|
2020-03-28 18:29:19 +00:00
|
|
|
this.displays.query.setVisibilityByStatus("waiting");
|
|
|
|
}
|
2020-03-28 19:45:33 +00:00
|
|
|
nopaque.socket.emit("pj_corpus_analysis_query", query);
|
2020-03-28 18:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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");}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|