diff --git a/tracks/app/controllers/contexts_controller.rb b/tracks/app/controllers/contexts_controller.rb index d50da8c7..bbdfc5da 100644 --- a/tracks/app/controllers/contexts_controller.rb +++ b/tracks/app/controllers/contexts_controller.rb @@ -116,21 +116,9 @@ class ContextsController < ApplicationController end def check_user_set_context - if params['url_friendly_name'] - @context = @user.contexts.find_by_url_friendly_name(params['url_friendly_name']) - elsif params['id'] && params['id'] =~ /^\d+$/ - @context = @user.contexts.find(params['id']) - elsif params['id'] - @context = @user.contexts.find_by_url_friendly_name(params['id']) - else - redirect_to :action => 'index' - end - if @context && @user == @context.user - return @context - else - @context = nil # Should be nil anyway. - notify :warning, "Item and session user mis-match: #{@context.user_id} and #{@user.id}!" - render :text => '' + @context = @user.contexts.find_by_params(params) + if @context.nil? + render :text => "Context not found.", :status => 404 end end diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb index 7c977d2f..9a5eae75 100644 --- a/tracks/app/controllers/feed_controller.rb +++ b/tracks/app/controllers/feed_controller.rb @@ -16,7 +16,7 @@ class FeedController < ApplicationController headers["Content-Type"] = "text/xml; charset=utf-8" end - # Builds a plain text page listing uncompleted next actions, + # Builds a plain text page listing incomplete next actions, # grouped by context (contexts are sorted by position, as on the home page). # Showing notes doesn't make much sense here so they are omitted. # Hidden contexts are also hidden in the text view @@ -26,20 +26,20 @@ class FeedController < ApplicationController # def text if params.key?('context') - @contexts = [ @user.contexts.find(params['context']) ] + @contexts = [ @user.contexts.find_by_params(params) ] else @contexts = @user.contexts.find_all_by_hide(false, "position ASC") end headers["Content-Type"] = "text/plain; charset=utf-8" end - # Builds an iCal compatible export of uncompleted todos + # Builds an iCal compatible export of incomplete todos # so that each action forms a VTODO in your iCal calendar. # Due dates are supported, and notes are included. # def ical if params.key?('context') - @contexts = [ @user.contexts.find(params['context']) ] + @contexts = [ @user.contexts.find_by_params(params) ] else @contexts = @user.contexts.find_all_by_hide(false, "position ASC") end @@ -69,15 +69,16 @@ protected if params.key?('limit') options[:limit] = limit = params['limit'] - @description = limit ? "Lists the last #{limit} uncompleted next actions" : "Lists uncompleted next actions" + @description = limit ? "Lists the last #{limit} incomplete next actions" : "Lists incomplete next actions" end @title = "Tracks - Next Actions" @description = "Filter: " if params.key?('due') due_within = params['due'].to_i - condition_builder.add('todos.due <= ?', due_within.days.from_now.utc) - due_within_date_s = @user.prefs.tz.adjust(due_within.days.from_now.utc).strftime("%Y-%m-%d") + due_within_when = @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) @title << " due within a week" if (due_within == 6) @description << " with a due date #{due_within_date_s} or earlier" @@ -85,20 +86,20 @@ protected if params.key?('done') done_in_last = params['done'].to_i - condition_builder.add('todos.completed_at >= ?', done_in_last.days.ago.utc) + condition_builder.add('todos.completed_at >= ?', @user.time - done_in_last.days) @title << " actions completed" @description << " in the last #{done_in_last.to_s} days" end if params.key?('context') - context = @user.contexts.find(params['context']) + context = @user.contexts.find_by_params(params) condition_builder.add('todos.context_id = ?', context.id) @title << " in #{context.name}" @description << " in context '#{context.name}'" end if params.key?('project') - project = @user.projects.find(params['project']) + project = @user.projects.find_by_params(params) condition_builder.add('todos.project_id = ?', project.id) @title << " for #{project.name}" @description << " for project '#{project.name}'" diff --git a/tracks/app/controllers/projects_controller.rb b/tracks/app/controllers/projects_controller.rb index 91a73dbf..bfa18d9b 100644 --- a/tracks/app/controllers/projects_controller.rb +++ b/tracks/app/controllers/projects_controller.rb @@ -138,22 +138,8 @@ class ProjectsController < ApplicationController end def check_user_set_project - if params["url_friendly_name"] - @project = @user.projects.find_by_url_friendly_name(params["url_friendly_name"]) - elsif params['id'] && params['id'] =~ /^\d+$/ - @project = @user.projects.find(params["id"]) - elsif params['id'] - @project = @user.projects.find_by_url_friendly_name(params["id"]) - else - redirect_to :action => 'index' - end - if @user == @project.user - return @project - else - @project = nil # Should be nil anyway - notify :warning, "Project and session user mis-match: #{@project.user_id} and #{@user.id}!" - render :text => '' - end + @project = @user.projects.find_by_params(params) + render :text => 'Project not found', :status => 404 if @project.nil? end def check_user_matches_project_user(id) diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index 8bdb7e82..fde674cf 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -213,15 +213,15 @@ class TodosController < ApplicationController def completed @page_title = "TRACKS::Completed tasks" @done = @user.completed_todos - @done_today = @done.completed_within 1.day.ago.utc - @done_this_week = @done.completed_within 1.week.ago.utc - @done_this_month = @done.completed_within 4.week.ago.utc + @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 end def completed_archive @page_title = "TRACKS::Archived completed tasks" @done = @user.completed_todos - @done_archive = @done.completed_more_than 28.day.ago.utc + @done_archive = @done.completed_more_than user_time - 28.days end def list_deferred diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index 44af293b..826ddf88 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -15,7 +15,7 @@ module ApplicationHelper end def user_time - @user.prefs.tz.adjust(Time.now.utc) + @user.time end diff --git a/tracks/app/helpers/todos_helper.rb b/tracks/app/helpers/todos_helper.rb index bf2395d0..3d6cd7eb 100644 --- a/tracks/app/helpers/todos_helper.rb +++ b/tracks/app/helpers/todos_helper.rb @@ -1,7 +1,7 @@ module TodosHelper require 'users_controller' - # Counts the number of uncompleted items in the specified context + # Counts the number of incomplete items in the specified context # def count_items(context) count = Todo.find_all("done=0 AND context_id=#{context.id}").length @@ -91,11 +91,11 @@ module TodosHelper def staleness_class(item) if item.due || item.completed? return "" - elsif item.created_at < (@user.prefs.staleness_starts * 3).days.ago.utc + elsif item.created_at < user_time - (@user.prefs.staleness_starts * 3).days return " stale_l3" - elsif item.created_at < (@user.prefs.staleness_starts * 2).days.ago.utc + elsif item.created_at < user_time - (@user.prefs.staleness_starts * 2).days return " stale_l2" - elsif item.created_at < (@user.prefs.staleness_starts).days.ago.utc + elsif item.created_at < user_time - (@user.prefs.staleness_starts).days return " stale_l1" else return "" diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index 204857a7..eb87de24 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -45,7 +45,7 @@ class Todo < ActiveRecord::Base validates_presence_of :context def validate - if deferred? && !show_from.blank? && show_from < Time.now.utc.to_date + if deferred? && !show_from.blank? && show_from < user.date errors.add("Show From", "must be a date in the future.") end end @@ -65,7 +65,7 @@ class Todo < ActiveRecord::Base def show_from=(date) activate! if deferred? && date.blank? - defer! if active? && !date.blank? && date > Time.now.utc.to_date + defer! if active? && !date.blank? && date > user.date self[:show_from] = date end diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb index d740e155..2ceccb2c 100644 --- a/tracks/app/models/user.rb +++ b/tracks/app/models/user.rb @@ -3,10 +3,34 @@ require 'digest/sha1' class User < ActiveRecord::Base has_many :contexts, :order => 'position ASC', - :dependent => :delete_all + :dependent => :delete_all do + def find_by_params(params) + if params['url_friendly_name'] + find_by_url_friendly_name(params['url_friendly_name']) + elsif params['id'] && params['id'] =~ /^\d+$/ + find(params['id']) + elsif params['id'] + find_by_url_friendly_name(params['id']) + elsif params['context'] + find_by_url_friendly_name(params['context']) + end + end + end has_many :projects, :order => 'position ASC', - :dependent => :delete_all + :dependent => :delete_all do + def find_by_params(params) + if params['url_friendly_name'] + find_by_url_friendly_name(params['url_friendly_name']) + elsif params['id'] && params['id'] =~ /^\d+$/ + find(params['id']) + elsif params['id'] + find_by_url_friendly_name(params['id']) + elsif params['project'] + find_by_url_friendly_name(params['project']) + end + end + end has_many :todos, :order => 'completed_at DESC, todos.created_at DESC', :dependent => :delete_all @@ -91,6 +115,14 @@ class User < ActiveRecord::Base def crypt_word write_attribute("word", self.class.sha1(login + Time.now.to_i.to_s + rand.to_s)) end + + def time + prefs.tz.adjust(Time.now.utc) + end + + def date + time.to_date + end protected diff --git a/tracks/app/views/contexts/_context.rhtml b/tracks/app/views/contexts/_context.rhtml index 62014a76..19eecbfd 100644 --- a/tracks/app/views/contexts/_context.rhtml +++ b/tracks/app/views/contexts/_context.rhtml @@ -28,7 +28,7 @@
-

Currently there are no uncompleted actions in this context

+

Currently there are no incomplete actions in this context

<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "context" } %>
diff --git a/tracks/app/views/feedlist/index.rhtml b/tracks/app/views/feedlist/index.rhtml index 8168477e..46ea8006 100644 --- a/tracks/app/views/feedlist/index.rhtml +++ b/tracks/app/views/feedlist/index.rhtml @@ -54,7 +54,7 @@ <%= text_formatted_link({:controller => 'projects', :action => 'index', :only_active_with_no_next_actions => true}) %> Active projects with no next actions -
  • Feeds for uncompleted actions in a specific context:

    +
  • Feeds for incomplete actions in a specific context:

  • -
  • Feeds for uncompleted actions in a specific project:

    +
  • Feeds for incomplete actions in a specific project: