Fix indent.

This commit is contained in:
Alexis Lahouze
2017-07-05 21:48:20 +02:00
parent c558994c6d
commit c14d88f421
7 changed files with 918 additions and 914 deletions

View File

@ -32,160 +32,162 @@ var balanceChartModule = angular.module('balanceChartModule', [
ngResource
])
.component('balanceChart', {
template: '<div></div>',
bindings: {
account: '<',
onUpdate: '&'
},
controller: function($routeParams, Balances, Account, $element) {
var vm = this;
.component('balanceChart', {
template: '<div></div>',
bindings: {
account: '<',
onUpdate: '&'
},
controller: function($routeParams, Balances, Account, $element) {
var vm = this;
vm.loadData = function() {
Balances.query({
id: $routeParams.accountId
}, function(results) {
var headers = [['date', 'balances', 'expenses', 'revenues']];
vm.loadData = function() {
Balances.query({
id: $routeParams.accountId
}, function(results) {
var headers = [['date', 'balances', 'expenses', 'revenues']];
var rows = results.map(function(result) {
return [
result.operation_date,
result.balance,
result.expenses,
result.revenues
];
});
vm.chart.unload();
vm.chart.load({
rows: headers.concat(rows)
});
var x = vm.chart.x();
var balances = x.balances;
vm.onUpdate(balances[0], balances[balances.length - 1]);
});
};
vm.$onInit = function() {
var tomorrow = moment().endOf('day').valueOf();
vm.chart = c3.generate({
bindto: $element[0].children[0],
size: {
height: 450,
},
data: {
x: 'date',
rows: [],
axes: {
expenses: 'y2',
revenues: 'y2'
},
type: 'bar',
types: {
balances: 'area'
},
groups: [
['expenses', 'revenues']
],
// Disable for the moment because there is an issue when
// using subchart line is not refreshed after subset
// selection.
//regions: {
// balances: [{
// start: tomorrow,
// style: 'dashed'
// }]
//}
},
regions: [{
start: tomorrow,
}],
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d',
rotate: 50,
}
},
y: {
label: {
text: 'Amount',
position: 'outer-middle'
}
},
y2: {
show: true,
label: {
text: 'Amount',
position: 'outer-middle'
}
}
},
grid: {
x: {
show: true,
},
y: {
show: true,
}
},
tooltip: {
format: {
value: function(value, ratio, id, index) {
return value + '€';
}
}
},
subchart: {
show: true,
onbrush: function(domain) {
vm.onUpdate({minDate: domain[0], maxDate: domain[1]});
}
}
});
vm.loadData();
};
vm.setLines = function(account) {
if(vm.chart) {
vm.chart.ygrids([
{ value: 0, axis: 'y2' },
{ value: 0, axis: 'y', class: 'zeroline'},
]);
vm.chart.ygrids.add({
value: account.authorized_overdraft,
axis: 'y',
class: 'overdraft'
});
}
};
vm.$onChanges = function(changes) {
if('account' in changes) {
if('$promise' in vm.account && vm.account.$resolved === false) {
vm.account.$promise.then(function(account) {
vm.setLines(account);
return account;
var rows = results.map(function(result) {
return [
result.operation_date,
result.balance,
result.expenses,
result.revenues
];
});
vm.chart.unload();
vm.chart.load({
rows: headers.concat(rows)
});
var x = vm.chart.x();
var balances = x.balances;
vm.onUpdate(balances[0], balances[balances.length - 1]);
});
};
vm.$onInit = function() {
var tomorrow = moment().endOf('day').valueOf();
vm.chart = c3.generate({
bindto: $element[0].children[0],
size: {
height: 450,
},
data: {
x: 'date',
rows: [],
axes: {
expenses: 'y2',
revenues: 'y2'
},
type: 'bar',
types: {
balances: 'area'
},
groups: [
['expenses', 'revenues']
],
// Disable for the moment because there is an issue when
// using subchart line is not refreshed after subset
// selection.
//regions: {
// balances: [{
// start: tomorrow,
// style: 'dashed'
// }]
//}
},
regions: [{
start: tomorrow,
}],
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d',
rotate: 50,
}
},
y: {
label: {
text: 'Amount',
position: 'outer-middle'
}
},
y2: {
show: true,
label: {
text: 'Amount',
position: 'outer-middle'
}
}
},
grid: {
x: {
show: true,
},
y: {
show: true,
}
},
tooltip: {
format: {
value: function(value, ratio, id, index) {
return value + '€';
}
}
},
subchart: {
show: true,
onbrush: function(domain) {
vm.onUpdate({minDate: domain[0], maxDate: domain[1]});
}
}
});
vm.loadData();
};
vm.setLines = function(account) {
if(vm.chart) {
vm.chart.ygrids([
{ value: 0, axis: 'y2' },
{ value: 0, axis: 'y', class: 'zeroline'},
]);
vm.chart.ygrids.add({
value: account.authorized_overdraft,
axis: 'y',
class: 'overdraft'
});
} else {
vm.setLines(vm.account);
}
}
};
}
}).factory('Balances', function($resource) {
return $resource(
'/api/account/:id/daily_balances', {
id: '@id'
};
vm.$onChanges = function(changes) {
if('account' in changes) {
if('$promise' in vm.account && vm.account.$resolved === false) {
vm.account.$promise.then(function(account) {
vm.setLines(account);
return account;
});
} else {
vm.setLines(vm.account);
}
}
};
}
);
});
})
.factory('Balances', function($resource) {
return $resource(
'/api/account/:id/daily_balances', {
id: '@id'
}
);
});
module.exports = balanceChartModule;

