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>',
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);
}
};
}
})

View File

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