Change HTML for corpus analysis

This commit is contained in:
Patrick Jentsch 2019-11-14 15:34:07 +01:00
parent 1b02d73d66
commit df98f3a900
2 changed files with 78 additions and 100 deletions

View File

@ -38,7 +38,7 @@ def init_corpus_analysis(corpus_id):
corpus_id, request.sid) corpus_id, request.sid)
@socketio.on('query_event') @socketio.on('query')
@login_required @login_required
def recv_query(message): def recv_query(message):
logger.warning(message) logger.warning(message)
@ -80,7 +80,7 @@ def recv_query(message):
match['word_list'] = [foo[cpos]['word'] for cpos in match['cpos_list']] match['word_list'] = [foo[cpos]['word'] for cpos in match['cpos_list']]
match.pop('cpos_list', None) match.pop('cpos_list', None)
logger.warning(matches) logger.warning(matches)
socketio.emit('query_results', matches, room=request.sid) socketio.emit('query', matches, room=request.sid)
def observe_corpus_analysis_connection(app, corpus_id, session_id): def observe_corpus_analysis_connection(app, corpus_id, session_id):

View File

@ -1,14 +1,13 @@
{% extends "full_width.html.j2" %} {% extends "full_width.html.j2" %}
{% block page_content %} {% block page_content %}
<div class="col s12 m3 l3 sticky"> <div class="col s12 m3 sticky">
<a class="waves-effect waves-light btn" href="{{ url_for('corpora.corpus', corpus_id=corpus_id) }}"><i class="material-icons left">arrow_back</i>Back to corpus overview</a> <a class="waves-effect waves-light btn" href="{{ url_for('corpora.corpus', corpus_id=corpus_id) }}"><i class="material-icons left">arrow_back</i>Back to corpus overview</a>
<div class="card"> <div class="card">
<form id="query_form" method="POST">
<div class="card-content"> <div class="card-content">
<form id="query-form" method="POST">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<span class="card-title">Query and analysis</span> <span class="card-title">Query and analysis</span>
<br>
<div class="input-field"> <div class="input-field">
{{ form.query(class='materialize-textarea') }} {{ form.query(class='materialize-textarea') }}
{{ form.query.label }} {{ form.query.label }}
@ -16,22 +15,12 @@
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
{% endfor %} {% endfor %}
</div> </div>
<div class="right-align"> <button class="btn waves-effect waves-light" id="query-form-submit" style="width: 100%;" type="submit">Start Query</button>
<button id="sent_query" class="btn" type="submit" name="action">Start Query <p>&nbsp;</p>
<i class="material-icons left">search</i>
</button>
</div>
<br>
<span class="card-title">Help</span> <span class="card-title">Help</span>
<ul> <p><a href="http://cwb.sourceforge.net/files/CQP_Tutorial/">CQP Query Language Tutorial</a></p>
<li> <p>&nbsp;</p>
<a href="http://cwb.sourceforge.net/files/CQP_Tutorial/">
CQP Query Language Tutorial</a>
</li>
</ul>
<br>
<span class="card-title">Options</span> <span class="card-title">Options</span>
<br>
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">format_list_numbered</i> <i class="material-icons prefix">format_list_numbered</i>
{{ form.hits_per_page() }} {{ form.hits_per_page() }}
@ -40,7 +29,6 @@
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
{% endfor %} {% endfor %}
</div> </div>
<br>
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">short_text</i> <i class="material-icons prefix">short_text</i>
{{ form.context() }} {{ form.context() }}
@ -49,12 +37,16 @@
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
{% endfor %} {% endfor %}
</div> </div>
<br>
</form> </form>
</div>
</div>
<div class="card">
<div class="card-content">
<form id="download-form" method="POST">
{{ dl_form.hidden_tag() }}
<span class="card-title">Download Results</span> <span class="card-title">Download Results</span>
<p>Downlaod all results of the current query as csv, excel or json file.</p> <p>Downlaod all results of the current query as csv, excel or json file.</p>
<form method="POST">
{{ form.hidden_tag() }}
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">insert_drive_file</i> <i class="material-icons prefix">insert_drive_file</i>
{{ dl_form.file_type() }} {{ dl_form.file_type() }}
@ -63,55 +55,20 @@
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
{% endfor %} {% endfor %}
</div> </div>
<div class="right-align"> <button class="btn waves-effect waves-light" id="download-form-submit" style="width: 100%;" type="submit">Download</button>
<button class="btn" type="submit" name="action">Download
<i class="material-icons left">file_download</i>
</button>
</div>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
<script>
socket.on('query_results', function(json_results) { <div class="col s12 m9">
console.log('Results recieved')
console.log(json_results)
var queryResultsElement = document.getElementById("query-results");
for (let json_result of json_results) {
queryResultsElement.innerHTML += json_result['word_list'] + '<br>';
}
});
</script>
<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>
<p id="query-results"></p> <div id="query-results"></div>
</div> </div>
</div> </div>
</div> </div>
<script>
let queryData = document.forms['query_form'].elements;
console.log(queryData);
var queryBtn = document.getElementById('sent_query');
queryBtn.addEventListener('click', function(event) {
event.preventDefault();
sendQueryData();
});
function sendQueryData() {
var query_data = {};
for (element of queryData) {
if (!element.value || element.name == 'csrf_token' || !element.id) {
continue;
}
query_data[element.id] = element.value
}
console.log(query_data)
socket.emit('query_event', query_data);
M.toast({html: 'Query has been sent'});
console.log('Query data has been sent!');
}
</script>
<div id="loading-modal" class="modal no-autoinit"> <div id="loading-modal" class="modal no-autoinit">
<div class="modal-content"> <div class="modal-content">
@ -133,16 +90,37 @@ function sendQueryData() {
</div> </div>
<script> <script>
var loadingModal; var loadingModal;
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
loadingModal = M.Modal.init(document.getElementById("loading-modal"), {"dismissible": false}); loadingModal = M.Modal.init(document.getElementById("loading-modal"),
{"dismissible": false});
loadingModal.open(); loadingModal.open();
}); });
socket.emit('init_corpus_analysis', {{ corpus_id }});
socket.emit('init_corpus_analysis', {{ corpus_id }}); var queryFormElement = document.getElementById("query-form");
socket.on('init_corpus_analysis', function(msg) { var queryFormSubmitElement = document.getElementById("query-form-submit");
var queryResultsElement = document.getElementById("query-results");
queryFormSubmitElement.addEventListener('click', function(event) {
event.preventDefault();
let formData = new FormData(queryFormElement);
let queryData = {'context': formData.get('context'),
'hits_per_page': formData.get('hits_per_page'),
'query': formData.get('query')};
socket.emit('query', queryData);
M.toast({html: 'Query has been sent!'});
});
socket.on('init_corpus_analysis', function(msg) {
if (msg === 'Ready') {loadingModal.close();} if (msg === 'Ready') {loadingModal.close();}
}); });
socket.on('query', function(results) {
queryResultsElement.innerHTML = '';
for (let result of results) {
queryResultsElement.innerHTML += '<p>' + result['word_list'] + '</p>';
}
});
</script> </script>
{% endblock %} {% endblock %}