diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 33e9a318..ecf86878 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -138,6 +138,30 @@ class History { return true; } + is_valid(opegroup) { + var options = this.api_options; + + if (options.from && dateUTCToParis(opegroup.content.at).isBefore(moment(options.from))) + return false; + + if (options.to && dateUTCToParis(opegroup.content.at).isAfter(moment(options.to))) + return false; + + if (options.transfersonly && opegroup.type === 'opegroup') + return false; + + if (options.accounts && options.accounts.length && + options.accounts.indexOf(opegroup.content.account_id) < 0) + return false; + + if (options.checkouts && options.checkouts.length && + (opegroup.type === 'transfergroup' || + options.checkouts.indexOf(opegroup.content.checkout_id) < 0)) + return false; + + return true; + } + update_data(data) { //Filter opegroups before ? var opegroups = data['opegroups']; @@ -164,10 +188,7 @@ class History { this.update_node('opegroup', opegroup.id, update_data); } - if (opegroup['add']) { - if (opegroup.type === 'opegroup' && this.api_options.transfersonly) - return; - + if (opegroup['add'] && this.is_valid(opegroup)) { this.add_node(opegroup); } } diff --git a/kfet/templates/kfet/account_read.html b/kfet/templates/kfet/account_read.html index 7618375c..7f3c951f 100644 --- a/kfet/templates/kfet/account_read.html +++ b/kfet/templates/kfet/account_read.html @@ -78,7 +78,20 @@ $(document).ready(function() { 'accounts': [{{ account.pk }}], }; - //TODO: add ws support ? + // ----- + // Synchronization + // ----- + + var websocket_msg_default = {'opegroups':[],'opes':[]} + + var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; + var location_host = window.location.host; + var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host; + var socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + "/ws/k-fet/k-psul/"); + socket.onmessage = function(e) { + var data = $.extend({}, websocket_msg_default, JSON.parse(e.data)); + history.update_data(data); + } history.reset(); }); diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html index 0b6841ae..34d2ac15 100644 --- a/kfet/templates/kfet/history.html +++ b/kfet/templates/kfet/history.html @@ -115,7 +115,7 @@ $(document).ready(function() { timeZone : 'Europe/Paris', format : 'YYYY-MM-DD HH:mm', stepping : 5, - defaultDate: moment(), + defaultDate: moment().add(5, 'minutes'), // workaround for 'stepping' rounding locale : 'fr', showTodayButton: true, }); diff --git a/kfet/views.py b/kfet/views.py index 27de08f8..0354d655 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1060,8 +1060,11 @@ def kpsul_perform_operations(request): 'is_cof': operationgroup.is_cof, 'comment': operationgroup.comment, 'valid_by': (operationgroup.valid_by and - operationgroup.valid_by.trigramme or None), + operationgroup.valid_by.trigramme or None), 'trigramme': operationgroup.on_acc.trigramme, + # Used to filter websocket updates + 'account_id': operationgroup.on_acc.pk, + 'checkout_id': operationgroup.checkout.pk, }, 'parent': { 'type': 'day',