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
This commit is contained in:
lukemelia 2007-02-22 05:15:52 +00:00
parent cf4adff2e6
commit 9e3f686f84
15 changed files with 93 additions and 58 deletions

View file

@ -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 + "&nbsp;" + 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

View file

@ -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'])

View file

@ -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"])

View file

@ -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("&nbsp;"," ")
def count_undone_todos_phrase_text(todos_parent, string="actions")
count_undone_todos_phrase(todos_parent, string).gsub("&nbsp;"," ")
end
def link_to_context(context, descriptor = sanitize(context.name))

View file

@ -5,7 +5,7 @@
<span class="handle">DRAG</span>
</div>
<div class="data">
<%= link_to_context( context ) %> <%= " (" + count_undone_todos(context,"actions") + ")" %>
<%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %>
</div>
<div class="buttons">

View file

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

View file

@ -49,6 +49,11 @@
<%= text_formatted_link({:controller => 'projects', :action => 'index'}) %>
All Projects
</li>
<li>
<%= 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
</li>
<li><h4>Feeds for uncompleted actions in a specific context:</h4>
<ul>
<% for context in @contexts %>

View file

@ -5,7 +5,7 @@
<span class="handle">DRAG</span>
</div>
<div class="data">
<%= link_to_project( project ) %><%= " (" + count_undone_todos(project,"actions") + ")" %>
<%= link_to_project( project ) %><%= " (" + count_undone_todos_phrase(project,"actions") + ")" %>
</div>
<div class="buttons">
<span class="grey"><%= project.current_state.to_s.upcase %></span>

View file

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

View file

@ -1 +1 @@
<li><%= link_to_context( context ) + " (" + count_undone_todos(context,"actions") + ")"%></li>
<li><%= link_to_context( context ) + " (" + count_undone_todos_phrase(context,"actions") + ")"%></li>

View file

@ -1 +1 @@
<li><%= link_to_project( project ) + " (" + count_undone_todos(project,"actions") + ")" %></li>
<li><%= link_to_project( project ) + " (" + count_undone_todos_phrase(project,"actions") + ")" %></li>

View file

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

View file

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

View file

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

View file

@ -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'
wait_for_text 'badge_count', '2'