From 69b17f350eaa4f25f599ec009aaec5a3fe4b61df Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Mon, 6 Apr 2020 15:28:58 +0200 Subject: [PATCH] Remove all pjs! --- app/corpora/events.py | 64 +++++++++---------- app/static/js/nopaque.CorpusAnalysisClient.js | 18 +++--- app/static/js/nopaque.analyse_corpus.js | 2 +- app/templates/corpora/analyse_corpus.html.j2 | 2 +- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/app/corpora/events.py b/app/corpora/events.py index b4b10d77..73d189f9 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -13,30 +13,30 @@ import math ' A dictionary containing lists of, with corpus ids associated, Socket.IO ' session ids (sid). {: [, ...], ...} ''' -pj_corpus_analysis_sessions = {} +corpus_analysis_sessions = {} ''' ' A dictionary containing Socket.IO session id - CQi client pairs. ' {: CQiClient, ...} ''' -pj_corpus_analysis_clients = {} +corpus_analysis_clients = {} -@socketio.on('pj_corpus_analysis_init') +@socketio.on('corpus_analysis_init') @socketio_login_required -def pj_init_corpus_analysis(corpus_id): - socketio.start_background_task(pj_corpus_analysis_session_handler, +def init_corpus_analysis(corpus_id): + socketio.start_background_task(corpus_analysis_session_handler, current_app._get_current_object(), corpus_id, current_user.id, request.sid) -@socketio.on('pj_corpus_analysis_query') +@socketio.on('corpus_analysis_query') @socketio_login_required -def pj_corpus_analysis_query(query): - client = pj_corpus_analysis_clients.get(request.sid) +def corpus_analysis_query(query): + client = corpus_analysis_clients.get(request.sid) if client is None: response = {'code': 404, 'desc': 'No client found for this session', 'msg': 'Failed Dependency'} - socketio.emit('pj_corpus_analysis_query', response, room=request.sid) + socketio.emit('corpus_analysis_query', response, room=request.sid) return if client.status == 'running': client.status = 'abort' @@ -48,7 +48,7 @@ def pj_corpus_analysis_query(query): response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error', 'payload': {'code': e.code, 'desc': e.description, 'msg': e.name}} - socketio.emit('pj_corpus_analysis_query', response, room=request.sid) + socketio.emit('corpus_analysis_query', response, room=request.sid) return try: query_status = corpus.query(query) @@ -56,7 +56,7 @@ def pj_corpus_analysis_query(query): response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error', 'payload': {'code': e.code, 'desc': e.description, 'msg': e.name}} - socketio.emit('pj_corpus_analysis_query', response, room=request.sid) + socketio.emit('corpus_analysis_query', response, room=request.sid) return try: results = corpus.subcorpora.get('Results') @@ -64,11 +64,11 @@ def pj_corpus_analysis_query(query): response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error', 'payload': {'code': e.code, 'desc': e.description, 'msg': e.name}} - socketio.emit('pj_corpus_analysis_query', response, room=request.sid) + socketio.emit('corpus_analysis_query', response, room=request.sid) return response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': {**query_status, 'match_count': results.size}} - socketio.emit('pj_corpus_analysis_query', response, room=request.sid) + socketio.emit('corpus_analysis_query', response, room=request.sid) chunk_size = 100 chunk_start = 0 context = 100 @@ -87,17 +87,17 @@ def pj_corpus_analysis_query(query): progress = min(100, int(math.ceil(progress))) response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': {'chunk': chunk, 'progress': progress}} - socketio.emit('pj_corpus_analysis_query_results', response, + socketio.emit('corpus_analysis_query_results', response, room=request.sid) chunk_start += chunk_size client.status = 'ready' -@socketio.on('pj_corpus_analysis_inspect_match') +@socketio.on('corpus_analysis_inspect_match') @socketio_login_required -def pj_corpus_analysis_inspect_match(payload): +def corpus_analysis_inspect_match(payload): payload = payload["payload"] - client = pj_corpus_analysis_clients.get(request.sid) + client = corpus_analysis_clients.get(request.sid) if client is None: socketio.emit('query', '[424]: Failed Dependency', room=request.sid) @@ -108,22 +108,22 @@ def pj_corpus_analysis_inspect_match(payload): match_context = s.export(payload['first_cpos'], payload['last_cpos'], context=3, expand_lists=False) match_context['cpos_ranges'] = True - socketio.emit('pj_match_context', + socketio.emit('match_context', {'payload': match_context}, room=request.sid) -def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id): +def corpus_analysis_session_handler(app, corpus_id, user_id, session_id): with app.app_context(): ''' Setup analysis session ''' corpus = Corpus.query.get(corpus_id) user = User.query.get(user_id) if corpus is None: response = {'code': 404, 'desc': None, 'msg': 'Not Found'} - socketio.emit('pj_corpus_analysis_init', response, room=session_id) + socketio.emit('corpus_analysis_init', response, room=session_id) return elif not (corpus.creator == user or user.is_administrator()): response = {'code': 403, 'desc': None, 'msg': 'Forbidden'} - socketio.emit('pj_corpus_analysis_init', response, room=session_id) + socketio.emit('corpus_analysis_init', response, room=session_id) return while corpus.status != 'analysing': db.session.refresh(corpus) @@ -136,22 +136,22 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id): 'msg': 'Internal Server Error', 'payload': {'code': e.code, 'desc': e.description, 'msg': e.name}} - socketio.emit('pj_corpus_analysis_init', response, room=session_id) + socketio.emit('corpus_analysis_init', response, room=session_id) return except gaierror: response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error'} - socketio.emit('pj_corpus_analysis_init', response, room=session_id) + socketio.emit('corpus_analysis_init', response, room=session_id) return - pj_corpus_analysis_clients[session_id] = client - if corpus_id not in pj_corpus_analysis_sessions: - pj_corpus_analysis_sessions[corpus_id] = [session_id] + corpus_analysis_clients[session_id] = client + if corpus_id not in corpus_analysis_sessions: + corpus_analysis_sessions[corpus_id] = [session_id] else: - pj_corpus_analysis_sessions[corpus_id].append(session_id) + corpus_analysis_sessions[corpus_id].append(session_id) client.status = 'ready' response = {'code': 200, 'desc': None, 'msg': 'OK', 'payload': {**connect_status}} - socketio.emit('pj_corpus_analysis_init', response, room=session_id) + socketio.emit('corpus_analysis_init', response, room=session_id) ''' Observe analysis session ''' while session_id in connected_sessions: socketio.sleep(3) @@ -164,9 +164,9 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id): client.disconnect() except cqi.errors.CQiException: pass - pj_corpus_analysis_clients.pop(session_id, None) - pj_corpus_analysis_sessions[corpus_id].remove(session_id) - if not pj_corpus_analysis_sessions[corpus_id]: - pj_corpus_analysis_sessions.pop(corpus_id, None) + corpus_analysis_clients.pop(session_id, None) + corpus_analysis_sessions[corpus_id].remove(session_id) + if not corpus_analysis_sessions[corpus_id]: + corpus_analysis_sessions.pop(corpus_id, None) corpus.status = 'stop analysis' db.session.commit() diff --git a/app/static/js/nopaque.CorpusAnalysisClient.js b/app/static/js/nopaque.CorpusAnalysisClient.js index 016d6222..77dd0d6f 100644 --- a/app/static/js/nopaque.CorpusAnalysisClient.js +++ b/app/static/js/nopaque.CorpusAnalysisClient.js @@ -6,11 +6,11 @@ class CorpusAnalysisClient { this.socket = socket; // socket on event fpr corpous analysis initialization - socket.on("pj_corpus_analysis_init", (response) => { + socket.on("corpus_analysis_init", (response) => { var errorText; if (response.code === 200) { - console.log(`pj_corpus_analysis_init: ${response.code} - ${response.msg}`); + console.log(`corpus_analysis_init: ${response.code} - ${response.msg}`); if (this.callbacks.init != undefined) { this.callbacks.init(response.payload); } @@ -25,16 +25,16 @@ class CorpusAnalysisClient { if (this.displays.init != undefined) { this.displays.init.setVisibilityByStatus("error"); } - console.error(`pj_corpus_analysis_init: ${errorText}`); + console.error(`corpus_analysis_init: ${errorText}`); } }); // socket on event for recieveing query results - socket.on("pj_corpus_analysis_query", (response) => { + socket.on("corpus_analysis_query", (response) => { var errorText; if (response.code === 200) { - console.log(`pj_corpus_analysis_query: ${response.code} - ${response.msg}`); + console.log(`corpus_analysis_query: ${response.code} - ${response.msg}`); if (this.callbacks.query != undefined) { this.callbacks.query(response.payload); } @@ -50,11 +50,11 @@ class CorpusAnalysisClient { if (this.displays.query != undefined) { this.displays.query.setVisibilityByStatus("error"); } - console.error(`pj_corpus_analysis_query: ${errorText}`); + console.error(`corpus_analysis_query: ${errorText}`); } }); - socket.on("pj_corpus_analysis_query_results", (response) => { + socket.on("corpus_analysis_query_results", (response) => { if (this.callbacks.query_results != undefined) {this.callbacks.query_results(response.payload);} }); } @@ -66,7 +66,7 @@ class CorpusAnalysisClient { if (this.displays.init != undefined) { this.displays.init.setVisibilityByStatus("waiting"); } - this.socket.emit("pj_corpus_analysis_init", this.corpusId); + this.socket.emit("corpus_analysis_init", this.corpusId); } query(queryStr) { @@ -79,7 +79,7 @@ class CorpusAnalysisClient { if (this.displays.query != undefined) { this.displays.query.setVisibilityByStatus("waiting"); } - nopaque.socket.emit("pj_corpus_analysis_query", queryStr); + nopaque.socket.emit("corpus_analysis_query", queryStr); } setCallback(type, callback) { diff --git a/app/static/js/nopaque.analyse_corpus.js b/app/static/js/nopaque.analyse_corpus.js index 11a07754..7bdc77ca 100644 --- a/app/static/js/nopaque.analyse_corpus.js +++ b/app/static/js/nopaque.analyse_corpus.js @@ -94,7 +94,7 @@ function inspect(dataIndex) { contextResultsElement = document.getElementById("context-results"); contextResultsElement.innerHTML = ""; // clear it from old inspects contextModal.open(); - nopaque.socket.emit("pj_corpus_analysis_inspect_match", + nopaque.socket.emit("corpus_analysis_inspect_match", {payload: { first_cpos: results.resultsJSON.matches[dataIndex].c[0], last_cpos: results.resultsJSON.matches[dataIndex].c[1] diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index 101c1215..c4ba83c9 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -328,7 +328,7 @@ }); // get context of one match if inspected via socket.io - nopaque.socket.on("pj_match_context", showMatchContext); + nopaque.socket.on("match_context", showMatchContext); // live update of hits per page if hits per page value is changed hitsPerPageInputElement = document.getElementById("display-options-form-results_per_page");