diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index 38ac8fc4..5454540d 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -72,4 +72,19 @@ class ApplicationController < ActionController::Base @admin = User.find(:first, :conditions => [ "is_admin = ?", true ]) end + def init_data_for_sidebar + @projects = @user.projects + @contexts = @user.contexts + init_not_done_counts + end + + def init_not_done_counts + @project_not_done_counts = Todo.count(:todo, + :conditions => ['todos.user_id = ? and todos.type = ? and todos.done = ?', @user.id, "Immediate", false], + :group => :project_id) + @context_not_done_counts = Todo.count(:todo, + :conditions => ['todos.user_id = ? and todos.type = ? and todos.done = ?', @user.id, "Immediate", false], + :group => :context_id) + end + end diff --git a/tracks/app/controllers/context_controller.rb b/tracks/app/controllers/context_controller.rb index 09391a0d..03099719 100644 --- a/tracks/app/controllers/context_controller.rb +++ b/tracks/app/controllers/context_controller.rb @@ -27,6 +27,7 @@ class ContextController < ApplicationController # def show init + check_user_set_context init_todos @on_page = "context" @page_title = "TRACKS::Context: #{@context.name}" @@ -219,13 +220,14 @@ class ContextController < ApplicationController @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") + init_not_done_counts end def init_todos check_user_set_context @done = @context.done_todos - @not_done = @context.not_done_todos - @count = @not_done.size + @not_done_todos = @context.not_done_todos + @count = @not_done_todos.size end end diff --git a/tracks/app/controllers/deferred_controller.rb b/tracks/app/controllers/deferred_controller.rb index b7b20e0a..b1822728 100644 --- a/tracks/app/controllers/deferred_controller.rb +++ b/tracks/app/controllers/deferred_controller.rb @@ -12,6 +12,7 @@ class DeferredController < ApplicationController def index init_projects_and_contexts + init_not_done_counts @page_title = "TRACKS::Tickler" @tickles = @user.todos.find(:all, :conditions => ['type = ?', "Deferred"], :order => "show_from ASC") @count = @tickles.size diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb index aebf2158..93a8d5b2 100644 --- a/tracks/app/controllers/feed_controller.rb +++ b/tracks/app/controllers/feed_controller.rb @@ -4,11 +4,16 @@ class FeedController < ApplicationController helper :feed model :todo, :context, :project - session :disabled => true # Prevents session control from interfering with feed + session :disabled => true, :except => 'index' # Prevents session control from interfering with feed - before_filter :check_token_against_user_word + before_filter :check_token_against_user_word, :except => 'index' + prepend_before_filter :login_required, :only => 'index' + def index + @page_title = 'TRACKS::Feeds' + init_data_for_sidebar + render :layout => 'standard' end # Build an RSS feed diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index 1b65b1d3..2df5c008 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -252,6 +252,7 @@ class ProjectController < ApplicationController @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") + init_not_done_counts end def init_todos diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index a9be5427..b1d5e098 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -14,14 +14,24 @@ class TodoController < ApplicationController # Number of completed actions to show is determined by a setting in settings.yml def index self.init + @projects = @user.projects.find(:all, :include => [ :todos ]) + @contexts = @user.contexts.find(:all, :include => [ :todos ]) + @on_page = "home" @page_title = "TRACKS::List tasks" # 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 - + @done = nil + if max_completed > 0 + @done = Todo.find(:all, + :conditions => ['todos.user_id = ? and todos.done = ?', @user.id, true], + :order => 'todos.completed DESC', + :limit => max_completed, + :include => [ :project, :context ]) + end + @contexts_to_show = @contexts.reject {|x| x.hide? } if @contexts.empty? @@ -37,10 +47,6 @@ class TodoController < ApplicationController end end - # Is this used? Seems like it should be deleted. -lukemelia, 2006-07-16 - def update_element - end - # Called by a form button # Parameters from form fields are passed to create new action # in the selected context. @@ -58,14 +64,15 @@ class TodoController < ApplicationController @saved = @item.save - if @saved - init_todos - @up_count = @todos.reject { |x| x.done? or x.context.hide? }.size.to_s - end - respond_to do |wants| wants.html { redirect_to :action => "index" } - wants.js + wants.js do + if @saved + init_todos + @up_count = @todos.reject { |x| x.done? or x.context.hide? }.size.to_s + end + render + end wants.xml { render :xml => @item.to_xml( :root => 'todo', :except => :user_id ) } end @@ -215,11 +222,13 @@ class TodoController < ApplicationController self.init @page_title = "TRACKS::Completed tasks" - unless @done.nil? - @done_today = @done.collect { |x| x.completed >= 1.day.ago ? x:nil }.compact - @done_this_week = @done.collect { |x| 1.week.ago <= x.completed ? x:nil }.compact - @done_this_month = @done.collect { |x| 4.week.ago <= x.completed ? x:nil }.compact - end + @done = Todo.find(:all, + :conditions => ['todos.user_id = ? and todos.done = ? and todos.completed is not null', @user.id, true], + :order => 'todos.completed DESC', + :include => [ :project, :context ]) + @done_today = @done.collect { |x| x.completed >= 1.day.ago ? x:nil }.compact + @done_this_week = @done.collect { |x| 1.week.ago <= x.completed ? x:nil }.compact + @done_this_month = @done.collect { |x| 4.week.ago <= x.completed ? x:nil }.compact end # Archived completed items, older than 28 days @@ -227,14 +236,13 @@ class TodoController < ApplicationController def completed_archive self.init @page_title = "TRACKS::Archived completed tasks" + @done = Todo.find(:all, + :conditions => ['todos.user_id = ? and todos.done = ? and todos.completed is not null', @user.id, true], + :order => 'todos.completed DESC', + :include => [ :project, :context ]) @done_archive = @done.collect { |x| 28.day.ago > x.completed ? x:nil }.compact end - def feeds - self.init - @page_title = "TRACKS::Feeds" - end - protected def check_user_return_item @@ -251,11 +259,18 @@ class TodoController < ApplicationController @projects = @user.projects @contexts = @user.contexts init_todos + init_not_done_counts end def init_todos - @todos = Todo.find(:all, :conditions => ['user_id = ? and type = ?', @user.id, "Immediate"]) - @done = Todo.find(:all, :conditions => ['user_id = ? and done = ?', @user.id, true], :order => 'completed DESC') + @todos = Todo.find(:all, + :conditions => ['todos.user_id = ? and todos.type = ?', @user.id, "Immediate"], + :include => [ :project, :context ]) + + @not_done_todos = Todo.find(:all, + :conditions => ['todos.user_id = ? and todos.type = ? and todos.done = ?', @user.id, "Immediate", false], + :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", + :include => [ :project, :context ]) end - + end diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index cd12a99f..ce213884 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -112,4 +112,21 @@ module ApplicationHelper end end + # Returns a count of next actions in the given context or project + # 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") + count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]" + count = 0 if count == nil + #count = todos_parent.todos.select{|t| !t.done }.size + if count == 1 + word = string.singularize + else + word = string.pluralize + end + return count.to_s + " " + word + end + + end diff --git a/tracks/app/helpers/feed_helper.rb b/tracks/app/helpers/feed_helper.rb index 345d9fe2..6bdc4a5e 100644 --- a/tracks/app/helpers/feed_helper.rb +++ b/tracks/app/helpers/feed_helper.rb @@ -37,7 +37,7 @@ module FeedHelper result_string << "\n" + p.name.upcase + "\n" result_string << p.description + "\n" if p.description_present? - result_string << "#{p.count_undone_todos}. Project is #{p.done? ? 'Done' : 'Active'}.\n" + result_string << "#{count_undone_todos(p)}. Project is #{p.done? ? 'Done' : 'Active'}.\n" result_string << "#{p.linkurl}\n" if p.linkurl_present? result_string << "\n" end @@ -50,7 +50,7 @@ module FeedHelper contexts.each do |c| result_string << "\n" + c.name.upcase + "\n" - result_string << "#{c.count_undone_todos}. Context is #{c.hidden? ? 'Hidden' : 'Active'}.\n" + result_string << "#{count_undone_todos(c)}. Context is #{c.hidden? ? 'Hidden' : 'Active'}.\n" result_string << "\n" end @@ -62,4 +62,24 @@ module FeedHelper joined_notes = split_notes.join("\\n") end + def rss_feed_link(options = {}) + image_tag = image_tag("feed-icon", :size => "16X16", :border => 0, :class => "rss-icon") + linkoptions = {:controller => 'feed', :action => 'rss', :name => "#{@user.login}", :token => "#{@user.word}"} + linkoptions.merge!(options) + link_to(image_tag, linkoptions, :title => "RSS feed") + end + + def text_feed_link(options = {}) + linkoptions = {:controller => 'feed', :action => 'text', :name => "#{@user.login}", :token => "#{@user.word}"} + linkoptions.merge!(options) + link_to('TXT', linkoptions, :title => "Plain text feed" ) + end + + def ical_feed_link(options = {}) + linkoptions = {:controller => 'feed', :action => 'ical', :name => "#{@user.login}", :token => "#{@user.word}"} + linkoptions.merge!(options) + link_to('iCal', linkoptions, :title => "iCal feed") + end + + end diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index ed8316a2..6bc0dba3 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -111,24 +111,5 @@ module TodoHelper str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n" javascript_tag str end - - def rss_feed_link(options = {}) - image_tag = image_tag("feed-icon", :size => "16X16", :border => 0, :class => "rss-icon") - linkoptions = {:controller => 'feed', :action => 'rss', :name => "#{@user.login}", :token => "#{@user.word}"} - linkoptions.merge!(options) - link_to(image_tag, linkoptions, :title => "RSS feed") - end - - def text_feed_link(options = {}) - linkoptions = {:controller => 'feed', :action => 'text', :name => "#{@user.login}", :token => "#{@user.word}"} - linkoptions.merge!(options) - link_to('TXT', linkoptions, :title => "Plain text feed" ) - end - - def ical_feed_link(options = {}) - linkoptions = {:controller => 'feed', :action => 'ical', :name => "#{@user.login}", :token => "#{@user.word}"} - linkoptions.merge!(options) - link_to('iCal', linkoptions, :title => "iCal feed") - end - + end diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb index a332c0aa..c8e47368 100644 --- a/tracks/app/models/context.rb +++ b/tracks/app/models/context.rb @@ -24,32 +24,20 @@ class Context < ActiveRecord::Base end def find_not_done_todos - todos = Todo.find :all, :conditions => ["todos.context_id = ? AND todos.done = ? AND type = ?", id, false, "Immediate"], - :include => [:context, :project], - :order => "due IS NULL, due ASC, created_at ASC" + todos = Todo.find(:all, + :conditions => ['todos.context_id = ? and todos.type = ? and todos.done = ?', id, "Immediate", false], + :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", + :include => [ :project, :context ]) + end def find_done_todos - todos = Todo.find :all, :conditions => ["todos.context_id = ? AND todos.done = ? AND type = ?", id, true, "Immediate"], - :include => [:context, :project], + todos = Todo.find :all, :conditions => ["todos.context_id = ? AND todos.type = ? AND todos.done = ?", id, "Immediate", true], :order => "completed DESC", + :include => [:context, :project], :limit => @user.preferences["no_completed"].to_i end - # Returns a count of next actions in the given context - # The result is count and a string descriptor, correctly pluralised if there are no - # actions or multiple actions - # - def count_undone_todos(string="actions") - count = self.not_done_todos.size - if count == 1 - word = string.singularize - else - word = string.pluralize - end - return count.to_s + " " + word - end - def hidden? self.hide == true end diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 754427a5..d080c9c7 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -33,28 +33,19 @@ class Project < ActiveRecord::Base end def find_not_done_todos - Todo.find :all, :conditions => ["project_id = ? AND done = ?", id, false], - :order => "due IS NULL, due ASC, created_at ASC" + todos = Todo.find(:all, + :conditions => ['todos.project_id = ? and todos.type = ? and todos.done = ?', id, "Immediate", false], + :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", + :include => [ :project, :context ]) + end def find_done_todos - Todo.find :all, :conditions => ["project_id = ? AND done = ?", id, true], - :order => "completed DESC", - :limit => @user.preferences["no_completed"].to_i + todos = Todo.find :all, :conditions => ["todos.project_id = ? AND todos.type = ? AND todos.done = ?", id, "Immediate", true], + :order => "completed DESC", + :include => [:context, :project], + :limit => @user.preferences["no_completed"].to_i end - # Returns a count of next actions in the given project - # The result is count and a string descriptor, correctly pluralised if there are no - # actions or multiple actions - # - def count_undone_todos(string="actions") - count = not_done_todos.size - if count == 1 - word = string.singularize - else - word = string.pluralize - end - return count.to_s + " " + word - end - + end diff --git a/tracks/app/views/context/_context.rhtml b/tracks/app/views/context/_context.rhtml index 18bcc5f0..1f4a9691 100644 --- a/tracks/app/views/context/_context.rhtml +++ b/tracks/app/views/context/_context.rhtml @@ -1,4 +1,4 @@ -<% @not_done = context.not_done_todos %> +<% @not_done = @not_done_todos.select {|t| t.context_id == context.id } %>