birth of the Assets page

This commit is contained in:
Gwenhael Le Moine 2014-11-03 17:33:15 +01:00
parent bed272f8bc
commit ada376412a
8 changed files with 64 additions and 18 deletions

8
app.rb
View file

@ -42,6 +42,14 @@ class LedgerRbApp < Sinatra::Base
.to_json
end
get '/api/ledger/monthly_register/?' do
param :categories, String, required: true
{ key: params[ :categories ],
values: Ledger.monthly_register( params[ :categories ] ) }
.to_json
end
get '/api/ledger/balance/?' do
param :depth, Integer, default: false
param :period, String, default: nil

View file

@ -36,6 +36,18 @@ module Ledger
.uniq
end
def monthly_register( categories = '' )
CSV.parse( run( '--monthly', 'csv', categories ) )
.map do
|row|
{ date: row[ 0 ],
payee: row[ 2 ],
account: row[ 3 ],
amount: row[ 5 ],
currency: row[ 4 ] }
end
end
def register( period = nil, categories = '' )
period = period.nil? ? '' : "-p '#{period}'"
@ -54,6 +66,7 @@ module Ledger
period = period.nil? ? '' : "-p '#{period}'"
depth = depth.nil? ? '' : "--depth #{depth}"
operation = cleared ? 'cleared' : 'balance'
run( "--flat --no-total --exchange '#{CURRENCY}' #{period} #{depth}", operation, categories )
.split( "\n" )
.map do |line|

View file

@ -59,6 +59,7 @@
<script src="/js/controllers/AppCtrl.js"></script>
<script src="/js/controllers/NavbarCtrl.js"></script>
<script src="/js/controllers/BalanceCtrl.js"></script>
<script src="/js/controllers/AssetsCtrl.js"></script>
</body>
</html>

View file

@ -0,0 +1,12 @@
app.controller( 'AssetsCtrl',
[ '$scope', 'API',
function ( $scope, API ) {
API.accounts().then( function( response ) {
$scope.assets = _(response.data).groupBy( 0 ).Assets.map( function( account ) { return account.join( ':' ); } );
API.monthly_register( { categories: 'Assets' } )
.then( function ( response ) {
$scope.monthly_assets = response.data;
} );
} );
} ] );

View file

@ -1,5 +1,5 @@
app.controller( 'NavbarCtrl',
[ '$scope',
function( $scope ) {
$scope.items = [ 'Balance' ];
$scope.items = [ 'Assets', 'Balance' ];
} ] );

View file

@ -3,19 +3,21 @@ app.service( 'API',
function( $http ) {
this.balance = function( params ) {
return $http.get( '/api/ledger/balance', {
params: {
period: params.period,
categories: params.categories
}
params: { period: params.period,
categories: params.categories }
} );
};
this.monthly_register = function( params ) {
return $http.get( '/api/ledger/monthly_register', {
params: { categories: params.categories }
} );
};
this.register = function( params ) {
return $http.get( '/api/ledger/register', {
params: {
period: params.period,
categories: params.categories
}
params: { period: params.period,
categories: params.categories }
} );
};

View file

@ -4,28 +4,33 @@ app.config( [ '$stateProvider', '$urlRouterProvider',
$urlRouterProvider.when( '', '/balance' );
$stateProvider
.state( 'app.balance', {
url: '/balance',
templateUrl: 'js/templates/balance.tpl.html',
controller: 'BalanceCtrl'
} )
.state( 'app', {
url: '',
controller: 'AppCtrl',
views: {
'navbar': {
templateUrl: 'js/templates/navbar.tpl.html',
controller: 'NavbarCtrl'
controller: 'NavbarCtrl',
templateUrl: 'js/templates/navbar.tpl.html'
},
'main': {
templateUrl: 'js/templates/main.tpl.html'
}
}
} )
.state( 'app.balance', {
url: '/balance',
controller: 'BalanceCtrl',
templateUrl: 'js/templates/balance.tpl.html'
} )
.state( 'app.assets', {
url: '/assets',
controller: 'AssetsCtrl',
templateUrl: 'js/templates/assets.tpl.html'
} )
.state( '404', {
url: '/404',
templateUrl: 'js/templates/404.tpl.html',
controller: 'AppCtrl'
controller: 'AppCtrl',
templateUrl: 'js/templates/404.tpl.html'
} );
}

View file

@ -0,0 +1,5 @@
<div layout="vertical" layout-padding>
{{assets}}
<br>
{{monthly_assets}}
</div>