Add socketio javascript

This commit is contained in:
Patrick Jentsch 2019-08-22 15:13:10 +02:00
parent a44407255b
commit 9f215d7613
3 changed files with 24 additions and 4 deletions

View File

@ -1,12 +1,10 @@
from flask import (abort, current_app, flash, redirect, request, from flask import (abort, current_app, flash, redirect, request,
render_template, url_for, send_from_directory) render_template, url_for, send_from_directory)
from flask_login import current_user, login_required from flask_login import current_user, login_required
from ..models import Corpus, User
from ..tables import AdminUserTable, AdminUserItem
from . import main from . import main
from .forms import CreateCorpusForm from .forms import CreateCorpusForm
from ..decorators import admin_required from .. import db, socketio
from .. import db from ..models import Corpus
import os import os
@ -15,6 +13,12 @@ def index():
return render_template('main/index.html.j2', title='Opaque') return render_template('main/index.html.j2', title='Opaque')
@socketio.on('my event')
@login_required
def handle_message(message):
print('received message: ' + str(message))
@main.route('/corpora/<int:corpus_id>') @main.route('/corpora/<int:corpus_id>')
@login_required @login_required
def corpus(corpus_id): def corpus(corpus_id):

File diff suppressed because one or more lines are too long

View File

@ -27,6 +27,13 @@
<script src="{{ url_for('static', filename='js/jsondiffpatch.umd.js') }}"></script> <script src="{{ url_for('static', filename='js/jsondiffpatch.umd.js') }}"></script>
<script src="{{ url_for('static', filename='js/polls.js') }}"></script> <script src="{{ url_for('static', filename='js/polls.js') }}"></script>
{% endif %} {% endif %}
<script src="{{ url_for('static', filename='js/socket.io.js') }}"></script>
<script type="text/javascript" charset="utf-8">
var socket = io();
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});
</script>
<script src="{{ url_for('static', filename='js/list.min.js') }}"></script> <script src="{{ url_for('static', filename='js/list.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/utils.js') }}"></script> <script src="{{ url_for('static', filename='js/utils.js') }}"></script>
<script src="{{ url_for('static', filename='js/CorpusList.js') }}"></script> <script src="{{ url_for('static', filename='js/CorpusList.js') }}"></script>