mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2025-01-26 07:58:10 +01:00
piecharts and reworked corresponding APIs
This commit is contained in:
parent
af352d2533
commit
36c6fcaa8b
4 changed files with 23 additions and 19 deletions
19
app.rb
19
app.rb
|
@ -36,19 +36,22 @@ class LedgerRbApp < Sinatra::Base
|
|||
params[ :categories ].map do
|
||||
|category|
|
||||
cat = category.first
|
||||
{ category: cat,
|
||||
data: Ledger.register( cat, "--#{params[ :period ]}" ) }
|
||||
{ key: cat,
|
||||
values: Ledger.register( cat, "--#{params[ :period ]}" ) }
|
||||
end.to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/balance/?' do
|
||||
Ledger.balance.to_json
|
||||
end
|
||||
param :depth, Integer, default: false
|
||||
param :period, String, default: nil
|
||||
param :cleared, Boolean, default: false
|
||||
param :categories, String, default: ''
|
||||
|
||||
get '/api/ledger/balance/depth/:depth/?' do
|
||||
param :depth, Integer, required: true
|
||||
|
||||
Ledger.balance( false, params[ :depth ] ).to_json
|
||||
Ledger.balance( params[ :cleared ],
|
||||
params[ :depth ],
|
||||
params[ :period ],
|
||||
params[ :categories ] )
|
||||
.to_json
|
||||
end
|
||||
|
||||
# get '/api/ledger/cleared/?' do
|
||||
|
|
|
@ -31,8 +31,8 @@ module Ledger
|
|||
.map do |line|
|
||||
line_array = line.split
|
||||
|
||||
{ date: line_array[ 0 ],
|
||||
amount: line_array[ 1 ].to_f }
|
||||
[ Time.new( line_array[ 0 ] ).to_i,
|
||||
line_array[ 1 ].to_f ]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,11 +44,11 @@ module Ledger
|
|||
register category, "--yearly"
|
||||
end
|
||||
|
||||
def balance( cleared=false, depth=nil, period=nil )
|
||||
period = period.nil? ? '' : "-p #{period}"
|
||||
def balance( cleared=false, depth=nil, period=nil, categories='' )
|
||||
period = period.nil? ? '' : "-p '#{period}'"
|
||||
depth = depth.nil? ? '' : "--depth #{depth}"
|
||||
operation = cleared ? 'cleared' : 'balance'
|
||||
run( "--flat --no-total --exchange '#{CURRENCY}' #{period} #{depth}", operation )
|
||||
run( "--flat --no-total --exchange '#{CURRENCY}' #{period} #{depth}", operation, categories )
|
||||
.split( "\n" )
|
||||
.map do |line|
|
||||
line_array = line.split( "#{CURRENCY}" )
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
var app = angular.module( 'app', [ 'ui.router',
|
||||
'legendDirectives' ] );
|
||||
'nvd3ChartDirectives' ] );
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"angular": "latest",
|
||||
"angular-ui-router": "latest",
|
||||
"angular-loader": "latest",
|
||||
"angular-mocks": "latest",
|
||||
"html5-boilerplate": "latest",
|
||||
"angularjs-nvd3-directives": "latest"
|
||||
"angular-ui-router": "latest",
|
||||
"angular-loader": "latest",
|
||||
"angular-mocks": "latest",
|
||||
"html5-boilerplate": "latest",
|
||||
"angularjs-nvd3-directives": "latest",
|
||||
"angular-bootstrap": "latest"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue