bugfixes
This commit is contained in:
@@ -1,6 +1,15 @@
|
|||||||
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
||||||
|
|
||||||
transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($http, $scope, $location, $resource, $q, $uibModal, $log, Transaction) {
|
function amountToNumber(amount) {
|
||||||
|
console.log("typeof amount: " + (typeof amount));
|
||||||
|
amount = amount.toString().replace(',', '.');
|
||||||
|
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
|
||||||
|
amount = '-' + amount;
|
||||||
|
}
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($scope, $location, $resource, $q, $uibModal, $log, Transaction) {
|
||||||
|
|
||||||
$scope.refreshList = function() {
|
$scope.refreshList = function() {
|
||||||
|
|
||||||
@@ -12,7 +21,8 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
|
|
||||||
$scope.transaction = {
|
$scope.transaction = {
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
date: new Date()
|
date: new Date(),
|
||||||
|
creditor: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof $scope.categories !== 'undefined') {
|
if (typeof $scope.categories !== 'undefined') {
|
||||||
@@ -20,8 +30,10 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get recent transactions
|
// 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();
|
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) {
|
transactions.$promise.then(function(data) {
|
||||||
|
$log.info(transactions._embedded.transactions);
|
||||||
$scope.transactions = transactions._embedded.transactions;
|
$scope.transactions = transactions._embedded.transactions;
|
||||||
$scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1);
|
$scope.nextPageAvailable = (transactions.page.totalPages !== transactions.page.number + 1);
|
||||||
$scope.prevPageAvailable = (transactions.page.number > 0);
|
$scope.prevPageAvailable = (transactions.page.number > 0);
|
||||||
@@ -72,12 +84,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
//console.log('Withdrawals by ' + $scope.accountUsers[i].name + ': ' + withdrawnSum);
|
//console.log('Withdrawals by ' + $scope.accountUsers[i].name + ': ' + withdrawnSum);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO for some reason this does not work upon reload
|
|
||||||
document.getElementsByName('expenseBy')[0].checked = true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.checkCategory = function() {
|
$scope.checkCategory = function() {
|
||||||
@@ -136,17 +143,9 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function amountToNumber(amount) {
|
|
||||||
amount = amount.replace(',', '.');
|
|
||||||
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
|
|
||||||
amount = '-' + amount;
|
|
||||||
}
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.postTransaction = function() {
|
$scope.postTransaction = function() {
|
||||||
|
|
||||||
amount = amountToNumber($scope.transaction.amount);
|
var amount = amountToNumber($scope.transaction.amount);
|
||||||
|
|
||||||
// handle withdrawals
|
// handle withdrawals
|
||||||
if ($scope.transaction.category._links.self.href === 'withdrawal') {
|
if ($scope.transaction.category._links.self.href === 'withdrawal') {
|
||||||
@@ -188,7 +187,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.deleteLastSubmission = function() {
|
$scope.deleteLastSubmission = function() {
|
||||||
console.log($scope.lastSubmission._links.self.href);
|
|
||||||
var testTrns = $resource($scope.lastSubmission._links.self.href).delete(function() {
|
var testTrns = $resource($scope.lastSubmission._links.self.href).delete(function() {
|
||||||
$scope.lastSubmission = undefined;
|
$scope.lastSubmission = undefined;
|
||||||
$scope.refreshList();
|
$scope.refreshList();
|
||||||
@@ -236,6 +234,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
|
|
||||||
modalInstance.result.then(function(transaction) {
|
modalInstance.result.then(function(transaction) {
|
||||||
$scope.lastSubmission = undefined;
|
$scope.lastSubmission = undefined;
|
||||||
|
$log.info('refresh');
|
||||||
$scope.refreshList();
|
$scope.refreshList();
|
||||||
}, function () {
|
}, function () {
|
||||||
$log.info('Modal dismissed at: ' + new Date());
|
$log.info('Modal dismissed at: ' + new Date());
|
||||||
@@ -251,7 +250,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
|
|||||||
|
|
||||||
$scope.accountUsers = accountUsers;
|
$scope.accountUsers = accountUsers;
|
||||||
|
|
||||||
transaction = Transaction.get({ id: transactionId });
|
var transaction = Transaction.get({ id: transactionId });
|
||||||
transaction.$promise.then(function(data) {
|
transaction.$promise.then(function(data) {
|
||||||
transaction.date = new Date(transaction.date);
|
transaction.date = new Date(transaction.date);
|
||||||
transaction.creditor = $resource(transaction._links.creditor.href).get();
|
transaction.creditor = $resource(transaction._links.creditor.href).get();
|
||||||
@@ -281,6 +280,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
|
|||||||
$scope.ok = function () {
|
$scope.ok = function () {
|
||||||
// set URI for category and save via PUT request
|
// 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.$update(function() {});
|
$scope.transaction.$update(function() {});
|
||||||
|
|
||||||
$uibModalInstance.close($scope.transaction);
|
$uibModalInstance.close($scope.transaction);
|
||||||
@@ -290,7 +290,6 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', '
|
|||||||
$uibModalInstance.dismiss('cancel');
|
$uibModalInstance.dismiss('cancel');
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO still used?
|
|
||||||
$scope.deleteTransaction = function() {
|
$scope.deleteTransaction = function() {
|
||||||
// TODO auf return code reagieren
|
// TODO auf return code reagieren
|
||||||
$resource($scope.transaction._links.self.href).remove().$promise.then(function() {
|
$resource($scope.transaction._links.self.href).remove().$promise.then(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user