From 02a015e633c6d3ff3f68d2acebeb39adcdc7a52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Tue, 16 May 2017 17:08:51 +0200 Subject: [PATCH 1/3] fix data sent to ws by perform_transfers --- kfet/views.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index 6751d95b..ea191ce3 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1799,22 +1799,27 @@ def perform_transfers(request): websocket_data['opegroups'] = [{ 'add': True, 'modelname': 'transfergroup', - 'id': transfergroup.pk, - 'at': transfergroup.at, - 'comment': transfergroup.comment, - 'valid_by__trigramme': (transfergroup.valid_by and - transfergroup.valid_by.trigramme or None), - 'opes': [], + 'content': { + 'id': transfergroup.pk, + 'at': transfergroup.at, + 'comment': transfergroup.comment, + 'valid_by__trigramme': (transfergroup.valid_by and + transfergroup.valid_by.trigramme or None), + 'children': [] + }, }] for transfer in transfers: ope_data = { - 'id': transfer.pk, - 'amount': transfer.amount, - 'from_acc': transfer.from_acc.trigramme, - 'to_acc': transfer.to_acc.trigramme, - 'canceled_by__trigramme': None, 'canceled_at': None, + 'modelname': 'transfer', + 'content': { + 'id': transfer.pk, + 'amount': transfer.amount, + 'from_acc': transfer.from_acc.trigramme, + 'to_acc': transfer.to_acc.trigramme, + 'canceled_by__trigramme': None, 'canceled_at': None, + }, } - websocket_data['opegroups'][0]['opes'].append(ope_data) + websocket_data['opegroups'][0]['content']['children'].append(ope_data) consumers.KPsul.group_send('kfet.kpsul', websocket_data) return JsonResponse(data) From cb0c0be8a24eacf32c60512bf9da7005221df3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Tue, 16 May 2017 18:08:40 +0200 Subject: [PATCH 2/3] filters on ws for khistory - fix filters on ws khistory updates - add filters for transfers against accounts --- kfet/static/kfet/js/history.js | 47 +++++++++++++++++++++++--------- kfet/templates/kfet/history.html | 3 +- kfet/views.py | 2 ++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 0f07f73b..58a9d3f5 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -155,26 +155,47 @@ class KHistory { is_valid(opegroup) { var options = this.api_options; - if (options.from && dateUTCToParis(opegroup.at).isBefore(moment(options.from))) + if (options.from && dateUTCToParis(opegroup.content.at).isBefore(moment(options.from))) return false; - if (options.to && dateUTCToParis(opegroup.at).isAfter(moment(options.to))) + if (options.to && dateUTCToParis(opegroup.content.at).isAfter(moment(options.to))) return false; - if (options.transfersonly && opegroup.constructor.verbose_name == 'opegroup') - return false; + var accounts_filter = options.accounts && options.accounts.length; + var checkouts_filter = options.checkouts && options.checkouts.length; - if (options.opesonly && opegroup.constructor.verbose_name == 'transfergroup') - return false; + if (opegroup.modelname == 'opegroup') { - if (options.accounts && options.accounts.length && - options.accounts.indexOf(opegroup.account_id) < 0) - return false; + if (options.transfersonly) + return false; - if (options.checkouts && options.checkouts.length && - (opegroup.modelname == 'transfergroup' || - options.checkouts.indexOf(opegroup.checkout_id) < 0)) - return false; + if (accounts_filter && options.accounts.indexOf(opegroup.content.account_id) < 0) + return false; + + if (checkouts_filter && options.checkouts.indexOf(opegroup.content.checkout_id) < 0) + return false; + + } else if (opegroup.modelname == 'transfergroup') { + + if (options.opesonly) + return false; + + if (checkouts_filter) + return false; + + if (accounts_filter) { + opegroup.content.children = + opegroup.content.children.filter( function(transfer) { + var is_from_in = + options.accounts.indexOf(transfer.content.from_acc_id) >= 0; + var is_to_in = + options.accounts.indexOf(transfer.content.to_acc_id) >= 0; + return is_from_in || is_to_in; + }); + if (opegroup.content.children.length == 0) + return false; + } + } return true; } diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html index 2075cf30..03a468ef 100644 --- a/kfet/templates/kfet/history.html +++ b/kfet/templates/kfet/history.html @@ -94,7 +94,8 @@ $(document).ready(function() { if ($checkouts) data['checkouts'] = checkouts; var accounts = getSelectedMultiple($accounts); - data['accounts'] = accounts; + if (accounts) + data['accounts'] = accounts.map(id => parseInt(id)); // Update history khistory.fetch(data); diff --git a/kfet/views.py b/kfet/views.py index ea191ce3..d2ed376c 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1817,6 +1817,8 @@ def perform_transfers(request): 'from_acc': transfer.from_acc.trigramme, 'to_acc': transfer.to_acc.trigramme, 'canceled_by__trigramme': None, 'canceled_at': None, + 'from_acc_id': transfer.from_acc.id, + 'to_acc_id': transfer.to_acc.id, }, } websocket_data['opegroups'][0]['content']['children'].append(ope_data) From 24b9aaae39394fe8a261e457c164643d42e170eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Tue, 16 May 2017 18:47:26 +0200 Subject: [PATCH 3/3] Revert template literals use They were adding spaces at some places. --- kfet/static/kfet/js/history.js | 62 ++++------------------------------ kfet/static/kfet/js/kpsul.js | 49 +++++---------------------- 2 files changed, 15 insertions(+), 96 deletions(-) diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 58a9d3f5..291cc675 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -5,53 +5,12 @@ class KHistory { static get default_options() { return { 'templates': { - 'purchase': ` -
- - - - - -
- `, - 'specialope': ` -
- - - - - -
- `, - 'opegroup': ` -
- - - - - -
`, - 'transfergroup': ` -
- - - - -
- `, - 'day': ` -
- -
- `, - 'transfer': ` -
- - - - - -
`, + 'purchase': '
', + 'specialope': '
', + 'opegroup': '
', + 'transfergroup': '
', + 'day': '
', + 'transfer': '
', }, 'api_options': { @@ -78,14 +37,7 @@ class KHistory { var templates = all_options.templates; if (all_options.no_trigramme) - templates['opegroup'] = ` -
- - - - -
- `; + templates['opegroup'] = '
'; this.display = new ForestDisplay(this._$container, templates, this.data); diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 9e14f709..4f37a47c 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -64,21 +64,9 @@ class AccountManager { // buttons: search, read or create this._$buttons_container = this._$container.find('.buttons'); this._buttons_templates = { - create: template` - - - - `, - read: template` - - - - `, - search: template` - - `, + create: template``, + read: template``, + search: template``, }; } @@ -208,10 +196,7 @@ class AccountSearch { constructor(manager) { this.manager = manager; - this._content = ` - -
- `; + this._content = '
'; this._input = '#search_autocomplete'; this._results_container = '#account_results'; @@ -305,16 +290,8 @@ class CheckoutManager { this._$buttons_container = this._$container.find('.buttons'); this._buttons_templates = { - read: template` - - - - `, - statement_create: template` - - - - `, + read: template``, + statement_create: template``, }; } @@ -457,18 +434,8 @@ class ArticleManager { this.data = new ArticleList(); var $container = $('#articles_data'); var templates = { - category: ` -
- -
- `, - article: ` -
- - - -
- `, + category: '
', + article: '
', }; this.display = new ForestDisplay($container, templates, this.data); this.autocomplete = new ArticleAutocomplete(this, $container);