nopaque/web/app/static/js/nopaque.callbacks.js

182 lines
8.2 KiB
JavaScript
Raw Normal View History

2020-06-26 08:04:54 +00:00
// This callback is called on a socket.on "corpus_analysis_send_meta_data".
// Handels incoming corpus metadata
function recvMetaData(payload) {
results.metaData.init(payload)
console.log("Metada recieved:", results.metaData);
}
2020-06-26 08:04:54 +00:00
// This callback is called in socket.on "corpus_analysis_inspect_match" but
// only if the response.type is "sub-results".
// Saves the incoming inspect match results into results.subResultsData.
2020-06-25 08:51:51 +00:00
function saveSubResultsChoices(response) {
console.log("Recieving results for export.");
if (response.type === "sub-results") {
results.subResultsData.init();
results.subResultsData.matches.push(...response.payload.matches);
results.subResultsData.addData(response.payload.cpos_lookup, "cpos_lookup");
results.subResultsData.addData(response.payload.text_lookup, "text_lookup");
results.subResultsData.addData(results.metaData);
results.subResultsData.query = results.data.query;
results.subResultsData.corpus_type = response.type;
results.subResultsData.match_count = [...response.payload.matches].length;
results.subResultsData.cpos_ranges = response.payload.cpos_ranges;
// hides create element after all results are revieved
subResultsCreateElement.classList.add("hide");
// shows export element after create element hs been hidden
subResultsExportElement.classList.remove("hide", "btn-flat");
subResultsExportElement.classList.add("pulse", "btn-small");
setTimeout(() => {
subResultsExportElement.classList.remove("pulse", "btn-small");
subResultsExportElement.classList.add("btn-flat");
clearTimeout();
}, 3000)
// Resets the subResultsCreateElement (removing spinner with setting innerText)
subResultsCreateElement.innerText = "Create Sub-Results";
subResultsCreateElement.insertAdjacentHTML("beforeend", `<i class="material-icons left">build</i>`);
// reactivate resultsCreateElement
resultsCreateElement.classList.remove("disabled");
} else if (response.type === "results") {
results.resultsData.init();
results.resultsData.matches.push(...response.payload.matches);
results.resultsData.addData(response.payload.cpos_lookup, "cpos_lookup");
results.resultsData.addData(response.payload.text_lookup, "text_lookup");
results.resultsData.addData(results.metaData);
results.resultsData.query = results.data.query;
results.resultsData.corpus_type = response.type;
results.resultsData.match_count = [...response.payload.matches].length;
results.resultsData.cpos_ranges = response.payload.cpos_ranges;
// hides create element after all results are revieved
resultsCreateElement.classList.add("hide");
// shows export element after create element hs been hidden
resultsExportElement.classList.remove("hide", "btn-flat");
resultsExportElement.classList.add("pulse", "btn-small");
setTimeout(() => {
resultsExportElement.classList.remove("pulse", "btn-small");
resultsExportElement.classList.add("btn-flat");
clearTimeout();
}, 3000)
// Resets the resultsCreateElement (removing spinner with setting innerText)
2020-07-20 07:31:27 +00:00
resultsCreateElement.innerText = "Create Results";
resultsCreateElement.insertAdjacentHTML("beforeend", `<i class="material-icons left">build</i>`);
// reactivate subResultsCreateElement
subResultsCreateElement.classList.remove("disabled");
}
2020-07-20 07:31:27 +00:00
// reactivate inspect
results.jsList.activateInspect();
activateInspectInteraction.setCallback("noCheck",
results.jsList.activateInspect,
results.jsList);
// set resultCreationRunning to flase
resultCreationRunning = false;
}
2020-06-26 08:04:54 +00:00
// This callback is called on socket.on "query".
// Does some hiding, showing disabling etc.
2020-03-31 08:17:04 +00:00
function querySetup(payload) {
2020-04-09 08:17:04 +00:00
// some hiding and resetting
2020-06-25 08:51:51 +00:00
let textarea = subResultsIdListElement.getElementsByTagName("textarea")[0];
textarea.innerText = "";
M.textareaAutoResize(textarea);
2020-06-29 09:09:12 +00:00
nrMarkedMatches.innerText = 0;
2020-06-25 08:51:51 +00:00
results.jsList.addToSubResultsStatus = {};
results.jsList.addToSubResultsIdsToShow = new Set();
resultsExportElement.classList.add("disabled");
2020-06-25 08:51:51 +00:00
addToSubResultsElement.setAttribute("disabled", "");
2020-03-31 08:17:04 +00:00
queryResultsDeterminateElement.style.width = "0%";
2020-03-31 08:27:26 +00:00
queryResultsProgressElement.classList.remove("hide");
2020-04-01 11:44:06 +00:00
queryResultsUserFeedbackElement.classList.remove("hide");
2020-07-20 07:31:27 +00:00
resultsCreateElement.classList.add("disabled");
resultsCreateElement.classList.remove("hide");
resultsExportElement.classList.add("hide");
2020-04-08 09:37:34 +00:00
// some initial values
2020-04-01 11:44:06 +00:00
receivedMatchCountElement.innerText = "0";
textLookupCountElement.innerText = "0";
matchCountElement.innerText = payload.match_count;
2020-06-19 10:30:05 +00:00
textTitlesElement.innterText = "";
2020-04-01 11:44:06 +00:00
// always re initializes results to delete old results from it
2020-04-08 09:37:34 +00:00
// this has to be done here again because the last chunk from old results was still being recieved
2020-04-09 08:17:04 +00:00
results.clearAll()
2020-04-07 11:13:48 +00:00
// Get query string again
results.data.getQueryStr(queryFormElement);
results.data.match_count = payload.match_count;
2020-03-31 08:17:04 +00:00
}
2020-06-26 08:04:54 +00:00
// This callback is called on socket.on "query_results"
// this handels the incoming result chunks
function queryRenderResults(payload, imported=false) {
2020-04-08 09:37:34 +00:00
let resultItems; // array of built html result items row element
2020-04-01 11:44:06 +00:00
// This is called when results are transmitted and being recieved
console.log("Current recieved chunk:", payload.chunk);
2020-04-02 12:22:03 +00:00
if (payload.chunk.cpos_ranges == true) {
results.data["cpos_ranges"] = true;
2020-04-02 12:22:03 +00:00
} else {
results.data["cpos_ranges"] = false;
2020-04-02 12:22:03 +00:00
}
2020-04-01 11:44:06 +00:00
// building the result list js list from incoming chunk
resultItems = []; // list for holding every row item
// get infos for full match row
for (let [index, match] of payload.chunk.matches.entries()) {
resultItems.push({...match, ...{"index": index + results.data.matches.length}});
2020-04-01 11:44:06 +00:00
}
2020-07-14 07:24:04 +00:00
if (!imported) {
2020-07-21 11:40:17 +00:00
// update progress bar
queryResultsDeterminateElement.style.width = `${payload.progress}%`;
2020-07-14 07:24:04 +00:00
results.jsList.add(resultItems, (items) => {
for (let item of items) {
item.elm = results.jsList.createResultRowElement(item, payload.chunk);
}
helperQueryRenderResults(payload);
if (progress === 100) {
2020-07-20 07:31:27 +00:00
resultsCreateElement.classList.remove("disabled");
queryResultsProgressElement.classList.add("hide");
queryResultsUserFeedbackElement.classList.add("hide");
resultsExportElement.classList.remove("disabled");
addToSubResultsElement.removeAttribute("disabled");
// inital expert mode check and sub results activation
results.jsList.activateInspect();
if (addToSubResultsElement.checked) {
results.jsList.activateAddToSubResults();
}
if (expertModeSwitchElement.checked) {
results.jsList.expertModeOn("query-display");
}
}
2020-07-14 07:24:04 +00:00
});
} else if (imported) {
2020-07-14 07:24:04 +00:00
results.jsList.add(resultItems, (items) => {
for (let item of items) {
item.elm = results.jsList.createResultRowElement(item, payload.chunk,
true);
}
helperQueryRenderResults(payload);
progress = 100;
results.jsList.activateInspect();
if (expertModeSwitchElement.checked) {
results.jsList.expertModeOn("query-display");
}
2020-07-14 07:24:04 +00:00
});
}
}
function helperQueryRenderResults (payload) {
// updating table on finished item creation callback via createResultRowElement
results.jsList.update();
2020-07-14 07:24:04 +00:00
results.jsList.changeContext(); // sets lr context on first result load
2020-03-31 08:17:04 +00:00
// incorporating new chunk results into full results
results.data.matches.push(...payload.chunk.matches);
2020-07-20 07:31:27 +00:00
results.data.addData(payload.chunk.cpos_lookup, "cpos_lookup");
results.data.addData(payload.chunk.text_lookup, "text_lookup");
// complete metaData
// results.metaData.add();
2020-04-01 11:44:06 +00:00
// show user current and total match count
receivedMatchCountElement.innerText = `${results.data.matches.length}`;
textLookupCountElement.innerText = `${Object.keys(results.data.text_lookup).length}`;
2020-06-19 10:30:05 +00:00
let titles = new Array();
for (let [key, value] of Object.entries(results.data.text_lookup)) {
titles.push(`${value.title} (${value.publishing_year})`);
};
textTitlesElement.innerText = `${titles.join(", ")}`;
console.log("Results recieved:", results.data);
2020-04-06 10:41:23 +00:00
// upate progress status
progress = payload.progress; // global declaration
2020-03-31 08:17:04 +00:00
}