Skip to content
Snippets Groups Projects
Commit 55cacf53 authored by Stephan Porada's avatar Stephan Porada :speech_balloon:
Browse files

Add JSON handling with emit and on

parent d8b8c9f6
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ from flask import current_app, request ...@@ -5,6 +5,7 @@ from flask import current_app, request
from flask_login import login_required from flask_login import login_required
from .CQiWrapper.CQiWrapper import CQiWrapper from .CQiWrapper.CQiWrapper import CQiWrapper
import logging import logging
import json
''' '''
...@@ -36,13 +37,16 @@ def recv_query(message): ...@@ -36,13 +37,16 @@ def recv_query(message):
logger.warning(message) logger.warning(message)
analysis_client = analysis_clients[request.sid] analysis_client = analysis_clients[request.sid]
corpus_name = 'CORPUS' corpus_name = 'CORPUS'
result_subcorpus_name = 'Query-results' # should be set by the user somehow result_subcorpus_name = 'Query-results'
query = message['query'] query = message['query']
analysis_client.set_corpus_name(corpus_name) analysis_client.set_corpus_name(corpus_name)
analysis_client.create_attribute_strings() analysis_client.create_attribute_strings()
analysis_client.query_subcorpus(result_subcorpus_name, query) analysis_client.query_subcorpus(result_subcorpus_name, query)
results = analysis_client.show_results() results = analysis_client.show_results()
logger.warning('Query results: {}'.format(str(results))) logger.warning('Query results: {}'.format(str(results)))
json_results = json.dumps(results)
logger.warning('JSON results are {}'.format(json_results))
socketio.emit('query_results', json_results)
def observe_corpus_analysis_connection(app, corpus_id, session_id): def observe_corpus_analysis_connection(app, corpus_id, session_id):
......
...@@ -81,27 +81,20 @@ socket.on('init_corpus_analysis', function(msg) { ...@@ -81,27 +81,20 @@ socket.on('init_corpus_analysis', function(msg) {
</div> </div>
</div> </div>
</div> </div>
<script>
socket.on('query_results', function(json_results) {
console.log('Results recieved')
console.log(json_results)
let json_results = json_results;
});
</script>
<div class="col s12 m9 l9"> <div class="col s12 m9 l9">
<div class="card"> <div class="card">
<div class="card-content"> <div class="card-content">
<span class="card-title">Query Results</span> <span class="card-title">Query Results</span>
<table class="responsive highlight"> <table class="responsive highlight">
<tr> {% for hit in json_results %}
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
{% for i in range(0,51) %}
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment