From 2812891b235c9c082a8f511e0c6a434a4e735090 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 29 Jul 2017 16:32:07 +0200 Subject: [PATCH] Inject account in category chart component instead of using accountIdService. --- src/operations/category-chart.component.ts | 26 +++++++++++----------- src/operations/operations.html | 3 ++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/operations/category-chart.component.ts b/src/operations/category-chart.component.ts index f07bec8..a90c637 100644 --- a/src/operations/category-chart.component.ts +++ b/src/operations/category-chart.component.ts @@ -33,17 +33,18 @@ module.exports = angular.module('categoryChartModule', [ template: '
', bindings: { minDate: '<', - maxDate: '<' + maxDate: '<', + account: '<' }, - controller: function(accountIdService, $element, Categories, Incomes) { + controller: function($element, Categories, Incomes) { var vm = this; - vm.loadData = function() { - Categories.query({ - id: accountIdService.get(), - begin: vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null, - end: vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null - }, function(results) { + vm.loadData = function(account: Account) { + categoryService.query( + accountIdService.get(), + vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null, + vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null + ).subscribe((results) => { var expenses=[], revenues=[], colors={}, @@ -107,14 +108,13 @@ module.exports = angular.module('categoryChartModule', [ show: false } }); - - //vm.loadData(); }; - vm.$onChanges = function() { - vm.loadData(); + vm.$onChanges = function(changes) { + if('account' in changes && changes.account.currentValue) { + vm.loadData(changes.account.currentValue); + } }; - } }) diff --git a/src/operations/operations.html b/src/operations/operations.html index a53afa7..0fca7d7 100644 --- a/src/operations/operations.html +++ b/src/operations/operations.html @@ -24,7 +24,8 @@
+ max-date="operationsCtrl.maxDate" + account="operationsCtrl.account"/>