diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index d6bd1e86..0c62cb39 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base helper :application include LoginSystem + helper_method :current_user, :prefs layout proc{ |controller| controller.mobile? ? "mobile" : "standard" } @@ -94,12 +95,12 @@ class ApplicationController < ActionController::Base count || 0 end - # Convert a date object to the format specified + # Convert a date object to the format specified in the user's preferences # in config/settings.yml # def format_date(date) if date - date_format = @user.prefs.date_format + date_format = prefs.date_format formatted_date = date.strftime("#{date_format}") else formatted_date = '' @@ -178,27 +179,27 @@ class ApplicationController < ActionController::Base def parse_date_per_user_prefs( s ) return nil if s.blank? - Date.strptime(s, @user.prefs.date_format) + Date.strptime(s, prefs.date_format) end def init_data_for_sidebar - @projects = @projects || @user.projects - @contexts = @contexts || @user.contexts + @projects = @projects || current_user.projects + @contexts = @contexts || current_user.contexts init_not_done_counts - if @prefs.show_hidden_projects_in_sidebar + if prefs.show_hidden_projects_in_sidebar init_project_hidden_todo_counts(['project']) end end def init_not_done_counts(parents = ['project','context']) parents.each do |parent| - eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'active'], :group => :#{parent}_id)") + eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || Todo.count(:conditions => ['user_id = ? and state = ?', current_user.id, 'active'], :group => :#{parent}_id)") end end def init_project_hidden_todo_counts(parents = ['project','context']) parents.each do |parent| - eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'project_hidden'], :group => :#{parent}_id)") + eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || Todo.count(:conditions => ['user_id = ? and state = ?', current_user.id, 'project_hidden'], :group => :#{parent}_id)") end end diff --git a/tracks/app/controllers/contexts_controller.rb b/tracks/app/controllers/contexts_controller.rb index 2f5addbd..b0582cef 100644 --- a/tracks/app/controllers/contexts_controller.rb +++ b/tracks/app/controllers/contexts_controller.rb @@ -10,7 +10,7 @@ class ContextsController < ApplicationController session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) } def index - @contexts = @user.contexts + @contexts = current_user.contexts init_not_done_counts(['context']) respond_to do |format| format.html &render_contexts_html @@ -46,7 +46,7 @@ class ContextsController < ApplicationController render_failure "Expected post format is valid xml like so: context name.", 400 return end - @context = @user.contexts.build + @context = current_user.contexts.build params_are_invalid = true if (params['context'] || (params['request'] && params['request']['context'])) @context.attributes = params['context'] || params['request']['context'] @@ -104,7 +104,7 @@ class ContextsController < ApplicationController # def order params["list-contexts"].each_with_index do |id, position| - @user.contexts.update(id, :position => position + 1) + current_user.contexts.update(id, :position => position + 1) end render :nothing => true end @@ -121,30 +121,31 @@ class ContextsController < ApplicationController def render_contexts_rss_feed lambda do - render_rss_feed_for @contexts, :feed => Context.feed_options(@user), + render_rss_feed_for @contexts, :feed => feed_options, :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), + render_atom_feed_for @contexts, :feed => feed_options, :item => { :description => lambda { |c| c.summary(count_undone_todos_phrase(c)) }, :author => lambda { |c| nil } } end end + + def feed_options + Context.feed_options(current_user) + end def set_context_from_params - @context = @user.contexts.find_by_params(params) + @context = current_user.contexts.find_by_params(params) rescue @context = nil end def init @source_view = params['_source_view'] || 'context' - # If we exclude completed projects, then we can't display them in the sidebar - # if the user sets the preference for them to be shown - # @projects = @user.projects.reject { |x| x.completed? } init_data_for_sidebar end diff --git a/tracks/app/controllers/data_controller.rb b/tracks/app/controllers/data_controller.rb index c5e1541d..53ef8d80 100644 --- a/tracks/app/controllers/data_controller.rb +++ b/tracks/app/controllers/data_controller.rb @@ -17,10 +17,10 @@ class DataController < ApplicationController def yaml_export all_tables = {} - all_tables['todos'] = @user.todos.find(:all) - all_tables['contexts'] = @user.contexts.find(:all) - all_tables['projects'] = @user.projects.find(:all) - all_tables['notes'] = @user.notes.find(:all) + all_tables['todos'] = current_user.todos.find(:all) + all_tables['contexts'] = current_user.contexts.find(:all) + all_tables['projects'] = current_user.projects.find(:all) + all_tables['notes'] = current_user.notes.find(:all) result = all_tables.to_yaml result.gsub!(/\n/, "\r\n") # TODO: general functionality for line endings @@ -33,7 +33,7 @@ class DataController < ApplicationController csv << ["ID", "Context", "Project", "Description", "Notes", "Created at", "Due", "Completed at", "User ID", "Show from", "state"] - @user.todos.find(:all, :include => [:context, :project]).each do |todo| + current_user.todos.find(:all, :include => [:context, :project]).each do |todo| # Format dates in ISO format for easy sorting in spreadsheet # Print context and project names for easy viewing csv << [todo.id, todo.context.name, @@ -57,7 +57,7 @@ class DataController < ApplicationController "Created at", "Updated at"] # had to remove project include because it's association order is leaking through # and causing an ambiguous column ref even with_exclusive_scope didn't seem to help -JamesKebinger - @user.notes.find(:all,:order=>"notes.created_at").each do |note| + current_user.notes.find(:all,:order=>"notes.created_at").each do |note| # Format dates in ISO format for easy sorting in spreadsheet # Print context and project names for easy viewing csv << [note.id, note.user_id, @@ -71,10 +71,10 @@ class DataController < ApplicationController def xml_export result = "" - result << @user.todos.find(:all).to_xml - result << @user.contexts.find(:all).to_xml(:skip_instruct => true) - result << @user.projects.find(:all).to_xml(:skip_instruct => true) - result << @user.notes.find(:all).to_xml(:skip_instruct => true) + result << current_user.todos.find(:all).to_xml + result << current_user.contexts.find(:all).to_xml(:skip_instruct => true) + result << current_user.projects.find(:all).to_xml(:skip_instruct => true) + result << current_user.notes.find(:all).to_xml(:skip_instruct => true) send_data(result, :filename => "tracks_backup.xml", :type => 'text/xml') end diff --git a/tracks/app/controllers/notes_controller.rb b/tracks/app/controllers/notes_controller.rb index c2e7fbdd..40c43175 100644 --- a/tracks/app/controllers/notes_controller.rb +++ b/tracks/app/controllers/notes_controller.rb @@ -1,7 +1,7 @@ class NotesController < ApplicationController def index - @all_notes = @user.notes + @all_notes = current_user.notes @page_title = "TRACKS::All notes" respond_to do |format| format.html @@ -10,14 +10,12 @@ class NotesController < ApplicationController end def show - @note = check_user_return_note + @note = current_user.notes.find(params['id']) @page_title = "TRACKS::Note " + @note.id.to_s end - # Add a new note to this project - # def create - note = @user.notes.build + note = current_user.notes.build note.attributes = params["new_note"] if note.save @@ -28,34 +26,24 @@ class NotesController < ApplicationController end def destroy - note = check_user_return_note + note = current_user.notes.find(params['id']) if note.destroy render :text => '' else - notify :warning, "Couldn't delete note \"#{note.id.to_s}\"" + notify :warning, "Couldn't delete note \"#{note.id}\"" render :text => '' end end def update - note = check_user_return_note + note = current_user.notes.find(params['id']) note.attributes = params["note"] - if note.save - render :partial => 'notes', :object => note - else - notify :warning, "Couldn't update note \"#{note.id.to_s}\"" - render :text => '' - end + if note.save + render :partial => 'notes', :object => note + else + notify :warning, "Couldn't update note \"#{note.id}\"" + render :text => '' + end end - protected - - def check_user_return_note - note = Note.find_by_id( params['id'] ) - if @user == note.user - return note - else - render :text => '' - end - end end diff --git a/tracks/app/controllers/preferences_controller.rb b/tracks/app/controllers/preferences_controller.rb index 89ae0a51..5e5f9640 100644 --- a/tracks/app/controllers/preferences_controller.rb +++ b/tracks/app/controllers/preferences_controller.rb @@ -2,20 +2,18 @@ class PreferencesController < ApplicationController def index @page_title = "TRACKS::Preferences" - @prefs = @user.preference + @prefs = prefs end def edit @page_title = "TRACKS::Edit Preferences" - @prefs = @user.preference - - render :object => @prefs + render :object => prefs end def update - user_success = @user.update_attributes(params['user']) - prefs_success = @user.preference.update_attributes(params['prefs']) - if user_success && prefs_success + user_updated = current_user.update_attributes(params['user']) + prefs_updated = current_user.preference.update_attributes(params['prefs']) + if user_updated && prefs_updated redirect_to :action => 'index' else render :action => 'edit' diff --git a/tracks/app/controllers/projects_controller.rb b/tracks/app/controllers/projects_controller.rb index 3dc87036..f5a64496 100644 --- a/tracks/app/controllers/projects_controller.rb +++ b/tracks/app/controllers/projects_controller.rb @@ -9,8 +9,8 @@ class ProjectsController < ApplicationController session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) } def index - @projects = @user.projects - @contexts = @user.contexts + @projects = current_user.projects + @contexts = current_user.contexts init_not_done_counts(['project']) if params[:only_active_with_no_next_actions] @projects = @projects.select { |p| p.active? && count_undone_todos(p) == 0 } @@ -26,15 +26,15 @@ class ProjectsController < ApplicationController def show init_data_for_sidebar - @projects = @user.projects - @contexts = @user.contexts + @projects = current_user.projects + @contexts = current_user.contexts @page_title = "TRACKS::Project: #{@project.name}" @not_done = @project.not_done_todos(:include_project_hidden_todos => true) @deferred = @project.deferred_todos @done = @project.done_todos @count = @not_done.size - @next_project = @user.projects.next_from(@project) - @previous_project = @user.projects.previous_from(@project) + @next_project = current_user.projects.next_from(@project) + @previous_project = current_user.projects.previous_from(@project) @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json respond_to do |format| format.html @@ -52,7 +52,7 @@ class ProjectsController < ApplicationController render_failure "Expected post format is valid xml like so: project name." return end - @project = @user.projects.build + @project = current_user.projects.build params_are_invalid = true if (params['project'] || (params['request'] && params['request']['project'])) @project.attributes = params['project'] || params['request']['project'] @@ -61,8 +61,8 @@ class ProjectsController < ApplicationController @go_to_project = params['go_to_project'] @saved = @project.save @project_not_done_counts = { @project.id => 0 } - @active_projects_count = @user.projects.count(:conditions => "state = 'active'") - @contexts = @user.contexts + @active_projects_count = current_user.projects.count(:conditions => "state = 'active'") + @contexts = current_user.contexts respond_to do |format| format.js format.xml do @@ -101,10 +101,10 @@ class ProjectsController < ApplicationController @project_not_done_counts = Hash.new @project_not_done_counts[@project.id] = @project.reload().not_done_todo_count(:include_project_hidden_todos => true) end - @contexts = @user.contexts - @active_projects_count = @user.projects.count(:conditions => "state = 'active'") - @hidden_projects_count = @user.projects.count(:conditions => "state = 'hidden'") - @completed_projects_count = @user.projects.count(:conditions => "state = 'completed'") + @contexts = current_user.contexts + @active_projects_count = current_user.projects.count(:conditions => "state = 'active'") + @hidden_projects_count = current_user.projects.count(:conditions => "state = 'hidden'") + @completed_projects_count = current_user.projects.count(:conditions => "state = 'completed'") render elsif boolean_param('update_status') render :action => 'update_status' @@ -121,9 +121,9 @@ class ProjectsController < ApplicationController def destroy @project.destroy - @active_projects_count = @user.projects.count(:conditions => "state = 'active'") - @hidden_projects_count = @user.projects.count(:conditions => "state = 'hidden'") - @completed_projects_count = @user.projects.count(:conditions => "state = 'completed'") + @active_projects_count = current_user.projects.count(:conditions => "state = 'active'") + @hidden_projects_count = current_user.projects.count(:conditions => "state = 'hidden'") + @completed_projects_count = current_user.projects.count(:conditions => "state = 'completed'") respond_to do |format| format.js format.xml { render :text => "Deleted project #{@project.name}" } @@ -132,7 +132,7 @@ class ProjectsController < ApplicationController def order project_ids = params["list-active-projects"] || params["list-hidden-projects"] || params["list-completed-projects"] - projects = @user.projects.update_positions( project_ids ) + projects = current_user.projects.update_positions( project_ids ) render :nothing => true rescue notify :error, $! @@ -141,8 +141,8 @@ class ProjectsController < ApplicationController def alphabetize @state = params['state'] - @projects = @user.projects.alphabetize(:state => @state) if @state - @contexts = @user.contexts + @projects = current_user.projects.alphabetize(:state => @state) if @state + @contexts = current_user.contexts init_not_done_counts(['project']) end @@ -157,26 +157,30 @@ class ProjectsController < ApplicationController @completed_projects = @projects.select{ |p| p.completed? } @no_projects = @projects.empty? @projects.cache_note_counts - @new_project = @user.projects.build + @new_project = current_user.projects.build render end end def render_rss_feed lambda do - render_rss_feed_for @projects, :feed => Project.feed_options(@user), + render_rss_feed_for @projects, :feed => feed_options, :item => { :title => :name, :description => lambda { |p| summary(p) } } end end def render_atom_feed lambda do - render_atom_feed_for @projects, :feed => Project.feed_options(@user), + render_atom_feed_for @projects, :feed => feed_options, :item => { :description => lambda { |p| summary(p) }, :title => :name, :author => lambda { |p| nil } } end end + + def feed_options + Project.feed_options(current_user) + end def render_text_feed lambda do @@ -186,7 +190,7 @@ class ProjectsController < ApplicationController end def set_project_from_params - @project = @user.projects.find_by_params(params) + @project = current_user.projects.find_by_params(params) end def set_source_view diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index 1b1dc760..8060f4e9 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -10,8 +10,8 @@ class TodosController < ApplicationController session :off, :only => :index, :if => Proc.new { |req| is_feed_request(req) } def index - @projects = @user.projects.find(:all, :include => [ :todos ]) - @contexts = @user.contexts.find(:all, :include => [ :todos ]) + @projects = current_user.projects.find(:all, :include => [ :todos ]) + @contexts = current_user.contexts.find(:all, :include => [ :todos ]) @contexts_to_show = @contexts.reject {|x| x.hide? } @@ -27,15 +27,15 @@ class TodosController < ApplicationController end def new - @projects = @user.projects.find(:all) - @contexts = @user.contexts.find(:all) + @projects = current_user.projects.find(:all) + @contexts = current_user.contexts.find(:all) respond_to do |format| format.m { render :action => "new_mobile" } end end def create - @todo = @user.todos.build + @todo = current_user.todos.build p = params['request'] || params if p['todo']['show_from'] && !mobile? @@ -45,9 +45,9 @@ class TodosController < ApplicationController @todo.attributes = p['todo'] if p['todo']['project_id'].blank? && !p['project_name'].blank? && p['project_name'] != 'None' - project = @user.projects.find_by_name(p['project_name'].strip) + project = current_user.projects.find_by_name(p['project_name'].strip) unless project - project = @user.projects.build + project = current_user.projects.build project.name = p['project_name'].strip project.save @new_project_created = true @@ -56,9 +56,9 @@ class TodosController < ApplicationController end if p['todo']['context_id'].blank? && !p['context_name'].blank? - context = @user.contexts.find_by_name(p['context_name'].strip) + context = current_user.contexts.find_by_name(p['context_name'].strip) unless context - context = @user.contexts.build + context = current_user.contexts.build context.name = p['context_name'].strip context.save @new_context_created = true @@ -75,7 +75,7 @@ class TodosController < ApplicationController @saved = @todo.save if @saved - @todo.tag_with(params[:tag_list],@user) if params[:tag_list] + @todo.tag_with(params[:tag_list], current_user) if params[:tag_list] @todo.reload end @@ -97,15 +97,15 @@ class TodosController < ApplicationController end def edit - @projects = @user.projects.find(:all) - @contexts = @user.contexts.find(:all) + @projects = current_user.projects.find(:all) + @contexts = current_user.contexts.find(:all) end def show respond_to do |format| format.m do - @projects = @user.projects.find(:all) - @contexts = @user.contexts.find(:all) + @projects = current_user.projects.find(:all) + @contexts = current_user.contexts.find(:all) render :action => 'show_mobile' end format.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ) } @@ -120,7 +120,7 @@ class TodosController < ApplicationController respond_to do |format| format.js do if @saved - @remaining_undone_in_context = @user.contexts.find(@todo.context_id).not_done_todo_count + @remaining_undone_in_context = current_user.contexts.find(@todo.context_id).not_done_todo_count determine_down_count determine_completed_count end @@ -145,7 +145,7 @@ class TodosController < ApplicationController end def update - @todo.tag_with(params[:tag_list],@user) if params[:tag_list] + @todo.tag_with(params[:tag_list], current_user) if params[:tag_list] @original_item_context_id = @todo.context_id @original_item_project_id = @todo.project_id @original_item_was_deferred = @todo.deferred? @@ -153,9 +153,9 @@ class TodosController < ApplicationController if params['project_name'] == 'None' project = Project.null_object else - project = @user.projects.find_by_name(params['project_name'].strip) + project = current_user.projects.find_by_name(params['project_name'].strip) unless project - project = @user.projects.build + project = current_user.projects.build project.name = params['project_name'].strip project.save @new_project_created = true @@ -165,9 +165,9 @@ class TodosController < ApplicationController end if params['todo']['context_id'].blank? && !params['context_name'].blank? - context = @user.contexts.find_by_name(params['context_name'].strip) + context = current_user.contexts.find_by_name(params['context_name'].strip) unless context - context = @user.contexts.build + context = current_user.contexts.build context.name = params['context_name'].strip context.save @new_context_created = true @@ -192,9 +192,9 @@ class TodosController < ApplicationController @saved = @todo.update_attributes params["todo"] @context_changed = @original_item_context_id != @todo.context_id @todo_was_activated_from_deferred_state = @original_item_was_deferred && @todo.active? - if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todo_count; end + if @context_changed then @remaining_undone_in_context = current_user.contexts.find(@original_item_context_id).not_done_todo_count; end @project_changed = @original_item_project_id != @todo.project_id - if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todo_count; end + if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = current_user.projects.find(@original_item_project_id).not_done_todo_count; end determine_down_count respond_to do |format| format.js @@ -231,7 +231,7 @@ class TodosController < ApplicationController determine_down_count source_view do |from| from.todo do - @remaining_undone_in_context = @user.contexts.find(@context_id).not_done_todo_count + @remaining_undone_in_context = current_user.contexts.find(@context_id).not_done_todo_count end end end @@ -245,27 +245,27 @@ class TodosController < ApplicationController def completed @page_title = "TRACKS::Completed tasks" - @done = @user.completed_todos - @done_today = @done.completed_within @user.time - 1.day - @done_this_week = @done.completed_within @user.time - 1.week - @done_this_month = @done.completed_within @user.time - 4.week + @done = current_user.completed_todos + @done_today = @done.completed_within current_user.time - 1.day + @done_this_week = @done.completed_within current_user.time - 1.week + @done_this_month = @done.completed_within current_user.time - 4.week end def completed_archive @page_title = "TRACKS::Archived completed tasks" - @done = @user.completed_todos - @done_archive = @done.completed_more_than @user.time - 28.days + @done = current_user.completed_todos + @done_archive = @done.completed_more_than current_user.time - 28.days end def list_deferred @source_view = 'deferred' @page_title = "TRACKS::Tickler" - @projects = @user.projects.find(:all, :include => [ :todos ]) - @contexts_to_show = @contexts = @user.contexts.find(:all, :include => [ :todos ]) + @projects = current_user.projects.find(:all, :include => [ :todos ]) + @contexts_to_show = @contexts = current_user.contexts.find(:all, :include => [ :todos ]) - @user.deferred_todos.find_and_activate_ready - @not_done_todos = @user.deferred_todos + current_user.deferred_todos.find_and_activate_ready + @not_done_todos = current_user.deferred_todos @count = @not_done_todos.size @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json end @@ -273,7 +273,7 @@ class TodosController < ApplicationController # Check for any due tickler items, activate them # Called by periodically_call_remote def check_deferred - @due_tickles = @user.deferred_todos.find_and_activate_ready + @due_tickles = current_user.deferred_todos.find_and_activate_ready respond_to do |format| format.html { redirect_to home_path } format.js @@ -281,12 +281,12 @@ class TodosController < ApplicationController end def filter_to_context - context = @user.contexts.find(params['context']['id']) + context = current_user.contexts.find(params['context']['id']) redirect_to formatted_context_todos_path(context, :m) end def filter_to_project - project = @user.projects.find(params['project']['id']) + project = current_user.projects.find(params['project']['id']) redirect_to formatted_project_todos_path(project, :m) end @@ -303,19 +303,19 @@ class TodosController < ApplicationController @not_done_todos = [] else tag_collection = Tag.find_by_name(tag_name).todos - @not_done_todos = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', @user.id, 'active']) + @not_done_todos = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'active']) end - @contexts = @user.contexts.find(:all, :include => [ :todos ]) + @contexts = current_user.contexts.find(:all, :include => [ :todos ]) @contexts_to_show = @contexts.reject {|x| x.hide? } - @deferred = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', @user.id, 'deferred']) + @deferred = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'deferred']) @page_title = "TRACKS::Tagged with \'#{@tag}\'" # If you've set no_completed to zero, the completed items box # isn't shown on the home page - max_completed = @user.prefs.show_number_completed - @done = tag_collection.find(:all, :limit => max_completed, :conditions => ['taggings.user_id = ? and state = ?', @user.id, 'completed']) + max_completed = current_user.prefs.show_number_completed + @done = tag_collection.find(:all, :limit => max_completed, :conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'completed']) # Set count badge to number of items with this tag @not_done_todos.empty? ? @count = 0 : @count = @not_done_todos.size @default_project_context_name_map = build_default_project_context_name_map(@projects).to_json @@ -325,7 +325,7 @@ class TodosController < ApplicationController private def get_todo_from_params - @todo = @user.todos.find(params['id']) + @todo = current_user.todos.find(params['id']) end def init @@ -353,7 +353,7 @@ class TodosController < ApplicationController if params.key?('due') due_within = params['due'].to_i - due_within_when = @user.time + due_within.days + due_within_when = current_user.time + due_within.days condition_builder.add('todos.due <= ?', due_within_when) due_within_date_s = due_within_when.strftime("%Y-%m-%d") @title << " due today" if (due_within == 0) @@ -363,7 +363,7 @@ class TodosController < ApplicationController if params.key?('done') done_in_last = params['done'].to_i - condition_builder.add('todos.completed_at >= ?', @user.time - done_in_last.days) + condition_builder.add('todos.completed_at >= ?', current_user.time - done_in_last.days) @title << " actions completed" @description << " in the last #{done_in_last.to_s} days" end @@ -376,12 +376,12 @@ class TodosController < ApplicationController def with_parent_resource_scope(&block) if (params[:context_id]) - @context = @user.contexts.find_by_params(params) + @context = current_user.contexts.find_by_params(params) Todo.with_scope :find => {:conditions => ['todos.context_id = ?', @context.id]} do yield end elsif (params[:project_id]) - @project = @user.projects.find_by_params(params) + @project = current_user.projects.find_by_params(params) Todo.with_scope :find => {:conditions => ['todos.project_id = ?', @project.id]} do yield end @@ -414,23 +414,23 @@ class TodosController < ApplicationController if mobile? - @todos, @page = @user.todos.paginate(:all, + @todos, @page = current_user.todos.paginate(:all, :conditions => ['state = ?', 'active' ], :include => [:context], :order => 'due IS NULL, due ASC, todos.created_at ASC', - :page => params[:page], :per_page => @prefs.mobile_todos_per_page) + :page => params[:page], :per_page => prefs.mobile_todos_per_page) @pagination_params = { :format => :m } @pagination_params[:context_id] = @context.to_param if @context @pagination_params[:project_id] = @project.to_param if @project else - # Note: these next two finds were previously using @users.todos.find but that broke with_scope for :limit + # Note: these next two finds were previously using current_users.todos.find but that broke with_scope for :limit # Exclude hidden projects from count on home page - @todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? or todos.state = ?', @user.id, 'active', 'completed'], :include => [ :project, :context, :tags ]) + @todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? or todos.state = ?', current_user.id, 'active', 'completed'], :include => [ :project, :context, :tags ]) # Exclude hidden projects from the home page - @not_done_todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ?', @user.id, 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ]) + @not_done_todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ?', current_user.id, 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ]) end @@ -442,19 +442,19 @@ class TodosController < ApplicationController def determine_down_count source_view do |from| from.todo do - @down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'active', false]) + @down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', current_user.id, 'active', false]) end from.context do - @down_count = @user.contexts.find(@todo.context_id).not_done_todo_count + @down_count = current_user.contexts.find(@todo.context_id).not_done_todo_count end from.project do unless @todo.project_id == nil - @down_count = @user.projects.find(@todo.project_id).not_done_todo_count - @deferred_count = @user.projects.find(@todo.project_id).deferred_todo_count + @down_count = current_user.projects.find(@todo.project_id).not_done_todo_count + @deferred_count = current_user.projects.find(@todo.project_id).deferred_todo_count end end from.deferred do - @down_count = @user.todos.count_in_state(:deferred) + @down_count = current_user.todos.count_in_state(:deferred) end end end @@ -462,14 +462,14 @@ class TodosController < ApplicationController def determine_completed_count source_view do |from| from.todo do - @completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'completed', false]) + @completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', current_user.id, 'completed', false]) end from.context do - @completed_count = @user.contexts.find(@todo.context_id).done_todo_count + @completed_count = current_user.contexts.find(@todo.context_id).done_todo_count end from.project do unless @todo.project_id == nil - @completed_count = @user.projects.find(@todo.project_id).done_todo_count + @completed_count = current_user.projects.find(@todo.project_id).done_todo_count end end end @@ -481,8 +481,8 @@ class TodosController < ApplicationController # If you've set no_completed to zero, the completed items box # isn't shown on the home page - max_completed = @user.prefs.show_number_completed - @done = @user.completed_todos.find(:all, :limit => max_completed, :include => [ :context, :project, :tags ]) unless max_completed == 0 + max_completed = current_user.prefs.show_number_completed + @done = current_user.completed_todos.find(:all, :limit => max_completed, :include => [ :context, :project, :tags ]) unless max_completed == 0 # Set count badge to number of not-done, not hidden context items @count = @todos.reject { |x| !x.active? || x.context.hide? }.size @@ -512,7 +512,7 @@ class TodosController < ApplicationController def render_rss_feed lambda do - render_rss_feed_for @todos, :feed => Todo.feed_options(@user), + render_rss_feed_for @todos, :feed => todo_feed_options, :item => { :title => :description, :link => lambda { |t| context_url(t.context) }, @@ -520,6 +520,10 @@ class TodosController < ApplicationController } end end + + def todo_feed_options + Todo.feed_options(current_user) + end def todo_feed_content lambda do |i| @@ -538,7 +542,7 @@ class TodosController < ApplicationController def render_atom_feed lambda do - render_atom_feed_for @todos, :feed => Todo.feed_options(@user), + render_atom_feed_for @todos, :feed => todo_feed_options, :item => { :title => :description, :link => lambda { |t| context_url(t.context) }, diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index 4280072f..ad5cef0a 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -2,7 +2,7 @@ module ApplicationHelper def user_time - @user.time + current_user.time end # Replicates the link_to method but also checks request.request_uri to find @@ -47,7 +47,7 @@ module ApplicationHelper "Due Tomorrow " # due 2-7 days away when 2..7 - if @user.prefs.due_style == Preference::DUE_ON_DUE_STYLE + if prefs.due_style == Preference::DUE_ON_DUE_STYLE "Due on #{due.strftime("%A")} " else "Due in #{pluralize(days, 'day')} " @@ -114,13 +114,13 @@ module ApplicationHelper def item_link_to_context(item) descriptor = "[C]" - descriptor = "[#{item.context.name}]" if (@user.prefs.verbose_action_descriptors) + descriptor = "[#{item.context.name}]" if prefs.verbose_action_descriptors link_to_context( item.context, descriptor ) end def item_link_to_project(item) descriptor = "[P]" - descriptor = "[#{item.project.name}]" if (@user.prefs.verbose_action_descriptors) + descriptor = "[#{item.project.name}]" if prefs.verbose_action_descriptors link_to_project( item.project, descriptor ) end diff --git a/tracks/app/helpers/feedlist_helper.rb b/tracks/app/helpers/feedlist_helper.rb index a8b34bb1..45ba5854 100644 --- a/tracks/app/helpers/feedlist_helper.rb +++ b/tracks/app/helpers/feedlist_helper.rb @@ -2,21 +2,28 @@ module FeedlistHelper def rss_formatted_link(options = {}) image_tag = image_tag("feed-icon.png", :size => "16X16", :border => 0, :class => "rss-icon") - linkoptions = { :token => @user.token, :format => 'rss' } - linkoptions.merge!(options) + linkoptions = merge_hashes( { :format => 'rss'}, user_token_hash, options) link_to(image_tag, linkoptions, :title => "RSS feed") end def text_formatted_link(options = {}) - linkoptions = { :token => @user.token, :format => 'txt' } - linkoptions.merge!(options) + linkoptions = merge_hashes( { :format => 'txt'}, user_token_hash, options) link_to('TXT', linkoptions, :title => "Plain text feed" ) end def ical_formatted_link(options = {}) - linkoptions = { :token => @user.token, :format => 'ics' } - linkoptions.merge!(options) + linkoptions = merge_hashes ( { :format => 'ics'}, user_token_hash, options) link_to('iCal', linkoptions, :title => "iCal feed" ) end + protected + + def merge_hashes(*hashes) + hashes.inject(Hash.new){ |result, h| result.merge(h) } + end + + def user_token_hash + { :token => current_user.token } + end + end diff --git a/tracks/app/helpers/todos_helper.rb b/tracks/app/helpers/todos_helper.rb index 593b26a3..e56020aa 100644 --- a/tracks/app/helpers/todos_helper.rb +++ b/tracks/app/helpers/todos_helper.rb @@ -107,11 +107,11 @@ module TodosHelper def staleness_class(item) if item.due || item.completed? return "" - elsif item.created_at < user_time - (@user.prefs.staleness_starts * 3).days + elsif item.created_at < user_time - (prefs.staleness_starts * 3).days return " stale_l3" - elsif item.created_at < user_time - (@user.prefs.staleness_starts * 2).days + elsif item.created_at < user_time - (prefs.staleness_starts * 2).days return " stale_l2" - elsif item.created_at < user_time - (@user.prefs.staleness_starts).days + elsif item.created_at < user_time - (prefs.staleness_starts).days return " stale_l1" else return "" @@ -138,7 +138,7 @@ module TodosHelper "Show Tomorrow " # due 2-7 days away when 2..7 - if @user.prefs.due_style == Preference::DUE_ON_DUE_STYLE + if prefs.due_style == Preference::DUE_ON_DUE_STYLE "Show on " + due.strftime("%A") + " " else "Show in " + days.to_s + " days " @@ -150,10 +150,8 @@ module TodosHelper end def calendar_setup( input_field ) - date_format = @user.prefs.date_format - week_starts = @user.prefs.week_starts - str = "Calendar.setup({ ifFormat:\"#{date_format}\"" - str << ",firstDay:#{week_starts},showOthers:true,range:[2004, 2010]" + str = "Calendar.setup({ ifFormat:\"#{prefs.date_format}\"" + str << ",firstDay:#{prefs.week_starts},showOthers:true,range:[2004, 2010]" str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n" javascript_tag str end diff --git a/tracks/app/views/contexts/show.rhtml b/tracks/app/views/contexts/show.rhtml index aeacc494..e2c4caf9 100644 --- a/tracks/app/views/contexts/show.rhtml +++ b/tracks/app/views/contexts/show.rhtml @@ -1,6 +1,6 @@
<%= render :partial => "contexts/context", :locals => { :context => @context, :collapsible => false } %> -<%= render :partial => "todos/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.prefs.show_number_completed})" } %> +<%= render :partial => "todos/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{prefs.show_number_completed})" } %>
diff --git a/tracks/app/views/layouts/standard.rhtml b/tracks/app/views/layouts/standard.rhtml index ef18bed4..cc4c2806 100644 --- a/tracks/app/views/layouts/standard.rhtml +++ b/tracks/app/views/layouts/standard.rhtml @@ -17,7 +17,7 @@ <%= javascript_include_tag "protoload" %> - <%= auto_discovery_link_tag(:rss,{:controller => "todos", :action => "index", :format => 'rss', :token => "#{@user.token}"}, {:title => "RSS feed of next actions"}) %> + <%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %>