Inject account in category chart component instead of using accountIdService.

This commit is contained in:
Alexis Lahouze 2017-07-29 16:32:07 +02:00
parent fa147e74fc
commit 2812891b23
2 changed files with 15 additions and 14 deletions

View File

@ -33,17 +33,18 @@ module.exports = angular.module('categoryChartModule', [
template: '<div></div>', template: '<div></div>',
bindings: { bindings: {
minDate: '<', minDate: '<',
maxDate: '<' maxDate: '<',
account: '<'
}, },
controller: function(accountIdService, $element, Categories, Incomes) { controller: function($element, Categories, Incomes) {
var vm = this; var vm = this;
vm.loadData = function() { vm.loadData = function(account: Account) {
Categories.query({ categoryService.query(
id: accountIdService.get(), accountIdService.get(),
begin: vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null, vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null,
end: vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null
}, function(results) { ).subscribe((results) => {
var expenses=[], var expenses=[],
revenues=[], revenues=[],
colors={}, colors={},
@ -107,14 +108,13 @@ module.exports = angular.module('categoryChartModule', [
show: false show: false
} }
}); });
//vm.loadData();
}; };
vm.$onChanges = function() { vm.$onChanges = function(changes) {
vm.loadData(); if('account' in changes && changes.account.currentValue) {
vm.loadData(changes.account.currentValue);
}
}; };
} }
}) })

View File

@ -24,7 +24,8 @@
<div class="col-md-3"> <div class="col-md-3">
<category-chart <category-chart
min-date="operationsCtrl.minDate" min-date="operationsCtrl.minDate"
max-date="operationsCtrl.maxDate"/> max-date="operationsCtrl.maxDate"
account="operationsCtrl.account"/>
</div> </div>
</div> </div>