From f5053d60c2afb6fd68cbaf7945c84c6cfdc54e97 Mon Sep 17 00:00:00 2001 From: bsag Date: Sun, 12 Jun 2005 17:30:19 +0000 Subject: [PATCH] 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 --- tracks/app/models/context.rb | 15 +++++++++++++-- tracks/app/models/project.rb | 15 +++++++++++++-- tracks/app/views/context/_context_listing.rhtml | 3 ++- tracks/app/views/context/show.rhtml | 12 ++++-------- tracks/app/views/project/_project_listing.rhtml | 2 +- tracks/app/views/project/show.rhtml | 15 +++++++-------- tracks/app/views/todo/list.rhtml | 12 ++++-------- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb index 8cc0f684..3fab268e 100644 --- a/tracks/app/models/context.rb +++ b/tracks/app/models/context.rb @@ -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 diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 13cce765..5b68d4ff 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -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 diff --git a/tracks/app/views/context/_context_listing.rhtml b/tracks/app/views/context/_context_listing.rhtml index 5ae72b75..623a6821 100644 --- a/tracks/app/views/context/_context_listing.rhtml +++ b/tracks/app/views/context/_context_listing.rhtml @@ -18,7 +18,8 @@ {:action => "move_bottom", :id => context.id}, :title => "Move to bottom", :class=>"to_bottom") %>
- <%= 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") + ")" %>
diff --git a/tracks/app/views/context/show.rhtml b/tracks/app/views/context/show.rhtml index 5f611c65..21a166e6 100644 --- a/tracks/app/views/context/show.rhtml +++ b/tracks/app/views/context/show.rhtml @@ -66,36 +66,32 @@

Active Projects:

Completed Projects:

Active Contexts:

Hidden Contexts:

diff --git a/tracks/app/views/project/_project_listing.rhtml b/tracks/app/views/project/_project_listing.rhtml index fe8f748e..6f2d0ef7 100644 --- a/tracks/app/views/project/_project_listing.rhtml +++ b/tracks/app/views/project/_project_listing.rhtml @@ -18,7 +18,7 @@ {:action => "move_bottom", :id => project.id}, :title => "Move to bottom", :class=>"to_bottom") %>
- <%= 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") + ")" %>
<% if project.done == 1 -%> diff --git a/tracks/app/views/project/show.rhtml b/tracks/app/views/project/show.rhtml index 0ec712c1..dbfbc0df 100644 --- a/tracks/app/views/project/show.rhtml +++ b/tracks/app/views/project/show.rhtml @@ -6,6 +6,9 @@
<% if @project.done == 1 -%>

This project has been completed

+ <% for item in @not_done -%> + <%= render_partial "show_items", item %> + <% end -%> <% elsif @not_done.empty? -%>

There are no next actions yet in this project

<% else -%> @@ -67,36 +70,32 @@

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)" %>
  • + :name => urlize(project.name) } ) + " (" + project.count_undone_todos("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)" %>
  • + :name => urlize(project.name) } ) + " (" + project.count_undone_todos("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)" %>
  • + :name => urlize(context.name) } ) + " (" + context.count_undone_todos("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)" %>
  • + :name => urlize(context.name) } ) + " (" + context.count_undone_todos("actions") + ")" %> <% end -%>
diff --git a/tracks/app/views/todo/list.rhtml b/tracks/app/views/todo/list.rhtml index 35a4ad1e..610e82ac 100644 --- a/tracks/app/views/todo/list.rhtml +++ b/tracks/app/views/todo/list.rhtml @@ -84,36 +84,32 @@

Active Projects:

Completed Projects:

Active Contexts:

Hidden Contexts: