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

@ -35,242 +35,242 @@ var accountModule = angular.module('accountant.accounts', [
ngUiNotification ngUiNotification
]) ])
.config(function($resourceProvider) { .config(function($resourceProvider) {
// Keep trailing slashes to avoid redirect by flask.. // Keep trailing slashes to avoid redirect by flask..
$resourceProvider.defaults.stripTrailingSlashes = false; $resourceProvider.defaults.stripTrailingSlashes = false;
}) })
.factory('Account', function($resource) { .factory('Account', function($resource) {
var Account = $resource( var Account = $resource(
'/api/account/:id', { '/api/account/:id', {
id: '@id' id: '@id'
} }
); );
Account.prototype.getBalances = function() { Account.prototype.getBalances = function() {
var Balances = $resource('/api/account/:id/balances', {id: this.id}); var Balances = $resource('/api/account/:id/balances', {id: this.id});
this.balances = Balances.get(); this.balances = Balances.get();
}; };
Account.prototype.getBalance = function(begin, end) { Account.prototype.getBalance = function(begin, end) {
var Balance = $resource( var Balance = $resource(
'/api/account/:id/balance', { '/api/account/:id/balance', {
id: this.id, id: this.id,
begin: begin.format('YYYY-MM-DD'), begin: begin.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD') end: end.format('YYYY-MM-DD')
});
this.balance = Balance.get();
};
return Account;
})
.controller('AccountController', function(Account, Notification, $uibModal, $log, $q) {
var vm = this;
/*
* Return the class for an account current value compared to authorized
* overdraft.
*/
vm.rowClass = function(account) {
// eslint-disable-next-line camelcase
if (!account || !account.authorized_overdraft || !account.current) {
return;
}
// eslint-disable-next-line camelcase
if (account.current < account.authorized_overdraft) {
return 'danger';
} else if (account.current < 0) {
return 'warning';
}
};
/*
* Return the class for a value compared to account authorized overdraft.
*/
vm.valueClass = function(account, value) {
if (!account || !value) {
return;
}
// eslint-disable-next-line camelcase
if (value < account.authorized_overdraft) {
return 'text-danger';
} else if (value < 0) {
return 'text-warning';
}
};
/*
* Add an empty account.
*/
vm.add = function() {
var account = new Account({
// eslint-disable-next-line camelcase
authorized_overdraft: 0
}); });
this.balance = Balance.get(); // Insert account at the begining of the array.
}; return vm.modify(account);
};
return Account; /*
}) * Save account.
*/
.controller('AccountController', function(Account, Notification, $uibModal, $log, $q) { vm.save = function(account) {
var vm = this; return account.$save().then(function(data) {
Notification.success('Account #' + data.id + ' saved.');
/*
* Return the class for an account current value compared to authorized
* overdraft.
*/
vm.rowClass = function(account) {
// eslint-disable-next-line camelcase
if (!account || !account.authorized_overdraft || !account.current) {
return;
}
// eslint-disable-next-line camelcase
if (account.current < account.authorized_overdraft) {
return 'danger';
} else if (account.current < 0) {
return 'warning';
}
};
/*
* Return the class for a value compared to account authorized overdraft.
*/
vm.valueClass = function(account, value) {
if (!account || !value) {
return;
}
// eslint-disable-next-line camelcase
if (value < account.authorized_overdraft) {
return 'text-danger';
} else if (value < 0) {
return 'text-warning';
}
};
/*
* Add an empty account.
*/
vm.add = function() {
var account = new Account({
// eslint-disable-next-line camelcase
authorized_overdraft: 0
});
// Insert account at the begining of the array.
return vm.modify(account);
};
/*
* Save account.
*/
vm.save = function(account) {
return account.$save().then(function(data) {
Notification.success('Account #' + data.id + ' saved.');
vm.accounts = Account.query();
return data;
}, function(result){
$log.error('Error while saving account', account, result);
Notification.error(
'Error while saving account: ' + result.message
);
return $q.reject(result);
});
};
/*
* Delete an account.
*/
vm.delete = function(account, $index) {
var id = account.id;
$uibModal.open({
component: 'accountDeleteModalComponent',
resolve: {
account: function() {
return account;
}
}
}).result.then(function(account) {
return account.$delete().then(function() {
Notification.success('account #' + id + ' deleted.');
vm.accounts = Account.query(); vm.accounts = Account.query();
return account; return data;
}, function(result) { }, function(result){
$log.error('Error while saving account', account, result);
Notification.error( Notification.error(
'An error occurred while trying to delete account #' + 'Error while saving account: ' + result.message
id + ':<br />' + result
); );
return $q.reject(result); return $q.reject(result);
}); });
}, function() { };
return false;
});
};
/* /*
* Open the popup to modify the account, save it on confirm. * Delete an account.
* @returns a promise. */
*/ vm.delete = function(account, $index) {
vm.modify = function(account) { var id = account.id;
return $uibModal.open({
component: 'accountModifyModalComponent', $uibModal.open({
resolve: { component: 'accountDeleteModalComponent',
account: function() { resolve: {
return account; account: function() {
return account;
}
} }
} }).result.then(function(account) {
}).result.then(function(account) { return account.$delete().then(function() {
return vm.save(account); Notification.success('account #' + id + ' deleted.');
}, function() {
return false;
});
};
// Load accounts. vm.accounts = Account.query();
vm.accounts = Account.query();
})
.component('accountModifyModalComponent', { return account;
templateUrl: accountFormTmpl, }, function(result) {
bindings: { Notification.error(
resolve: '<', 'An error occurred while trying to delete account #' +
close: '&', id + ':<br />' + result
dismiss: '&' );
},
controller: function() {
var vm = this;
vm.$onInit = function() { return $q.reject(result);
vm.account = vm.resolve.account; });
vm.authorized_overdraft = - vm.account.authorized_overdraft; }, function() {
}; return false;
vm.authorizedOverdraftChange = function() {
vm.account.authorized_overdraft = - vm.authorized_overdraft;
};
vm.ok = function() {
vm.close({
$value: vm.account
}); });
}; };
vm.cancel = function() { /*
vm.dismiss({ * Open the popup to modify the account, save it on confirm.
$value: 'cancel' * @returns a promise.
*/
vm.modify = function(account) {
return $uibModal.open({
component: 'accountModifyModalComponent',
resolve: {
account: function() {
return account;
}
}
}).result.then(function(account) {
return vm.save(account);
}, function() {
return false;
}); });
}; };
vm.title = function() { // Load accounts.
// FIXME Alexis Lahouze 2017-06-15 i18n vm.accounts = Account.query();
if (vm.account.id) { })
return "Account #" + vm.account.id;
} else {
return "Account";
}
};
}
})
.component('accountDeleteModalComponent', { .component('accountModifyModalComponent', {
templateUrl: accountDeleteTmpl, templateUrl: accountFormTmpl,
bindings: { bindings: {
resolve: '<', resolve: '<',
close: '&', close: '&',
dismiss: '&' dismiss: '&'
}, },
controller: function() { controller: function() {
var vm = this; var vm = this;
vm.$onInit = function() { vm.$onInit = function() {
vm.account = vm.resolve.account; vm.account = vm.resolve.account;
}; vm.authorized_overdraft = - vm.account.authorized_overdraft;
};
vm.ok = function() { vm.authorizedOverdraftChange = function() {
vm.close({ vm.account.authorized_overdraft = - vm.authorized_overdraft;
$value: vm.account };
});
};
vm.cancel = function() { vm.ok = function() {
vm.dismiss({ vm.close({
$value: 'cancel' $value: vm.account
}); });
}; };
vm.title = function() { vm.cancel = function() {
// FIXME Alexis Lahouze 2017-06-15 i18n vm.dismiss({
if (vm.account.id) { $value: 'cancel'
return "Account #" + vm.account.id; });
} else { };
return "Account";
} vm.title = function() {
}; // FIXME Alexis Lahouze 2017-06-15 i18n
} if (vm.account.id) {
}); return "Account #" + vm.account.id;
} else {
return "Account";
}
};
}
})
.component('accountDeleteModalComponent', {
templateUrl: accountDeleteTmpl,
bindings: {
resolve: '<',
close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
vm.$onInit = function() {
vm.account = vm.resolve.account;
};
vm.ok = function() {
vm.close({
$value: vm.account
});
};
vm.cancel = function() {
vm.dismiss({
$value: 'cancel'
});
};
vm.title = function() {
// FIXME Alexis Lahouze 2017-06-15 i18n
if (vm.account.id) {
return "Account #" + vm.account.id;
} else {
return "Account";
}
};
}
});
module.exports = accountModule; module.exports = accountModule;

View File

@ -41,27 +41,27 @@ var app = angular.module('accountant', [
ngRoute, ngRoute,
]) ])
.config(function($routeProvider) { .config(function($routeProvider) {
// Defining template and controller in function of route. // Defining template and controller in function of route.
$routeProvider $routeProvider
.when('/account/:accountId/operations', { .when('/account/:accountId/operations', {
templateUrl: operationsTmpl, templateUrl: operationsTmpl,
controller: 'OperationController', controller: 'OperationController',
controllerAs: 'operationsCtrl' controllerAs: 'operationsCtrl'
}) })
.when('/account/:accountId/scheduler', { .when('/account/:accountId/scheduler', {
templateUrl: schedulerTmpl, templateUrl: schedulerTmpl,
controller: 'SchedulerController', controller: 'SchedulerController',
controllerAs: 'schedulerCtrl' controllerAs: 'schedulerCtrl'
}) })
.when('/accounts', { .when('/accounts', {
templateUrl: accountsTmpl, templateUrl: accountsTmpl,
controller: 'AccountController', controller: 'AccountController',
controllerAs: 'accountsCtrl' controllerAs: 'accountsCtrl'
}) })
.otherwise({ .otherwise({
redirectTo: '/accounts' redirectTo: '/accounts'
}); });
}); });
module.exports = app; module.exports = app;

