diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb
index 1c0abccd..8cc0f684 100644
--- a/tracks/app/models/context.rb
+++ b/tracks/app/models/context.rb
@@ -8,4 +8,13 @@ class Context < ActiveRecord::Base
validates_presence_of :name, :message => "context must have a name"
validates_length_of :name, :maximum => 255, :message => "context name must be less than %d"
validates_uniqueness_of :name, :message => "already exists"
+
+ def self.list_of(hidden=0)
+ find(:all, :conditions => [ "hide = ?" , hidden ], :order => "position ASC")
+ end
+
+ def count_undone_todos
+ Todo.count( "context_id=#{self.id} AND done=0" )
+ end
+
end
diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb
index da486009..13cce765 100644
--- a/tracks/app/models/project.rb
+++ b/tracks/app/models/project.rb
@@ -8,5 +8,13 @@ class Project < ActiveRecord::Base
validates_presence_of :name, :message => "project must have a name"
validates_length_of :name, :maximum => 255, :message => "project name must be less than %d"
validates_uniqueness_of :name, :message => "already exists"
-
+
+ def self.list_of(isdone=0)
+ find(:all, :conditions => [ "done = ?" , isdone ], :order => "position ASC")
+ end
+
+ def count_undone_todos
+ Todo.count( "project_id=#{self.id} AND done=0" )
+ end
+
end
diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb
index df160c8d..d7317c04 100644
--- a/tracks/app/models/user.rb
+++ b/tracks/app/models/user.rb
@@ -24,7 +24,8 @@ class User < ActiveRecord::Base
write_attribute("word", self.class.sha1(word))
end
- validates_length_of :password, :login, :within => 5..40
+ validates_length_of :password, :within => 5..40
+ validates_length_of :login, :within => 3..80
validates_presence_of :password, :login, :word
validates_uniqueness_of :login, :on => :create
validates_uniqueness_of :word, :on => :create
diff --git a/tracks/app/views/context/show.rhtml b/tracks/app/views/context/show.rhtml
index 3efc108b..f2b401ca 100644
--- a/tracks/app/views/context/show.rhtml
+++ b/tracks/app/views/context/show.rhtml
@@ -63,33 +63,42 @@
-
Active Contexts:
-
- <% for other_context in Context.find(:all, :conditions => "hide=0", :order => "position ASC") %>
- - <%= link_to( other_context.name, { :controller => "context", :action => "show", :name => urlize(other_context.name) } ) + " (" + Todo.count( "project_id=#{other_context.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
-
- Hidden Contexts:
-
- <% for other_context in Context.find(:all, :conditions => "hide=1", :order => "position ASC") %>
- - <%= link_to( other_context.name, { :controller => "context", :action => "show", :name => urlize(other_context.name) } ) + " (" + Todo.count( "project_id=#{other_context.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
-
- Active Projects:
-
- <% for active_project in Project.find(:all, :conditions => "done=0", :order => "position") %>
- - <%= link_to( active_project.name, { :controller => "project", :action => "show", :name => urlize(active_project.name) } ) + " (" + Todo.count( "project_id=#{active_project.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
+Active Projects:
+
+ <% for project in Project.list_of -%>
+ <% count = project.count_undone_todos -%>
+ - <%= link_to( project.name, { :controller => "project", :action => "show",
+ :name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
+
+Completed Projects:
+
+ <% for project in Project.list_of( isdone=1 ) -%>
+ <% count = project.count_undone_todos -%>
+ - <%= link_to( project.name, { :controller => "project", :action => "show",
+ :name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
+
+Active Contexts:
+
+ <% for context in Context.list_of -%>
+ <% count = context.count_undone_todos -%>
+ - <%= link_to( context.name, { :controller => "context", :action => "show",
+ :name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
+
+Hidden Contexts:
+
+ <% for context in Context.list_of( hidden=1 ) -%>
+ <% count = context.count_undone_todos -%>
+ - <%= link_to( context.name, { :controller => "context", :action => "show",
+ :name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
- Completed Projects:
-
- <% for done_project in Project.find(:all, :conditions => "done=1", :order => "position") %>
- - <%= link_to( done_project.name, { :controller => "project", :action => "show", :name => urlize(done_project.name) } ) + " (" + Todo.count( "project_id=#{active_project.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
<% if @flash["confirmation"] %><%= @flash["confirmation"] %>
<% end %>
diff --git a/tracks/app/views/project/show.rhtml b/tracks/app/views/project/show.rhtml
index d91bcc56..f8433aaa 100644
--- a/tracks/app/views/project/show.rhtml
+++ b/tracks/app/views/project/show.rhtml
@@ -63,34 +63,42 @@
-
- Active Projects:
-
- <% for active_project in Project.find(:all, :conditions => "done=0", :order => "position") %>
- - <%= link_to( active_project.name, { :controller => "project", :action => "show", :name => urlize(active_project.name) } ) + " (" + Todo.count( "project_id=#{active_project.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
-
- Completed Projects:
-
- <% for done_project in Project.find(:all, :conditions => "done=1", :order => "position") %>
- - <%= link_to( done_project.name, { :controller => "project", :action => "show", :name => urlize(done_project.name) } ) + " (" + Todo.count( "project_id=#{active_project.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
-
- Active Contexts:
-
- <% for other_context in Context.find(:all, :conditions => "hide=0", :order => "position ASC") %>
- - <%= link_to( other_context.name, { :controller => "context", :action => "show", :name => urlize(other_context.name) } ) + " (" + Todo.count( "project_id=#{other_context.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
- Hidden Contexts:
-
- <% for other_context in Context.find(:all, :conditions => "hide=1", :order => "position ASC") %>
- - <%= link_to( other_context.name, { :controller => "context", :action => "show", :name => urlize(other_context.name) } ) + " (" + Todo.count( "project_id=#{other_context.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
+Active Projects:
+
+ <% for project in Project.list_of -%>
+ <% count = project.count_undone_todos -%>
+ - <%= link_to( project.name, { :controller => "project", :action => "show",
+ :name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
+
+Completed Projects:
+
+ <% for project in Project.list_of( isdone=1 ) -%>
+ <% count = project.count_undone_todos -%>
+ - <%= link_to( project.name, { :controller => "project", :action => "show",
+ :name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
+
+Active Contexts:
+
+ <% for context in Context.list_of -%>
+ <% count = context.count_undone_todos -%>
+ - <%= link_to( context.name, { :controller => "context", :action => "show",
+ :name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
+
+Hidden Contexts:
+
+ <% for context in Context.list_of( hidden=1 ) -%>
+ <% count = context.count_undone_todos -%>
+ - <%= link_to( context.name, { :controller => "context", :action => "show",
+ :name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
<% if @flash["confirmation"] %><%= @flash["confirmation"] %>
<% end %>
diff --git a/tracks/app/views/todo/list.rhtml b/tracks/app/views/todo/list.rhtml
index c6a44ca8..cafcb3bd 100644
--- a/tracks/app/views/todo/list.rhtml
+++ b/tracks/app/views/todo/list.rhtml
@@ -75,33 +75,41 @@
- Active Projects:
-
- <% for active_project in Project.find(:all, :conditions => "done=0", :order => "position") %>
- - <%= link_to( active_project.name, { :controller => "project", :action => "show", :name => urlize(active_project.name) } ) + " (" + Todo.count( "project_id=#{active_project.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
+Active Projects:
+
+ <% for project in Project.list_of -%>
+ <% count = project.count_undone_todos -%>
+ - <%= link_to( project.name, { :controller => "project", :action => "show",
+ :name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
- Completed Projects:
-
- <% for done_project in Project.find(:all, :conditions => "done=1", :order => "position") %>
- - <%= link_to( done_project.name, { :controller => "project", :action => "show", :name => urlize(done_project.name) } ) + " (" + Todo.count( "project_id=#{active_project.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
+Completed Projects:
+
+ <% for project in Project.list_of( isdone=1 ) -%>
+ <% count = project.count_undone_todos -%>
+ - <%= link_to( project.name, { :controller => "project", :action => "show",
+ :name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
- Active Contexts:
-
- <% for other_context in Context.find(:all, :conditions => "hide=0", :order => "position ASC") %>
- - <%= link_to( other_context.name, { :controller => "context", :action => "show", :name => urlize(other_context.name) } ) + " (" + Todo.count( "context_id=#{other_context.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
+Active Contexts:
+
+ <% for context in Context.list_of -%>
+ <% count = context.count_undone_todos -%>
+ - <%= link_to( context.name, { :controller => "context", :action => "show",
+ :name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+
- Hidden Contexts:
-
- <% for other_context in Context.find(:all, :conditions => "hide=1", :order => "position ASC") %>
- - <%= link_to( other_context.name, { :controller => "context", :action => "show", :name => urlize(other_context.name) } ) + " (" + Todo.count( "context_id=#{other_context.id} AND done=0" ).to_s + " actions)" %>
- <% end %>
-
+Hidden Contexts:
+
+ <% for context in Context.list_of( hidden=1 ) -%>
+ <% count = context.count_undone_todos -%>
+ - <%= link_to( context.name, { :controller => "context", :action => "show",
+ :name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %>
+ <% end -%>
+