View File

@ -29,100 +29,104 @@ var categoryChartModule = angular.module('categoryChartModule', [
ngResource
])
.component('categoryChart', {
template: '<div></div>',
bindings: {
minDate: '<',
maxDate: '<'
},
controller: function($routeParams, $element, Categories, Incomes) {
var vm = this;
.component('categoryChart', {
template: '<div></div>',
bindings: {
minDate: '<',
maxDate: '<'
},
controller: function($routeParams, $element, Categories, Incomes) {
var vm = this;
vm.loadData = function() {
Categories.query({
id: $routeParams.accountId,
begin: vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null,
end: vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null
}, function(results) {
var expenses=[],
revenues=[],
colors={},
names={};
vm.loadData = function() {
Categories.query({
id: $routeParams.accountId,
begin: vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null,
end: vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null
}, function(results) {
var expenses=[],
revenues=[],
colors={},
names={};
var revenuesColor = 'green',
expensesColor = 'orange';
var revenuesColor = 'green',
expensesColor = 'orange';
angular.forEach(results, function(result) {
var revenuesName = 'revenues-' + result.category;
angular.forEach(results, function(result) {
var revenuesName = 'revenues-' + result.category;
revenues.push([revenuesName, result.revenues]);
names[revenuesName] = result.category;
colors[revenuesName] = revenuesColor;
revenues.push([revenuesName, result.revenues]);
names[revenuesName] = result.category;
colors[revenuesName] = revenuesColor;
var expensesName = 'expenses-' + result.category;
var expensesName = 'expenses-' + result.category;
expenses.splice(0, 0, [expensesName, -result.expenses]);
names[expensesName] = result.category;
colors[expensesName] = expensesColor;
expenses.splice(0, 0, [expensesName, -result.expenses]);
names[expensesName] = result.category;
colors[expensesName] = expensesColor;
});
vm.chart.unload();
vm.chart.load({
columns: revenues.concat(expenses),
names: names,
colors: colors
});
});
};
vm.$onInit = function() {
vm.chart = c3.generate({
bindto: $element[0].children[0],
data: {
columns: [],
type: 'donut',
order: null,
},
tooltip: {
format: {
value: function(value, ratio, id, index) {
return value + '€';
}
}
},
donut: {
label: {
format: function(value) {
return value + '€';
}
}
},
legend: {
show: false
}
});
vm.chart.unload();
//vm.loadData();
};
vm.chart.load({
columns: revenues.concat(expenses),
names: names,
colors: colors
});
});
};
vm.$onChanges = function() {
vm.loadData();
};
vm.$onInit = function() {
vm.chart = c3.generate({
bindto: $element[0].children[0],
data: {
columns: [],
type: 'donut',
order: null,
},
tooltip: {
format: {
value: function(value, ratio, id, index) {
return value + '€';
}
}
},
donut: {
label: {
format: function(value) {
return value + '€';
}
}
},
legend: {
show: false
}
});
//vm.loadData();
};
vm.$onChanges = function() {
vm.loadData();
};
}
}).factory('Categories', function($resource) {
return $resource(
'/api/account/:id/category', {
id: '@id'
}
);
}).factory('Incomes', function($resource) {
return $resource(
'/api/account/:id/income', {
id: '@id'
}
);
});
})
.factory('Categories', function($resource) {
return $resource(
'/api/account/:id/category', {
id: '@id'
}
);
})
.factory('Incomes', function($resource) {
return $resource(
'/api/account/:id/income', {
id: '@id'
}
);
});
module.exports = categoryChartModule;

View File

@ -44,226 +44,226 @@ var operationModule = angular.module('accountant.operations', [
categoryChartModule.name
])
.config(function($resourceProvider) {
// Keep trailing slashes to avoid redirect by flask..
$resourceProvider.defaults.stripTrailingSlashes = false;
})
.config(function($resourceProvider) {
// Keep trailing slashes to avoid redirect by flask..
$resourceProvider.defaults.stripTrailingSlashes = false;
})
.factory('Operation', function($resource) {
return $resource(
'/api/operation/:id', {
id: '@id'
}
);
})
/*
* Controller for the operations.
*/
.controller('OperationController', function($routeParams, $uibModal,
Notification, Operation, $log, $q) {
var vm = this;
/*
* Add an empty operation.
*/
vm.add = function() {
var operation = new Operation({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
return vm.modify(operation);
};
/*
* Load operations.
*/
vm.load = function(minDate, maxDate) {
vm.minDate = minDate;
vm.maxDate = maxDate;
return Operation.query({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId,
begin: minDate ? moment(minDate).format('YYYY-MM-DD') : null,
end: maxDate ? moment(maxDate).format('YYYY-MM-DD') : null
});
};
/*
* Toggle pointed indicator for an operation.
*/
vm.togglePointed = function(operation, rowform) {
operation.pointed = !operation.pointed;
vm.save(operation);
};
/*
* Toggle cancel indicator for an operation.
*/
vm.toggleCanceled = function(operation) {
operation.canceled = !operation.canceled;
vm.save(operation);
};
/*
* Save an operation and return a promise.
*/
vm.save = function(operation) {
operation.confirmed = true;
return operation.$save().then(function(operation) {
Notification.success('Operation #' + operation.id + ' saved.');
vm.operations = vm.load();
return operation;
}, function(result){
$log.error('Error while saving operation', operation, result);
Notification.error(
'Error while saving operation: ' + result.message
);
return $q.reject(result);
});
};
/*
* Delete an operation and return a promise.
*/
vm.delete = function(operation) {
var id = operation.id;
$uibModal.open({
component: 'operationDeleteModalComponent',
resolve: {
operation: function() {
return operation;
}
.factory('Operation', function($resource) {
return $resource(
'/api/operation/:id', {
id: '@id'
}
}).result.then(function(operation) {
return operation.$delete().then(function() {
Notification.success('Operation #' + id + ' deleted.');
);
})
/*
* Controller for the operations.
*/
.controller('OperationController', function($routeParams, $uibModal,
Notification, Operation, Account, $log, $q) {
var vm = this;
/*
* Add an empty operation.
*/
vm.add = function() {
var operation = new Operation({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
return vm.modify(operation);
};
/*
* Load operations.
*/
vm.load = function(minDate, maxDate) {
vm.minDate = minDate;
vm.maxDate = maxDate;
return Operation.query({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId,
begin: minDate ? moment(minDate).format('YYYY-MM-DD') : null,
end: maxDate ? moment(maxDate).format('YYYY-MM-DD') : null
});
};
/*
* Toggle pointed indicator for an operation.
*/
vm.togglePointed = function(operation, rowform) {
operation.pointed = !operation.pointed;
vm.save(operation);
};
/*
* Toggle cancel indicator for an operation.
*/
vm.toggleCanceled = function(operation) {
operation.canceled = !operation.canceled;
vm.save(operation);
};
/*
* Save an operation and return a promise.
*/
vm.save = function(operation) {
operation.confirmed = true;
return operation.$save().then(function(operation) {
Notification.success('Operation #' + operation.id + ' saved.');
vm.operations = vm.load();
return operation;
}, function(result) {
}, function(result){
$log.error('Error while saving operation', operation, result);
Notification.error(
'An error occurred while trying to delete operation #' +
id + ':<br />' + result
'Error while saving operation: ' + result.message
);
return $q.reject(result);
});
}, function() {
return false;
});
};
};
/*
* Open the popup to modify the operation, save it on confirm.
* @returns a promise.
*/
vm.modify = function(operation) {
return $uibModal.open({
component: 'operationModifyModalComponent',
resolve: {
operation: function() {
return operation;
/*
* Delete an operation and return a promise.
*/
vm.delete = function(operation) {
var id = operation.id;
$uibModal.open({
component: 'operationDeleteModalComponent',
resolve: {
operation: function() {
return operation;
}
}
}
}).result.then(function(operation) {
return vm.save(operation);
}, function() {
return false;
});
};
}).result.then(function(operation) {
return operation.$delete().then(function() {
Notification.success('Operation #' + id + ' deleted.');
vm.onUpdate = function(minDate, maxDate) {
vm.operations = vm.load(minDate, maxDate);
};
vm.operations = vm.load();
//vm.operations = vm.load();
})
return operation;
}, function(result) {
Notification.error(
'An error occurred while trying to delete operation #' +
id + ':<br />' + result
);
.component('operationModifyModalComponent', {
templateUrl: operationFormTmpl,
bindings: {
resolve: '<',
close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
vm.$onInit = function() {
vm.operation = vm.resolve.operation;
};
vm.ok = function() {
vm.close({
$value: vm.operation
return $q.reject(result);
});
}, function() {
return false;
});
};
vm.cancel = function() {
vm.dismiss({
$value: 'cancel'
/*
* Open the popup to modify the operation, save it on confirm.
* @returns a promise.
*/
vm.modify = function(operation) {
return $uibModal.open({
component: 'operationModifyModalComponent',
resolve: {
operation: function() {
return operation;
}
}
}).result.then(function(operation) {
return vm.save(operation);
}, function() {
return false;
});
};
vm.title = function() {
// FIXME Alexis Lahouze 2017-06-15 i18n
if (vm.operation.id) {
return "Operation #" + vm.operation.id;
} else {
return "Operation";
}
};
}
})
.component('operationDeleteModalComponent', {
templateUrl: operationDeleteTmpl,
bindings: {
resolve: '<',
close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
vm.$onInit = function() {
vm.operation = vm.resolve.operation;
vm.onUpdate = function(minDate, maxDate) {
vm.operations = vm.load(minDate, maxDate);
};
vm.ok = function() {
vm.close({
$value: vm.operation
});
};
vm.account = Account.get({id: $routeParams.accountId});
})
vm.cancel = function() {
vm.dismiss({
$value: 'cancel'
});
};
.component('operationModifyModalComponent', {
templateUrl: operationFormTmpl,
bindings: {
resolve: '<',
close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
vm.title = function() {
// FIXME Alexis Lahouze 2017-06-15 i18n
if (vm.operation.id) {
return "Operation #" + vm.operation.id;
} else {
return "Operation";
}
};
}
});
vm.$onInit = function() {
vm.operation = vm.resolve.operation;
};
vm.ok = function() {
vm.close({
$value: vm.operation
});
};
vm.cancel = function() {
vm.dismiss({
$value: 'cancel'
});
};
vm.title = function() {
// FIXME Alexis Lahouze 2017-06-15 i18n
if (vm.operation.id) {
return "Operation #" + vm.operation.id;
} else {
return "Operation";
}
};
}
})
.component('operationDeleteModalComponent', {
templateUrl: operationDeleteTmpl,
bindings: {
resolve: '<',
close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
vm.$onInit = function() {
vm.operation = vm.resolve.operation;
};
vm.ok = function() {
vm.close({
$value: vm.operation
});
};
vm.cancel = function() {
vm.dismiss({
$value: 'cancel'
});
};
vm.title = function() {
// FIXME Alexis Lahouze 2017-06-15 i18n
if (vm.operation.id) {
return "Operation #" + vm.operation.id;
} else {
return "Operation";
}
};
}
});
module.exports = operationModule;