View File

@ -37,123 +37,122 @@ var loginModule = angular.module('accountant.login', [
ngUiBootstrap ngUiBootstrap
]) ])
.factory('LoginService', function($uibModal, $storage, $document, $log, authService) { .factory('LoginService', function($uibModal, $storage, $document, $log, authService) {
var login = function () { var login = function () {
$storage.session.clear(); $storage.session.clear();
var modalInstance = $uibModal.open({ var modalInstance = $uibModal.open({
ariaLabelledBy: 'modal-title', ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body', ariaDescribedBy: 'modal-body',
templateUrl: loginTmpl, templateUrl: loginTmpl,
controller: 'LoginModalController', controller: 'LoginModalController',
controllerAs: '$ctrl' controllerAs: '$ctrl'
}); });
modalInstance.result.then(function (data) { modalInstance.result.then(function (data) {
$log.log(data); $log.log(data);
$storage.session.set('refresh_token', data.refresh_token); $storage.session.set('refresh_token', data.refresh_token);
$storage.session.set('access_token', data.access_token); $storage.session.set('access_token', data.access_token);
authService.loginConfirmed(); authService.loginConfirmed();
}, function () { }, function () {
$log.info('Modal dismissed at: ' + new Date()); $log.info('Modal dismissed at: ' + new Date());
// FIXME Alexis Lahouze 2017-06-11 Redirect to error page.
authService.loginCancelled(null, 'Login cancelled by user action.');
});
};
var cancelLogin = function () {
// FIXME Alexis Lahouze 2017-06-11 Redirect to error page. // FIXME Alexis Lahouze 2017-06-11 Redirect to error page.
authService.loginCancelled(null, 'Login cancelled by user action.'); };
});
};
var cancelLogin = function () { return {
// FIXME Alexis Lahouze 2017-06-11 Redirect to error page. 'login': login,
}; 'cancelLogin': cancelLogin
};
})
return { .factory('sessionInjector', function($storage) {
'login': login, var sessionInjector = {
'cancelLogin': cancelLogin request: function(config) {
}; var access_token = $storage.session.get('access_token');
})
.factory('sessionInjector', function($storage) { if (access_token) {
var sessionInjector = { //var tokenType = $storage.get('token_type');
request: function(config) { var tokenType = 'Bearer';
var access_token = $storage.session.get('access_token'); var authorization = tokenType + ' ' + access_token;
config.headers.authorization = authorization;
}
if (access_token) { return config;
//var tokenType = $storage.get('token_type');
var tokenType = 'Bearer';
var authorization = tokenType + ' ' + access_token;
config.headers.authorization = authorization;
} }
};
return config; return sessionInjector;
} })
};
return sessionInjector; .config(function($httpProvider, $storageProvider) {
}) // Define interceptors.
$httpProvider.interceptors.push('sessionInjector');
.config(function($httpProvider, $storageProvider) { // Configure storage
// Define interceptors. // Set global prefix for stored keys
$httpProvider.interceptors.push('sessionInjector'); $storageProvider.setPrefix('accountant');
// Configure storage // Change the default storage engine
// Set global prefix for stored keys // Defaults to 'local'
$storageProvider.setPrefix('accountant'); $storageProvider.setDefaultStorageEngine('session');
// Change the default storage engine // Change the enabled storage engines
// Defaults to 'local' // Defaults to ['memory', 'cookie', 'session', 'local']
$storageProvider.setDefaultStorageEngine('session'); $storageProvider.setEnabledStorageEngines(['local', 'session']);
})
// Change the enabled storage engines .controller('LoginModalController', function($scope, $uibModalInstance, $http, $log) {
// Defaults to ['memory', 'cookie', 'session', 'local'] var vm = this;
$storageProvider.setEnabledStorageEngines(['local', 'session']);
})
.controller('LoginModalController', function($scope, $uibModalInstance, $http, $log) { vm.data = {
var vm = this; email: null,
password: null
};
vm.data = { vm.ok = function() {
email: null, var email = vm.data.email;
password: null var password = vm.data.password;
};
vm.ok = function() { // Encode authentication data.
var email = vm.data.email; var authdata = base64.encode(email + ':' + password);
var password = vm.data.password;
// Encode authentication data. return $http.post('/api/user/login', {}, {
var authdata = base64.encode(email + ':' + password); ignoreAuthModule: true,
headers: {
'authorization': 'Basic ' + authdata
}
}).then(function(result) {
$log.log(result);
return $http.post('/api/user/login', {}, { $uibModalInstance.close(result.data);
ignoreAuthModule: true, }, function(response) {
headers: { // FIXME Alexis Lahouze 2017-06-11 Handle error.
'authorization': 'Basic ' + authdata $log.log("Error on login", response);
} });
}).then(function(result) { };
$log.log(result);
$uibModalInstance.close(result.data); vm.cancel = function() {
}, function(response) { $uibModalInstance.dismiss('cancel');
// FIXME Alexis Lahouze 2017-06-11 Handle error. };
$log.log("Error on login", response); })
.run(function($rootScope, LoginService) {
var onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', LoginService.login);
var onAuthLoginCancelled = $rootScope.$on('event:auth-loginCancelled', LoginService.cancelLogin);
$rootScope.$on('$destroy', function() {
onAuthLoginRequired = angular.noop();
}); });
};
vm.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
})
.run(function($rootScope, LoginService) {
var onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', LoginService.login);
var onAuthLoginCancelled = $rootScope.$on('event:auth-loginCancelled', LoginService.cancelLogin);
$rootScope.$on('$destroy', function() {
onAuthLoginRequired = angular.noop();
}); });
});
module.exports = loginModule; module.exports = loginModule;

