diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index 88aef29d..9fb16a6f 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -67,14 +67,8 @@ class ApplicationController < ActionController::Base # The result is count and a string descriptor, correctly pluralised if there are no # actions or multiple actions # - def count_undone_todos(todos_parent, string="actions") - if (todos_parent.is_a?(Project) && todos_parent.hidden?) - count = eval "@project_project_hidden_todo_counts[#{todos_parent.id}]" - else - count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]" - end - count = 0 if count == nil - #count = todos_parent.todos.select{|t| !t.done }.size + def count_undone_todos_phrase(todos_parent, string="actions") + count = count_undone_todos(todos_parent) if count == 1 word = string.singularize else @@ -82,6 +76,16 @@ class ApplicationController < ActionController::Base end return count.to_s + " " + word end + + def count_undone_todos(todos_parent) + if (todos_parent.is_a?(Project) && todos_parent.hidden?) + count = eval "@project_project_hidden_todo_counts[#{todos_parent.id}]" + else + count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]" + end + count = 0 if count == nil + count + end protected diff --git a/tracks/app/controllers/contexts_controller.rb b/tracks/app/controllers/contexts_controller.rb index 9f5dd721..d50da8c7 100644 --- a/tracks/app/controllers/contexts_controller.rb +++ b/tracks/app/controllers/contexts_controller.rb @@ -11,26 +11,14 @@ class ContextsController < ApplicationController def index respond_to do |format| - format.html do - @page_title = "TRACKS::List Contexts" - render - end - format.xml { render :xml => @contexts.to_xml( :except => :user_id ) } - format.rss do - render_rss_feed_for @contexts, :feed => Context.feed_options(@user), - :item => { :description => lambda { |c| c.summary(count_undone_todos(c)) } } - end - format.atom do - render_atom_feed_for @contexts, :feed => Context.feed_options(@user), - :item => { :description => lambda { |c| c.summary(count_undone_todos(c)) }, - :author => lambda { |c| nil } } - end - format.text do - render :action => 'index_text', :layout => false, :content_type => Mime::TEXT - end + format.html { @page_title = "TRACKS::List Contexts"; render } + format.xml { render :xml => @contexts.to_xml( :except => :user_id ) } + format.rss &render_contexts_rss_feed + format.atom &render_contexts_atom_feed + format.text { render :action => 'index_text', :layout => false, :content_type => Mime::TEXT } end end - + def show @page_title = "TRACKS::Context: #{@context.name}" end @@ -112,6 +100,21 @@ class ContextsController < ApplicationController protected + def render_contexts_rss_feed + lambda do + render_rss_feed_for @contexts, :feed => Context.feed_options(@user), + :item => { :description => lambda { |c| c.summary(count_undone_todos_phrase(c)) } } + end + end + + def render_contexts_atom_feed + lambda do + render_atom_feed_for @contexts, :feed => Context.feed_options(@user), + :item => { :description => lambda { |c| c.summary(count_undone_todos_phrase(c)) }, + :author => lambda { |c| nil } } + end + end + def check_user_set_context if params['url_friendly_name'] @context = @user.contexts.find_by_url_friendly_name(params['url_friendly_name']) diff --git a/tracks/app/controllers/projects_controller.rb b/tracks/app/controllers/projects_controller.rb index 43c3ef60..91a73dbf 100644 --- a/tracks/app/controllers/projects_controller.rb +++ b/tracks/app/controllers/projects_controller.rb @@ -8,25 +8,15 @@ class ProjectsController < ApplicationController session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) } def index + if params[:only_active_with_no_next_actions] + @projects = @projects.select { |p| p.active? && count_undone_todos(p) == 0 } + end respond_to do |format| - format.html do - init_project_hidden_todo_counts - @page_title = "TRACKS::List Projects" - render - end - format.xml { render :xml => @projects.to_xml( :except => :user_id ) } - format.rss do - render_rss_feed_for @projects, :feed => Project.feed_options(@user), - :item => { :description => lambda { |p| p.summary(count_undone_todos(p)) } } - end - format.atom do - render_atom_feed_for @projects, :feed => Project.feed_options(@user), - :item => { :description => lambda { |p| p.summary(count_undone_todos(p)) }, - :author => lambda { |p| nil } } - end - format.text do - render :action => 'index_text', :layout => false, :content_type => Mime::TEXT - end + format.html &render_projects_html + format.xml { render :xml => @projects.to_xml( :except => :user_id ) } + format.rss &render_projects_rss_feed + format.atom &render_projects_atom_feed + format.text { render :action => 'index_text', :layout => false, :content_type => Mime::TEXT } end end @@ -124,6 +114,29 @@ class ProjectsController < ApplicationController protected + def render_projects_html + lambda do + init_project_hidden_todo_counts + @page_title = "TRACKS::List Projects" + render + end + end + + def render_projects_rss_feed + lambda do + render_rss_feed_for @projects, :feed => Project.feed_options(@user), + :item => { :description => lambda { |p| p.summary(count_undone_todos_phrase(p)) } } + end + end + + def render_projects_atom_feed + lambda do + render_atom_feed_for @projects, :feed => Project.feed_options(@user), + :item => { :description => lambda { |p| p.summary(count_undone_todos_phrase(p)) }, + :author => lambda { |p| nil } } + end + end + def check_user_set_project if params["url_friendly_name"] @project = @user.projects.find_by_url_friendly_name(params["url_friendly_name"]) diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index aefd9d1b..44af293b 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -112,12 +112,12 @@ module ApplicationHelper # The result is count and a string descriptor, correctly pluralised if there are no # actions or multiple actions # - def count_undone_todos(todos_parent, string="actions") - @controller.count_undone_todos(todos_parent, string) + def count_undone_todos_phrase(todos_parent, string="actions") + @controller.count_undone_todos_phrase(todos_parent, string) end - def count_undone_todos_text(todos_parent, string="actions") - count_undone_todos(todos_parent, string).gsub(" "," ") + def count_undone_todos_phrase_text(todos_parent, string="actions") + count_undone_todos_phrase(todos_parent, string).gsub(" "," ") end def link_to_context(context, descriptor = sanitize(context.name)) diff --git a/tracks/app/views/contexts/_context_listing.rhtml b/tracks/app/views/contexts/_context_listing.rhtml index 099d034c..c824d14e 100644 --- a/tracks/app/views/contexts/_context_listing.rhtml +++ b/tracks/app/views/contexts/_context_listing.rhtml @@ -5,7 +5,7 @@ DRAG