show changes after modal has been closed
This commit is contained in:
@@ -22,7 +22,7 @@ public class SpringDataRestEventHandler {
|
|||||||
@HandleBeforeSave
|
@HandleBeforeSave
|
||||||
public void applyUserInformationUsingSecurityContext(Transaction transaction) {
|
public void applyUserInformationUsingSecurityContext(Transaction transaction) {
|
||||||
Date timestamp = new Date();
|
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);
|
transaction.setLastChange(timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
||||||
|
|
||||||
function amountToNumber(amount) {
|
function amountToNumber(amount) {
|
||||||
console.log("typeof amount: " + (typeof amount));
|
|
||||||
amount = amount.toString().replace(',', '.');
|
amount = amount.toString().replace(',', '.');
|
||||||
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
|
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
|
||||||
amount = '-' + amount;
|
amount = '-' + amount;
|
||||||
@@ -10,36 +9,8 @@ function amountToNumber(amount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($scope, $location, $resource, $q, $uibModal, $log, Transaction) {
|
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($scope, $location, $resource, $q, $uibModal, $log, Transaction) {
|
||||||
|
|
||||||
$scope.refreshList = function() {
|
function refreshExpenses() {
|
||||||
|
|
||||||
// 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;
|
|
||||||
});
|
|
||||||
|
|
||||||
var accountUsers = $resource($scope.account._links.users.href).get();
|
var accountUsers = $resource($scope.account._links.users.href).get();
|
||||||
accountUsers.$promise.then(function(data) {
|
accountUsers.$promise.then(function(data) {
|
||||||
$scope.accountUsers = accountUsers._embedded.users;
|
$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() {
|
$scope.checkCategory = function() {
|
||||||
|
|
||||||
var radioButtons = document.getElementsByName('expenseBy');
|
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({
|
var modalInstance = $uibModal.open({
|
||||||
templateUrl: 'detailsTemplate.html',
|
templateUrl: 'detailsTemplate.html',
|
||||||
controller: 'DetailsModalCtrl',
|
controller: 'DetailsModalCtrl',
|
||||||
resolve: {
|
resolve: {
|
||||||
transactionId: transactionId,
|
transactionId: transaction.id,
|
||||||
categories: function () {
|
categories: function () {
|
||||||
return $scope.categories;
|
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.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 () {
|
}, function () {
|
||||||
$log.info('Modal dismissed at: ' + new Date());
|
$log.info('Modal dismissed at: ' + new Date());
|
||||||
});
|
});
|
||||||
@@ -277,12 +298,11 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
|
|||||||
});
|
});
|
||||||
|
|
||||||
$scope.ok = function () {
|
$scope.ok = function () {
|
||||||
// set URI for category and save via PUT request
|
|
||||||
$scope.transaction.category = $scope.transaction.category._links.self.href;
|
$scope.transaction.category = $scope.transaction.category._links.self.href;
|
||||||
$scope.transaction.amount = amountToNumber($scope.transaction.amount);
|
$scope.transaction.amount = amountToNumber($scope.transaction.amount);
|
||||||
$scope.transaction.$update(function() {});
|
$scope.transaction.$update(function(data) {}).then(
|
||||||
|
$uibModalInstance.close($scope.transaction)
|
||||||
$uibModalInstance.close($scope.transaction);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.cancel = function () {
|
$scope.cancel = function () {
|
||||||
@@ -290,9 +310,9 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.deleteTransaction = function() {
|
$scope.deleteTransaction = function() {
|
||||||
// TODO auf return code reagieren
|
var deletedTransactionId = $scope.transaction.id;
|
||||||
$resource($scope.transaction._links.self.href).remove().$promise.then(function() {
|
$resource($scope.transaction._links.self.href).remove().$promise.then(function() {
|
||||||
$uibModalInstance.close();
|
$uibModalInstance.close(deletedTransactionId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} ]);
|
} ]);
|
||||||
|
|||||||
@@ -61,8 +61,7 @@
|
|||||||
<input
|
<input
|
||||||
id="descriptionInput"
|
id="descriptionInput"
|
||||||
ng-model="transaction.description"
|
ng-model="transaction.description"
|
||||||
uib-typeahead="address for address in updateSuggestions($viewValue)"
|
uib-typeahead="suggestion for suggestion in updateSuggestions($viewValue)"
|
||||||
typeahead-loading="loadingLocations"
|
|
||||||
class="form-control">
|
class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@
|
|||||||
<th>Betrag</th>
|
<th>Betrag</th>
|
||||||
<th>Beschreibung</th>
|
<th>Beschreibung</th>
|
||||||
</tr>
|
</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.date | date:'dd.MM.yyyy'}}</td>
|
||||||
<td>{{transaction.category.name}}</td>
|
<td>{{transaction.category.name}}</td>
|
||||||
<td align="right" ng-class="{credit: transaction.creditor.name}">{{transaction.amount | number : 2}} €</td>
|
<td align="right" ng-class="{credit: transaction.creditor.name}">{{transaction.amount | number : 2}} €</td>
|
||||||
@@ -151,8 +150,7 @@
|
|||||||
<input
|
<input
|
||||||
id="descriptionInput"
|
id="descriptionInput"
|
||||||
ng-model="transaction.description"
|
ng-model="transaction.description"
|
||||||
uib-typeahead="address for address in updateSuggestions($viewValue)"
|
autocomplete="off"
|
||||||
typeahead-loading="loadingLocations"
|
|
||||||
class="form-control">
|
class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user