diff --git a/src/accounts/index.js b/src/accounts/index.js
index 1d82593..89ef412 100644
--- a/src/accounts/index.js
+++ b/src/accounts/index.js
@@ -35,242 +35,242 @@ var accountModule = angular.module('accountant.accounts', [
ngUiNotification
])
-.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('Account', function($resource) {
- var Account = $resource(
- '/api/account/:id', {
- id: '@id'
- }
- );
+ .factory('Account', function($resource) {
+ var Account = $resource(
+ '/api/account/:id', {
+ id: '@id'
+ }
+ );
- Account.prototype.getBalances = function() {
- var Balances = $resource('/api/account/:id/balances', {id: this.id});
+ Account.prototype.getBalances = function() {
+ var Balances = $resource('/api/account/:id/balances', {id: this.id});
- this.balances = Balances.get();
- };
+ this.balances = Balances.get();
+ };
- Account.prototype.getBalance = function(begin, end) {
- var Balance = $resource(
- '/api/account/:id/balance', {
- id: this.id,
- begin: begin.format('YYYY-MM-DD'),
- end: end.format('YYYY-MM-DD')
+ Account.prototype.getBalance = function(begin, end) {
+ var Balance = $resource(
+ '/api/account/:id/balance', {
+ id: this.id,
+ begin: begin.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;
-})
-
-.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
- });
-
- // 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.');
+ /*
+ * Save account.
+ */
+ vm.save = function(account) {
+ return account.$save().then(function(data) {
+ Notification.success('Account #' + data.id + ' saved.');
vm.accounts = Account.query();
- return account;
- }, function(result) {
+ return data;
+ }, function(result){
+ $log.error('Error while saving account', account, result);
+
Notification.error(
- 'An error occurred while trying to delete account #' +
- id + ':
' + result
+ 'Error while saving account: ' + result.message
);
return $q.reject(result);
});
- }, function() {
- return false;
- });
- };
+ };
- /*
- * Open the popup to modify the account, save it on confirm.
- * @returns a promise.
- */
- vm.modify = function(account) {
- return $uibModal.open({
- component: 'accountModifyModalComponent',
- resolve: {
- account: function() {
- return account;
+ /*
+ * 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 vm.save(account);
- }, function() {
- return false;
- });
- };
+ }).result.then(function(account) {
+ return account.$delete().then(function() {
+ Notification.success('account #' + id + ' deleted.');
- // Load accounts.
- vm.accounts = Account.query();
-})
+ vm.accounts = Account.query();
-.component('accountModifyModalComponent', {
- templateUrl: accountFormTmpl,
- bindings: {
- resolve: '<',
- close: '&',
- dismiss: '&'
- },
- controller: function() {
- var vm = this;
+ return account;
+ }, function(result) {
+ Notification.error(
+ 'An error occurred while trying to delete account #' +
+ id + ':
' + result
+ );
- vm.$onInit = function() {
- vm.account = vm.resolve.account;
- vm.authorized_overdraft = - vm.account.authorized_overdraft;
- };
-
- vm.authorizedOverdraftChange = function() {
- vm.account.authorized_overdraft = - vm.authorized_overdraft;
- };
-
- vm.ok = function() {
- vm.close({
- $value: vm.account
+ return $q.reject(result);
+ });
+ }, function() {
+ return false;
});
};
- vm.cancel = function() {
- vm.dismiss({
- $value: 'cancel'
+ /*
+ * Open the popup to modify the account, save it on confirm.
+ * @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() {
- // FIXME Alexis Lahouze 2017-06-15 i18n
- if (vm.account.id) {
- return "Account #" + vm.account.id;
- } else {
- return "Account";
- }
- };
- }
-})
+ // Load accounts.
+ vm.accounts = Account.query();
+ })
-.component('accountDeleteModalComponent', {
- templateUrl: accountDeleteTmpl,
- bindings: {
- resolve: '<',
- close: '&',
- dismiss: '&'
- },
- controller: function() {
- var vm = this;
+ .component('accountModifyModalComponent', {
+ templateUrl: accountFormTmpl,
+ bindings: {
+ resolve: '<',
+ close: '&',
+ dismiss: '&'
+ },
+ controller: function() {
+ var vm = this;
- vm.$onInit = function() {
- vm.account = vm.resolve.account;
- };
+ vm.$onInit = function() {
+ vm.account = vm.resolve.account;
+ vm.authorized_overdraft = - vm.account.authorized_overdraft;
+ };
- vm.ok = function() {
- vm.close({
- $value: vm.account
- });
- };
+ vm.authorizedOverdraftChange = function() {
+ vm.account.authorized_overdraft = - vm.authorized_overdraft;
+ };
- vm.cancel = function() {
- vm.dismiss({
- $value: 'cancel'
- });
- };
+ vm.ok = function() {
+ vm.close({
+ $value: vm.account
+ });
+ };
- vm.title = function() {
- // FIXME Alexis Lahouze 2017-06-15 i18n
- if (vm.account.id) {
- return "Account #" + vm.account.id;
- } else {
- return "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";
+ }
+ };
+ }
+ })
+
+ .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;
diff --git a/src/app.js b/src/app.js
index cd4b48e..3b63321 100644
--- a/src/app.js
+++ b/src/app.js
@@ -41,27 +41,27 @@ var app = angular.module('accountant', [
ngRoute,
])
-.config(function($routeProvider) {
- // Defining template and controller in function of route.
- $routeProvider
- .when('/account/:accountId/operations', {
- templateUrl: operationsTmpl,
- controller: 'OperationController',
- controllerAs: 'operationsCtrl'
- })
- .when('/account/:accountId/scheduler', {
- templateUrl: schedulerTmpl,
- controller: 'SchedulerController',
- controllerAs: 'schedulerCtrl'
- })
- .when('/accounts', {
- templateUrl: accountsTmpl,
- controller: 'AccountController',
- controllerAs: 'accountsCtrl'
- })
- .otherwise({
- redirectTo: '/accounts'
- });
-});
+ .config(function($routeProvider) {
+ // Defining template and controller in function of route.
+ $routeProvider
+ .when('/account/:accountId/operations', {
+ templateUrl: operationsTmpl,
+ controller: 'OperationController',
+ controllerAs: 'operationsCtrl'
+ })
+ .when('/account/:accountId/scheduler', {
+ templateUrl: schedulerTmpl,
+ controller: 'SchedulerController',
+ controllerAs: 'schedulerCtrl'
+ })
+ .when('/accounts', {
+ templateUrl: accountsTmpl,
+ controller: 'AccountController',
+ controllerAs: 'accountsCtrl'
+ })
+ .otherwise({
+ redirectTo: '/accounts'
+ });
+ });
module.exports = app;
diff --git a/src/login/index.js b/src/login/index.js
index cb64dc5..76bd4d0 100644
--- a/src/login/index.js
+++ b/src/login/index.js
@@ -37,123 +37,122 @@ var loginModule = angular.module('accountant.login', [
ngUiBootstrap
])
-.factory('LoginService', function($uibModal, $storage, $document, $log, authService) {
- var login = function () {
- $storage.session.clear();
+ .factory('LoginService', function($uibModal, $storage, $document, $log, authService) {
+ var login = function () {
+ $storage.session.clear();
- var modalInstance = $uibModal.open({
- ariaLabelledBy: 'modal-title',
- ariaDescribedBy: 'modal-body',
- templateUrl: loginTmpl,
- controller: 'LoginModalController',
- controllerAs: '$ctrl'
- });
+ var modalInstance = $uibModal.open({
+ ariaLabelledBy: 'modal-title',
+ ariaDescribedBy: 'modal-body',
+ templateUrl: loginTmpl,
+ controller: 'LoginModalController',
+ controllerAs: '$ctrl'
+ });
- modalInstance.result.then(function (data) {
- $log.log(data);
+ modalInstance.result.then(function (data) {
+ $log.log(data);
- $storage.session.set('refresh_token', data.refresh_token);
- $storage.session.set('access_token', data.access_token);
+ $storage.session.set('refresh_token', data.refresh_token);
+ $storage.session.set('access_token', data.access_token);
- authService.loginConfirmed();
- }, function () {
- $log.info('Modal dismissed at: ' + new Date());
+ authService.loginConfirmed();
+ }, function () {
+ $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.
- authService.loginCancelled(null, 'Login cancelled by user action.');
- });
- };
+ };
- var cancelLogin = function () {
- // FIXME Alexis Lahouze 2017-06-11 Redirect to error page.
- };
+ return {
+ 'login': login,
+ 'cancelLogin': cancelLogin
+ };
+ })
- return {
- 'login': login,
- 'cancelLogin': cancelLogin
- };
-})
+ .factory('sessionInjector', function($storage) {
+ var sessionInjector = {
+ request: function(config) {
+ var access_token = $storage.session.get('access_token');
-.factory('sessionInjector', function($storage) {
- var sessionInjector = {
- request: function(config) {
- var access_token = $storage.session.get('access_token');
+ if (access_token) {
+ //var tokenType = $storage.get('token_type');
+ var tokenType = 'Bearer';
+ var authorization = tokenType + ' ' + access_token;
+ config.headers.authorization = authorization;
+ }
- if (access_token) {
- //var tokenType = $storage.get('token_type');
- var tokenType = 'Bearer';
- var authorization = tokenType + ' ' + access_token;
- config.headers.authorization = authorization;
+ return config;
}
+ };
- return config;
- }
- };
+ return sessionInjector;
+ })
- return sessionInjector;
-})
+ .config(function($httpProvider, $storageProvider) {
+ // Define interceptors.
+ $httpProvider.interceptors.push('sessionInjector');
-.config(function($httpProvider, $storageProvider) {
- // Define interceptors.
- $httpProvider.interceptors.push('sessionInjector');
+ // Configure storage
+ // Set global prefix for stored keys
+ $storageProvider.setPrefix('accountant');
- // Configure storage
- // Set global prefix for stored keys
- $storageProvider.setPrefix('accountant');
+ // Change the default storage engine
+ // Defaults to 'local'
+ $storageProvider.setDefaultStorageEngine('session');
- // Change the default storage engine
- // Defaults to 'local'
- $storageProvider.setDefaultStorageEngine('session');
+ // Change the enabled storage engines
+ // Defaults to ['memory', 'cookie', 'session', 'local']
+ $storageProvider.setEnabledStorageEngines(['local', 'session']);
+ })
- // Change the enabled storage engines
- // Defaults to ['memory', 'cookie', 'session', 'local']
- $storageProvider.setEnabledStorageEngines(['local', 'session']);
-})
+ .controller('LoginModalController', function($scope, $uibModalInstance, $http, $log) {
+ var vm = this;
-.controller('LoginModalController', function($scope, $uibModalInstance, $http, $log) {
- var vm = this;
+ vm.data = {
+ email: null,
+ password: null
+ };
- vm.data = {
- email: null,
- password: null
- };
+ vm.ok = function() {
+ var email = vm.data.email;
+ var password = vm.data.password;
- vm.ok = function() {
- var email = vm.data.email;
- var password = vm.data.password;
+ // Encode authentication data.
+ var authdata = base64.encode(email + ':' + password);
- // Encode authentication data.
- var authdata = base64.encode(email + ':' + password);
+ return $http.post('/api/user/login', {}, {
+ ignoreAuthModule: true,
+ headers: {
+ 'authorization': 'Basic ' + authdata
+ }
+ }).then(function(result) {
+ $log.log(result);
- return $http.post('/api/user/login', {}, {
- ignoreAuthModule: true,
- headers: {
- 'authorization': 'Basic ' + authdata
- }
- }).then(function(result) {
- $log.log(result);
+ $uibModalInstance.close(result.data);
+ }, function(response) {
+ // FIXME Alexis Lahouze 2017-06-11 Handle error.
+ $log.log("Error on login", response);
+ });
+ };
- $uibModalInstance.close(result.data);
- }, function(response) {
- // FIXME Alexis Lahouze 2017-06-11 Handle error.
- $log.log("Error on login", response);
+ 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();
});
- };
-
- 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;
diff --git a/src/operations/balance-chart.component.js b/src/operations/balance-chart.component.js
index eb3c471..e2a3173 100644
--- a/src/operations/balance-chart.component.js
+++ b/src/operations/balance-chart.component.js
@@ -32,160 +32,162 @@ var balanceChartModule = angular.module('balanceChartModule', [
ngResource
])
-.component('balanceChart', {
- template: '