From a2120f6ee1e7f696bb9b294a0486705654120348 Mon Sep 17 00:00:00 2001 From: bsag Date: Tue, 11 Apr 2006 17:19:30 +0000 Subject: [PATCH] Setting no_completed in the user preferences to zero now removes the completed items box completely from the home page and from the individual context and project pages. Fixes #251. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@220 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/todo_controller.rb | 5 ++++- tracks/app/models/context.rb | 2 +- tracks/app/models/project.rb | 3 ++- tracks/app/views/context/show.rhtml | 4 +++- tracks/app/views/context/toggle_check.rjs | 15 +++++++++------ tracks/app/views/project/show.rhtml | 4 +++- tracks/app/views/project/toggle_check.rjs | 15 +++++++++------ tracks/app/views/todo/list.rhtml | 4 +++- tracks/app/views/todo/toggle_check.rjs | 7 +++++-- tracks/app/views/user/preference_edit_form.rhtml | 2 +- 10 files changed, 40 insertions(+), 21 deletions(-) diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 783ab045..29d26d9a 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -24,7 +24,10 @@ class TodoController < ApplicationController @on_page = "home" @page_title = "TRACKS::List tasks" - @done = @done[0..(@user.preferences["no_completed"].to_i-1)] + # If you've set no_completed to zero, the completed items box + # isn't shown on the home page + max_completed = @user.preferences["no_completed"].to_i-1 + @done = (max_completed > 0) ? @done[0..max_completed] : nil @contexts_to_show = @contexts.clone @contexts_to_show = @contexts_to_show.collect {|x| (!x.hide? and !x.find_not_done_todos.empty?) ? x:nil }.compact diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb index a65ead83..85179573 100644 --- a/tracks/app/models/context.rb +++ b/tracks/app/models/context.rb @@ -26,7 +26,7 @@ class Context < ActiveRecord::Base todos = Todo.find :all, :conditions => ["todos.context_id = #{id} AND todos.done = ?", true], :include => [:context, :project], :order => "due IS NULL, due ASC, created_at ASC", - :limit => @user.preferences["no_completed"] + :limit => @user.preferences["no_completed"].to_i end # Returns a count of next actions in the given context diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 210f21d9..a04b5b05 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -24,7 +24,8 @@ class Project < ActiveRecord::Base def find_done_todos todos = Todo.find :all, :conditions => ["project_id = #{id} AND done = ?", true], - :order => "due IS NULL, due ASC, created_at ASC" + :order => "due IS NULL, due ASC, created_at ASC", + :limit => @user.preferences["no_completed"].to_i end # Returns a count of next actions in the given project diff --git a/tracks/app/views/context/show.rhtml b/tracks/app/views/context/show.rhtml index 1c6c8774..4b45492f 100644 --- a/tracks/app/views/context/show.rhtml +++ b/tracks/app/views/context/show.rhtml @@ -7,7 +7,9 @@ <% end %> <%= render :partial => "context/context", :locals => { :context => @context, :collapsible => false } %> -<%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.preferences["no_completed"]})" } %> +<% unless @done.empty? -%> + <%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.preferences["no_completed"]})" } %> +<% end -%> diff --git a/tracks/app/views/context/toggle_check.rjs b/tracks/app/views/context/toggle_check.rjs index d4a9b169..dc18d508 100644 --- a/tracks/app/views/context/toggle_check.rjs +++ b/tracks/app/views/context/toggle_check.rjs @@ -1,12 +1,15 @@ if @saved - page.call "fadeAndRemoveItem", "item-#{@item.id}-container" + page.remove "item-#{@item.id}-container" if @item.done? - page.insert_html :top, "completed", :partial => 'todo/item' - page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} - if @down_count == '0' - page.show "empty-nd" + # Don't try to insert contents into a non-existent container! + unless @user.preferences["no_completed"].to_i == 0 + page.insert_html :top, "completed", :partial => 'todo/item' + page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} + if @down_count == '0' + page.show "empty-nd" + end + page.hide "empty-d" # If we've checked something as done, completed items can't be empty end - page.hide "empty-d" # If we've checked something as done, completed items can't be empty else page.call "ensureVisibleWithEffectAppear", "c#{@item.context_id}" page.insert_html :bottom, "c#{@item.context_id}", :partial => 'todo/item' diff --git a/tracks/app/views/project/show.rhtml b/tracks/app/views/project/show.rhtml index b72b4672..39ec875a 100644 --- a/tracks/app/views/project/show.rhtml +++ b/tracks/app/views/project/show.rhtml @@ -7,7 +7,9 @@ <% end %> <%= render :partial => "project/project", :locals => { :project => @project, :collapsible => false } %> -<%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this project" } %> +<% unless @done.empty? -%> + <%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this project" } %> +<% end -%>
diff --git a/tracks/app/views/project/toggle_check.rjs b/tracks/app/views/project/toggle_check.rjs index e0c4d037..15bfa97f 100644 --- a/tracks/app/views/project/toggle_check.rjs +++ b/tracks/app/views/project/toggle_check.rjs @@ -1,12 +1,15 @@ if @saved - page.call "fadeAndRemoveItem", "item-#{@item.id}-container" + page.remove "item-#{@item.id}-container" if @item.done? - page.insert_html :top, "completed", :partial => 'todo/item' - page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} - if @down_count == '0' - page.show "empty-nd" + # Don't try to insert contents into a non-existent container! + unless @user.preferences["no_completed"].to_i == 0 + page.insert_html :top, "completed", :partial => 'todo/item' + page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} + if @down_count == '0' + page.show "empty-nd" + end + page.hide "empty-d" # If we've checked something as done, completed items can't be empty end - page.hide "empty-d" # If we've checked something as done, completed items can't be empty else page.call "ensureVisibleWithEffectAppear", "p#{@item.project_id}" page.insert_html :bottom, "p#{@item.project_id}", :partial => 'todo/item' diff --git a/tracks/app/views/todo/list.rhtml b/tracks/app/views/todo/list.rhtml index aabd9c4e..b88b86d0 100644 --- a/tracks/app/views/todo/list.rhtml +++ b/tracks/app/views/todo/list.rhtml @@ -8,8 +8,10 @@ <%= render :partial => "context/context", :collection => @contexts_to_show, :locals => { :collapsible => true } %> - <%= render :partial => "todo/completed", + <% unless @done.nil? -%> + <%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => true, :append_descriptor => nil } %> + <% end -%>
diff --git a/tracks/app/views/todo/toggle_check.rjs b/tracks/app/views/todo/toggle_check.rjs index e91ef39b..5735bfc3 100644 --- a/tracks/app/views/todo/toggle_check.rjs +++ b/tracks/app/views/todo/toggle_check.rjs @@ -4,8 +4,11 @@ if @saved # not on the todo/list page when the item being deleted has just been added # page.call "fadeAndRemoveItem", "item-#{@item.id}-container" if @item.done? - page.insert_html :top, "completed", :partial => 'todo/item' - page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} + # Don't try to insert contents into a non-existent container! + unless @user.preferences["no_completed"].to_i == 0 + page.insert_html :top, "completed", :partial => 'todo/item' + page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} + end else page.call "ensureVisibleWithEffectAppear", "c#{@item.context_id}" page.insert_html :bottom, "c#{@item.context_id}", :partial => 'todo/item' diff --git a/tracks/app/views/user/preference_edit_form.rhtml b/tracks/app/views/user/preference_edit_form.rhtml index 87ef509d..cfb5f5ee 100644 --- a/tracks/app/views/user/preference_edit_form.rhtml +++ b/tracks/app/views/user/preference_edit_form.rhtml @@ -4,7 +4,7 @@
  • staleness_starts: the number of days before items with no due date get marked as stale (with a yellow highlight)
  • date_format: the format in which you'd like dates to be shown. For example, for the date 31st January 2006, %d/%m/%Y will show 31/01/2006, %b-%e-%y will show Jan-31-06. See the strftime manual for more formatting options for the date.
  • -
  • no_completed: number of completed actions to show on the home page
  • +
  • no_completed: number of completed actions to show on the home page. If you set this to zero, the completed actions box will not be shown on the home page or on the individual context or project pages. You can still see all your completed items by clicking the 'Done' link in the navigation bar at the top of each page.
  • <% if @user.is_admin? %>
  • admin_email: email address for the admin user of Tracks (displayed on the signup page for users to contact to obtain an account)
  • <% end %>