mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Some fixes and clean up
This commit is contained in:
parent
24cc8975a9
commit
ca333e29ee
@ -108,7 +108,7 @@ def corpus_analysis_inspect_match(payload):
|
|||||||
match_context = s.export(payload['first_cpos'], payload['last_cpos'],
|
match_context = s.export(payload['first_cpos'], payload['last_cpos'],
|
||||||
context=3, expand_lists=False)
|
context=3, expand_lists=False)
|
||||||
match_context['cpos_ranges'] = True
|
match_context['cpos_ranges'] = True
|
||||||
socketio.emit('match_context', {'payload': match_context},
|
socketio.emit('corpus_analysis_match_context', {'payload': match_context},
|
||||||
room=request.sid)
|
room=request.sid)
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +57,10 @@ class CorpusAnalysisClient {
|
|||||||
socket.on("corpus_analysis_query_results", (response) => {
|
socket.on("corpus_analysis_query_results", (response) => {
|
||||||
if (this.callbacks.query_results != undefined) {this.callbacks.query_results(response.payload);}
|
if (this.callbacks.query_results != undefined) {this.callbacks.query_results(response.payload);}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: set callback for this
|
||||||
|
// get context of one match if inspected via socket.io
|
||||||
|
socket.on("corpus_analysis_match_context", (response) => { results.resultsList.showMatchContext(response)});
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -4,7 +4,7 @@ class Results {
|
|||||||
this.resultsList = resultsList;
|
this.resultsList = resultsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_all() {
|
clearAll() {
|
||||||
this.resultsList.clear();
|
this.resultsList.clear();
|
||||||
this.resultsList.update();
|
this.resultsList.update();
|
||||||
this.resultsJSON.init();
|
this.resultsJSON.init();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
function querySetup(payload) {
|
function querySetup(payload) {
|
||||||
// This is called when a query was successfull
|
// This is called when a query was successfull
|
||||||
// some hiding
|
// some hiding and resetting
|
||||||
queryResultsExportElement.classList.add("disabled");
|
queryResultsExportElement.classList.add("disabled");
|
||||||
queryResultsDeterminateElement.style.width = "0%";
|
queryResultsDeterminateElement.style.width = "0%";
|
||||||
queryResultsProgressElement.classList.remove("hide");
|
queryResultsProgressElement.classList.remove("hide");
|
||||||
@ -11,7 +11,7 @@ function querySetup(payload) {
|
|||||||
matchCountElement.innerText = payload.match_count;
|
matchCountElement.innerText = payload.match_count;
|
||||||
// always re initializes results to delete old results from it
|
// 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
|
// this has to be done here again because the last chunk from old results was still being recieved
|
||||||
results.clear_all()
|
results.clearAll()
|
||||||
// Get query string again
|
// Get query string again
|
||||||
results.resultsJSON.getQueryStr(queryFormElement);
|
results.resultsJSON.getQueryStr(queryFormElement);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,8 @@ class ResultsList extends List {
|
|||||||
contextResultsElement.innerHTML = ""; // clear it from old inspects
|
contextResultsElement.innerHTML = ""; // clear it from old inspects
|
||||||
contextModal.open();
|
contextModal.open();
|
||||||
nopaque.socket.emit("corpus_analysis_inspect_match",
|
nopaque.socket.emit("corpus_analysis_inspect_match",
|
||||||
{payload: {
|
{
|
||||||
|
payload: {
|
||||||
first_cpos: results.resultsJSON.matches[dataIndex].c[0],
|
first_cpos: results.resultsJSON.matches[dataIndex].c[0],
|
||||||
last_cpos: results.resultsJSON.matches[dataIndex].c[1]
|
last_cpos: results.resultsJSON.matches[dataIndex].c[1]
|
||||||
}
|
}
|
||||||
@ -203,22 +204,22 @@ class ResultsList extends List {
|
|||||||
// create sentence strings as tokens
|
// create sentence strings as tokens
|
||||||
partElement = document.createElement("p");
|
partElement = document.createElement("p");
|
||||||
for (let cpos of lc) {
|
for (let cpos of lc) {
|
||||||
token = contextData["cpos_lookup"][cpos];
|
token = contextData.cpos_lookup[cpos];
|
||||||
partElement.insertAdjacentHTML("beforeend",
|
partElement.insertAdjacentHTML("beforeend",
|
||||||
`<span class="token" data-cpos="${cpos}">${token["word"]} </span>`);
|
`<span class="token" data-cpos="${cpos}">${token.word} </span>`);
|
||||||
contextResultsElement.append(partElement);
|
contextResultsElement.append(partElement);
|
||||||
}
|
}
|
||||||
for (let cpos of c) {
|
for (let cpos of c) {
|
||||||
token = contextData["cpos_lookup"][cpos];
|
token = contextData.cpos_lookup[cpos];
|
||||||
partElement.insertAdjacentHTML("beforeend",
|
partElement.insertAdjacentHTML("beforeend",
|
||||||
`<span class="token bold light-green" data-cpos="${cpos}"` +
|
`<span class="token bold light-green" data-cpos="${cpos}"` +
|
||||||
`style="text-decoration-line: underline;">${token["word"]} </span>`);
|
`style="text-decoration-line: underline;">${token.word} </span>`);
|
||||||
contextResultsElement.append(partElement);
|
contextResultsElement.append(partElement);
|
||||||
}
|
}
|
||||||
for (let cpos of rc) {
|
for (let cpos of rc) {
|
||||||
token = contextData["cpos_lookup"][cpos];
|
token = contextData.cpos_lookup[cpos];
|
||||||
partElement.insertAdjacentHTML("beforeend",
|
partElement.insertAdjacentHTML("beforeend",
|
||||||
`<span class="token" data-cpos="${cpos}">${token["word"]} </span>`);
|
`<span class="token" data-cpos="${cpos}">${token.word} </span>`);
|
||||||
contextResultsElement.append(partElement);
|
contextResultsElement.append(partElement);
|
||||||
}
|
}
|
||||||
if (expertModeSwitchElement.checked) {
|
if (expertModeSwitchElement.checked) {
|
||||||
@ -294,15 +295,14 @@ class ResultsList extends List {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// function to apply extra information and animation to every token
|
// function to apply extra information and animation to every token
|
||||||
expertModeOn(tokenElements, results) {
|
expertModeOn(tokenElements) {
|
||||||
let token;
|
let token;
|
||||||
for (let tokenElement of tokenElements) {
|
for (let tokenElement of tokenElements) {
|
||||||
tokenElement.classList.add("chip");
|
tokenElement.classList.add("chip");
|
||||||
tokenElement.classList.add("hoverable");
|
tokenElement.classList.add("hoverable");
|
||||||
tokenElement.classList.add("expert-view");
|
tokenElement.classList.add("expert-view");
|
||||||
token = results.cpos_lookup[tokenElement.dataset.cpos];
|
|
||||||
tokenElement.addEventListener("mouseover", (event) => {
|
tokenElement.addEventListener("mouseover", (event) => {
|
||||||
token = results.cpos_lookup[event.target.dataset.cpos];
|
token = results.resultsJSON.cpos_lookup[event.target.dataset.cpos];
|
||||||
this.addToolTipToTokenElement(event.target, token);
|
this.addToolTipToTokenElement(event.target, token);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -345,6 +345,7 @@ class ResultsList extends List {
|
|||||||
tokenElement.classList.remove("hoverable");
|
tokenElement.classList.remove("hoverable");
|
||||||
tokenElement.classList.remove("expert-view");
|
tokenElement.classList.remove("expert-view");
|
||||||
tokenElement.outerHTML = tokenElement.outerHTML; // this is actually a workaround, but it works pretty fast
|
tokenElement.outerHTML = tokenElement.outerHTML; // this is actually a workaround, but it works pretty fast
|
||||||
|
// TODO: use M.Tooltip.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +380,7 @@ class ResultsList extends List {
|
|||||||
}
|
}
|
||||||
// get infos for full match row
|
// get infos for full match row
|
||||||
matchRowElement = document.createElement("tr");
|
matchRowElement = document.createElement("tr");
|
||||||
matchRowElement.setAttribute("data-index", values["index"])
|
matchRowElement.setAttribute("data-index", values.index)
|
||||||
lcCellElement = document.createElement("td");
|
lcCellElement = document.createElement("td");
|
||||||
lcCellElement.classList.add("left-context");
|
lcCellElement.classList.add("left-context");
|
||||||
matchRowElement.appendChild(lcCellElement);
|
matchRowElement.appendChild(lcCellElement);
|
||||||
@ -424,7 +425,7 @@ class ResultsList extends List {
|
|||||||
rcCellElement.classList.add("right-context");
|
rcCellElement.classList.add("right-context");
|
||||||
matchRowElement.appendChild(rcCellElement);
|
matchRowElement.appendChild(rcCellElement);
|
||||||
for (cpos of rc) {
|
for (cpos of rc) {
|
||||||
token = chunk["cpos_lookup"][cpos];
|
token = chunk.cpos_lookup[cpos];
|
||||||
rcCellElement.insertAdjacentHTML("beforeend",
|
rcCellElement.insertAdjacentHTML("beforeend",
|
||||||
`<span class="token" data-cpos="${cpos}">${token.word} </span>`);
|
`<span class="token" data-cpos="${cpos}">${token.word} </span>`);
|
||||||
}
|
}
|
||||||
|
@ -247,6 +247,9 @@
|
|||||||
var resultsListOptions; // specifies ResultsList options
|
var resultsListOptions; // specifies ResultsList options
|
||||||
var textLookupCountElement // Nr of texts the matches occured in will be shown in this element
|
var textLookupCountElement // Nr of texts the matches occured in will be shown in this element
|
||||||
var xpath; // xpath to grab first resultsList page pagination element
|
var xpath; // xpath to grab first resultsList page pagination element
|
||||||
|
var hitsPerPageInputElement;
|
||||||
|
var paginationElements;
|
||||||
|
var contextPerItemElement;
|
||||||
|
|
||||||
// ###### Initialize variables ######
|
// ###### Initialize variables ######
|
||||||
client = undefined;
|
client = undefined;
|
||||||
@ -267,6 +270,7 @@
|
|||||||
queryResultsUserFeedbackElement = document.getElementById("query-results-user-feedback");
|
queryResultsUserFeedbackElement = document.getElementById("query-results-user-feedback");
|
||||||
receivedMatchCountElement = document.getElementById("received-match-count");
|
receivedMatchCountElement = document.getElementById("received-match-count");
|
||||||
textLookupCountElement = document.getElementById("text-lookup-count");
|
textLookupCountElement = document.getElementById("text-lookup-count");
|
||||||
|
paginationElements = document.getElementsByClassName("pagination");
|
||||||
|
|
||||||
// ###### js list options and intialization ######
|
// ###### js list options and intialization ######
|
||||||
displayOptionsData = ResultsList.getDisplayOptions(displayOptionsFormElement);
|
displayOptionsData = ResultsList.getDisplayOptions(displayOptionsFormElement);
|
||||||
@ -289,20 +293,20 @@
|
|||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
//set accordion of collapsibles to false
|
//set accordion of collapsibles to false
|
||||||
M.Collapsible.init(collapsibleElements, {accordion: false});
|
M.Collapsible.init(collapsibleElements, {accordion: false});
|
||||||
// creates some models on DOMContentLoaded
|
// creates some modals on DOMContentLoaded
|
||||||
contextModal = M.Modal.init(contextModal, {"dismissible": true});
|
contextModal = M.Modal.init(contextModal, {"dismissible": true});
|
||||||
exportModal = M.Modal.init(exportModal, {"dismissible": true});
|
exportModal = M.Modal.init(exportModal, {"dismissible": true});
|
||||||
initModal = M.Modal.init(initDisplayElement, {"dismissible": false});
|
initModal = M.Modal.init(initDisplayElement, {"dismissible": false});
|
||||||
// Init corpus analysis components
|
// Init corpus analysis components
|
||||||
resultsJSON = new ResultsJSON();
|
resultsJSON = new ResultsJSON();
|
||||||
resultsList = new ResultsList("result-list", resultsListOptions);
|
resultsList = new ResultsList("result-list", resultsListOptions);
|
||||||
results = new Results(resultsJSON, resultsList)
|
results = new Results(resultsJSON, resultsList);
|
||||||
initDisplay = new CorpusAnalysisDisplay(initDisplayElement);
|
initDisplay = new CorpusAnalysisDisplay(initDisplayElement);
|
||||||
queryDisplay = new CorpusAnalysisDisplay(queryDisplayElement);
|
queryDisplay = new CorpusAnalysisDisplay(queryDisplayElement);
|
||||||
client = new CorpusAnalysisClient({{ corpus_id }}, nopaque.socket);
|
client = new CorpusAnalysisClient({{ corpus_id }}, nopaque.socket);
|
||||||
initModal.open();
|
initModal.open();
|
||||||
|
|
||||||
// set displays visibilitys and Callback functions
|
// set displays and callback functions
|
||||||
client.setDisplay("init", initDisplay);
|
client.setDisplay("init", initDisplay);
|
||||||
client.setCallback("init", () => {
|
client.setCallback("init", () => {
|
||||||
initModal.close();
|
initModal.close();
|
||||||
@ -335,16 +339,11 @@
|
|||||||
}
|
}
|
||||||
// Prevent page from reloading on submit
|
// Prevent page from reloading on submit
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// empty ResultsList and ResultsJSON for new query
|
|
||||||
results.clear_all()
|
|
||||||
// Get query string and send query to server
|
// Get query string and send query to server
|
||||||
results.resultsJSON.getQueryStr(queryFormElement);
|
results.resultsJSON.getQueryStr(queryFormElement);
|
||||||
client.query(results.resultsJSON.query);
|
client.query(results.resultsJSON.query);
|
||||||
});
|
});
|
||||||
|
|
||||||
// get context of one match if inspected via socket.io
|
|
||||||
nopaque.socket.on("match_context", (response) => { results.resultsList.showMatchContext(response)});
|
|
||||||
|
|
||||||
// live update of hits per page if hits per page value is changed
|
// live update of hits per page if hits per page value is changed
|
||||||
hitsPerPageInputElement = document.getElementById("display-options-form-results_per_page");
|
hitsPerPageInputElement = document.getElementById("display-options-form-results_per_page");
|
||||||
hitsPerPageInputElement.onchange = results.resultsList.changeHitsPerPage;
|
hitsPerPageInputElement.onchange = results.resultsList.changeHitsPerPage;
|
||||||
@ -354,22 +353,22 @@
|
|||||||
contextPerItemElement.onchange = results.resultsList.changeContext;
|
contextPerItemElement.onchange = results.resultsList.changeContext;
|
||||||
|
|
||||||
// eventListener if pagination is used to apply new context size to new page
|
// eventListener if pagination is used to apply new context size to new page
|
||||||
// and also activate inspect match if queryFinished is true
|
// and also activate inspect match if progress is 100
|
||||||
paginationElements = document.getElementsByClassName("pagination");
|
for (let element of paginationElements) {
|
||||||
for (element of paginationElements) {
|
|
||||||
element.addEventListener("click", results.resultsList.changeContext);
|
element.addEventListener("click", results.resultsList.changeContext);
|
||||||
element.addEventListener("click", results.resultsList.activateInspect);
|
element.addEventListener("click", results.resultsList.activateInspect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// epxert mode table view
|
// epxert mode table view
|
||||||
expertModeSwitchElement.addEventListener("change", function(event) {
|
// TODO: Redo this
|
||||||
|
expertModeSwitchElement.addEventListener("change", (event) => {
|
||||||
let currentTokenElements = document.getElementsByClassName("token");
|
let currentTokenElements = document.getElementsByClassName("token");
|
||||||
let paginationElements = document.getElementsByClassName("pagination");
|
|
||||||
if (event.target.checked) {
|
if (event.target.checked) {
|
||||||
results.resultsList.expertModeOn(currentTokenElements, resultsJSON);
|
results.resultsList.expertModeOn(currentTokenElements, resultsJSON);
|
||||||
for (element of paginationElements) {
|
for (let element of paginationElements) {
|
||||||
element.tokenElements = currentTokenElements;
|
element.tokenElements = currentTokenElements;
|
||||||
element.addEventListener("click", (event) => { results.resultsList.eventHandlerCheck(event)});
|
element.addEventListener("click", (event) => { results.resultsList.eventHandlerCheck(event)});
|
||||||
|
// TODO: This replicates itself on expertModeSwitchElement use
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
results.resultsList.expertModeOff(currentTokenElements);
|
results.resultsList.expertModeOff(currentTokenElements);
|
||||||
@ -378,13 +377,13 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Add onclick to open download modal when Export Results button is pressed
|
// Add onclick to open download modal when Export Results button is pressed
|
||||||
queryResultsExportElement.onclick = function() {
|
queryResultsExportElement.onclick = () => {
|
||||||
exportModal.open();
|
exportModal.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
// add onclick to download JSON button and download the file
|
// add onclick to download JSON button and download the file
|
||||||
downloadResultsJSONElement = document.getElementById("download-results-json")
|
downloadResultsJSONElement = document.getElementById("download-results-json")
|
||||||
downloadResultsJSONElement.onclick = function() {
|
downloadResultsJSONElement.onclick = () => {
|
||||||
let filename = results.resultsJSON.createDownloadFilename();
|
let filename = results.resultsJSON.createDownloadFilename();
|
||||||
results.resultsJSON.downloadJSONRessource(filename)};
|
results.resultsJSON.downloadJSONRessource(filename)};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user