show changes after modal has been closed
This commit is contained in:
@@ -22,7 +22,7 @@ public class SpringDataRestEventHandler {
|
||||
@HandleBeforeSave
|
||||
public void applyUserInformationUsingSecurityContext(Transaction transaction) {
|
||||
Date timestamp = new Date();
|
||||
log.info("Setting date '" + timestamp + "' on new transaction: " + transaction.getDescription());
|
||||
log.info("Setting date '" + timestamp + "' on transaction: " + transaction.getId() + "(" + transaction.getDescription() + ")");
|
||||
transaction.setLastChange(timestamp);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
||||
|
||||
function amountToNumber(amount) {
|
||||
console.log("typeof amount: " + (typeof amount));
|
||||
amount = amount.toString().replace(',', '.');
|
||||
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
|
||||
amount = '-' + amount;
|
||||
@@ -11,35 +10,7 @@ function amountToNumber(amount) {
|
||||
|
||||
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($scope, $location, $resource, $q, $uibModal, $log, Transaction) {
|
||||
|
||||
$scope.refreshList = function() {
|
||||
|
||||
// reset form
|
||||
if ($scope.form) {
|
||||
$scope.form.$setPristine();
|
||||
$scope.form.$setUntouched();
|
||||
}
|
||||
|
||||
$scope.transaction = {
|
||||
amount: undefined,
|
||||
date: new Date(),
|
||||
creditor: ""
|
||||
};
|
||||
|
||||
if (typeof $scope.categories !== 'undefined') {
|
||||
$scope.transaction.category = $scope.categories[0];
|
||||
}
|
||||
|
||||
// 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);
|
||||
$scope.pageNumber = transactions.page.number;
|
||||
});
|
||||
|
||||
function refreshExpenses() {
|
||||
var accountUsers = $resource($scope.account._links.users.href).get();
|
||||
accountUsers.$promise.then(function(data) {
|
||||
$scope.accountUsers = accountUsers._embedded.users;
|
||||
@@ -87,6 +58,36 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
});
|
||||
}
|
||||
|
||||
$scope.refreshList = function() {
|
||||
|
||||
// reset form
|
||||
if ($scope.form) {
|
||||
$scope.form.$setPristine();
|
||||
$scope.form.$setUntouched();
|
||||
}
|
||||
|
||||
$scope.transaction = {
|
||||
amount: undefined,
|
||||
date: new Date(),
|
||||
creditor: ""
|
||||
};
|
||||
|
||||
if (typeof $scope.categories !== 'undefined') {
|
||||
$scope.transaction.category = $scope.categories[0];
|
||||
}
|
||||
|
||||
// get recent 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) {
|
||||
$scope.transactions = transactions._embedded.transactions;
|
||||
$scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1);
|
||||
$scope.prevPageAvailable = (transactions.page.number > 0);
|
||||
$scope.pageNumber = transactions.page.number;
|
||||
});
|
||||
|
||||
refreshExpenses();
|
||||
}
|
||||
|
||||
$scope.checkCategory = function() {
|
||||
|
||||
var radioButtons = document.getElementsByName('expenseBy');
|
||||
@@ -217,12 +218,12 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openDetails = function(transactionId) {
|
||||
$scope.openDetails = function(transaction) {
|
||||
var modalInstance = $uibModal.open({
|
||||
templateUrl: 'detailsTemplate.html',
|
||||
controller: 'DetailsModalCtrl',
|
||||
resolve: {
|
||||
transactionId: transactionId,
|
||||
transactionId: transaction.id,
|
||||
categories: function () {
|
||||
return $scope.categories;
|
||||
},
|
||||
@@ -232,9 +233,29 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
|
||||
}
|
||||
});
|
||||
|
||||
modalInstance.result.then(function(transaction) {
|
||||
modalInstance.result.then(function(editedTransaction) {
|
||||
|
||||
$scope.lastSubmission = undefined;
|
||||
$scope.refreshList();
|
||||
|
||||
if (editedTransaction.amount != undefined) {
|
||||
transaction.amount = editedTransaction.amount;
|
||||
transaction.date = editedTransaction.date;
|
||||
transaction.description = editedTransaction.description;
|
||||
|
||||
transaction.creditor = $resource(editedTransaction.creditor).get();
|
||||
transaction.category = $resource(editedTransaction.category).get();
|
||||
}
|
||||
else {
|
||||
// if the transaction has been deleted, only the ID is returned
|
||||
for (i = 0; i < $scope.transactions.length; i++) {
|
||||
if ($scope.transactions[i].id == editedTransaction) {
|
||||
$scope.transactions.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
refreshExpenses();
|
||||
|
||||
}, function () {
|
||||
$log.info('Modal dismissed at: ' + new Date());
|
||||
});
|
||||
@@ -277,12 +298,11 @@ 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);
|
||||
$scope.transaction.$update(function(data) {}).then(
|
||||
$uibModalInstance.close($scope.transaction)
|
||||
);
|
||||
};
|
||||
|
||||
$scope.cancel = function () {
|
||||
@@ -290,9 +310,9 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
|
||||
};
|
||||
|
||||
$scope.deleteTransaction = function() {
|
||||
// TODO auf return code reagieren
|
||||
var deletedTransactionId = $scope.transaction.id;
|
||||
$resource($scope.transaction._links.self.href).remove().$promise.then(function() {
|
||||
$uibModalInstance.close();
|
||||
$uibModalInstance.close(deletedTransactionId);
|
||||
});
|
||||
}
|
||||
} ]);
|
||||
|
||||
@@ -61,8 +61,7 @@
|
||||
<input
|
||||
id="descriptionInput"
|
||||
ng-model="transaction.description"
|
||||
uib-typeahead="address for address in updateSuggestions($viewValue)"
|
||||
typeahead-loading="loadingLocations"
|
||||
uib-typeahead="suggestion for suggestion in updateSuggestions($viewValue)"
|
||||
class="form-control">
|
||||
</div>
|
||||
|
||||
@@ -89,7 +88,7 @@
|
||||
<th>Betrag</th>
|
||||
<th>Beschreibung</th>
|
||||
</tr>
|
||||
<tr ng-repeat="transaction in transactions" ng-click="openDetails(transaction.id)" class="clickable">
|
||||
<tr ng-repeat="transaction in transactions" ng-click="openDetails(transaction)" class="clickable">
|
||||
<td>{{transaction.date | date:'dd.MM.yyyy'}}</td>
|
||||
<td>{{transaction.category.name}}</td>
|
||||
<td align="right" ng-class="{credit: transaction.creditor.name}">{{transaction.amount | number : 2}} €</td>
|
||||
@@ -151,8 +150,7 @@
|
||||
<input
|
||||
id="descriptionInput"
|
||||
ng-model="transaction.description"
|
||||
uib-typeahead="address for address in updateSuggestions($viewValue)"
|
||||
typeahead-loading="loadingLocations"
|
||||
autocomplete="off"
|
||||
class="form-control">
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user