// 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(results.metaData); } // 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. function saveSubResultsChoices(response) { console.log("Recieve match with context"); 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 = "sub-results"; results.subResultsData.match_count = [...response.payload.matches].length; results.subResultsData.cpos_ranges = response.payload.cpos_ranges; console.log(results.subResultsData); subResultsCreateElement.getElementsByClassName("button-icon-spinner")[0].remove(); subResultsCreateElement.getElementsByTagName("i")[0].classList.remove("hide"); subResultsCreateElement.firstElementChild.classList.add("disabled"); subResultsExportElement.classList.remove("disabled", "btn-flat"); subResultsExportElement.classList.add("pulse", "btn-small"); setTimeout(() => { subResultsExportElement.classList.remove("pulse", "btn-small"); subResultsExportElement.classList.add("btn-flat"); clearTimeout(); }, 3000) } // This callback is called on socket.on "query". // Does some hiding, showing disabling etc. function querySetup(payload) { // some hiding and resetting let textarea = subResultsIdListElement.getElementsByTagName("textarea")[0]; textarea.innerText = ""; M.textareaAutoResize(textarea); nrMarkedMatches.innerText = 0; results.jsList.addToSubResultsStatus = {}; results.jsList.addToSubResultsIdsToShow = new Set(); queryResultsExportElement.classList.add("disabled"); addToSubResultsElement.setAttribute("disabled", ""); queryResultsDeterminateElement.style.width = "0%"; queryResultsProgressElement.classList.remove("hide"); queryResultsUserFeedbackElement.classList.remove("hide"); // some initial values receivedMatchCountElement.innerText = "0"; textLookupCountElement.innerText = "0"; matchCountElement.innerText = payload.match_count; textTitlesElement.innterText = ""; // always re initializes results to delete old results from it // this has to be done here again because the last chunk from old results was still being recieved results.clearAll() // Get query string again results.data.getQueryStr(queryFormElement); results.data.match_count = payload.match_count; } // This callback is called on socket.on "query_results" // this handels the incoming result chunks function queryRenderResults(payload, imported=false) { let resultItems; // array of built html result items row element // This is called when results are transmitted and being recieved console.log("Current recieved chunk:", payload.chunk); if (payload.chunk.cpos_ranges == true) { results.data["cpos_ranges"] = true; } else { results.data["cpos_ranges"] = false; } // update progress bar queryResultsDeterminateElement.style.width = `${payload.progress}%`; // 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}}); } if (!imported) { results.jsList.add(resultItems, (items) => { for (let item of items) { item.elm = results.jsList.createResultRowElement(item, payload.chunk); } }); } else { results.jsList.add(resultItems, (items) => { for (let item of items) { item.elm = results.jsList.createResultRowElement(item, payload.chunk, true); } }); } results.jsList.changeContext(); // sets lr context on first result load // incorporating new chunk results into full results results.data.matches.push(...payload.chunk.matches); Object.assign(results.data.cpos_lookup, payload.chunk.cpos_lookup); Object.assign(results.data.text_lookup, payload.chunk.text_lookup); // show user current and total match count receivedMatchCountElement.innerText = `${results.data.matches.length}`; textLookupCountElement.innerText = `${Object.keys(results.data.text_lookup).length}`; 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); // upate progress status progress = payload.progress; // global declaration if (progress === 100 && !imported) { queryResultsProgressElement.classList.add("hide"); queryResultsUserFeedbackElement.classList.add("hide"); queryResultsExportElement.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"); } } else if (imported) { progress = 100; results.jsList.activateInspect(); if (expertModeSwitchElement.checked) { results.jsList.expertModeOn("query-display"); } } }