diff --git a/src/main/java/de/tilman/transactions/Application.java b/src/main/java/de/tilman/transactions/Application.java index afe69eb..96fff2e 100644 --- a/src/main/java/de/tilman/transactions/Application.java +++ b/src/main/java/de/tilman/transactions/Application.java @@ -2,11 +2,14 @@ package de.tilman.transactions; import javax.annotation.PostConstruct; +import org.h2.server.web.WebServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.embedded.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.context.SecurityContextHolder; @@ -53,5 +56,12 @@ public class Application { SecurityContextHolder.clearContext(); } + // XXX for dev - make H2 database available as jdbc:h2:mem:testdb at /console (http://stackoverflow.com/a/24727653/3761783) +// @Bean +// public ServletRegistrationBean h2servletRegistration() { +// ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet()); +// registration.addUrlMappings("/console/*"); +// return registration; +// } } diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index 446149f..51956c2 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -25,7 +25,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' // initialize attributes for outstanding amounts for (i = 0; i < $scope.accountUsers.length; i++) { - $scope.accountUsers[i].outstandings = 0.0; + $scope.accountUsers[i].outstandingSum = 0.0; } // get expenses for all users of the account @@ -37,12 +37,14 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' $q.all(promises).then(function(data) { for (i = 0; i < data.length; i++) { + $scope.accountUsers[i].expenses = new Array(data[i]._embedded.transactions.length); var expenseSum = 0; for (j = 0; j < data[i]._embedded.transactions.length; j++) { + $scope.accountUsers[i].expenses[j] = data[i]._embedded.transactions[j]; +// XXX $scope.accountUsers[i].expenses[j].amount = numberToAmount(data[i]._embedded.transactions[j].amount); expenseSum = expenseSum + data[i]._embedded.transactions[j].amount; } - $scope.accountUsers[i].outstandings -= expenseSum; - //console.log('Expenses by ' + $scope.accountUsers[i].name + ': ' + expenseSum); + $scope.accountUsers[i].outstandingSum -= expenseSum; } }); @@ -55,12 +57,13 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' $q.all(promises).then(function(data) { for (i = 0; i < data.length; i++) { + $scope.accountUsers[i].withdrawals = new Array(data[i]._embedded.withdrawals.length); var withdrawnSum = 0; for (j = 0; j < data[i]._embedded.withdrawals.length; j++) { + $scope.accountUsers[i].withdrawals[j] = data[i]._embedded.withdrawals[j]; withdrawnSum = withdrawnSum + data[i]._embedded.withdrawals[j].amount; } - $scope.accountUsers[i].outstandings -= withdrawnSum; - //console.log('Withdrawals by ' + $scope.accountUsers[i].name + ': ' + withdrawnSum); + $scope.accountUsers[i].outstandingSum -= withdrawnSum; } }); }); @@ -273,7 +276,23 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' refreshExpenses(); }, function () { - $log.info('Modal dismissed at: ' + new Date()); + $log.info('DetailsModal dismissed ' + new Date()); + }); + }; + + $scope.openExpenses = function(user) { + var modalInstance = $uibModal.open({ + templateUrl: 'expensesTemplate.html', + controller: 'ExpensesModalCtrl', + resolve: { + accountUser: user + } + }); + + modalInstance.result.then(function() { + refreshExpenses(); + }, function () { + $log.info('ExpensesModal dismissed ' + new Date()); }); }; @@ -333,3 +352,17 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', ' }); } } ]); + +transactionControllers.controller('ExpensesModalCtrl', [ '$scope', '$uibModalInstance', 'accountUser', function($scope, $uibModalInstance, accountUser) { + + $scope.accountUser = accountUser; + console.log($scope.accountUser); + + $scope.ok = function () { + $uibModalInstance.close(); + }; + + $scope.close = function () { + $uibModalInstance.dismiss('close'); + }; +} ]); diff --git a/src/main/resources/static/partials/transaction-list.html b/src/main/resources/static/partials/transaction-list.html index 7bd253f..c7d9860 100644 --- a/src/main/resources/static/partials/transaction-list.html +++ b/src/main/resources/static/partials/transaction-list.html @@ -100,7 +100,7 @@
- {{user.name}} {{user.outstandings | number : 2}} €
+ {{user.name}} {{user.outstandingSum | number : 2}} €
@@ -176,6 +176,50 @@ + +