Feature parity with old implementation

This commit is contained in:
Stephan Porada 2020-09-08 10:42:39 +02:00
parent 521fd72d9b
commit ccfbf852b2
5 changed files with 97 additions and 147 deletions

View File

@ -35,14 +35,25 @@ def init_corpus_analysis(corpus_id):
def corpus_analysis_get_meta_data(corpus_id): def corpus_analysis_get_meta_data(corpus_id):
# get meta data from db # get meta data from db
db_corpus = Corpus.query.get(corpus_id) db_corpus = Corpus.query.get(corpus_id)
# TODO: Check if current user is actually the creator of the corpus?
metadata = {} metadata = {}
metadata['corpus_name'] = db_corpus.title metadata['corpus_name'] = db_corpus.title
metadata['corpus_description'] = db_corpus.description metadata['corpus_description'] = db_corpus.description
metadata['corpus_creation_date'] = db_corpus.creation_date.isoformat() metadata['corpus_creation_date'] = db_corpus.creation_date.isoformat()
metadata['corpus_last_edited_date'] = db_corpus.last_edited_date.isoformat() metadata['corpus_last_edited_date'] = db_corpus.last_edited_date.isoformat()
# get meta data from corpus in cqp server
client = corpus_analysis_clients.get(request.sid) client = corpus_analysis_clients.get(request.sid)
if client is None:
response = {'code': 424, 'desc': 'No client found for this session',
'msg': 'Failed Dependency'}
socketio.emit('corpus_analysis_query', response, room=request.sid)
return
# check if client is busy or not
if client.status == 'running':
client.status = 'abort'
while client.status != 'ready':
socketio.sleep(0.1)
# get meta data from corpus in cqp server
client.status = 'running'
try:
client_corpus = client.corpora.get('CORPUS') client_corpus = client.corpora.get('CORPUS')
metadata['corpus_properties'] = client_corpus.attrs['properties'] metadata['corpus_properties'] = client_corpus.attrs['properties']
metadata['corpus_size_tokens'] = client_corpus.attrs['size'] metadata['corpus_size_tokens'] = client_corpus.attrs['size']
@ -70,6 +81,12 @@ def corpus_analysis_get_meta_data(corpus_id):
response = {'code': 200, 'desc': 'Corpus meta data', 'msg': 'OK', response = {'code': 200, 'desc': 'Corpus meta data', 'msg': 'OK',
'payload': payload} 'payload': payload}
socketio.emit('corpus_analysis_meta_data', response, room=request.sid) socketio.emit('corpus_analysis_meta_data', response, room=request.sid)
except cqi.errors.CQiException as e:
payload = {'code': e.code, 'desc': e.description, 'msg': e.name}
response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error',
'payload': payload}
socketio.emit('corpus_analysis_meta_data', response, room=request.sid)
client.status = 'ready'
@socketio.on('corpus_analysis_query') @socketio.on('corpus_analysis_query')
@ -100,7 +117,6 @@ def corpus_analysis_query(query):
'match_count': results.attrs['size']} 'match_count': results.attrs['size']}
response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': payload} response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': payload}
socketio.emit('corpus_analysis_query', response, room=request.sid) socketio.emit('corpus_analysis_query', response, room=request.sid)
# TODO: Stop here and add a new method for transmission
chunk_size = 100 chunk_size = 100
chunk_start = 0 chunk_start = 0
context = 50 context = 50
@ -142,6 +158,11 @@ def corpus_analysis_inspect_match(payload):
socketio.emit('corpus_analysis_inspect_match', response, socketio.emit('corpus_analysis_inspect_match', response,
room=request.sid) room=request.sid)
return return
if client.status == 'running':
client.status = 'abort'
while client.status != 'ready':
socketio.sleep(0.1)
client.status = 'running'
try: try:
corpus = client.corpora.get('CORPUS') corpus = client.corpora.get('CORPUS')
s = corpus.structural_attributes.get('s') s = corpus.structural_attributes.get('s')
@ -171,6 +192,7 @@ def corpus_analysis_inspect_match(payload):
'type': type, 'type': type,
'data_indexes': data_indexes} 'data_indexes': data_indexes}
socketio.emit('corpus_analysis_inspect_match', response, room=request.sid) socketio.emit('corpus_analysis_inspect_match', response, room=request.sid)
client.status = 'ready'
def corpus_analysis_session_handler(app, corpus_id, user_id, session_id): def corpus_analysis_session_handler(app, corpus_id, user_id, session_id):

