mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Change event names
This commit is contained in:
		@@ -35,47 +35,42 @@ def disconnect():
 | 
			
		||||
    connected_sessions.remove(request.sid)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@socketio.on('subscribe_user_ressources')
 | 
			
		||||
@socketio.on('user_ressources_init')
 | 
			
		||||
@login_required
 | 
			
		||||
def subscribe_user_ressources():
 | 
			
		||||
    socketio.start_background_task(user_ressource_subscription_handler,
 | 
			
		||||
    socketio.start_background_task(user_ressource_session_handler,
 | 
			
		||||
                                   current_app._get_current_object(),
 | 
			
		||||
                                   current_user.id, request.sid)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@socketio.on('subscribe_foreign_user_ressources')
 | 
			
		||||
@socketio.on('foreign_user_ressources_init')
 | 
			
		||||
@login_required
 | 
			
		||||
@admin_required
 | 
			
		||||
def subscribe_foreign_user_ressources(user_id):
 | 
			
		||||
    socketio.start_background_task(user_ressource_subscription_handler,
 | 
			
		||||
    socketio.start_background_task(user_ressource_session_handler,
 | 
			
		||||
                                   current_app._get_current_object(),
 | 
			
		||||
                                   user_id, request.sid, True)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def user_ressource_subscription_handler(app, user_id, session_id,
 | 
			
		||||
                                        foreign=False):
 | 
			
		||||
def user_ressource_session_handler(app, user_id, session_id, foreign=False):
 | 
			
		||||
    '''
 | 
			
		||||
    ' Sends initial corpus and job lists to the client. Afterwards it checks
 | 
			
		||||
    ' every 3 seconds if changes to the initial values appeared. If changes are
 | 
			
		||||
    ' detected, a RFC 6902 compliant JSON patch gets send.
 | 
			
		||||
    '
 | 
			
		||||
    ' NOTE: The initial values are send as a init-* events.
 | 
			
		||||
    '       The JSON patches are send as update-* events.
 | 
			
		||||
    '           > where '*' is either 'corpora' or 'jobs'
 | 
			
		||||
    ' NOTE: The initial values are send as a init events.
 | 
			
		||||
    '       The JSON patches are send as update events.
 | 
			
		||||
    '''
 | 
			
		||||
    init_events = {'corpora': 'init-foreign-corpora' if foreign
 | 
			
		||||
                   else 'init-corpora',
 | 
			
		||||
                   'jobs': 'init-foreign-jobs' if foreign else 'init-jobs'}
 | 
			
		||||
    update_events = {'corpora': 'update-foreign-corpora' if foreign
 | 
			
		||||
                     else 'update-corpora',
 | 
			
		||||
                     'jobs': 'update-foreign-jobs' if foreign
 | 
			
		||||
                     else 'update-jobs'}
 | 
			
		||||
    init_events = {'corpora': 'foreign_corpora_init' if foreign
 | 
			
		||||
                   else 'corpora_init',
 | 
			
		||||
                   'jobs': 'foreign_jobs_init' if foreign else 'jobs_init'}
 | 
			
		||||
    update_events = {'corpora': 'foreign_corpora_update' if foreign
 | 
			
		||||
                     else 'corpora_update',
 | 
			
		||||
                     'jobs': 'foreign_jobs_update' if foreign
 | 
			
		||||
                     else 'jobs_update'}
 | 
			
		||||
    with app.app_context():
 | 
			
		||||
        # Gather current values from database.
 | 
			
		||||
        user = User.query.get(user_id)
 | 
			
		||||
        if user is None:
 | 
			
		||||
            ''' TODO: Handle this '''
 | 
			
		||||
            return
 | 
			
		||||
        corpora = {corpus.id: corpus.to_dict() for corpus in user.corpora}
 | 
			
		||||
        jobs = {job.id: job.to_dict() for job in user.jobs}
 | 
			
		||||
        # Send initial values to the user.
 | 
			
		||||
 
 | 
			
		||||
@@ -108,19 +108,19 @@ nopaque["toast"] = function(message, color="") {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// socket event handlers
 | 
			
		||||
nopaque.socket.on('init-corpora', function(msg) {
 | 
			
		||||
nopaque.socket.on('corpora_init', function(msg) {
 | 
			
		||||
  nopaque.corpora = JSON.parse(msg);
 | 
			
		||||
  for (let subscriber of nopaque.corporaSubscribers) {subscriber._init(nopaque.corpora);}
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nopaque.socket.on('init-jobs', function(msg) {
 | 
			
		||||
nopaque.socket.on('jobs_init', function(msg) {
 | 
			
		||||
  nopaque.jobs = JSON.parse(msg);
 | 
			
		||||
  for (let subscriber of nopaque.jobsSubscribers) {subscriber._init(nopaque.jobs);}
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nopaque.socket.on('update-corpora', function(msg) {
 | 
			
		||||
nopaque.socket.on('corpora_update', function(msg) {
 | 
			
		||||
  var patch;
 | 
			
		||||
 | 
			
		||||
  patch = JSON.parse(msg);
 | 
			
		||||
@@ -129,7 +129,7 @@ nopaque.socket.on('update-corpora', function(msg) {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nopaque.socket.on('update-jobs', function(msg) {
 | 
			
		||||
nopaque.socket.on('jobs_update', function(msg) {
 | 
			
		||||
  var patch;
 | 
			
		||||
 | 
			
		||||
  patch = JSON.parse(msg);
 | 
			
		||||
@@ -138,19 +138,19 @@ nopaque.socket.on('update-jobs', function(msg) {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nopaque.socket.on('init-foreign-corpora', function(msg) {
 | 
			
		||||
nopaque.socket.on('foreign_corpora_init', function(msg) {
 | 
			
		||||
  nopaque.foreignCorpora = JSON.parse(msg);
 | 
			
		||||
  for (let subscriber of nopaque.foreignCorporaSubscribers) {subscriber._init(nopaque.foreignCorpora);}
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nopaque.socket.on('init-foreign-jobs', function(msg) {
 | 
			
		||||
nopaque.socket.on('foreign_jobs_init', function(msg) {
 | 
			
		||||
  nopaque.foreignJobs = JSON.parse(msg);
 | 
			
		||||
  for (let subscriber of nopaque.foreignJobsSubscribers) {subscriber._init(nopaque.foreignJobs);}
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nopaque.socket.on('update-foreign-corpora', function(msg) {
 | 
			
		||||
nopaque.socket.on('foreign_corpora_update', function(msg) {
 | 
			
		||||
  var patch;
 | 
			
		||||
 | 
			
		||||
  patch = JSON.parse(msg);
 | 
			
		||||
@@ -159,7 +159,7 @@ nopaque.socket.on('update-foreign-corpora', function(msg) {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
nopaque.socket.on('update-foreign-jobs', function(msg) {
 | 
			
		||||
nopaque.socket.on('foreign_jobs_update', function(msg) {
 | 
			
		||||
  var patch;
 | 
			
		||||
 | 
			
		||||
  patch = JSON.parse(msg);
 | 
			
		||||
@@ -175,5 +175,5 @@ document.addEventListener("DOMContentLoaded", function() {
 | 
			
		||||
                  {"alignment": "right", "constrainWidth": false, "coverTrigger": false});
 | 
			
		||||
  nopaque.forms.init();
 | 
			
		||||
  nopaque.navigation.init();
 | 
			
		||||
  nopaque.socket.emit("subscribe_user_ressources");
 | 
			
		||||
  nopaque.socket.emit("user_ressources_init");
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -102,6 +102,6 @@
 | 
			
		||||
<script>
 | 
			
		||||
  var corpusList = new CorpusList("corpora", nopaque.foreignCorporaSubscribers);
 | 
			
		||||
  var jobList = new JobList("jobs", nopaque.foreignJobsSubscribers);
 | 
			
		||||
  nopaque.socket.emit("subscribe_foreign_user_ressources", {{ user.id }});
 | 
			
		||||
  nopaque.socket.emit("foreign_user_ressources_init", {{ user.id }});
 | 
			
		||||
</script>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user