short_text
{{ query_form.context() }}
{{ query_form.context.label }}
@@ -253,16 +253,23 @@
var result;
var resultList;
- // Get query form element and save its data on submit and send this data via
- // socket.io to the CQP server
- var queryFormElement = document.getElementById("query-form");
- queryFormElement.addEventListener("submit", function(event) {
- event.preventDefault();
- let formData = new FormData(queryFormElement);
+ //function to get queryData
+ function getQueryData(queryFormElement) {
+ // Get query form element and save its data on submit and send this data via
+ formData = new FormData(queryFormElement);
queryData = {"context": formData.get("context"), // global declaration
"hits_per_page": formData.get("hits_per_page"),
"query": formData.get("query")};
- hitsPerPage = formData.get("hits_per_page");
+ return queryData
+ }
+
+ // socket.io analysis submit to the CQP server
+ let queryFormElement = document.getElementById("query-form");
+ queryFormElement.addEventListener("submit", sendQuery);
+
+ function sendQuery(event) {
+ event.preventDefault();
+ queryData = getQueryData(queryFormElement);
nopaque.socket.emit("corpus_analysis", queryData);
// full results object declaration, kind of global maybe store it later?
// will always be reset if a query is sent, so that only the chunks of the
@@ -271,6 +278,7 @@
result["matches"] = [];
result["cpos_lookup"] = {};
result["text_lookup"] = {};
+ result["loaded_match_count"] = 0;
result["match_count"] = 0;
result["query"] = "";
// some hiding/showing for loading animation
@@ -278,7 +286,7 @@
queryResultsTableElement.classList.add("hide");
nopaque.toast("Query has been sent!");
- var options = {page: hitsPerPage,
+ resultListOptions = {page: queryData["hits_per_page"],
pagination: [{
name: "paginationTop",
paginationClass: "paginationTop",
@@ -291,10 +299,41 @@
}],
valueNames: ["titles", "lc", "hit", "rc", {data: ["index"]}],
item: `
`};
- resultList = new ResultList('result-list', options);
+ resultList = new ResultList('result-list', resultListOptions);
resultList.clear(); // empty list for new query
- });
+ }
+ // live update of hits per page
+ var hitsPerPageInputElement = document.getElementById("hits-per-page");
+ hitsPerPageInputElement.addEventListener("change", changeResultList);
+
+ function changeResultList(event) {
+ let queryFormElement = document.getElementById("query-form");
+ queryData = getQueryData(queryFormElement);
+ try {
+ resultList.page = queryData["hits_per_page"];
+ resultList.update();
+ nopaque.toast("Updated matches per page.")
+ } catch (e) {
+ console.log("resultList has no results right now. Live update of items per page is useless for now.");
+ }
+ }
+
+ // live update of lr context per item
+ var contextPerItemElement = document.getElementById("context-per-item");
+ contextPerItemElement.addEventListener("change", changeContext);
+
+ function changeContext(event) {
+ let queryFormElement = document.getElementById("query-form");
+ queryData = getQueryData(queryFormElement);
+ console.log(queryData);
+ try {
+ nopaque.toast("Loading more context.");
+ sendQuery(event);
+ } catch (e) {
+ console.log("No query given.");
+ }
+ }
// socket.on triggered when result chunks are recieved
nopaque.socket.on("corpus_analysis_query", function(response) {
@@ -327,6 +366,7 @@
Object.assign(result["cpos_lookup"], chunk["cpos_lookup"]);
Object.assign(result["text_lookup"], chunk["text_lookup"]);
result["match_count"] = chunk["match_count"];
+ console.log("Before Current match count", result["loaded_match_count"]);
result["query"] = queryData["query"];
console.log(result);
// Some hiding and showing of loading animations
@@ -344,20 +384,22 @@
// List building/appending the chunks when query had results
match_count = chunk["match_count"];
let count_corpus_files = Object.keys(result["text_lookup"]).length;
- queryResultsMetadataElement.innerHTML = chunk["match_count"] + " matches in " + count_corpus_files + " corpus files.";
- queryResultsMetadataElement.appendChild(exportQueryResults);
- exportQueryResults.classList.remove("hide");
var resultItems = []; // list for holding every row item
// get infos for full match row
for (let [index, match] of chunk["matches"].entries()) {
- resultItems.push({...match, ...{"index": index}});
+ resultItems.push({...match, ...{"index": index + result["loaded_match_count"]}});
}
resultList.add(resultItems, items => {
for (let item of items) {
item.elm = resultList.createResultRowElement(item, chunk);}
resultList.update();
});
+ result["loaded_match_count"] += Object.keys(chunk["matches"]).length;
+ console.log("After current match count", result["loaded_match_count"]);
+ queryResultsMetadataElement.innerHTML = `
The query resulted in a total of ${chunk["match_count"]} matches.
${result["loaded_match_count"]} of ${result["match_count"]} matches in ${count_corpus_files} corpus files have been loaded.
`;
+ queryResultsMetadataElement.appendChild(exportQueryResults);
+ exportQueryResults.classList.remove("hide");
});
// inspect match functions
@@ -403,14 +445,6 @@
}
}
- // TODO:
- // if expert switch is clicked and true
- // add chips and expert info to visible tokenElements
- // else if expert switch is true and user is using pagination:
- //add chips and expert info to visible token elements AND remove that information from the tokens that have been visible before (saves later removal steps)
- // else if expert switch is false:
- // remove chips and expert info from visible tokens
-
// epxert mode
var expertModeSwitchElement = document.getElementById("expert-mode-switch");
expertModeSwitchElement.addEventListener("change", function(event) {