Modified display of undone next actions to return the correct case for "actions" depending on whether there are none, many or one. Fixes #69.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@108 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2005-06-12 17:30:19 +00:00
parent dd255218b9
commit f5053d60c2
7 changed files with 44 additions and 30 deletions

View file

@ -13,8 +13,19 @@ class Context < ActiveRecord::Base
find(:all, :conditions => [ "hide = ?" , hidden ], :order => "position ASC")
end
def count_undone_todos
Todo.count( "context_id=#{self.id} AND done=0" )
# Returns a count of next actions in the given context
# The result is count and a string descriptor, correctly pluralised if there are no
# actions or multiple actions
#
def count_undone_todos(string="actions")
count = Todo.count( "context_id=#{self.id} AND done=0" )
if count == 1
word = string.singularize
else
word = string.pluralize
end
return count.to_s + " " + word
end
end

View file

@ -13,8 +13,19 @@ class Project < ActiveRecord::Base
find(:all, :conditions => [ "done = ?" , isdone ], :order => "position ASC")
end
def count_undone_todos
Todo.count( "project_id=#{self.id} AND done=0" )
# Returns a count of next actions in the given project
# The result is count and a string descriptor, correctly pluralised if there are no
# actions or multiple actions
#
def count_undone_todos(string="actions")
count = Todo.count( "project_id=#{self.id} AND done=0" )
if count == 1
word = string.singularize
else
word = string.pluralize
end
return count.to_s + " " + word
end
end

View file

@ -18,7 +18,8 @@
{:action => "move_bottom", :id => context.id}, :title => "Move to bottom", :class=>"to_bottom") %>
</div>
<div class="data">
<%= link_to( "#{context.name}", :action => "show", :name => urlize(context.name) ) %><%= " (" + Todo.count( "context_id=#{context.id} AND done=0" ).to_s + " actions)" %>
<%= link_to( "#{context.name}", :action => "show", :name => urlize(context.name) ) %>
<%= " (" + context.count_undone_todos("actions") + ")" %>
</div>
<div class="buttons">

View file

@ -66,36 +66,32 @@
<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>
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("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>
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("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>
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("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>
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("actions") + ")" %></li>
<% end -%>
</ul>

View file

@ -18,7 +18,7 @@
{:action => "move_bottom", :id => project.id}, :title => "Move to bottom", :class=>"to_bottom") %>
</div>
<div class="data">
<%= link_to( "#{project.name}", :action => "show", :name => urlize(project.name) ) %><%= " (" + Todo.count( "project_id=#{project.id} AND done=0" ).to_s + " actions)" %>
<%= link_to( "#{project.name}", :action => "show", :name => urlize(project.name) ) %><%= " (" + project.count_undone_todos("actions") + ")" %>
</div>
<div class="buttons">
<% if project.done == 1 -%>

View file

@ -6,6 +6,9 @@
<div id="next_actions">
<% if @project.done == 1 -%>
<p class="info">This project has been completed</p>
<% for item in @not_done -%>
<%= render_partial "show_items", item %>
<% end -%>
<% elsif @not_done.empty? -%>
<p>There are no next actions yet in this project</p>
<% else -%>
@ -67,36 +70,32 @@
<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>
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("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>
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("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>
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("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>
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("actions") + ")" %></li>
<% end -%>
</ul>
</div><!-- End of input box -->

View file

@ -84,36 +84,32 @@
<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>
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("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>
:name => urlize(project.name) } ) + " (" + project.count_undone_todos("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>
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("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>
:name => urlize(context.name) } ) + " (" + context.count_undone_todos("actions") + ")" %></li>
<% end -%>
</ul>
</div><!-- End of input box -->