diff --git a/app.rb b/app.rb index 98f9f709..0e3a1f8c 100644 --- a/app.rb +++ b/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 diff --git a/lib/ledger.rb b/lib/ledger.rb index 5c8428b9..28982ba0 100644 --- a/lib/ledger.rb +++ b/lib/ledger.rb @@ -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}" ) diff --git a/public/app/js/app.js b/public/app/js/app.js index 9898f657..30a1627f 100644 --- a/public/app/js/app.js +++ b/public/app/js/app.js @@ -1,2 +1,2 @@ var app = angular.module( 'app', [ 'ui.router', - 'legendDirectives' ] ); + 'nvd3ChartDirectives' ] ); diff --git a/public/bower.json b/public/bower.json index 6d420684..99f24e50 100644 --- a/public/bower.json +++ b/public/bower.json @@ -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" } }