Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development

This commit is contained in:
Patrick Jentsch 2020-04-20 14:24:41 +02:00
commit d16e749ee7
3 changed files with 64 additions and 24 deletions

View File

@ -61,8 +61,8 @@ def analyse_corpus(corpus_id):
results_per_page=request.args.get('results_per_page', 30)) results_per_page=request.args.get('results_per_page', 30))
query_form = QueryForm(prefix='query-form', query_form = QueryForm(prefix='query-form',
query=request.args.get('query')) query=request.args.get('query'))
query_download_form = QueryDownloadForm() query_download_form = QueryDownloadForm(prefix='query-download-form')
inspect_display_options_form = InspectDisplayOptionsForm(prefix='query_download_form') inspect_display_options_form = InspectDisplayOptionsForm(prefix='inspect-display-options-form')
return render_template('corpora/analyse_corpus.html.j2', return render_template('corpora/analyse_corpus.html.j2',
corpus_id=corpus_id, corpus_id=corpus_id,
display_options_form=display_options_form, display_options_form=display_options_form,

View File

@ -193,22 +193,24 @@ class ResultsList extends List {
let contextModalLoading; let contextModalLoading;
let contextModalReady; let contextModalReady;
let contextResultsElement; let contextResultsElement;
let modalExpertModeSwitchElement;
let highlightSentencesSwitchElement; let highlightSentencesSwitchElement;
let htmlTokenStr;
let lc; let lc;
let modalExpertModeSwitchElement;
let modalTokenElements; let modalTokenElements;
let nrOfContextSentences;
let partElement; let partElement;
let rc; let rc;
let token; let token;
let tokenHTMLArray; let tokenHTMLArray;
let uniqueS;
let htmlTokenStr;
let tokenHTMlElement; let tokenHTMlElement;
let uniqueS;
this.contextData = response.payload; this.contextData = response.payload;
contextResultsElement = document.getElementById("context-results"); contextResultsElement = document.getElementById("context-results");
modalExpertModeSwitchElement = document.getElementById("query_download_form-expert_mode_inspect"); modalExpertModeSwitchElement = document.getElementById("inspect-display-options-form-expert_mode_inspect");
highlightSentencesSwitchElement = document.getElementById("query_download_form-highlight_sentences"); highlightSentencesSwitchElement = document.getElementById("inspect-display-options-form-highlight_sentences");
nrOfContextSentences = document.getElementById("context-sentences");
uniqueS = new Set(); uniqueS = new Set();
// check if cpos ranges are used or not // check if cpos ranges are used or not
if (this.contextData.cpos_ranges == true) { if (this.contextData.cpos_ranges == true) {
@ -276,51 +278,87 @@ class ResultsList extends List {
contextResultsElement.appendChild(sentenceElement); contextResultsElement.appendChild(sentenceElement);
} }
modalExpertModeSwitchElement.addEventListener("change", (event) => {
// add inspect display options events
modalExpertModeSwitchElement.onchange = (event) => {
if (event.target.checked) { if (event.target.checked) {
this.expertModeOn("context-results"); this.expertModeOn("context-results");
} else { } else {
this.expertModeOff("context-results") this.expertModeOff("context-results")
} }
}); };
if (modalExpertModeSwitchElement.checked) { highlightSentencesSwitchElement.onchange = (event) => {
this.expertModeOn("context-results");
}
highlightSentencesSwitchElement.addEventListener("change", (event) => {
if (event.target.checked) { if (event.target.checked) {
this.higlightContextSentences(); this.higlightContextSentences();
} else { } else {
this.unhighlightContextSentences(); this.unhighlightContextSentences();
} }
}); };
nrOfContextSentences.onchange = (event) => {
console.log(event.target.value);
this.changeSentenceContext(event.target.value);
}
// checks on new modal opening if switches are checked
// if switches are checked functions are executed
if (modalExpertModeSwitchElement.checked) {
this.expertModeOn("context-results");
}
if (highlightSentencesSwitchElement.checked) { if (highlightSentencesSwitchElement.checked) {
this.higlightContextSentences(); this.higlightContextSentences();
} }
// checks the value of the number of sentences to show on modal opening
// sets context sentences accordingly
this.changeSentenceContext(nrOfContextSentences.value)
} }
higlightContextSentences() { higlightContextSentences() {
let sentences; let sentences;
sentences = document.getElementById("context-results").getElementsByClassName("sentence"); sentences = document.getElementById("context-results").getElementsByClassName("sentence");
for (let s of sentences) { for (let s of sentences) {
s.insertAdjacentHTML("afterend", `<br>`) s.insertAdjacentHTML("beforeend", `<span><br><br></span>`)
} }
} }
unhighlightContextSentences() { unhighlightContextSentences() {
let sentences; let sentences;
let sibling; let br;
sentences = document.getElementById("context-results").getElementsByClassName("sentence"); sentences = document.getElementById("context-results").getElementsByClassName("sentence");
for (let s of sentences) { for (let s of sentences) {
sibling = s.nextSibling; br = s.lastChild;
sibling.remove(); br.remove();
} }
} }
changeSentenceContext(sValue) { changeSentenceContext(sValue, maxSValue=10) {
// TODO: let array;
let sentences;
let toHideArray;
let toShowArray;
sValue = maxSValue - sValue;
console.log(sValue);
sentences = document.getElementById("context-results").getElementsByClassName("sentence");
array = Array.from(sentences);
if (sValue != 0) {
toHideArray = array.slice(0, sValue).concat(array.slice(-(sValue)));
toShowArray = array.slice(sValue, 9).concat(array.slice(9, -(sValue)))
} else {
toHideArray = [];
toShowArray = array;
}
console.log(array);
console.log("#######");
console.log(toHideArray);
for (let s of toHideArray) {
s.classList.add("hide");
}
for (let s of toShowArray) {
s.classList.remove("hide");
}
} }
// ###### Display options changing live how the matches are being displayed ###### // ###### Display options changing live how the matches are being displayed ######
@ -332,8 +370,9 @@ class ResultsList extends List {
// console.log(this); // console.log(this);
this.page = event.target.value; this.page = event.target.value;
this.update(); this.update();
this.activateInspect();
if (expertModeSwitchElement.checked) { if (expertModeSwitchElement.checked) {
this.expertModeOn(); // page holds new result rows, so add new tooltips this.expertModeOn("query-display"); // page holds new result rows, so add new tooltips
} }
nopaque.flash("Updated matches per page.") nopaque.flash("Updated matches per page.")
} catch (e) { } catch (e) {
@ -417,11 +456,11 @@ class ResultsList extends List {
this.currentExpertTokenElements[htmlId] = document.getElementById(htmlId).getElementsByClassName("token"); this.currentExpertTokenElements[htmlId] = document.getElementById(htmlId).getElementsByClassName("token");
this.tooltipEventCreateBind = this.tooltipEventCreate.bind(this); this.tooltipEventCreateBind = this.tooltipEventCreate.bind(this);
this.tooltipEventDestroyBind = this.tooltipEventDestroy.bind(this); this.tooltipEventDestroyBind = this.tooltipEventDestroy.bind(this);
this.eventTokens[htmlId] = [];
for (let tokenElement of this.currentExpertTokenElements[htmlId]) { for (let tokenElement of this.currentExpertTokenElements[htmlId]) {
tokenElement.classList.add("chip", "hoverable", "expert-view"); tokenElement.classList.add("chip", "hoverable", "expert-view");
tokenElement.onmouseover = this.tooltipEventCreateBind; tokenElement.onmouseover = this.tooltipEventCreateBind;
tokenElement.onmouseout = this.tooltipEventDestroyBind; tokenElement.onmouseout = this.tooltipEventDestroyBind;
this.eventTokens[htmlId] = [];
this.eventTokens[htmlId].push(tokenElement); this.eventTokens[htmlId].push(tokenElement);
} }
} }
@ -463,6 +502,7 @@ class ResultsList extends List {
tokenElement.classList.remove("chip", "hoverable", "expert-view"); tokenElement.classList.remove("chip", "hoverable", "expert-view");
} }
this.currentExpertTokenElements[htmlId] = []; this.currentExpertTokenElements[htmlId] = [];
for (let eventToken of this.eventTokens[htmlId]) { for (let eventToken of this.eventTokens[htmlId]) {
eventToken.onmouseover = ""; eventToken.onmouseover = "";
eventToken.onmouseout = ""; eventToken.onmouseout = "";

View File

@ -234,7 +234,7 @@
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a href="#!" class="left waves-effect waves-light btn">Export</a> <a href="#!" class="left waves-effect waves-light btn disabled">Export</a>
<a href="#!" class="modal-close waves-effect waves-light red btn">Close</a> <a href="#!" class="modal-close waves-effect waves-light red btn">Close</a>
</div> </div>
</div> </div>