Simplify some find methods in todo_controller using associations. Fix a bug in the RSS and TEXT feeds created by yesterday's change to the project status.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@327 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2006-10-12 05:00:46 +00:00
parent fa4b1c4c7b
commit f67e36871c
5 changed files with 29 additions and 24 deletions

View file

@ -206,7 +206,7 @@ class ContextController < ApplicationController
def init
@source_view = params['_source_view'] || 'context'
@projects = @user.projects.collect { |x| x.done? ? nil:x }.compact
@projects = @user.projects.reject { |x| x.completed? }
@contexts = @user.contexts
@todos = @user.todos
@done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ?", @user.id, true], :include => [:project], :order => "completed DESC")

View file

@ -111,7 +111,7 @@ class TodoController < ApplicationController
@item.toggle!('done')
@item.completed = Time.now() # For some reason, the before_save in todo.rb stopped working
@saved = @item.save
@remaining_undone_in_context = Todo.count(:conditions => ['user_id = ? and context_id = ? and type = ? and done = ?', @user.id, @item.context_id, "Immediate", false])
@remaining_undone_in_context = @user.contexts.find(@item.context_id).not_done_todos.length
if @saved
@down_count = @todos.reject { |x| x.done? || x.context.hide? }.size.to_s
end
@ -136,8 +136,10 @@ class TodoController < ApplicationController
params["item"]["due"] = ""
end
@saved = @item.update_attributes params["item"]
@remaining_undone_in_original_context = Todo.count(:conditions => ['user_id = ? and context_id = ? and type = ? and done = ?', @user.id, @original_item_context_id, "Immediate", false])
@remaining_undone_in_original_project = Todo.count(:conditions => ['user_id = ? and project_id = ? and type = ? and done = ?', @user.id, @original_item_project_id, "Immediate", false])
@context_changed = @original_item_context_id != @item.context_id
if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todos.length; end
@project_changed = @original_item_project_id != @item.project_id
if @project_changed then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todos.length; end
end
def update_context
@ -195,8 +197,7 @@ class TodoController < ApplicationController
@down_count = determine_down_count
source_view do |from|
from.todo do
@remaining_undone_in_context = Todo.count(:conditions => ['user_id = ? and context_id = ? and type = ? and done = ?',
@user.id, @context_id, "Immediate", false])
@remaining_undone_in_context = @user.contexts.find(@context_id).not_done_todos.length
end
end
end

View file

@ -37,7 +37,7 @@ module FeedHelper
result_string << "\n" + p.name.upcase + "\n"
result_string << p.description + "\n" if p.description_present?
result_string << "#{count_undone_todos(p)}. Project is #{p.done? ? 'Done' : 'Active'}.\n"
result_string << "#{count_undone_todos(p)}. Project is #{p.state}.\n"
result_string << "#{p.linkurl}\n" if p.linkurl_present?
result_string << "\n"
end

View file

@ -11,7 +11,7 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
project_description = ''
project_description += sanitize(markdown( p.description )) if p.description_present?
project_description += "<p>#{count_undone_todos(p)}. "
project_description += "Project is #{p.done? ? 'Done' : 'Active'}. "
project_description += "Project is #{p.state}. "
project_description += "<a href=\"#{p.linkurl}\">#{p.linkurl}</a>" if p.linkurl_present?
project_description += "</p>"
xml.description(project_description)

View file

@ -2,10 +2,7 @@ page.hide "info"
if @saved
item_container_id = "item-#{@item.id}-container"
if source_view_is_one_of [:todo, :context]
if @item.context_id == @original_item_context_id
page.replace item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => "context" }
page.visual_effect :highlight, item_container_id, :duration => 3
else
if @context_changed
page[item_container_id].remove
if (@remaining_undone_in_original_context == 0)
source_view do |from|
@ -13,24 +10,31 @@ if @saved
from.context { page.show "c#{@original_item_context_id}empty-nd" }
end
end
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}"
page.call "todoItems.expandNextActionListingByContext", "c#{@item.context_id}items", true
page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todo/item', :locals => { :parent_container_type => "context" }
if source_view_is :todo
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}"
page.call "todoItems.expandNextActionListingByContext", "c#{@item.context_id}items", true
page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todo/item', :locals => { :parent_container_type => "context" }
end
page.replace_html("badge_count", @remaining_undone_in_context) if source_view_is :context
page.delay(0.5) do
page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items"
page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items"
page.visual_effect :highlight, item_container_id, :duration => 3
if source_view_is :todo
page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items"
page.visual_effect :highlight, item_container_id, :duration => 3
end
end
end
else
page.replace item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => "context" }
page.visual_effect :highlight, item_container_id, :duration => 3
end
elsif source_view_is :project
if @item.project_id == @original_item_project_id
if @project_changed
page[item_container_id].remove
page.show("p#{@original_item_project_id}empty-nd") if (@remaining_undone_in_project == 0)
page.replace_html "badge_count", @remaining_undone_in_project
else
page.replace item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => "project" }
page.visual_effect :highlight, item_container_id, :duration => 3
else
page[item_container_id].remove
if (@remaining_undone_in_original_project == 0)
page.show "p#{@original_item_project_id}empty-nd"
end
end
else
logger.error "unexpected source_view '#{params[:_source_view]}'"