problems saving - try curl first

This commit is contained in:
2016-03-08 17:21:39 +01:00
parent 56799eaefe
commit 4113246222
5 changed files with 83 additions and 15 deletions
+29 -7
View File
@@ -2,21 +2,37 @@ var transactionControllers = angular.module('transactionControllers', ['ngResour
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', function($scope, $location, $resource) {
// TODO pass accountId
$scope.accountId = 1;
$scope.initList = function() {
$scope.refreshList = function() {
console.log('refreshList()');
var transactions = $resource('/transactions/search/last10', { accountId: $scope.accountId }).get();
transactions.$promise.then(function(data) {
$scope.transactions = transactions._embedded.transactions;
for (var i = 0; i < $scope.transactions.length; i++) {
$scope.transactions[i].category = $resource($scope.transactions[i]._links.category.href).get();
$scope.transactions[i].creditor = $resource($scope.transactions[i]._links.creditor.href).get();
// $scope.transactions[i].account = $resource($scope.transactions[i]._links.account.href).get();
}
// XXX get selected account from frontend
$scope.account = $scope.transactions[0]._links.account;
});
}
$scope.initList = function() {
// TODO pass accountId
$scope.accountId = 1;
console.log('initList()');
$scope.date = new Date();
$scope.refreshList();
var categories = $resource('/categories/search/listForAccount', { accountId: $scope.accountId }).get();
@@ -24,14 +40,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
$scope.categories = categories._embedded.categories;
// select the first entry as default
$scope.categorySelection = categories._embedded.categories[0];
$scope.category = categories._embedded.categories[0];
});
}
$scope.postTransaction = function() {
// // simple HTTP POST
console.log('postTransaction()');
// simple HTTP POST
// $http.post('/transactions', { "amount" : $scope.amount /* date, */ }).success(function() {
// console.log('REFRESH');
// $scope.initList();
@@ -49,7 +67,11 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
"creditor" : $scope.creditor
});
console.log(newTransaction);
newTransaction.$save();
$scope.refreshList();
};
$scope.showTransaction = function(transaction) {
@@ -3,23 +3,24 @@
<div>
<form role="form" ng-submit="postTransaction()">
<div>
<input ng-model='amount' type='text' size='10' maxlength='10' />
Betrag: <input ng-model='amount' type='number' />
</div>
<div>
<select ng-model='categorySelection' size='1' ng-options="category.name for category in categories track by category._links.self.href">
Kategorie: <select ng-model='category' size='1'
ng-options="category.name for category in categories track by category._links.self.href">
</select>
</div>
<div>
<input ng-model='date' type='text' size='10' maxlength='10' />
Datum: <input ng-model='date' type='date' placeholder="yyyy-MM-dd" required />
</div>
<div>
<input ng-model='description' type='text' size='10' maxlength='10' />
Notiz: <input ng-model='description' type='text' size='10' />
</div>
<div>
<input type="submit"/>
<input type="submit" />
</div>
</form>
<table class="listing">
<tr>
<th>Datum</th>
@@ -35,6 +36,14 @@
</tr>
</table>
<div>
<pre style="font-size: 75%">{{account | json}}</pre>
</div>
<div>
<pre style="font-size: 75%">{{transactions | json}}</pre>
</div>
</div>
</div>
</div>