View File

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

View File

@ -29,100 +29,104 @@ var categoryChartModule = angular.module('categoryChartModule', [
ngResource ngResource
]) ])
.component('categoryChart', { .component('categoryChart', {
template: '<div></div>', template: '<div></div>',
bindings: { bindings: {
minDate: '<', minDate: '<',
maxDate: '<' maxDate: '<'
}, },
controller: function($routeParams, $element, Categories, Incomes) { controller: function($routeParams, $element, Categories, Incomes) {
var vm = this; var vm = this;
vm.loadData = function() { vm.loadData = function() {
Categories.query({ Categories.query({
id: $routeParams.accountId, id: $routeParams.accountId,
begin: vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null, begin: vm.minDate ? moment(vm.minDate).format('YYYY-MM-DD') : null,
end: vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null end: vm.maxDate ? moment(vm.maxDate).format('YYYY-MM-DD') : null
}, function(results) { }, function(results) {
var expenses=[], var expenses=[],
revenues=[], revenues=[],
colors={}, colors={},
names={}; names={};
var revenuesColor = 'green', var revenuesColor = 'green',
expensesColor = 'orange'; expensesColor = 'orange';
angular.forEach(results, function(result) { angular.forEach(results, function(result) {
var revenuesName = 'revenues-' + result.category; var revenuesName = 'revenues-' + result.category;
revenues.push([revenuesName, result.revenues]); revenues.push([revenuesName, result.revenues]);
names[revenuesName] = result.category; names[revenuesName] = result.category;
colors[revenuesName] = revenuesColor; colors[revenuesName] = revenuesColor;
var expensesName = 'expenses-' + result.category; var expensesName = 'expenses-' + result.category;
expenses.splice(0, 0, [expensesName, -result.expenses]); expenses.splice(0, 0, [expensesName, -result.expenses]);
names[expensesName] = result.category; names[expensesName] = result.category;
colors[expensesName] = expensesColor; 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({ vm.$onChanges = function() {
columns: revenues.concat(expenses), vm.loadData();
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.loadData();
};
vm.$onChanges = function() {
vm.loadData();
};
}
}).factory('Categories', function($resource) {
return $resource(
'/api/account/:id/category', {
id: '@id'
} }
); })
}).factory('Incomes', function($resource) {
return $resource( .factory('Categories', function($resource) {
'/api/account/:id/income', { return $resource(
id: '@id' '/api/account/:id/category', {
} id: '@id'
); }
}); );
})
.factory('Incomes', function($resource) {
return $resource(
'/api/account/:id/income', {
id: '@id'
}
);
});
module.exports = categoryChartModule; module.exports = categoryChartModule;

View File

@ -44,226 +44,226 @@ var operationModule = angular.module('accountant.operations', [
categoryChartModule.name categoryChartModule.name
]) ])
.config(function($resourceProvider) { .config(function($resourceProvider) {
// Keep trailing slashes to avoid redirect by flask.. // Keep trailing slashes to avoid redirect by flask..
$resourceProvider.defaults.stripTrailingSlashes = false; $resourceProvider.defaults.stripTrailingSlashes = false;
}) })
.factory('Operation', function($resource) { .factory('Operation', function($resource) {
return $resource( return $resource(
'/api/operation/:id', { '/api/operation/:id', {
id: '@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;
}
} }
}).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(); vm.operations = vm.load();
return operation; return operation;
}, function(result) { }, function(result){
$log.error('Error while saving operation', operation, result);
Notification.error( Notification.error(
'An error occurred while trying to delete operation #' + 'Error while saving operation: ' + result.message
id + ':<br />' + result
); );
return $q.reject(result); return $q.reject(result);
}); });
}, function() { };
return false;
});
};
/* /*
* Open the popup to modify the operation, save it on confirm. * Delete an operation and return a promise.
* @returns a promise. */
*/ vm.delete = function(operation) {
vm.modify = function(operation) { var id = operation.id;
return $uibModal.open({
component: 'operationModifyModalComponent', $uibModal.open({
resolve: { component: 'operationDeleteModalComponent',
operation: function() { resolve: {
return operation; operation: function() {
return operation;
}
} }
} }).result.then(function(operation) {
}).result.then(function(operation) { return operation.$delete().then(function() {
return vm.save(operation); Notification.success('Operation #' + id + ' deleted.');
}, function() {
return false;
});
};
vm.onUpdate = function(minDate, maxDate) { vm.operations = vm.load();
vm.operations = vm.load(minDate, maxDate);
};
//vm.operations = vm.load(); return operation;
}) }, function(result) {
Notification.error(
'An error occurred while trying to delete operation #' +
id + ':<br />' + result
);
.component('operationModifyModalComponent', { return $q.reject(result);
templateUrl: operationFormTmpl, });
bindings: { }, function() {
resolve: '<', return false;
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({ * Open the popup to modify the operation, save it on confirm.
$value: 'cancel' * @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() { vm.onUpdate = function(minDate, maxDate) {
// FIXME Alexis Lahouze 2017-06-15 i18n vm.operations = vm.load(minDate, maxDate);
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.account = Account.get({id: $routeParams.accountId});
vm.close({ })
$value: vm.operation
});
};
vm.cancel = function() { .component('operationModifyModalComponent', {
vm.dismiss({ templateUrl: operationFormTmpl,
$value: 'cancel' bindings: {
}); resolve: '<',
}; close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
vm.title = function() { vm.$onInit = function() {
// FIXME Alexis Lahouze 2017-06-15 i18n vm.operation = vm.resolve.operation;
if (vm.operation.id) { };
return "Operation #" + vm.operation.id;
} else { vm.ok = function() {
return "Operation"; 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; module.exports = operationModule;

View File

@ -35,197 +35,196 @@ var schedulerModule = angular.module('accountant.scheduler', [
ngStrap ngStrap
]) ])
.config(function($resourceProvider) { .config(function($resourceProvider) {
// Keep trailing slashes to avoid redirect by flask.. // Keep trailing slashes to avoid redirect by flask..
$resourceProvider.defaults.stripTrailingSlashes = false; $resourceProvider.defaults.stripTrailingSlashes = false;
}) })
.factory('ScheduledOperation', function($resource) { .factory('ScheduledOperation', function($resource) {
return $resource( return $resource(
'/api/scheduled_operation/:id', { '/api/scheduled_operation/:id', {
id: '@id' id: '@id'
}
);
})
.controller('SchedulerController', function($rootScope, $routeParams, Notification, ScheduledOperation, $log, $uibModal, $q) {
var vm = this;
// Operation store.
vm.operations = [];
/*
* Add a new operation at the beginning of th array.
*/
vm.add = function() {
var operation = new ScheduledOperation({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
return vm.modify(operation);
};
/*
* Load operations.
*/
vm.load = function() {
return ScheduledOperation.query({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
};
/*
* Save operation.
*/
vm.save = function(operation) {
return operation.$save().then(function(operation) {
Notification.success('Scheduled operation #' + operation.id + ' saved.');
vm.operations = vm.load();
return operation;
}, function(result){
$log.error('Error while saving scheduled operation', operation, result);
Notification.error(
'Error while saving scheduled operation: ' + result.message
);
return $q.reject(result);
});
};
/*
* Delete operation.
*/
vm.delete = function(operation) {
var id = operation.id;
$uibModal.open({
component: 'scheduleDeleteModalComponent',
resolve: {
operation: function() {
return operation;
}
} }
}).result.then(function(operation) { );
return operation.$delete().then(function() { })
Notification.success('Operation #' + id + ' deleted.');
.controller('SchedulerController', function($rootScope, $routeParams, Notification, ScheduledOperation, $log, $uibModal, $q) {
var vm = this;
// Operation store.
vm.operations = [];
/*
* Add a new operation at the beginning of th array.
*/
vm.add = function() {
var operation = new ScheduledOperation({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
return vm.modify(operation);
};
/*
* Load operations.
*/
vm.load = function() {
return ScheduledOperation.query({
// eslint-disable-next-line camelcase
account_id: $routeParams.accountId
});
};
/*
* Save operation.
*/
vm.save = function(operation) {
return operation.$save().then(function(operation) {
Notification.success('Scheduled operation #' + operation.id + ' saved.');
vm.operations = vm.load(); vm.operations = vm.load();
return operation; return operation;
}, function(result) { }, function(result){
$log.error('Error while saving scheduled operation', operation, result);
Notification.error( Notification.error(
'An error occurred while trying to delete operation #' + 'Error while saving scheduled operation: ' + result.message
id + ':<br />' + result
); );
return $q.reject(result); return $q.reject(result);
}); });
}, function() { };
return false;
});
};
/* /*
* Open the popup to modify the operation, save it on confirm. * Delete operation.
* @returns a promise. */
*/ vm.delete = function(operation) {
vm.modify = function(operation) { var id = operation.id;
return $uibModal.open({
component: 'scheduleModifyModalComponent', $uibModal.open({
resolve: { component: 'scheduleDeleteModalComponent',
operation: function() { resolve: {
return operation; operation: function() {
return operation;
}
} }
} }).result.then(function(operation) {
}).result.then(function(operation) { return operation.$delete().then(function() {
return vm.save(operation); Notification.success('Operation #' + id + ' deleted.');
}, function() {
return false;
});
};
// Load operations on controller initialization. vm.operations = vm.load();
vm.operations = vm.load();
})
.component('scheduleModifyModalComponent', { return operation;
templateUrl: scheduleFormTmpl, }, function(result) {
bindings: { Notification.error(
resolve: '<', 'An error occurred while trying to delete operation #' +
close: '&', id + ':<br />' + result
dismiss: '&' );
},
controller: function() {
var vm = this;
vm.$onInit = function() { return $q.reject(result);
vm.operation = vm.resolve.operation; });
}; }, function() {
return false;
vm.ok = function() {
vm.close({
$value: vm.operation
}); });
}; };
vm.cancel = function() { /*
vm.dismiss({ * Open the popup to modify the operation, save it on confirm.
$value: 'cancel' * @returns a promise.
*/
vm.modify = function(operation) {
return $uibModal.open({
component: 'scheduleModifyModalComponent',
resolve: {
operation: function() {
return operation;
}
}
}).result.then(function(operation) {
return vm.save(operation);
}, function() {
return false;
}); });
}; };
vm.title = function() { // Load operations on controller initialization.
// FIXME Alexis Lahouze 2017-06-15 i18n vm.operations = vm.load();
if (vm.operation.id) { })
return "Scheduled operation #" + vm.operation.id;
} else {
return "Scheduled operation";
}
};
}
})
.component('scheduleModifyModalComponent', {
templateUrl: scheduleFormTmpl,
bindings: {
resolve: '<',
close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
.component('scheduleDeleteModalComponent', { vm.$onInit = function() {
templateUrl: scheduleDeleteTmpl, vm.operation = vm.resolve.operation;
bindings: { };
resolve: '<',
close: '&',
dismiss: '&'
},
controller: function() {
var vm = this;
vm.$onInit = function() { vm.ok = function() {
vm.operation = vm.resolve.operation; vm.close({
}; $value: vm.operation
});
};
vm.ok = function() { vm.cancel = function() {
vm.close({ vm.dismiss({
$value: vm.operation $value: 'cancel'
}); });
}; };
vm.cancel = function() { vm.title = function() {
vm.dismiss({ // FIXME Alexis Lahouze 2017-06-15 i18n
$value: 'cancel' if (vm.operation.id) {
}); return "Scheduled operation #" + vm.operation.id;
}; } else {
return "Scheduled operation";
}
};
}
})
vm.title = function() { .component('scheduleDeleteModalComponent', {
// FIXME Alexis Lahouze 2017-06-15 i18n templateUrl: scheduleDeleteTmpl,
if (vm.operation.id) { bindings: {
return "Scheduled operation #" + vm.operation.id; resolve: '<',
} else { close: '&',
return "Scheduled operation"; 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 "Scheduled operation #" + vm.operation.id;
} else {
return "Scheduled operation";
}
};
}
});
module.exports = schedulerModule; module.exports = schedulerModule;