From 9e3f686f84911788a019818c9194d4516b36307e Mon Sep 17 00:00:00 2001 From: lukemelia Date: Thu, 22 Feb 2007 05:15:52 +0000 Subject: [PATCH] Added feed for active projects with no next actions. Closes #423. Refactored ProjectsController#index and ContextsController#index to simplify them. Tweak the taggings fixtures to fix broken tests. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@451 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/application.rb | 20 +++++--- tracks/app/controllers/contexts_controller.rb | 39 ++++++++------- tracks/app/controllers/projects_controller.rb | 49 ++++++++++++------- tracks/app/helpers/application_helper.rb | 8 +-- .../app/views/contexts/_context_listing.rhtml | 2 +- tracks/app/views/contexts/index_text.rhtml | 2 +- tracks/app/views/feedlist/index.rhtml | 5 ++ .../app/views/projects/_project_listing.rhtml | 2 +- tracks/app/views/projects/index_text.rhtml | 2 +- tracks/app/views/sidebar/_context.rhtml | 2 +- tracks/app/views/sidebar/_project.rhtml | 2 +- tracks/test/fixtures/taggings.yml | 4 +- .../functional/projects_controller_test.rb | 10 ++++ .../test/functional/todos_controller_test.rb | 2 +- tracks/test/selenium/tags/find_tagged.rsel | 2 +- 15 files changed, 93 insertions(+), 58 deletions(-) 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
- <%= link_to_context( context ) %> <%= " (" + count_undone_todos(context,"actions") + ")" %> + <%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %>
diff --git a/tracks/app/views/contexts/index_text.rhtml b/tracks/app/views/contexts/index_text.rhtml index 2b875773..b976258a 100644 --- a/tracks/app/views/contexts/index_text.rhtml +++ b/tracks/app/views/contexts/index_text.rhtml @@ -1,5 +1,5 @@ <% @contexts.each do |c| -%> <%= c.name.upcase %> -<%= count_undone_todos_text(c)%>. Context is <%= c.hidden? ? "Hidden" : "Active" %>. +<%= count_undone_todos_phrase_text(c)%>. Context is <%= c.hidden? ? "Hidden" : "Active" %>. <% end -%> \ No newline at end of file diff --git a/tracks/app/views/feedlist/index.rhtml b/tracks/app/views/feedlist/index.rhtml index 7954bbf1..8168477e 100644 --- a/tracks/app/views/feedlist/index.rhtml +++ b/tracks/app/views/feedlist/index.rhtml @@ -49,6 +49,11 @@ <%= text_formatted_link({:controller => 'projects', :action => 'index'}) %> All Projects +
  • + <%= rss_formatted_link({:controller => 'projects', :action => 'index', :only_active_with_no_next_actions => true}) %> + <%= text_formatted_link({:controller => 'projects', :action => 'index', :only_active_with_no_next_actions => true}) %> + Active projects with no next actions +
  • Feeds for uncompleted actions in a specific context:

      <% for context in @contexts %> diff --git a/tracks/app/views/projects/_project_listing.rhtml b/tracks/app/views/projects/_project_listing.rhtml index bacb3f0b..fa9706ce 100644 --- a/tracks/app/views/projects/_project_listing.rhtml +++ b/tracks/app/views/projects/_project_listing.rhtml @@ -5,7 +5,7 @@ DRAG
  • - <%= link_to_project( project ) %><%= " (" + count_undone_todos(project,"actions") + ")" %> + <%= link_to_project( project ) %><%= " (" + count_undone_todos_phrase(project,"actions") + ")" %>
    <%= project.current_state.to_s.upcase %> diff --git a/tracks/app/views/projects/index_text.rhtml b/tracks/app/views/projects/index_text.rhtml index 478ca227..a8163dfe 100644 --- a/tracks/app/views/projects/index_text.rhtml +++ b/tracks/app/views/projects/index_text.rhtml @@ -2,6 +2,6 @@ <%= p.name.upcase %> <%= p.description + "\n" if p.description_present? -%> -<%= count_undone_todos_text(p)%>. Project is <%= p.state %>. +<%= count_undone_todos_phrase_text(p)%>. Project is <%= p.state %>. <%= p.linkurl + "\n" if p.linkurl_present? -%> <% end -%> \ No newline at end of file diff --git a/tracks/app/views/sidebar/_context.rhtml b/tracks/app/views/sidebar/_context.rhtml index 70f69ca6..61b254fe 100644 --- a/tracks/app/views/sidebar/_context.rhtml +++ b/tracks/app/views/sidebar/_context.rhtml @@ -1 +1 @@ -
  • <%= link_to_context( context ) + " (" + count_undone_todos(context,"actions") + ")"%>
  • +
  • <%= link_to_context( context ) + " (" + count_undone_todos_phrase(context,"actions") + ")"%>
  • diff --git a/tracks/app/views/sidebar/_project.rhtml b/tracks/app/views/sidebar/_project.rhtml index a4be5026..c9dd678e 100644 --- a/tracks/app/views/sidebar/_project.rhtml +++ b/tracks/app/views/sidebar/_project.rhtml @@ -1 +1 @@ -
  • <%= link_to_project( project ) + " (" + count_undone_todos(project,"actions") + ")" %>
  • +
  • <%= link_to_project( project ) + " (" + count_undone_todos_phrase(project,"actions") + ")" %>
  • diff --git a/tracks/test/fixtures/taggings.yml b/tracks/test/fixtures/taggings.yml index 6d5aa4d7..2d1b1de7 100644 --- a/tracks/test/fixtures/taggings.yml +++ b/tracks/test/fixtures/taggings.yml @@ -14,14 +14,14 @@ foo_bar2: user_id: 1 # Todo 2 should be tagged with foo -foo: +foo1: id: 3 tag_id: 1 taggable_id: 2 # Call dinosaur exterminator taggable_type: Todo user_id: 1 -foo: +foo2: id: 4 tag_id: 1 taggable_id: 3 # Buy milk - completed diff --git a/tracks/test/functional/projects_controller_test.rb b/tracks/test/functional/projects_controller_test.rb index d9934377..7bb799ca 100644 --- a/tracks/test/functional/projects_controller_test.rb +++ b/tracks/test/functional/projects_controller_test.rb @@ -163,6 +163,16 @@ class ProjectsControllerTest < TodoContainerControllerTestBase #puts @response.body end + def test_text_feed_content_for_projects_with_no_actions + @request.session['user_id'] = users(:admin_user).id + p = projects(:timemachine) + p.todos.each { |t| t.destroy } + + get :index, { :format => "txt", :only_active_with_no_next_actions => true } + assert (/^\s*BUILD A WORKING TIME MACHINE\s+0 actions. Project is active.\s*$/.match(@response.body)) + assert !(/[1-9] actions/.match(@response.body)) + end + def test_text_feed_not_accessible_to_anonymous_user_without_token @request.session['user_id'] = nil get :index, { :format => "txt" } diff --git a/tracks/test/functional/todos_controller_test.rb b/tracks/test/functional/todos_controller_test.rb index 6ae87e34..94506db0 100644 --- a/tracks/test/functional/todos_controller_test.rb +++ b/tracks/test/functional/todos_controller_test.rb @@ -121,7 +121,7 @@ class TodosControllerTest < Test::Unit::TestCase @tagged = tag.find(:all, :conditions => ['taggings.user_id = ?', @user.id]).size get :tag, :name => 'foo' assert_response :success - assert_equal 2, @tagged + assert_equal 3, @tagged end diff --git a/tracks/test/selenium/tags/find_tagged.rsel b/tracks/test/selenium/tags/find_tagged.rsel index ee7d1445..51603c50 100644 --- a/tracks/test/selenium/tags/find_tagged.rsel +++ b/tracks/test/selenium/tags/find_tagged.rsel @@ -3,4 +3,4 @@ include_partial 'login/login', :username => 'admin', :password => 'abracadabra' open "/todos/tag/foo" wait_for_element_present "xpath=//div[@id='t'] //h2" assert_not_visible "t_empty-nd" -assert_text 'badge_count', '2' \ No newline at end of file +wait_for_text 'badge_count', '2' \ No newline at end of file