Emit query data via socketio

This commit is contained in:
Stephan Porada 2019-11-04 13:19:15 +01:00
parent fa61f97413
commit 9c611afdc3

View File

@ -3,7 +3,7 @@
{% block page_content %} {% block page_content %}
<div class="col s12 m3 l3 sticky"> <div class="col s12 m3 l3 sticky">
<div class="card"> <div class="card">
<form method="POST"> <form id="query_form" method="POST">
<div class="card-content"> <div class="card-content">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<span class="card-title">Query and analysis</span> <span class="card-title">Query and analysis</span>
@ -16,7 +16,7 @@
{% endfor %} {% endfor %}
</div> </div>
<div class="right-align"> <div class="right-align">
<button class="btn" type="submit" name="action">Start Query <button id="sent_query" class="btn" type="submit" name="action">Start Query
<i class="material-icons left">search</i> <i class="material-icons left">search</i>
</button> </button>
</div> </div>
@ -50,24 +50,24 @@
</div> </div>
<br> <br>
</form> </form>
<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 method="POST">
{{ form.hidden_tag() }} {{ 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() }}
{{ dl_form.file_type.label }} {{ dl_form.file_type.label }}
{% for error in dl_form.file_type.errors %} {% for error in dl_form.file_type.errors %}
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
{% endfor %} {% endfor %}
</div> </div>
<div class="right-align"> <div class="right-align">
<button class="btn" type="submit" name="action">Download <button class="btn" type="submit" name="action">Download
<i class="material-icons left">file_download</i> <i class="material-icons left">file_download</i>
</button> </button>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
@ -97,4 +97,25 @@
</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);
console.log('Query data has been sent!')
}
</script>
{% endblock %} {% endblock %}