moneyrail 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY ADDED
@@ -0,0 +1,38 @@
1
+ 2009-09-30 Yutaka HARA <yhara(at)kmc.gr.jp>
2
+
3
+ * Released 0.0.3
4
+
5
+ * new: show statistics
6
+
7
+ * new: showing/hiding tables
8
+
9
+ * new: show links to neighbor months
10
+
11
+ * new: show day of week
12
+
13
+ 2009-08-20 Yutaka HARA <yhara(at)kmc.gr.jp>
14
+
15
+ * Released 0.0.2
16
+
17
+ * fix: item deletion raises an error other than firefox
18
+
19
+ 2009-08-19 Yutaka HARA <yhara(at)kmc.gr.jp>
20
+
21
+ * Released 0.0.1
22
+
23
+ * new: delete an item when title and amount are both empty
24
+
25
+ * fix: item deletion raises an error
26
+
27
+ * fix: fails to update cells whose position > 0
28
+
29
+ * new: show logs
30
+
31
+ 2009-08-16 Yutaka HARA <yhara(at)kmc.gr.jp>
32
+
33
+ * Released 0.0.0
34
+
35
+
36
+
37
+
38
+
data/Rakefile CHANGED
@@ -26,7 +26,9 @@ Jeweler::Tasks.new do |gemspec|
26
26
  gemspec.homepage = "http://github.com/yhara/#{PROJECT_NAME}"
27
27
  gemspec.description = gemspec.summary
28
28
  gemspec.authors = ["Yutaka HARA"]
29
- gemspec.add_dependency('rails', '= 2.3.3')
30
- gemspec.add_dependency('ruby-station-runtime', '>= 0.0.2')
29
+ gemspec.add_dependency('rails', '= 2.3.4')
30
+ gemspec.add_dependency('ruby-station-runtime', '>= 0.0.4')
31
+ gemspec.add_dependency('less')
32
+ gemspec.add_dependency('sqlite3-ruby')
31
33
  gemspec.files.concat Dir["vendor/plugins/**/*"]
32
34
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -24,7 +24,7 @@ class HomeController < ApplicationController
24
24
  def append_current_month(months)
25
25
  current = Time.now.to_date.beginning_of_month
26
26
  unless months.include?(current)
27
- months.push current
27
+ months.unshift current
28
28
  end
29
29
  end
30
30
 
@@ -1,12 +1,15 @@
1
1
  class LogsController < ApplicationController
2
2
 
3
3
  def view
4
+ # param
4
5
  @mode = params[:mode]
5
6
  @year, @month = params[:year].to_i, params[:month].to_i
6
7
 
7
- first_day = Date.new(@year, @month)
8
- @month_range = first_day .. ((first_day >> 1) - 1)
8
+ # date
9
+ @current_month = Date.new(@year, @month)
10
+ @month_range = @current_month .. ((@current_month >> 1) - 1)
9
11
 
12
+ # items
10
13
  @accounts = Account.all(:order => "position")
11
14
  @categories = Category.hashed
