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

64 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-03-31 08:17:04 +00:00
function querySetup(payload) {
// This is called when a query was successfull
2020-04-01 11:44:06 +00:00
// some hiding
queryResultsExportElement.classList.add("disabled");
console.log("Query initial setup seccessfull.");
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");
receivedMatchCountElement.innerText = "0";
textLookupCountElement.innerText = "0";
matchCountElement.innerText = payload.match_count;
// always re initializes results to delete old results from it
2020-04-02 12:22:03 +00:00
results.resultsJSON["matches"] = []; // list of all c with lc and rc
results.resultsJSON["cpos_lookup"] = {}; // object contains all cpos as key value pair
results.resultsJSON["text_lookup"] = {}; // same as above for all text ids
results.resultsJSON["match_count"] = payload.match_count;
results.resultsJSON["query"] = getQueryStr(queryFormElement);
2020-03-31 08:17:04 +00:00
}
function queryRenderResults(payload) {
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.resultsJSON["cpos_ranges"] = true;
} else {
results.resultsJSON["cpos_ranges"] = false;
}
2020-04-01 11:44:06 +00:00
// update progress bar
2020-03-31 08:17:04 +00:00
queryResultsDeterminateElement.style.width = `${payload.progress}%`;
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()) {
2020-04-02 12:22:03 +00:00
resultItems.push({...match, ...{"index": index + results.resultsJSON.matches.length}});
2020-04-01 11:44:06 +00:00
}
2020-04-02 12:22:03 +00:00
resultsList.add(resultItems, (items) => {
2020-04-01 11:44:06 +00:00
for (let item of items) {
2020-04-02 12:22:03 +00:00
item.elm = resultsList.createResultRowElement(item, payload.chunk);
2020-04-01 11:44:06 +00:00
}
2020-04-02 12:22:03 +00:00
resultsList.update();
2020-04-01 11:44:06 +00:00
changeContext(); // sets lr context on first result load
});
2020-03-31 08:17:04 +00:00
// incorporating new chunk results into full results
2020-04-02 12:22:03 +00:00
results.resultsJSON.matches.push(...payload.chunk.matches);
Object.assign(results.resultsJSON.cpos_lookup, payload.chunk.cpos_lookup);
Object.assign(results.resultsJSON.text_lookup, payload.chunk.text_lookup);
2020-04-01 11:44:06 +00:00
// show user current and total match count
2020-04-02 12:22:03 +00:00
receivedMatchCountElement.innerText = `${results.resultsJSON.matches.length}`;
textLookupCountElement.innerText = `${Object.keys(results.resultsJSON.text_lookup).length}`;
console.log("Results recieved:", results.resultsJSON);
2020-04-06 10:41:23 +00:00
// upate progress status
if (payload.progress === 100) {
queryResultsProgressElement.classList.add("hide");
queryResultsUserFeedbackElement.classList.add("hide");
queryResultsExportElement.classList.remove("disabled");
activateInspect();
}
2020-04-06 12:09:12 +00:00
// inital expert mode check and activation
2020-04-06 10:52:26 +00:00
if (expertModeSwitchElement) {
let initialTokenElements = document.getElementsByClassName("token");
expertModeOn(initialTokenElements, resultsJSON);
}
2020-03-31 08:17:04 +00:00
}