mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 18:34:18 +00:00
Add interaactive context change
This commit is contained in:
parent
db7ccb2b11
commit
5c134dd8c5
@ -68,11 +68,16 @@ class QueryForm(FlaskForm):
|
|||||||
validators=[DataRequired()])
|
validators=[DataRequired()])
|
||||||
context = SelectField('Context',
|
context = SelectField('Context',
|
||||||
choices=[('', 'Words of context around hit'),
|
choices=[('', 'Words of context around hit'),
|
||||||
('5', '5'),
|
|
||||||
('10', '10'),
|
('10', '10'),
|
||||||
('15', '15'),
|
|
||||||
('20', '20'),
|
('20', '20'),
|
||||||
('25', '25')],
|
('30', '30'),
|
||||||
|
('40', '40'),
|
||||||
|
('50', '50'),
|
||||||
|
('60', '60'),
|
||||||
|
('70', '70'),
|
||||||
|
('80', '80'),
|
||||||
|
('90', '90'),
|
||||||
|
('100', '100')],
|
||||||
validators=[DataRequired()])
|
validators=[DataRequired()])
|
||||||
submit = SubmitField('Start Query')
|
submit = SubmitField('Start Query')
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ def analyse_corpus(corpus_id):
|
|||||||
corpus.status = 'start analysis'
|
corpus.status = 'start analysis'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
query_download_form = QueryDownloadForm()
|
query_download_form = QueryDownloadForm()
|
||||||
query_form = QueryForm(context=request.args.get('context', 10),
|
query_form = QueryForm(context=request.args.get('context', 20),
|
||||||
hits_per_page=request.args.get('hits_per_page', 30),
|
hits_per_page=request.args.get('hits_per_page', 30),
|
||||||
query=request.args.get('query'))
|
query=request.args.get('query'))
|
||||||
return render_template('corpora/analyse_corpus.html.j2',
|
return render_template('corpora/analyse_corpus.html.j2',
|
||||||
|
@ -305,13 +305,11 @@
|
|||||||
|
|
||||||
// live update of hits per page
|
// live update of hits per page
|
||||||
var hitsPerPageInputElement = document.getElementById("hits-per-page");
|
var hitsPerPageInputElement = document.getElementById("hits-per-page");
|
||||||
hitsPerPageInputElement.addEventListener("change", changeResultList);
|
hitsPerPageInputElement.onchange = changeHitsPerPage;
|
||||||
|
|
||||||
function changeResultList(event) {
|
function changeHitsPerPage(event) {
|
||||||
let queryFormElement = document.getElementById("query-form");
|
|
||||||
queryData = getQueryData(queryFormElement);
|
|
||||||
try {
|
try {
|
||||||
resultList.page = queryData["hits_per_page"];
|
resultList.page = event.target.value;
|
||||||
resultList.update();
|
resultList.update();
|
||||||
nopaque.toast("Updated matches per page.")
|
nopaque.toast("Updated matches per page.")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -319,19 +317,47 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// live update of lr context per item
|
// live update of lr context per item if context value is changed
|
||||||
var contextPerItemElement = document.getElementById("context-per-item");
|
var contextPerItemElement = document.getElementById("context-per-item");
|
||||||
contextPerItemElement.addEventListener("change", changeContext);
|
contextPerItemElement.onchange = changeContext;
|
||||||
|
|
||||||
|
// eventListener if pagination is used to apply new context size to new page
|
||||||
|
var paginationElements = document.getElementsByClassName("pagination");
|
||||||
|
for (element of paginationElements) {
|
||||||
|
element.addEventListener("click", changeContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
// event triggered on context select change and also if pagination is clicked
|
||||||
function changeContext(event) {
|
function changeContext(event) {
|
||||||
let queryFormElement = document.getElementById("query-form");
|
// newValue = event.target.value; // cannot use this anymore due to reuse of this function in the above paginationElements eventListener
|
||||||
queryData = getQueryData(queryFormElement);
|
var contextPerItemElement = document.getElementById("context");
|
||||||
console.log(queryData);
|
newValue = contextPerItemElement.value;
|
||||||
try {
|
console.log(newValue);
|
||||||
nopaque.toast("Loading more context.");
|
var lc = document.getElementsByClassName("left-context");
|
||||||
sendQuery(event);
|
var rc = document.getElementsByClassName("right-context");
|
||||||
} catch (e) {
|
// console.log("LC", lc);
|
||||||
console.log("No query given.");
|
// console.log("RC", rc);
|
||||||
|
for (let element of lc) {
|
||||||
|
// console.log(element.childNodes);
|
||||||
|
array = Array.from(element.childNodes);
|
||||||
|
// console.log(array);
|
||||||
|
for (let element of array.slice(newValue)) {
|
||||||
|
element.classList.add("hide");
|
||||||
|
}
|
||||||
|
for (let element of array.slice(0, newValue)) {
|
||||||
|
element.classList.remove("hide");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let element of rc) {
|
||||||
|
// console.log(element.childNodes);
|
||||||
|
array = Array.from(element.childNodes);
|
||||||
|
// console.log(array);
|
||||||
|
for (let element of array.slice(newValue)) {
|
||||||
|
element.classList.add("hide");
|
||||||
|
}
|
||||||
|
for (let element of array.slice(0, newValue)) {
|
||||||
|
element.classList.remove("hide");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,8 +418,10 @@
|
|||||||
}
|
}
|
||||||
resultList.add(resultItems, items => {
|
resultList.add(resultItems, items => {
|
||||||
for (let item of items) {
|
for (let item of items) {
|
||||||
item.elm = resultList.createResultRowElement(item, chunk);}
|
item.elm = resultList.createResultRowElement(item, chunk);
|
||||||
|
}
|
||||||
resultList.update();
|
resultList.update();
|
||||||
|
changeContext(); // sets lr context to current/default value
|
||||||
});
|
});
|
||||||
result["loaded_match_count"] += Object.keys(chunk["matches"]).length;
|
result["loaded_match_count"] += Object.keys(chunk["matches"]).length;
|
||||||
console.log("After current match count", result["loaded_match_count"]);
|
console.log("After current match count", result["loaded_match_count"]);
|
||||||
|
Loading…
Reference in New Issue
Block a user