moved Transaction into service
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
<script src="js/app.js"></script>
|
<script src="js/app.js"></script>
|
||||||
<script src="js/controllers.js"></script>
|
<script src="js/controllers.js"></script>
|
||||||
|
<script src="js/services.js"></script>
|
||||||
|
|
||||||
<!-- Google fonts -->
|
<!-- Google fonts -->
|
||||||
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
|
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var transactionsApp = angular.module('transactionsApp', ['ui.bootstrap', 'ngRoute', 'transactionControllers' ]);
|
var transactionsApp = angular.module('transactionsApp', ['ui.bootstrap', 'ngRoute', 'transactionControllers', 'transactionServices' ]);
|
||||||
|
|
||||||
transactionsApp.config([ '$routeProvider', function($routeProvider) {
|
transactionsApp.config([ '$routeProvider', function($routeProvider) {
|
||||||
$routeProvider.when('/list', {
|
$routeProvider.when('/list', {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
var transactionControllers = angular.module('transactionControllers', ['ngResource']);
|
||||||
|
|
||||||
transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$location', '$resource', '$q', '$uibModal', '$log', function($http, $scope, $location, $resource, $q, $uibModal, $log) {
|
transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$location', '$resource', '$q', '$uibModal', '$log', 'Transaction', function($http, $scope, $location, $resource, $q, $uibModal, $log, Transaction) {
|
||||||
|
|
||||||
$scope.refreshList = function() {
|
$scope.refreshList = function() {
|
||||||
|
|
||||||
@@ -136,13 +136,17 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.postTransaction = function() {
|
function amountToNumber(amount) {
|
||||||
|
amount = amount.replace(',', '.');
|
||||||
var amount = $scope.transaction.amount.replace(',', '.');
|
|
||||||
|
|
||||||
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
|
if (amount.charAt(0) !== '+' && amount.charAt(0) !== '-') {
|
||||||
amount = '-' + amount;
|
amount = '-' + amount;
|
||||||
}
|
}
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.postTransaction = function() {
|
||||||
|
|
||||||
|
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') {
|
||||||
@@ -167,12 +171,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$http', '$scope', '$
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// via Resource (might be moved into a service)
|
|
||||||
var Transaction = $resource('/transactions');
|
|
||||||
|
|
||||||
console.log('Creditor:');
|
|
||||||
console.log($scope.transaction.creditor);
|
|
||||||
|
|
||||||
var newTransaction = new Transaction({
|
var newTransaction = new Transaction({
|
||||||
"account" : $scope.account._links.self.href,
|
"account" : $scope.account._links.self.href,
|
||||||
"amount" : amount,
|
"amount" : amount,
|
||||||
@@ -267,69 +265,12 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$uibModalInst
|
|||||||
$scope.cancel = function () {
|
$scope.cancel = function () {
|
||||||
$uibModalInstance.dismiss('cancel');
|
$uibModalInstance.dismiss('cancel');
|
||||||
};
|
};
|
||||||
} ]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO to be removed
|
|
||||||
transactionControllers.controller('TransactionDetailCtrl', [ '$scope', '$routeParams', '$resource', '$location', function($scope, $routeParams, $resource, $location) {
|
|
||||||
|
|
||||||
$scope.initDetails = function() {
|
|
||||||
console.log('initDetails()');
|
|
||||||
|
|
||||||
var transaction = $resource($routeParams.transactionURI).get();
|
|
||||||
transaction.$promise.then(function(data) {
|
|
||||||
transaction.date = new Date(transaction.date);
|
|
||||||
transaction.category = $resource(transaction._links.category.href).get();
|
|
||||||
transaction.creditor = $resource(transaction._links.creditor.href).get();
|
|
||||||
transaction.account = $resource(transaction._links.account.href).get();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.transaction = transaction;
|
|
||||||
|
|
||||||
// FIXME
|
|
||||||
// TODO The rest of this function is *copied code* from TransactionListCtrl and desperately needs to be moved into a service
|
|
||||||
|
|
||||||
var userinfo = $resource('/user').get();
|
|
||||||
userinfo.$promise.then(function(data) {
|
|
||||||
$scope.userid = userinfo.name;
|
|
||||||
|
|
||||||
userinfo = $resource('/users/search/findByUsername', { username: $scope.userid }).get();
|
|
||||||
userinfo.$promise.then(function(data) {
|
|
||||||
$scope.userinfo = userinfo;
|
|
||||||
});
|
|
||||||
|
|
||||||
var accountInfo = $resource('/accounts/search/findByUserName', { username: $scope.userid }).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.categories.push({id: -1, name: '────────────────', position: 9999, disabled: true});
|
|
||||||
$scope.categories.push({id: -1, name: 'private Entnahme', position: 10000, _links: { self: {href: 'withdrawal'}}});
|
|
||||||
|
|
||||||
// FIXME Code from TransactionListCtrl.refreshList()
|
|
||||||
var accountUsers = $resource($scope.account._links.users.href).get();
|
|
||||||
accountUsers.$promise.then(function(data) {
|
|
||||||
$scope.accountUsers = accountUsers._embedded.users;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// TODO still used?
|
||||||
$scope.deleteTransaction = function(transaction) {
|
$scope.deleteTransaction = function(transaction) {
|
||||||
// TODO auf return code reagieren
|
// TODO auf return code reagieren
|
||||||
$resource(transaction._links.self.href).remove().$promise.then(function() {
|
$resource(transaction._links.self.href).remove().$promise.then(function() {
|
||||||
$location.path('/');
|
$location.path('/');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.initDetails();
|
|
||||||
|
|
||||||
} ]);
|
} ]);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
var transactionServices = angular.module('transactionServices', [ 'ngResource' ]);
|
||||||
|
|
||||||
|
transactionServices.factory('Transaction', [ '$resource', function($resource) {
|
||||||
|
return $resource('/transactions/:id', {}, {
|
||||||
|
/*query : {
|
||||||
|
method : 'GET',
|
||||||
|
params : {
|
||||||
|
phoneId : 'phones'
|
||||||
|
},
|
||||||
|
isArray : true
|
||||||
|
}*/
|
||||||
|
});
|
||||||
|
} ]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
// via Resource (might be moved into a service)
|
||||||
|
var Transaction = $resource('/transactions');
|
||||||
|
|
||||||
|
var newTransaction = new Transaction({
|
||||||
|
"account" : $scope.account._links.self.href,
|
||||||
|
"amount" : amount,
|
||||||
|
"date" : $scope.transaction.date,
|
||||||
|
"description" : $scope.transaction.description,
|
||||||
|
"category" : $scope.transaction.category._links.self.href,
|
||||||
|
"creditor" : $scope.transaction.creditor
|
||||||
|
});
|
||||||
|
|
||||||
|
newTransaction.$save(function(transaction) {
|
||||||
|
$scope.refreshList();
|
||||||
|
$scope.lastSubmission = newTransaction;
|
||||||
|
});
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user