View File

@ -1,97 +0,0 @@
// TODO: Simplify this so that things are executed on change page and on first
// load look below at function doc strings
// one interaction can have more than one type when the associatee callback
// can be executed
class Interaction {
constructor(htmlId="",
checkStatus=true,
disabledBefore=true,
disabledAfter=false,
hideBefore=true,
hideAfter=false) {
this.htmlId = htmlId;
this.element = ((htmlId) => {
document.getElementById(htmlId);
})()
this.checkStatus = checkStatus;
this.callbacks = {};
this.disabledBefore = disabledBefore;
this.disabledAfter = disabledAfter;
this.hideBefore = hideBefore;
this.hideAfter = hideAfter;
}
setCallback(trigger, callback, bindThis, args=[]) {
this.callbacks[trigger] = {
"function": callback,
"bindThis": bindThis,
"args": args
};
}
bindThisToCallback(trigger) {
let callback = this.callbacks[trigger];
let boundedCallback = callback["function"].bind(callback.bindThis);
return boundedCallback;
}
}
class Interactions {
constructor() {
this.interactions = [];
}
addInteractions (interactions) {
this.interactions.push(...interactions);
}
/**
* This function executes all registered interactions of the type
* onElementChange.
* Interactions and their associated callbacks will be executed every time
* a chante event occurs on the specified element.
*/
onElementChangeExecute() {
// checks if a change for every interactionElement happens and executes
// the callbacks accordingly
for (let interaction of this.interactions) {
if (interaction.checkStatus) {
interaction.element.addEventListener("change", (event) => {
if (event.target.checked) {
let f_on = interaction.bindThisToCallback("on");
let args_on = interaction.callbacks.on.args;
f_on(...args_on);
} else if (!event.target.checked){
let f_off = interaction.bindThisToCallback("off");
let args_off = interaction.callbacks.off.args;
f_off(...args_off);
}
});
} else {
continue
}
};
}
/**
* This function executes all registered interactions of the type onQueryLoad.
* Interactions and their associated callbacks will be executed once if when
* the first query results of a query request are being displayed.
*/
onQueryLoadExecute() {
}
/**
* This function executes all registered interactions of the type
* onPageChange.
* Interactions and their associated callbacks will be executed everytime if
* the user used the page navigation and a new result page is being displayed.
*/
onPageChangeExecute() {
}
}
// export Classes
export { InteractionElement, InteractionElements };

View File

@ -251,7 +251,8 @@ class ResultsList extends List {
/** /**
* Also activate/deactivate buttons in the table/jsList results accordingly * Also activate/deactivate buttons in the table/jsList results accordingly
* if button in inspect was activated/deactivated. * if button in inspect was activated/deactivated.
* This part only runs if tableCall is false. * This part only runs if tableCall is set to false when this function is
* called.
*/ */
if (!tableCall) { if (!tableCall) {
this.getHTMLElements(['#query-results-table']); this.getHTMLElements(['#query-results-table']);
@ -350,7 +351,7 @@ class ResultsList extends List {
this.contextModal.open(); this.contextModal.open();
// add a button to add this match to sub results with onclick event // add a button to add this match to sub results with onclick event
let classes = `btn-floating btn waves-effect` + let classes = `btn-floating btn waves-effect` +
`waves-light grey right` ` waves-light grey right`
let addToSubResultsIdsBtn = document.createElement("a"); let addToSubResultsIdsBtn = document.createElement("a");
addToSubResultsIdsBtn.setAttribute("class", classes + ` add`); addToSubResultsIdsBtn.setAttribute("class", classes + ` add`);
addToSubResultsIdsBtn.innerHTML = '<i class="material-icons">add</i>'; addToSubResultsIdsBtn.innerHTML = '<i class="material-icons">add</i>';
@ -545,12 +546,10 @@ class ResultsList extends List {
this.page = this.displayOptionsFormResultsPerPage.value; this.page = this.displayOptionsFormResultsPerPage.value;
this.update(); this.update();
} }
// TODO: reimplement the followinmg stuff this.activateInspect();
// this.activateInspect(); if (this.displayOptionsFormExpertMode.checked) {
// this.pageChangeEventInteractionHandler(interactionElements); this.expertModeOn("query-display");
// if (expertModeSwitchElement.checked) { }
// this.expertModeOn("query-display"); // page holds new result rows, so add new tooltips
// }
} }
// Event function triggered on context select change // Event function triggered on context select change
@ -612,7 +611,7 @@ class ResultsList extends List {
this.currentExpertTokenElements[htmlId] = []; this.currentExpertTokenElements[htmlId] = [];
} }
let container = document.getElementById(htmlId); let container = document.getElementById(htmlId);
let tokens = container.querySelectorAll("span.token"); let tokens = container.querySelectorAll('span.token');
this.currentExpertTokenElements[htmlId].push(...tokens); this.currentExpertTokenElements[htmlId].push(...tokens);
this.eventTokens[htmlId] = []; this.eventTokens[htmlId] = [];
for (let tokenElement of this.currentExpertTokenElements[htmlId]) { for (let tokenElement of this.currentExpertTokenElements[htmlId]) {

View File

@ -51,8 +51,8 @@ function queryDataPreparingCallback(resultsList, detail) {
resultsList.clear() resultsList.clear()
// get needed HTML Elements // get needed HTML Elements
let results = detail.results; let results = detail.results;
resultsList.getHTMLElements( resultsList.getHTMLElements([
['#interactions-menu', '#interactions-menu',
'#recieved-match-count', '#recieved-match-count',
'#total-match-count', '#total-match-count',
'#text-lookup-count', '#text-lookup-count',
@ -108,6 +108,10 @@ function queryDataRecievingCallback(resultsList, detail) {
resultsList.update(); resultsList.update();
resultsList.changeHitsPerPage(); resultsList.changeHitsPerPage();
resultsList.changeContext(); resultsList.changeContext();
//activate expertMode of switch is checked
if (resultsList.displayOptionsFormExpertMode.checked) {
resultsList.expertModeOn('query-display', results);
}
} else if (!client.dynamicMode) { } else if (!client.dynamicMode) {
results.jsList.add(resultItems, (items) => { results.jsList.add(resultItems, (items) => {
for (let item of items) { for (let item of items) {

View File

@ -123,8 +123,9 @@ document.addEventListener("DOMContentLoaded", () => {
'dynamicMode': true}); 'dynamicMode': true});
/** /**
* Initializing the results object as a model holding all the data of a query. * Initializing the results object as a model holding all the data of a query.
* Also holds the metadata of one query. After that initialize the ResultsList * Also holds the metadata of one query.
* object as the View handeling the represnetation of the data. * After that initialize the ResultsList object as the View handeling the
* represnetation of the data for the user.
*/ */
let results = new Results(); let results = new Results();
let resultsList = new ResultsList('result-list', ResultsList.options); let resultsList = new ResultsList('result-list', ResultsList.options);
@ -174,7 +175,7 @@ document.addEventListener("DOMContentLoaded", () => {
listenForResults]); listenForResults]);
client.loadSocketEventListeners(); client.loadSocketEventListeners();
/** /**
* Register resultsList listeners listening to nitification events. * Register resultsList listeners listening to notification events.
*/ */
const listenForClientNotification = new ViewEventListener('notify-view', const listenForClientNotification = new ViewEventListener('notify-view',
recieveClientNotification); recieveClientNotification);
@ -221,7 +222,28 @@ document.addEventListener("DOMContentLoaded", () => {
'#query-results-download-modal', '#query-results-download-modal',
'#query-results-table', '#query-results-table',
'#display-options-form-expert_mode', '#display-options-form-expert_mode',
'.pagination',
]); ]);
/**
* The following listener handles what functions are called when the user
* does use the page navigation to navigate to a new page.
*/
for (let element of resultsList.pagination) {
element.addEventListener("click", (event) => {
// shows match context according to the user picked value
resultsList.changeContext();
// activates or deactivates expertMode on new page depending switch value
if (resultsList.displayOptionsFormExpertMode.checked) {
resultsList.expertModeOn('query-display', results);
} else {
resultsList.expertModeOff('query-display');
}
// activates inspect buttons on new page if client is not busy
resultsList.activateInspect();
});
}
/** /**
* The following event Listener handles the expert mode switch for the list * The following event Listener handles the expert mode switch for the list
*/ */