From c14d88f4219e58757c23df369ebb668d5f196462 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Wed, 5 Jul 2017 21:48:20 +0200 Subject: [PATCH] Fix indent. --- src/accounts/index.js | 412 ++++++++++----------- src/app.js | 44 +-- src/login/index.js | 185 +++++---- src/operations/balance-chart.component.js | 302 +++++++-------- src/operations/category-chart.component.js | 172 ++++----- src/operations/index.js | 390 +++++++++---------- src/scheduler/index.js | 327 ++++++++-------- 7 files changed, 918 insertions(+), 914 deletions(-) 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: '
', - bindings: { - account: '<', - onUpdate: '&' - }, - controller: function($routeParams, Balances, Account, $element) { - var vm = this; + .component('balanceChart', { + template: '
', + 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; diff --git a/src/operations/category-chart.component.js b/src/operations/category-chart.component.js index 905821e..65b2062 100644 --- a/src/operations/category-chart.component.js +++ b/src/operations/category-chart.component.js @@ -29,100 +29,104 @@ var categoryChartModule = angular.module('categoryChartModule', [ ngResource ]) -.component('categoryChart', { - template: '
', - bindings: { - minDate: '<', - maxDate: '<' - }, - controller: function($routeParams, $element, Categories, Incomes) { - var vm = this; + .component('categoryChart', { + template: '
', + 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; diff --git a/src/operations/index.js b/src/operations/index.js index 50ee30f..d1521f1 100644 --- a/src/operations/index.js +++ b/src/operations/index.js @@ -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 + ':
' + 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 + ':
' + 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; diff --git a/src/scheduler/index.js b/src/scheduler/index.js index deaf866..d5b5c96 100644 --- a/src/scheduler/index.js +++ b/src/scheduler/index.js @@ -35,197 +35,196 @@ var schedulerModule = angular.module('accountant.scheduler', [ ngStrap ]) -.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('ScheduledOperation', function($resource) { - return $resource( - '/api/scheduled_operation/: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; - } + .factory('ScheduledOperation', function($resource) { + return $resource( + '/api/scheduled_operation/:id', { + id: '@id' } - }).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(); return operation; - }, function(result) { + }, function(result){ + $log.error('Error while saving scheduled operation', operation, result); + Notification.error( - 'An error occurred while trying to delete operation #' + - id + ':
' + result + 'Error while saving scheduled 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: 'scheduleModifyModalComponent', - resolve: { - operation: function() { - return operation; + /* + * Delete operation. + */ + vm.delete = function(operation) { + var id = operation.id; + + $uibModal.open({ + component: 'scheduleDeleteModalComponent', + 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.'); - // Load operations on controller initialization. - vm.operations = vm.load(); -}) + vm.operations = vm.load(); -.component('scheduleModifyModalComponent', { - templateUrl: scheduleFormTmpl, - bindings: { - resolve: '<', - close: '&', - dismiss: '&' - }, - controller: function() { - var vm = this; + return operation; + }, function(result) { + Notification.error( + 'An error occurred while trying to delete operation #' + + id + ':
' + result + ); - 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: 'scheduleModifyModalComponent', + 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 "Scheduled operation #" + vm.operation.id; - } else { - return "Scheduled operation"; - } - }; - } -}) + // Load operations on controller initialization. + vm.operations = vm.load(); + }) + .component('scheduleModifyModalComponent', { + templateUrl: scheduleFormTmpl, + bindings: { + resolve: '<', + close: '&', + dismiss: '&' + }, + controller: function() { + var vm = this; -.component('scheduleDeleteModalComponent', { - templateUrl: scheduleDeleteTmpl, - bindings: { - resolve: '<', - close: '&', - dismiss: '&' - }, - controller: function() { - var vm = this; + vm.$onInit = function() { + vm.operation = vm.resolve.operation; + }; - vm.$onInit = function() { - vm.operation = vm.resolve.operation; - }; + vm.ok = function() { + vm.close({ + $value: vm.operation + }); + }; - vm.ok = function() { - vm.close({ - $value: vm.operation - }); - }; + vm.cancel = function() { + vm.dismiss({ + $value: 'cancel' + }); + }; - 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"; + } + }; + } + }) - vm.title = function() { - // FIXME Alexis Lahouze 2017-06-15 i18n - if (vm.operation.id) { - return "Scheduled operation #" + vm.operation.id; - } else { - return "Scheduled operation"; - } - }; - } -}); + .component('scheduleDeleteModalComponent', { + templateUrl: scheduleDeleteTmpl, + 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 "Scheduled operation #" + vm.operation.id; + } else { + return "Scheduled operation"; + } + }; + } + }); module.exports = schedulerModule;