12
15
  @cat_all = [
@@ -0,0 +1,57 @@
1
+ class StatsController < ApplicationController
2
+ def show
3
+ year = params[:year].to_i
4
+ month = params[:month].to_i
5
+
6
+ @month = Date.new(year, month)
7
+ @month_range = @month .. ((@month >> 1) - 1)
8
+
9
+ @categories = Category.hashed.values_at(:expense, :income).flatten(1)
10
+
11
+ @stat = make_stats
12
+ end
13
+
14
+ private
15
+
16
+ # Expense Income
17
+ # cat1 cat2 cat3 cat4 cat5 cat6
18
+ # acc1 99 99 99 0 0 33
19
+ # acc2 12 34 567 8 9 0
20
+ # ------------------------------------
21
+ # sum
22
+ def make_stats
23
+ items = Item.all(:conditions => {:date => @month_range, :type => ["Expense", "Income"]}).group_by(&:category)
24
+
25
+ accounts = Account.all(:order => "position")
26
+
27
+ rows = accounts.map{|account|
28
+ make_stat_row(account, items)
29
+ }
30
+
31
+ return rows.push make_sum_row(rows)
32
+ end
33
+
34
+ def make_stat_row(account, items)
35
+ row = @categories.map{|category|
36
+ if items[category]
37
+ items[category].
38
+ find_all{|item| item.account == account}.
39
+ map{|item| item.amount}.
40
+ sum
41
+ else
42
+ 0
43
+ end
44
+ }
45
+ row.unshift(account.name)
46
+ end
47
+
48
+ def make_sum_row(rows)
49
+ rows.transpose.map{|cells|
50
+ if cells.first.class == String
51
+ ""
52
+ else
53
+ cells.sum
54
+ end
55
+ }
56
+ end
57
+ end
@@ -1,3 +1,41 @@
1
1
  # Methods added to this helper will be available to all templates in the application.
2
2
  module ApplicationHelper
3
+ def format_date(d)
4
+ d.strftime("%Y-%m-%d (%a)")
5
+ end
6
+
7
+ def format_month(d)
8
+ d.strftime("%Y-%m")
9
+ end
10
+
11
+ # (str, date) or (date)
12
+ def link_to_edit_logs(a, b=nil)
13
+ str, date = str_and_date(a, b)
14
+
15
+ link_to str, edit_logs_path(:year => date.year, :month => date.month)
16
+ end
17
+
18
+ def link_to_show_logs(a, b=nil)
19
+ str, date = str_and_date(a, b)
20
+
21
+ link_to str, show_logs_path(:year => date.year, :month => date.month)
22
+ end
23
+
24
+ def link_to_show_stats(a, b=nil)
25
+ str, date = str_and_date(a, b)
26
+
27
+ link_to str, show_stats_path(:year => date.year, :month => date.month)
28
+ end
29
+
30
+ private
31
+
32
+ def str_and_date(a, b)
33
+ if b
34
+ [a, b]
35
+ else
36
+ [format_month(a), a]
37
+ end
38
+ end
39
+
40
+
3
41
  end
@@ -1,5 +1,13 @@
1
1
  module LogsHelper
2
2
 
3
+ def link_to_edit_or_show(str, month)
4
+ if @mode == :edit
5
+ link_to_edit_logs str, month
6
+ else
7
+ link_to_show_logs str, month
8
+ end
9
+ end
10
+
3
11
  def cell(value)
4
12
  if @mode == :edit
5
13
  "<input type='text' value='#{h value}' />"
@@ -10,6 +10,8 @@
10
10
  show_logs_path(:year => m.year, :month => m.month) %>
11
11
  <%= link_to "(edit)",
12
12
  edit_logs_path(:year => m.year, :month => m.month) %>
13
+ <%= link_to "stats",
14
+ show_stats_path(:year => m.year, :month => m.month) %>
13
15
  </li>
14
16
  <% end %>
15
17
  </ul>
@@ -1,17 +1,27 @@
1
- <h2><%=h @year %>/<%=h @month %></h2>
2
- <% unless @mode == :edit %>
3
- <%= link_to "(edit)", edit_logs_path(:year => @year, :month => @month) %>
1
+ <h2>
2
+ <small><%= link_to_edit_or_show("<<", @current_month << 1) %></small>
3
+ <%= h format_month(@current_month) %>
4
+ <small><%= link_to_edit_or_show(">>", @current_month >> 1) %></small>
5
+ </h2>
6
+ <% if @mode != :edit %>
7
+ <%= link_to_edit_logs "(edit)", @current_month %>
4
8
  <% end %>
5
9
 
6
- <ul>
10
+ <ul id="account_links">
11
+ <li>
12
+ <%= link_to_function "all",
13
+ "MoneyRail.show_all_accounts();" %>
14
+ </li>
7
15
  <% @accounts.each_with_index do |account, i| %>
8
- <li><%= link_to account.name, "#account_#{i}" %></li>
16
+ <li><%= link_to_function account.name,
17
+ "MoneyRail.show_only_account(#{i});" %></li>
9
18
  <% end %>
10
19
  </ul>
20
+ <br class="clear">
11
21
 
12
22
  <% @accounts.each_with_index do |account, i| %>
13
23
  <%# for each account %>
14
- <a name="account_<%=h i%>" />
24
+ <div id="account_<%=h i%>">
15
25
  <h3>
16
26
  <%=h account.name %>
17
27
  <%= link_to '△', move_up_account_path(account) %>
@@ -64,7 +74,7 @@
64
74
  <% case item
65
75
  when Date %>
66
76
  <td>
67
- <%=h item.to_s %>
77
+ <%=h format_date(item) %>
68
78
  </td>
69
79
 
70
80
  <% when :no_date %>
@@ -86,6 +96,7 @@
86
96
  </tr>
87
97
  <% end %>
88
98
  </table>
99
+ </div>
89
100
  <% end %>
90
101
 
91
102
  <% javascript_tag do %>
@@ -105,6 +116,8 @@
105
116
  <%=h @cat_all.map{|c| c.id.to_s}.join(", ") %>
106
117
  ];
