Patch by nic, fixes the incorrect count for next actions in contexts and projects in the sidebar, and also packages up the methods nicely into the models files. Thanks, nic! Fixes #53.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@96 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2005-06-05 09:54:58 +00:00
parent 9f89610fab
commit 78c118181c
6 changed files with 122 additions and 79 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -63,33 +63,42 @@
</div><!-- [end:context-new-action] -->
<h3>Active Contexts:</h3>
<ul>
<% for other_context in Context.find(:all, :conditions => "hide=0", :order => "position ASC") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Hidden Contexts:</h3>
<ul>
<% for other_context in Context.find(:all, :conditions => "hide=1", :order => "position ASC") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Active Projects:</h3>
<ul>
<% for active_project in Project.find(:all, :conditions => "done=0", :order => "position") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Active Projects:</h3>
<ul>
<% for project in Project.list_of -%>
<% count = project.count_undone_todos -%>
<li><%= link_to( project.name, { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Completed Projects:</h3>
<ul>
<% for project in Project.list_of( isdone=1 ) -%>
<% count = project.count_undone_todos -%>
<li><%= link_to( project.name, { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Active Contexts:</h3>
<ul>
<% for context in Context.list_of -%>
<% count = context.count_undone_todos -%>
<li><%= link_to( context.name, { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Hidden Contexts:</h3>
<ul>
<% for context in Context.list_of( hidden=1 ) -%>
<% count = context.count_undone_todos -%>
<li><%= link_to( context.name, { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Completed Projects:</h3>
<ul>
<% for done_project in Project.find(:all, :conditions => "done=1", :order => "position") %>
<li><%= 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)" %></li>
<% end %>
</ul>
</div><!-- End of input box -->
<% if @flash["confirmation"] %><div class="confirmation"><%= @flash["confirmation"] %></div><% end %>

View file

@ -63,34 +63,42 @@
</script>
</div><!-- [end:project-new-action] -->
<h3>Active Projects:</h3>
<ul>
<% for active_project in Project.find(:all, :conditions => "done=0", :order => "position") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Completed Projects:</h3>
<ul>
<% for done_project in Project.find(:all, :conditions => "done=1", :order => "position") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Active Contexts:</h3>
<ul>
<% for other_context in Context.find(:all, :conditions => "hide=0", :order => "position ASC") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Hidden Contexts:</h3>
<ul>
<% for other_context in Context.find(:all, :conditions => "hide=1", :order => "position ASC") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Active Projects:</h3>
<ul>
<% for project in Project.list_of -%>
<% count = project.count_undone_todos -%>
<li><%= link_to( project.name, { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Completed Projects:</h3>
<ul>
<% for project in Project.list_of( isdone=1 ) -%>
<% count = project.count_undone_todos -%>
<li><%= link_to( project.name, { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Active Contexts:</h3>
<ul>
<% for context in Context.list_of -%>
<% count = context.count_undone_todos -%>
<li><%= link_to( context.name, { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Hidden Contexts:</h3>
<ul>
<% for context in Context.list_of( hidden=1 ) -%>
<% count = context.count_undone_todos -%>
<li><%= link_to( context.name, { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
</div><!-- End of input box -->
<% if @flash["confirmation"] %><div class="confirmation"><%= @flash["confirmation"] %></div><% end %>

View file

@ -75,33 +75,41 @@
</div><!-- [end:todo-new-action] -->
<h3>Active Projects:</h3>
<ul>
<% for active_project in Project.find(:all, :conditions => "done=0", :order => "position") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Active Projects:</h3>
<ul>
<% for project in Project.list_of -%>
<% count = project.count_undone_todos -%>
<li><%= link_to( project.name, { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Completed Projects:</h3>
<ul>
<% for done_project in Project.find(:all, :conditions => "done=1", :order => "position") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Completed Projects:</h3>
<ul>
<% for project in Project.list_of( isdone=1 ) -%>
<% count = project.count_undone_todos -%>
<li><%= link_to( project.name, { :controller => "project", :action => "show",
:name => urlize(project.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Active Contexts:</h3>
<ul>
<% for other_context in Context.find(:all, :conditions => "hide=0", :order => "position ASC") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Active Contexts:</h3>
<ul>
<% for context in Context.list_of -%>
<% count = context.count_undone_todos -%>
<li><%= link_to( context.name, { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
<h3>Hidden Contexts:</h3>
<ul>
<% for other_context in Context.find(:all, :conditions => "hide=1", :order => "position ASC") %>
<li><%= 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)" %></li>
<% end %>
</ul>
<h3>Hidden Contexts:</h3>
<ul>
<% for context in Context.list_of( hidden=1 ) -%>
<% count = context.count_undone_todos -%>
<li><%= link_to( context.name, { :controller => "context", :action => "show",
:name => urlize(context.name) } ) + " (" + count.to_s + " actions)" %></li>
<% end -%>
</ul>
</div><!-- End of input box -->