exposed IDs and account switching
This commit is contained in:
@@ -19,11 +19,12 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
|
||||
if (typeof $scope.categories !== 'undefined') {
|
||||
// TODO default-Kategorie sollte per Account einstellbar sein
|
||||
console.log('DID IT!');
|
||||
$scope.transaction.category = $scope.categories[0];
|
||||
}
|
||||
|
||||
// get recent transactions
|
||||
var transactions = $resource('/transactions/search/last10', { accountId: $scope.accountId }).get();
|
||||
var transactions = $resource('/transactions/search/last10', { accountId: $scope.account.id }).get();
|
||||
|
||||
transactions.$promise.then(function(data) {
|
||||
$scope.transactions = transactions._embedded.transactions;
|
||||
@@ -37,34 +38,31 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
}
|
||||
|
||||
$scope.initList = function() {
|
||||
|
||||
// TODO get account from frontend
|
||||
$scope.accountId = 1;
|
||||
$scope.account = 'http://localhost:8080/accounts/1';
|
||||
|
||||
//http://localhost:8080/accounts/search/findByUserName?username=betty@mail.com
|
||||
|
||||
// var accounts = $resource('/accounts/search/findByUserName', { username: $scope.accountId }).get();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
console.log('initList()');
|
||||
|
||||
$scope.refreshList();
|
||||
|
||||
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accountId }).get();
|
||||
|
||||
categories.$promise.then(function(data) {
|
||||
$scope.categories = categories._embedded.categories;
|
||||
var userinfo = $resource('/user').get();
|
||||
userinfo.$promise.then(function(data) {
|
||||
$scope.username = userinfo.name;
|
||||
|
||||
// select the first entry as default
|
||||
$scope.transaction.category = categories._embedded.categories[0];
|
||||
var accountInfo = $resource('/accounts/search/findByUserName', { username: userinfo.name }).get();
|
||||
accountInfo.$promise.then(function(data) {
|
||||
$scope.accounts = accountInfo._embedded.accounts;
|
||||
$scope.account = $scope.accounts[0];
|
||||
|
||||
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accounts[0].id }).get();
|
||||
categories.$promise.then(function(data) {
|
||||
$scope.categories = categories._embedded.categories;
|
||||
$scope.refreshList();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$scope.refreshAccount = function() {
|
||||
console.log('BINGO!');
|
||||
$scope.refreshList();
|
||||
};
|
||||
|
||||
$scope.postTransaction = function() {
|
||||
|
||||
// via Resource (might be moved into a service)
|
||||
@@ -87,6 +85,10 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
$scope.showTransaction = function(transaction) {
|
||||
$location.path('/transaction/' + transaction._links.self.href);
|
||||
};
|
||||
|
||||
|
||||
// initialize (http://stackoverflow.com/a/25662066/3761783)
|
||||
$scope.initList();
|
||||
|
||||
} ]);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div ng-init="initList()">
|
||||
<div>
|
||||
<div>
|
||||
<div><select ng-model='user.accounts' ng-options="account.name for account in accounts"></select></div>
|
||||
<div><select ng-model='account' ng-change='refreshAccount()' ng-options="account.name for account in accounts track by account.id"></select></div>
|
||||
<div>
|
||||
<form role="form" ng-submit="postTransaction()">
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user