forked from DGNum/gestioCOF
Improve websocket filter for special history pages
This commit is contained in:
parent
7a00096170
commit
66c5a6953c
4 changed files with 44 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -1062,6 +1062,9 @@ def kpsul_perform_operations(request):
|
|||
'valid_by': (operationgroup.valid_by and
|
||||
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',
|
||||
|
|
Loading…
Reference in a new issue