107
118
 
119
+ MoneyRail.n_accounts = <%=h @accounts.size %>;
120
+
108
121
  MoneyRail.item_update_path = function(item_id){
109
122
  var str = "<%=h update_item_path(9999) %>.json";
110
123
  return str.replace(/9999/, item_id);
@@ -0,0 +1,22 @@
1
+ <h2>Statictics
2
+ <small><%= link_to_show_stats("<<", @month << 1) %></small>
3
+ <%= format_month(@month) %>
4
+ <small><%= link_to_show_stats(">>", @month >> 1) %></small>
5
+ </h2>
6
+
7
+ <table>
8
+ <tr>
9
+ <th>account</th>
10
+ <% @categories.each do |category| %>
11
+ <th><%=h category.name %></th>
12
+ <% end %>
13
+ </tr>
14
+
15
+ <% @stat.each do |row| %>
16
+ <tr>
17
+ <% row.each do |cell| %>
18
+ <td><%=h cell%></td>
19
+ <% end %>
20
+ </tr>
21
+ <% end %>
22
+ </table>
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file
2
2
 
3
3
  # Specifies gem version of Rails to use when vendor/rails is not present
4
- RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION
4
+ RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
5
5
 
6
6
  # Bootstrap the Rails environment, frameworks, and default configuration
7
7
  require File.join(File.dirname(__FILE__), 'boot')
@@ -38,4 +38,5 @@ Rails::Initializer.run do |config|
38
38
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
39
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40
40
  # config.i18n.default_locale = :de
41
- end
41
+
42
+ end
data/config/routes.rb CHANGED
@@ -34,6 +34,10 @@ ActionController::Routing::Routes.draw do |map|
34
34
  map.edit_logs 'logs/:year/:month/edit',
35
35
  :controller => :logs, :action => 'view', :mode => :edit
36
36
 
37
+ # -- statistics
38
+ map.show_stats 'stats/:year/:month',
39
+ :controller => :stats, :action => 'show'
40
+
37
41
  # The priority is based upon order of creation: first created -> highest priority.
38
42
 
39
43
  # Sample of regular route:
data/db/seeds.rb ADDED
@@ -0,0 +1,10 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Major.create(:name => 'Daley', :city => cities.first)
8
+ Account.create(:name => "wallet")
9
+ Category.create(:name => "Sarary", :kind => "Income")
10
+ Category.create(:name => "Foods", :kind => "Expense")
data/main.rb CHANGED
@@ -2,4 +2,16 @@
2
2
  require 'optparse'
3
3
  require 'ruby-station'; RubyStation.parse_argv
4
4
 
5
- RubyStation::Helper::Rails.run
5
+ # setup database
6
+ unless File.exist?(RubyStation.data_path("production.sqlite3"))
7
+ yml_path = File.join(File.dirname(__FILE__), "config/database.yml")
8
+ conf = YAML.load_file(yml_path)
9
+ conf["production"]["database"] = RubyStation.data_path("production.sqlite3")
10
+ File.open(yml_path, "w"){|f| YAML.dump(conf, f) }
11
+
12
+ system "rake db:migrate db:seed RAILS_ENV=production"
13
+ end
14
+
15
+ ARGV.push "--port=#{RubyStation.port}"
16
+ ARGV.push "--environment=production"
17
+ load File.join(File.dirname(__FILE__), 'script/server')
data/moneyrail.gemspec CHANGED
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{moneyrail}
5
- s.version = "0.0.2"
8
+ s.version = "0.1.0"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Yutaka HARA"]
9
- s.date = %q{2009-08-20}
12
+ s.date = %q{2009-11-03}
10
13
  s.description = %q{Household account book, written in Rails}
11
14
  s.email = %q{yutaka.hara/at/gmail.com}
12
15
  s.extra_rdoc_files = [
@@ -15,7 +18,7 @@ Gem::Specification.new do |s|
15
18
  s.files = [
16
19
  ".gitignore",
17
20
  ".gitmodules",
18
- "Changelog",
21
+ "HISTORY",
19
22
  "README",
20
23
  "Rakefile",
21
24
  "VERSION",
@@ -25,6 +28,7 @@ Gem::Specification.new do |s|
25
28
  "app/controllers/home_controller.rb",
26
29
  "app/controllers/items_controller.rb",
27
30
  "app/controllers/logs_controller.rb",
31
+ "app/controllers/stats_controller.rb",
28
32
  "app/helpers/accounts_helper.rb",
29
33
  "app/helpers/application_helper.rb",
30
34
  "app/helpers/categories_helper.rb",
@@ -53,6 +57,7 @@ Gem::Specification.new do |s|
53
57
  "app/views/items/show.html.erb",
54
58
  "app/views/layouts/application.html.erb",
55
59
  "app/views/logs/view.html.erb",
60
+ "app/views/stats/show.html.erb",
56
61
  "config/boot.rb",
57
62
  "config/database.yml",
58
63
  "config/environment.rb",
@@ -71,6 +76,7 @@ Gem::Specification.new do |s|
71
76
  "db/migrate/20090802073601_create_categories.rb",
72
77
  "db/migrate/20090804065900_create_items.rb",
73
78
  "db/production.sqlite3",
79
+ "db/seeds.rb",
74
80
  "doc/README_FOR_APP",
75
81
  "features/step_definitions/webrat_steps.rb",
76
82
  "features/support/env.rb",
@@ -157,14 +163,20 @@ Gem::Specification.new do |s|
157
163
  s.specification_version = 3
158
164
 
159
165
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
160
- s.add_runtime_dependency(%q<rails>, ["= 2.3.3"])
161
- s.add_runtime_dependency(%q<ruby-station-runtime>, [">= 0.0.2"])
166
+ s.add_runtime_dependency(%q<rails>, ["= 2.3.4"])
167
+ s.add_runtime_dependency(%q<ruby-station-runtime>, [">= 0.0.4"])
168
+ s.add_runtime_dependency(%q<less>, [">= 0"])
169
+ s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 0"])
162
170
  else
163
- s.add_dependency(%q<rails>, ["= 2.3.3"])
164
- s.add_dependency(%q<ruby-station-runtime>, [">= 0.0.2"])
171
+ s.add_dependency(%q<rails>, ["= 2.3.4"])
172
+ s.add_dependency(%q<ruby-station-runtime>, [">= 0.0.4"])
173
+ s.add_dependency(%q<less>, [">= 0"])
174
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
165
175
  end
166
176
  else
167
- s.add_dependency(%q<rails>, ["= 2.3.3"])
168
- s.add_dependency(%q<ruby-station-runtime>, [">= 0.0.2"])
177
+ s.add_dependency(%q<rails>, ["= 2.3.4"])
178
+ s.add_dependency(%q<ruby-station-runtime>, [">= 0.0.4"])
179
+ s.add_dependency(%q<less>, [">= 0"])
180
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
169
181
  end
170
182
  end
@@ -172,6 +172,20 @@ MoneyRail.on_row_button_clicked = function(e){
172
172
  MoneyRail.insert_row(e.target);
173
173
  };
174
174
 
175
+ MoneyRail.show_all_accounts = function(){
176
+ MoneyRail.n_accounts.times(function(i){
177
+ $j("#account_"+i).show();
178
+ });
179
+ };
180
+
181
+ MoneyRail.show_only_account = function(k){
182
+ MoneyRail.n_accounts.times(function(i){
183
+ $j("#account_"+i)[i==k ? 'show' : 'hide']();
184
+ });
185
+ };
186
+
187
+ // main
188
+
175
189
  MoneyRail.register_events = function(){
176
190
  // register input updated
177
191
  $j.each($j("input"), function(input){
@@ -1,5 +1,18 @@
1
1
  @cell_width: 70px;
2
2
 
3
+ br.clear{
4
+ clear: both;
5
+ }
6
+
7
+ ul#account_links{
8
+ list-style: none;
9
+
10
+ li{
11
+ float: left;
12
+ margin-right: 1em;
13
+ }
14
+ }
15
+
3
16
  table.editor {
4
17
  border-collapse: collapse;
5
18
 
@@ -19,8 +32,7 @@ table.editor {
19
32
  }
20
33
 
21
34
  th.date {
22
- min-width: @cell_width;
23
- width: @cell_width;
35
+ min-width: @cell_width * 2;
24
36
  }
25
37
 
26
38
  th.category {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneyrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka HARA
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-20 00:00:00 +09:00
12
+ date: 2009-11-03 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.3.3
23
+ version: 2.3.4
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-station-runtime
@@ -30,7 +30,27 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.2
33
+ version: 0.0.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: less
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: sqlite3-ruby
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
34
54
  version:
35
55
  description: Household account book, written in Rails
36
56
  email: yutaka.hara/at/gmail.com
@@ -43,7 +63,7 @@ extra_rdoc_files:
43
63
  files:
44
64
  - .gitignore
45
65
  - .gitmodules
46
- - Changelog
66
+ - HISTORY
47
67
  - README
48
68
  - Rakefile
49
69
  - VERSION
@@ -53,6 +73,7 @@ files:
53
73
  - app/controllers/home_controller.rb
54
74
  - app/controllers/items_controller.rb
55
75
  - app/controllers/logs_controller.rb
76
+ - app/controllers/stats_controller.rb
56
77
  - app/helpers/accounts_helper.rb
57
78
  - app/helpers/application_helper.rb
58
79
  - app/helpers/categories_helper.rb
@@ -81,6 +102,7 @@ files:
81
102
  - app/views/items/show.html.erb
82
103
  - app/views/layouts/application.html.erb
83
104
  - app/views/logs/view.html.erb
105
+ - app/views/stats/show.html.erb
84
106
  - config/boot.rb
85
107
  - config/database.yml
86
108
  - config/environment.rb
@@ -99,6 +121,7 @@ files:
99
121
  - db/migrate/20090802073601_create_categories.rb
100
122
  - db/migrate/20090804065900_create_items.rb
101
123
  - db/production.sqlite3
124
+ - db/seeds.rb
102
125
  - doc/README_FOR_APP
103
126
  - features/step_definitions/webrat_steps.rb
104
127
  - features/support/env.rb
data/Changelog DELETED
@@ -1,21 +0,0 @@
1
- 2009-08-19 Yutaka HARA <yhara(at)kmc.gr.jp>
2
-
3
- * Released 0.0.1
4
-
5
- * new: delete an item when title and amount are both empty
6
-
7
- * fix: item deletion raises an error
8
-
9
- * fix: fails to update cells whose position > 0
10
-
11
- 2009-08-17 Yutaka HARA <yhara(at)kmc.gr.jp>
12
-
13
- * new: show logs
14
-
15
- 2009-08-16 Yutaka HARA <yhara(at)kmc.gr.jp>
16
-
17
- * Released 0.0.0
18
-
19
-
20
-
21
-