diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index 8c83250..f91abd3 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -1,6 +1,15 @@ var transactionControllers = angular.module('transactionControllers', ['ngResource']); -transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($http, $scope, $location, $resource, $q, $uibModal, $log, Transaction) { +function amountToNumber(amount) { + console.log("typeof amount: " + (typeof amount)); + amount = amount.toString().replace(',', '.'); + if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') { + amount = '-' + amount; + } + return amount; +} + +transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($scope, $location, $resource, $q, $uibModal, $log, Transaction) { $scope.refreshList = function() { @@ -12,7 +21,8 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$ $scope.transaction = { amount: undefined, - date: new Date() + date: new Date(), + creditor: "" }; if (typeof $scope.categories !== 'undefined') { @@ -20,8 +30,10 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$ } // get recent transactions + $log.info('get transactions:'); var transactions = $resource('http://localhost:8080/transactions/search/forAccount', { accountId: $scope.account.id, size: $scope.pageSize, sort: 'date,desc' }).get(); transactions.$promise.then(function(data) { + $log.info(transactions._embedded.transactions); $scope.transactions = transactions._embedded.transactions; $scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1); $scope.prevPageAvailable = (transactions.page.number > 0); @@ -72,12 +84,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$ //console.log('Withdrawals by ' + $scope.accountUsers[i].name + ': ' + withdrawnSum); } }); - }); - - // TODO for some reason this does not work upon reload - document.getElementsByName('expenseBy')[0].checked = true; - } $scope.checkCategory = function() { @@ -136,17 +143,9 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$ } - function amountToNumber(amount) { - amount = amount.replace(',', '.'); - if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') { - amount = '-' + amount; - } - return amount; - } - $scope.postTransaction = function() { - amount = amountToNumber($scope.transaction.amount); + var amount = amountToNumber($scope.transaction.amount); // handle withdrawals if ($scope.transaction.category._links.self.href === 'withdrawal') { @@ -188,7 +187,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$ }; $scope.deleteLastSubmission = function() { - console.log($scope.lastSubmission._links.self.href); var testTrns = $resource($scope.lastSubmission._links.self.href).delete(function() { $scope.lastSubmission = undefined; $scope.refreshList(); @@ -236,6 +234,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$ modalInstance.result.then(function(transaction) { $scope.lastSubmission = undefined; + $log.info('refresh'); $scope.refreshList(); }, function () { $log.info('Modal dismissed at: ' + new Date()); @@ -251,7 +250,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', ' $scope.accountUsers = accountUsers; - transaction = Transaction.get({ id: transactionId }); + var transaction = Transaction.get({ id: transactionId }); transaction.$promise.then(function(data) { transaction.date = new Date(transaction.date); transaction.creditor = $resource(transaction._links.creditor.href).get(); @@ -281,6 +280,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', ' $scope.ok = function () { // set URI for category and save via PUT request $scope.transaction.category = $scope.transaction.category._links.self.href; + $scope.transaction.amount = amountToNumber($scope.transaction.amount); $scope.transaction.$update(function() {}); $uibModalInstance.close($scope.transaction); @@ -290,7 +290,6 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', ' $uibModalInstance.dismiss('cancel'); }; - // TODO still used? $scope.deleteTransaction = function() { // TODO auf return code reagieren $resource($scope.transaction._links.self.href).remove().$promise.then(function() {