fix all upgrade warnings from the rails_upgrade plugin

This commit is contained in:
Reinier Balt 2012-04-18 14:22:58 +02:00
parent fd4fb6df9e
commit fd433d76d8
47 changed files with 288 additions and 2284 deletions

View file

@ -18,9 +18,9 @@ class DataController < ApplicationController
def yaml_export
all_tables = {}
all_tables['todos'] = current_user.todos.find(:all, :include => [:tags])
all_tables['contexts'] = current_user.contexts.find(:all)
all_tables['projects'] = current_user.projects.find(:all)
all_tables['todos'] = current_user.todos.includes(:tags)
all_tables['contexts'] = current_user.contexts.all
all_tables['projects'] = current_user.projects.all
todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+
@ -34,13 +34,13 @@ class DataController < ApplicationController
"WHERE recurring_todos.user_id=? "+
"AND tags.id = taggings.tag_id " +
"AND taggings.taggable_id = recurring_todos.id ", current_user.id])
tags = Tag.find(:all, :conditions => ["id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids])
taggings = Tagging.find(:all, :conditions => ["tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids])
tags = Tag.where("id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids)
taggings = Tagging.where("tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids)
all_tables['tags'] = tags
all_tables['taggings'] = taggings
all_tables['notes'] = current_user.notes.find(:all)
all_tables['recurring_todos'] = current_user.recurring_todos.find(:all)
all_tables['notes'] = current_user.notes
all_tables['recurring_todos'] = current_user.recurring_todos
result = all_tables.to_yaml
result.gsub!(/\n/, "\r\n") # TODO: general functionality for line endings
@ -53,7 +53,7 @@ class DataController < ApplicationController
csv << ["id", "Context", "Project", "Description", "Notes", "Tags",
"Created at", "Due", "Completed at", "User ID", "Show from",
"state"]
current_user.todos.find(:all, :include => [:context, :project]).each do |todo|
current_user.todos.include(:context, :project).all.each do |todo|
csv << [todo.id, todo.context.name,
todo.project_id.nil? ? "" : todo.project.name,
todo.description,
@ -78,13 +78,13 @@ class DataController < ApplicationController
# 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
current_user.notes.find(:all,:order=>"notes.created_at").each do |note|
current_user.notes.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,
csv << [note.id, note.user_id,
note.project_id = note.project_id.nil? ? "" : note.project.name,
note.body, note.created_at.to_formatted_s(:db),
note.updated_at.to_formatted_s(:db)]
note.updated_at.to_formatted_s(:db)]
end
end
send_data(result, :filename => "notes.csv", :type => content_type)
@ -103,17 +103,17 @@ class DataController < ApplicationController
"WHERE recurring_todos.user_id=? "+
"AND tags.id = taggings.tag_id " +
"AND taggings.taggable_id = recurring_todos.id ", current_user.id])
tags = Tag.find(:all, :conditions => ["id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids])
taggings = Tagging.find(:all, :conditions => ["tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids])
tags = Tag.where("id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids)
taggings = Tagging.where("tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids)
result = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><tracks_data>"
result << current_user.todos.find(:all).to_xml(:skip_instruct => true)
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.todos.to_xml(:skip_instruct => true)
result << current_user.contexts.to_xml(:skip_instruct => true)
result << current_user.projects.to_xml(:skip_instruct => true)
result << tags.to_xml(:skip_instruct => true)
result << taggings.to_xml(:skip_instruct => true)
result << current_user.notes.find(:all).to_xml(:skip_instruct => true)
result << current_user.recurring_todos.find(:all).to_xml(:skip_instruct => true)
result << current_user.notes.to_xml(:skip_instruct => true)
result << current_user.recurring_todos.to_xml(:skip_instruct => true)
result << "</tracks_data>"
send_data(result, :filename => "tracks_data.xml", :type => 'text/xml')
end
@ -126,7 +126,7 @@ class DataController < ApplicationController
def adjust_time(timestring)
if (timestring=='') or ( timestring == nil)
return nil
else
else
return Time.parse(timestring + 'UTC')
end
end
@ -186,7 +186,7 @@ class DataController < ApplicationController
case item.ivars['attributes']['state']
when 'active' then newitem.activate!
when 'project_hidden' then newitem.hide!
when 'completed'
when 'completed'
newitem.complete!
newitem.completed_at = adjust_time(item.ivars['attributes']['completed_at'])
when 'deferred' then newitem.defer!

View file

@ -27,7 +27,8 @@ class IntegrationsController < ApplicationController
end
def search_plugin
@icon_data = [File.open(RAILS_ROOT + '/public/images/done.png').read].
# TODO: ASSET PATH!!
@icon_data = [File.open(Rails.root + '/public/images/done.png').read].
pack('m').gsub(/\n/, '')
render :layout => false
@ -52,7 +53,7 @@ class IntegrationsController < ApplicationController
message = Mail.new(params[:message])
# find user
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", message.from])
user = User.where("preferences.sms_email = ?", message.from).includes(:preferences).first
if user.nil?
render :text => "No user found", :status => 404
return false

View file

@ -13,13 +13,13 @@ class ProjectsController < ApplicationController
if params[:projects_and_actions]
projects_and_actions
else
@contexts = current_user.contexts.all
@contexts = current_user.contexts
init_not_done_counts(['project'])
init_project_hidden_todo_counts(['project'])
if params[:only_active_with_no_next_actions]
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
else
@projects = current_user.projects.all
@projects = current_user.projects
end
respond_to do |format|
format.html &render_projects_html
@ -101,15 +101,15 @@ class ProjectsController < ApplicationController
init_data_for_sidebar unless mobile?
@page_title = t('projects.page_title', :project => @project.name)
@not_done = @project.todos.active_or_hidden(:include => Todo::DEFAULT_INCLUDES)
@deferred = @project.todos.deferred(:include => Todo::DEFAULT_INCLUDES)
@pending = @project.todos.pending(:include => Todo::DEFAULT_INCLUDES)
@not_done = @project.todos.active_or_hidden.includes(Todo::DEFAULT_INCLUDES)
@deferred = @project.todos.deferred.includes(Todo::DEFAULT_INCLUDES)
@pending = @project.todos.pending.includes(Todo::DEFAULT_INCLUDES)
@done = {}
@done = @project.todos.find_in_state(:all, :completed,
:order => "todos.completed_at DESC",
:limit => current_user.prefs.show_number_completed,
:include => Todo::DEFAULT_INCLUDES) unless current_user.prefs.show_number_completed == 0
@done = @project.todos.completed.
order("todos.completed_at DESC").
limit(current_user.prefs.show_number_completed).
includes(Todo::DEFAULT_INCLUDES) unless current_user.prefs.show_number_completed == 0
@count = @not_done.size
@down_count = @count + @deferred.size + @pending.size
@ -318,7 +318,7 @@ class ProjectsController < ApplicationController
@count = current_user.projects.count
@active_projects = current_user.projects.active
@hidden_projects = current_user.projects.hidden
@completed_projects = current_user.projects.completed.find(:all, :limit => 10)
@completed_projects = current_user.projects.completed.limit(10)
@completed_count = current_user.projects.completed.count
@no_projects = current_user.projects.empty?
current_user.projects.cache_note_counts

View file

@ -9,12 +9,12 @@ class RecurringTodosController < ApplicationController
@page_title = t('todos.recurring_actions_title')
@source_view = params['_source_view'] || 'recurring_todo'
find_and_inactivate
@recurring_todos = current_user.recurring_todos.active.find(:all, :include => [:tags, :taggings])
@completed_recurring_todos = current_user.recurring_todos.completed.find(:all, :limit => 10, :include => [:tags, :taggings])
@recurring_todos = current_user.recurring_todos.active.includes(:tags, :taggings)
@completed_recurring_todos = current_user.recurring_todos.completed.limit(10).includes(:tags, :taggings)
@no_recurring_todos = @recurring_todos.size == 0
@no_completed_recurring_todos = @completed_recurring_todos.size == 0
@count = @recurring_todos.size
@no_recurring_todos = @recurring_todos.count == 0
@no_completed_recurring_todos = @completed_recurring_todos.count == 0
@count = @recurring_todos.count
@new_recurring_todo = RecurringTodo.new
end
@ -271,8 +271,8 @@ class RecurringTodosController < ApplicationController
end
@xth_day = [[t('common.first'),1],[t('common.second'),2],[t('common.third'),3],[t('common.fourth'),4],[t('common.last'),5]]
@projects = current_user.projects.find(:all, :include => [:default_context])
@contexts = current_user.contexts.find(:all)
@projects = current_user.projects.includes(:default_context)
@contexts = current_user.contexts
end
def get_recurring_todo_from_param
@ -282,10 +282,11 @@ class RecurringTodosController < ApplicationController
def find_and_inactivate
# find active recurring todos without active todos and inactivate them
current_user.recurring_todos.active.all(
:select => "recurring_todos.id, recurring_todos.state",
:joins => "LEFT JOIN todos fai_todos ON (recurring_todos.id = fai_todos.recurring_todo_id) AND (NOT fai_todos.state='completed')",
:conditions => "fai_todos.id IS NULL").each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
current_user.recurring_todos.active.
select("recurring_todos.id, recurring_todos.state").
joins("LEFT JOIN todos fai_todos ON (recurring_todos.id = fai_todos.recurring_todo_id) AND (NOT fai_todos.state='completed')").
where("fai_todos.id IS NULL").
each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
end
end

View file

@ -7,19 +7,22 @@ class SearchController < ApplicationController
@page_title = "TRACKS::Search Results for #{params[:search]}"
terms = '%' + params[:search] + '%'
@found_not_complete_todos = current_user.todos.find(:all,
:conditions => ["(todos.description LIKE ? OR todos.notes LIKE ?) AND todos.completed_at IS NULL", terms, terms],
:include => Todo::DEFAULT_INCLUDES,
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
@found_complete_todos = current_user.todos.find(:all,
:conditions => ["(todos.description LIKE ? OR todos.notes LIKE ?) AND NOT (todos.completed_at IS NULL)", terms, terms],
:include => Todo::DEFAULT_INCLUDES,
:order => "todos.completed_at DESC")
@found_not_complete_todos = current_user.todos.
where("(todos.description LIKE ? OR todos.notes LIKE ?) AND todos.completed_at IS NULL", terms, terms).
includes(Todo::DEFAULT_INCLUDES).
order("todos.due IS NULL, todos.due ASC, todos.created_at ASC")
@found_complete_todos = current_user.todos.
where("(todos.description LIKE ? OR todos.notes LIKE ?) AND NOT (todos.completed_at IS NULL)", terms, terms).
includes(Todo::DEFAULT_INCLUDES).
order("todos.completed_at DESC")
@found_todos = @found_not_complete_todos + @found_complete_todos
@found_projects = current_user.projects.find(:all, :conditions => ["name LIKE ? OR description LIKE ?", terms, terms])
@found_notes = current_user.notes.find(:all, :conditions => ["body LIKE ?", terms])
@found_contexts = current_user.contexts.find(:all, :conditions => ["name LIKE ?", terms])
@found_projects = current_user.projects.where("name LIKE ? OR description LIKE ?", terms, terms)
@found_notes = current_user.notes.where("body LIKE ?", terms)
@found_contexts = current_user.contexts.where("name LIKE ?", terms)
# TODO: limit search to tags on todos
@found_tags = Tagging.find_by_sql([
"SELECT DISTINCT tags.name as name "+

View file

@ -1,8 +1,7 @@
class StatsController < ApplicationController
helper :todos, :projects, :recurring_todos
append_before_filter :init, :exclude => []
append_before_filter :init
def index
@page_title = t('stats.index_title')
@ -10,7 +9,7 @@ class StatsController < ApplicationController
@tags_count = get_total_number_of_tags_of_user
@unique_tags_count = get_unique_tags_of_user.size
@hidden_contexts = current_user.contexts.hidden
@first_action = current_user.todos.find(:first, :order => "created_at ASC")
@first_action = current_user.todos.order("created_at ASC").first
get_stats_actions
get_stats_contexts
@ -23,10 +22,10 @@ class StatsController < ApplicationController
def actions_done_last12months_data
# get actions created and completed in the past 12+3 months. +3 for running
# average
@actions_done_last12months = current_user.todos.completed_after(@cut_off_year).find(:all, { :select => "completed_at" })
@actions_created_last12months = current_user.todos.created_after(@cut_off_year).find(:all, { :select => "created_at"})
@actions_done_last12monthsPlus3 = current_user.todos.completed_after(@cut_off_year_plus3).find(:all, { :select => "completed_at" })
@actions_created_last12monthsPlus3 = current_user.todos.created_after(@cut_off_year_plus3).find(:all, { :select => "created_at"})
@actions_done_last12months = current_user.todos.completed_after(@cut_off_year).select("completed_at" )
@actions_created_last12months = current_user.todos.created_after(@cut_off_year).select("created_at")
@actions_done_last12monthsPlus3 = current_user.todos.completed_after(@cut_off_year_plus3).select("completed_at" )
@actions_created_last12monthsPlus3 = current_user.todos.created_after(@cut_off_year_plus3).select("created_at")
# convert to array and fill in non-existing months
@actions_done_last12months_array = convert_to_months_from_today_array(@actions_done_last12months, 13, :completed_at)
@ -56,8 +55,8 @@ class StatsController < ApplicationController
end
def actions_done_lastyears_data
@actions_done_last_months = current_user.todos.completed.find(:all, { :select => "completed_at", :order => "completed_at DESC" })
@actions_created_last_months = current_user.todos.find(:all, { :select => "created_at", :order => "created_at DESC" })
@actions_done_last_months = current_user.todos.completed.select("completed_at").order("completed_at DESC")
@actions_created_last_months = current_user.todos.select("created_at").order("created_at DESC" )
# query is sorted, so use last todo to calculate number of months
@month_count = [difference_in_months(@today, @actions_created_last_months.last.created_at),
@ -88,8 +87,8 @@ class StatsController < ApplicationController
def actions_done_last30days_data
# get actions created and completed in the past 30 days.
@actions_done_last30days = current_user.todos.completed_after(@cut_off_month).find(:all, { :select => "completed_at" })
@actions_created_last30days = current_user.todos.created_after(@cut_off_month).find(:all, { :select => "created_at" })
@actions_done_last30days = current_user.todos.completed_after(@cut_off_month).select("completed_at")
@actions_created_last30days = current_user.todos.created_after(@cut_off_month).select("created_at")
# convert to array. 30+1 to have 30 complete days and one current day [0]
@actions_done_last30days_array = convert_to_days_from_today_array(@actions_done_last30days, 31, :completed_at)
@ -102,7 +101,7 @@ class StatsController < ApplicationController
end
def actions_completion_time_data
@actions_completion_time = current_user.todos.completed.find(:all, { :select => "completed_at, created_at", :order => "completed_at DESC" })
@actions_completion_time = current_user.todos.completed.select("completed_at, created_at").order("completed_at DESC" )
# convert to array and fill in non-existing weeks with 0
@max_weeks = difference_in_weeks(@today, @actions_completion_time.last.completed_at)
@ -122,7 +121,7 @@ class StatsController < ApplicationController
end
def actions_running_time_data
@actions_running_time = current_user.todos.not_completed.find(:all, { :select => "created_at", :order => "created_at DESC" })
@actions_running_time = current_user.todos.not_completed.select("created_at").order("created_at DESC")
# convert to array and fill in non-existing weeks with 0
@max_weeks = difference_in_weeks(@today, @actions_running_time.last.created_at)
@ -150,8 +149,9 @@ class StatsController < ApplicationController
# - actions not deferred (show_from must be null)
# - actions not pending/blocked
@actions_running_time = current_user.todos.not_completed.not_hidden.not_deferred_or_blocked.find(
:all, :select => "todos.created_at", :order => "todos.created_at DESC")
@actions_running_time = current_user.todos.not_completed.not_hidden.not_deferred_or_blocked.
select("todos.created_at").
order("todos.created_at DESC")
@max_weeks = difference_in_weeks(@today, @actions_running_time.last.created_at)
@actions_running_per_week_array = convert_to_weeks_from_today_array(@actions_running_time, @max_weeks+1, :created_at)
@ -170,8 +170,9 @@ class StatsController < ApplicationController
end
def actions_open_per_week_data
@actions_started = current_user.todos.created_after(@today-53.weeks).find(:all,
:select => "todos.created_at, todos.completed_at",:order => "todos.created_at DESC")
@actions_started = current_user.todos.created_after(@today-53.weeks).
select("todos.created_at, todos.completed_at").
order("todos.created_at DESC")
@max_weeks = difference_in_weeks(@today, @actions_started.last.created_at)
@ -259,8 +260,8 @@ class StatsController < ApplicationController
end
def actions_day_of_week_all_data
@actions_creation_day = current_user.todos.find(:all, { :select => "created_at" })
@actions_completion_day = current_user.todos.completed.find(:all, { :select => "completed_at" })
@actions_creation_day = current_user.todos.select("created_at")
@actions_completion_day = current_user.todos.completed.select("completed_at")
# convert to array and fill in non-existing days
@actions_creation_day_array = Array.new(7) { |i| 0}
@ -276,8 +277,8 @@ class StatsController < ApplicationController
end
def actions_day_of_week_30days_data
@actions_creation_day = current_user.todos.created_after(@cut_off_month).find(:all, { :select => "created_at" })
@actions_completion_day = current_user.todos.completed_after(@cut_off_month).find(:all, { :select => "completed_at" })
@actions_creation_day = current_user.todos.created_after(@cut_off_month).select("created_at")
@actions_completion_day = current_user.todos.completed_after(@cut_off_month).select("completed_at")
# convert to hash to be able to fill in non-existing days
@max=0
@ -294,8 +295,8 @@ class StatsController < ApplicationController
end
def actions_time_of_day_all_data
@actions_creation_hour = current_user.todos.find(:all, { :select => "created_at" })
@actions_completion_hour = current_user.todos.completed.find(:all, { :select => "completed_at" })
@actions_creation_hour = current_user.todos.select("created_at")
@actions_completion_hour = current_user.todos.completed.select("completed_at")
# convert to hash to be able to fill in non-existing days
@actions_creation_hour_array = Array.new(24) { |i| 0}
@ -311,8 +312,8 @@ class StatsController < ApplicationController
end
def actions_time_of_day_30days_data
@actions_creation_hour = current_user.todos.created_after(@cut_off_month).find(:all, { :select => "created_at" })
@actions_completion_hour = current_user.todos.completed_after(@cut_off_month).find(:all, { :select => "completed_at" })
@actions_creation_hour = current_user.todos.created_after(@cut_off_month).select("created_at")
@actions_completion_hour = current_user.todos.completed_after(@cut_off_month).select("completed_at")
# convert to hash to be able to fill in non-existing days
@actions_creation_hour_array = Array.new(24) { |i| 0}
@ -355,11 +356,12 @@ class StatsController < ApplicationController
end
# get all running actions that are visible
@actions_running_time = current_user.todos.not_completed.not_hidden.not_deferred_or_blocked.find(
:all, :select => "todos.id, todos.created_at", :order => "todos.created_at DESC")
@actions_running_time = current_user.todos.not_completed.not_hidden.not_deferred_or_blocked.
select("todos.id, todos.created_at").
order("todos.created_at DESC")
selected_todo_ids = get_ids_from(@actions_running_time, week_from, week_to, params['id']== 'avrt_end')
@selected_actions = selected_todo_ids.size == 0 ? [] : current_user.todos.find(:all, { :conditions => "id in (" + selected_todo_ids.join(",") + ")" })
@selected_actions = selected_todo_ids.size == 0 ? [] : current_user.todos.where("id in (" + selected_todo_ids.join(",") + ")")
@count = @selected_actions.size
render :action => "show_selection_from_chart"
@ -379,10 +381,10 @@ class StatsController < ApplicationController
end
# get all running actions
@actions_running_time = current_user.todos.not_completed.find(:all, { :select => "id, created_at" })
@actions_running_time = current_user.todos.not_completed.select("id, created_at")
selected_todo_ids = get_ids_from(@actions_running_time, week_from, week_to, params['id']=='art_end')
@selected_actions = selected_todo_ids.size == 0 ? [] : current_user.todos.find(:all, { :conditions => "id in (" + selected_todo_ids.join(",") + ")" })
@selected_actions = selected_todo_ids.size == 0 ? [] : current_user.todos.where("id in (#{selected_todo_ids.join(",")})")
@count = @selected_actions.size
render :action => "show_selection_from_chart"
@ -397,10 +399,10 @@ class StatsController < ApplicationController
init_not_done_counts
@done_recently = current_user.todos.completed.all(:limit => 10, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES)
@last_completed_projects = current_user.projects.completed.all(:limit => 10, :order => 'completed_at DESC', :include => [:todos, :notes])
@done_recently = current_user.todos.completed.limit(10).order('completed_at DESC').includes(Todo::DEFAULT_INCLUDES)
@last_completed_projects = current_user.projects.completed.limit(10).order('completed_at DESC').includes(:todos, :notes)
@last_completed_contexts = []
@last_completed_recurring_todos = current_user.recurring_todos.completed.all(:limit => 10, :order => 'completed_at DESC', :include => [:tags, :taggings])
@last_completed_recurring_todos = current_user.recurring_todos.completed.limit(10).order('completed_at DESC').includes(:tags, :taggings)
#TODO: @last_completed_contexts = current_user.contexts.completed.all(:limit => 10, :order => 'completed_at DESC')
end
@ -415,7 +417,7 @@ class StatsController < ApplicationController
"AND todos.user_id = #{current_user.id}"])
tags_ids_s = tag_ids.map(&:id).sort.join(",")
return {} if tags_ids_s.blank? # return empty hash for .size to work
return Tag.find(:all, :conditions => "id in (" + tags_ids_s + ")")
return Tag.where("id in (#{tags_ids_s})")
end
def get_total_number_of_tags_of_user
@ -452,7 +454,7 @@ class StatsController < ApplicationController
def get_stats_actions
# time to complete
@completed_actions = current_user.todos.completed.find(:all, { :select => "completed_at, created_at" })
@completed_actions = current_user.todos.completed.select("completed_at, created_at")
actions_sum, actions_max = 0,0
actions_min = @completed_actions.first ? @completed_actions.first.completed_at - @completed_actions.first.created_at : 0
@ -475,12 +477,12 @@ class StatsController < ApplicationController
@actions_min_ttc_sec = (actions_min / @seconds_per_day).round.to_s + " days " + @actions_min_ttc_sec if actions_min > @seconds_per_day
# get count of actions created and actions done in the past 30 days.
@sum_actions_done_last30days = current_user.todos.completed.completed_after(@cut_off_month).count(:all)
@sum_actions_created_last30days = current_user.todos.created_after(@cut_off_month).count(:all)
@sum_actions_done_last30days = current_user.todos.completed.completed_after(@cut_off_month).count
@sum_actions_created_last30days = current_user.todos.created_after(@cut_off_month).count
# get count of actions done in the past 12 months.
@sum_actions_done_last12months = current_user.todos.completed.completed_after(@cut_off_year).count(:all)
@sum_actions_created_last12months = current_user.todos.created_after(@cut_off_year).count(:all)
@sum_actions_done_last12months = current_user.todos.completed.completed_after(@cut_off_year).count
@sum_actions_created_last12months = current_user.todos.created_after(@cut_off_year).count
end
def get_stats_contexts

View file

@ -18,7 +18,7 @@ class TodosController < ApplicationController
extend ActionView::Helpers::SanitizeHelper::ClassMethods
def index
@projects = current_user.projects.all(:include => [:default_context])
@projects = current_user.projects.includes(:default_context)
@contexts = current_user.contexts
@contexts_to_show = current_user.contexts.active
@ -36,7 +36,7 @@ class TodosController < ApplicationController
def new
@projects = current_user.projects.active
@contexts = current_user.contexts.find(:all)
@contexts = current_user.contexts
respond_to do |format|
format.m {
@new_mobile = true
@ -126,16 +126,16 @@ class TodosController < ApplicationController
if @saved
redirect_to @return_path
else
@projects = current_user.projects.find(:all)
@contexts = current_user.contexts.find(:all)
@projects = current_user.projects
@contexts = current_user.contexts
render :action => "new"
end
end
format.js do
if @saved
determine_down_count
@contexts = current_user.contexts.find(:all) if @new_context_created
@projects = current_user.projects.find(:all) if @new_project_created
@contexts = current_user.contexts if @new_context_created
@projects = current_user.projects if @new_project_created
@initial_context_name = params['default_context_name']
@initial_project_name = params['default_project_name']
@initial_tags = params['initial_tag_list']
@ -225,8 +225,8 @@ class TodosController < ApplicationController
format.html { redirect_to :action => "index" }
format.js do
determine_down_count if @saved
@contexts = current_user.contexts.find(:all) if @new_context_created
@projects = current_user.projects.find(:all) if @new_project_created
@contexts = current_user.contexts if @new_context_created
@projects = current_user.projects if @new_project_created
@initial_context_name = params['default_context_name']
@initial_project_name = params['default_project_name']
@initial_tags = params['initial_tag_list']
@ -255,14 +255,14 @@ class TodosController < ApplicationController
end
def edit
@todo = current_user.todos.find(params['id'], :include => Todo::DEFAULT_INCLUDES)
@todo = current_user.todos.find_by_id(params['id']).includes(Todo::DEFAULT_INCLUDES)
@source_view = params['_source_view'] || 'todo'
@tag_name = params['_tag_name']
respond_to do |format|
format.js
format.m {
@projects = current_user.projects.active
@contexts = current_user.contexts.find(:all)
@contexts = current_user.contexts
@edit_mobile = true
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
render :template => "/todos/edit_mobile.html.erb"
@ -271,7 +271,7 @@ class TodosController < ApplicationController
end
def show
@todo = current_user.todos.find(params['id'])
@todo = current_user.todos.find_by_id(params['id'])
respond_to do |format|
format.m { render :action => 'show' }
format.xml { render :xml => @todo.to_xml( *to_xml_params ) }
@ -280,9 +280,9 @@ class TodosController < ApplicationController
def add_predecessor
@source_view = params['_source_view'] || 'todo'
@predecessor = current_user.todos.find(params['predecessor'])
@predecessor = current_user.todos.find_by_id(params['predecessor'])
@predecessors = @predecessor.predecessors
@todo = current_user.todos.find(params['successor'], :include => Todo::DEFAULT_INCLUDES)
@todo = current_user.todos.find_by_id(params['successor']).includes(Todo::DEFAULT_INCLUDES)
@original_state = @todo.state
unless @predecessor.completed?
@todo.add_predecessor(@predecessor)
@ -301,8 +301,8 @@ class TodosController < ApplicationController
def remove_predecessor
@source_view = params['_source_view'] || 'todo'
@todo = current_user.todos.find(params['id'], :include => Todo::DEFAULT_INCLUDES)
@predecessor = current_user.todos.find(params['predecessor'])
@todo = current_user.todos.find_by_id(params['id']).includes(Todo::DEFAULT_INCLUDES)
@predecessor = current_user.todos.find_by_id(params['predecessor'])
@predecessors = @predecessor.predecessors
@successor = @todo
@removed = @successor.remove_predecessor(@predecessor)
@ -315,7 +315,7 @@ class TodosController < ApplicationController
# Toggles the 'done' status of the action
#
def toggle_check
@todo = current_user.todos.find(params['id'])
@todo = current_user.todos.find_by_id(params['id'])
@source_view = params['_source_view'] || 'todo'
@original_item_due = @todo.due
@original_item_was_deferred = @todo.deferred?
@ -385,7 +385,7 @@ class TodosController < ApplicationController
end
def toggle_star
@todo = current_user.todos.find(params['id'])
@todo = current_user.todos.find_by_id(params['id'])
@todo.toggle_star!
@saved = true # cannot determine error
respond_to do |format|
@ -408,9 +408,9 @@ class TodosController < ApplicationController
def change_context
# TODO: is this method used?
@todo = Todo.find(params[:todo][:id])
@todo = Todo.find_by_id(params[:todo][:id])
@original_item_context_id = @todo.context_id
@context = Context.find(params[:todo][:context_id])
@context = Context.find_by_id(params[:todo][:context_id])
@todo.context = @context
@saved = @todo.save
@ -426,7 +426,7 @@ class TodosController < ApplicationController
end
def update
@todo = current_user.todos.find(params['id'])
@todo = current_user.todos.find_by_id(params['id'])
@source_view = params['_source_view'] || 'todo'
init_data_for_sidebar unless mobile?
@ -480,7 +480,7 @@ class TodosController < ApplicationController
def destroy
@source_view = params['_source_view'] || 'todo'
@todo = current_user.todos.find(params['id'])
@todo = current_user.todos.find_by_id(params['id'])
@original_item_due = @todo.due
@context_id = @todo.context_id
@project_id = @todo.project_id
@ -565,7 +565,7 @@ class TodosController < ApplicationController
@source_view = 'done'
@page_title = t('todos.completed_tasks_title')
@done = current_user.todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@done = current_user.todos.completed.includes(Todo::DEFAULT_INCLUDES).order('completed_at DESC').paginate :page => params[:page], :per_page => 20
@count = @done.size
end
@ -577,7 +577,7 @@ class TodosController < ApplicationController
includes = params[:format]=='xml' ? [:context, :project] : Todo::DEFAULT_INCLUDES
@not_done_todos = current_user.todos.deferred(:include => includes) + current_user.todos.pending(:include => includes)
@not_done_todos = current_user.todos.deferred.includes(includes) + current_user.todos.pending.includes(includes)
@down_count = @count = @not_done_todos.size
respond_to do |format|
@ -587,8 +587,8 @@ class TodosController < ApplicationController
end
end
# Check for any due tickler items, activate them Called by
# periodically_call_remote
# Check for any due tickler items, activate them
# Called by periodically_call_remote
def check_deferred
@due_tickles = current_user.deferred_todos.find_and_activate_ready
respond_to do |format|
@ -598,12 +598,12 @@ class TodosController < ApplicationController
end
def filter_to_context
context = current_user.contexts.find(params['context']['id'])
context = current_user.contexts.find_by_id(params['context']['id'])
redirect_to context_todos_path(context, :format => 'm')
end
def filter_to_project
project = current_user.projects.find(params['project']['id'])
project = current_user.projects.find_by_id(params['project']['id'])
redirect_to project_todos_path(project, :format => 'm')
end
@ -622,21 +622,29 @@ class TodosController < ApplicationController
todos_with_tag_ids = find_todos_with_tag_expr(@tag_expr)
@not_done_todos = todos_with_tag_ids.active.not_hidden.find(:all,
:order => 'todos.due IS NULL, todos.due ASC, todos.created_at ASC', :include => Todo::DEFAULT_INCLUDES)
@hidden_todos = todos_with_tag_ids.hidden.find(:all,
:include => Todo::DEFAULT_INCLUDES,
:order => 'todos.completed_at DESC, todos.created_at DESC')
@deferred = todos_with_tag_ids.deferred.find(:all,
:order => 'todos.show_from ASC, todos.created_at DESC', :include => Todo::DEFAULT_INCLUDES)
@pending = todos_with_tag_ids.blocked.find(:all,
:order => 'todos.show_from ASC, todos.created_at DESC', :include => Todo::DEFAULT_INCLUDES)
@not_done_todos = todos_with_tag_ids.
active.not_hidden.
order('todos.due IS NULL, todos.due ASC, todos.created_at ASC').
includes(Todo::DEFAULT_INCLUDES)
@hidden_todos = todos_with_tag_ids.
hidden.
order('todos.completed_at DESC, todos.created_at DESC').
includes(Todo::DEFAULT_INCLUDES)
@deferred = todos_with_tag_ids.
deferred.
order('todos.show_from ASC, todos.created_at DESC').
includes(Todo::DEFAULT_INCLUDES)
@pending = todos_with_tag_ids.
blocked.
order('todos.show_from ASC, todos.created_at DESC').
includes(Todo::DEFAULT_INCLUDES)
# If you've set no_completed to zero, the completed items box isn't shown on
# the tag page
@done = todos_with_tag_ids.completed.find(:all,
:limit => current_user.prefs.show_number_completed,
:order => 'todos.completed_at DESC', :include => Todo::DEFAULT_INCLUDES)
@done = todos_with_tag_ids.completed.
limit(current_user.prefs.show_number_completed).
order('todos.completed_at DESC').
includes(Todo::DEFAULT_INCLUDES)
@projects = current_user.projects
@contexts = current_user.contexts
@ -688,15 +696,15 @@ class TodosController < ApplicationController
@tag = Tag.find_by_name(@tag_name)
@tag = Tag.new(:name => @tag_name) if @tag.nil?
@done = current_user.todos.completed.with_tag(@tag.id).paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@done = current_user.todos.completed.with_tag(@tag.id).order('completed_at DESC').includes(Todo::DEFAULT_INCLUDES).paginate :page => params[:page], :per_page => 20
@count = @done.size
render :template => 'todos/all_done'
end
def tags
# TODO: limit to current_user
tags_beginning = Tag.find(:all, :conditions => ['name like ?', params[:term]+'%'])
tags_all = Tag.find(:all, :conditions =>['name like ?', '%'+params[:term]+'%'])
tags_beginning = Tag.where('name like ?', params[:term]+'%')
tags_all = Tag.where('name like ?', '%'+params[:term]+'%')
tags_all= tags_all - tags_beginning
respond_to do |format|
@ -708,7 +716,7 @@ class TodosController < ApplicationController
@source_view = params['_source_view'] || 'todo'
numdays = params['days'].to_i
@todo = current_user.todos.find(params[:id])
@todo = current_user.todos.find_by_id(params[:id])
@original_item_context_id = @todo.context_id
@todo_deferred_state_changed = true
@new_context_created = false
@ -725,7 +733,7 @@ class TodosController < ApplicationController
determine_remaining_in_context_count(@todo.context_id)
source_view do |page|
page.project {
@remaining_undone_in_project = current_user.projects.find(@todo.project_id).todos.not_completed.count
@remaining_undone_in_project = current_user.projects.find_by_id(@todo.project_id).todos.not_completed.count
@original_item_project_id = @todo.project_id
}
page.tag {
@ -753,45 +761,45 @@ class TodosController < ApplicationController
@source_view = params['_source_view'] || 'calendar'
@page_title = t('todos.calendar_page_title')
@projects = current_user.projects.find(:all)
@projects = current_user.projects
due_today_date = Time.zone.now
due_this_week_date = Time.zone.now.end_of_week
due_this_week_date = due_today_date.end_of_week
due_next_week_date = due_this_week_date + 7.days
due_this_month_date = Time.zone.now.end_of_month
due_this_month_date = due_today_date.end_of_month
included_tables = Todo::DEFAULT_INCLUDES
@due_today = current_user.todos.not_completed.find(:all,
:include => included_tables,
:conditions => ['todos.due <= ?', due_today_date],
:order => "due")
@due_this_week = current_user.todos.not_completed.find(:all,
:include => included_tables,
:conditions => ['todos.due > ? AND todos.due <= ?', due_today_date, due_this_week_date],
:order => "due")
@due_next_week = current_user.todos.not_completed.find(:all,
:include => included_tables,
:conditions => ['todos.due > ? AND todos.due <= ?', due_this_week_date, due_next_week_date],
:order => "due")
@due_this_month = current_user.todos.not_completed.find(:all,
:include => included_tables,
:conditions => ['todos.due > ? AND todos.due <= ?', due_next_week_date, due_this_month_date],
:order => "due")
@due_after_this_month = current_user.todos.not_completed.find(:all,
:include => included_tables,
:conditions => ['todos.due > ?', due_this_month_date],
:order => "due")
@due_today = current_user.todos.not_completed.
where('todos.due <= ?', due_today_date).
includes(included_tables).
order("due")
@due_this_week = current_user.todos.not_completed.
where('todos.due > ? AND todos.due <= ?', due_today_date, due_this_week_date).
includes(included_tables).
order("due")
@due_next_week = current_user.todos.not_completed.
where('todos.due > ? AND todos.due <= ?', due_this_week_date, due_next_week_date).
includes(included_tables).
order("due")
@due_this_month = current_user.todos.not_completed.
where('todos.due > ? AND todos.due <= ?', due_next_week_date, due_this_month_date).
includes(included_tables).
order("due")
@due_after_this_month = current_user.todos.not_completed.
where('todos.due > ?', due_this_month_date).
includes(included_tables).
order("due")
@count = current_user.todos.not_completed.are_due.count
respond_to do |format|
format.html
format.ics {
@due_all = current_user.todos.not_completed.are_due.find(:all, :order => "due")
@due_all = current_user.todos.not_completed.are_due.order("due")
render :action => 'calendar', :layout => false, :content_type => Mime::ICS
}
format.xml {
@due_all = current_user.todos.not_completed.are_due.find(:all, :order => "due")
@due_all = current_user.todos.not_completed.are_due.order("due")
render :xml => @due_all.to_xml( *to_xml_params )
}
end
@ -810,40 +818,36 @@ class TodosController < ApplicationController
unless params['id'].nil?
get_todo_from_params
# Begin matching todos in current project, excluding @todo itself
@items = @todo.project.todos.not_completed.find(:all,
:include => [:context, :project],
:conditions => ['(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id],
:order => 'description ASC',
:limit => 10
) unless @todo.project.nil?
@items = @todo.project.todos.not_completed.
where('(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id).
includes(:context, :project).
order('description ASC').
limit(10) unless @todo.project.nil?
# Then look in the current context, excluding @todo itself
@items = @todo.context.todos.not_completed.find(:all,
:include => [:context, :project],
:conditions => ['(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id],
:order => 'description ASC',
:limit => 10
) unless !@items.empty? || @todo.context.nil?
@items = @todo.context.todos.not_completed
where('(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id).
includes(:context, :project).
order('description ASC').
limit(10) unless !@items.empty? || @todo.context.nil?
# Match todos in other projects, excluding @todo itself
@items = current_user.todos.not_completed.find(:all,
:include => [:context, :project],
:conditions => ['(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id],
:order => 'description ASC',
:limit => 10
) unless !@items.empty?
@items = current_user.todos.not_completed.
where('(LOWER(todos.description) LIKE ?) AND NOT(todos.id=?)', "%#{params[:term].downcase}%", @todo.id).
includes(:context, :project).
order('description ASC').
limit(10) unless !@items.empty?
else
# New todo - TODO: Filter on current project in project view
@items = current_user.todos.not_completed.find(:all,
:include => [:context, :project],
:conditions => ['(LOWER(todos.description) LIKE ?)', "%#{params[:term].downcase}%"],
:order => 'description ASC',
:limit => 10
)
@items = current_user.todos.not_completed.
where('(LOWER(todos.description) LIKE ?)', "%#{params[:term].downcase}%").
includes(:context, :project).
order('description ASC').
limit(10)
end
render :inline => format_dependencies_as_json_for_auto_complete(@items)
end
def convert_to_project
@todo = current_user.todos.find(params[:id])
@todo = current_user.todos.find_by_id(params[:id])
@project = current_user.projects.new(:name => @todo.description, :description => @todo.notes,
:default_context => @todo.context)
@ -858,7 +862,7 @@ class TodosController < ApplicationController
end
def show_notes
@todo = current_user.todos.find(params['id'])
@todo = current_user.todos.find_by_id(params['id'])
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
respond_to do |format|
format.html {
@ -883,7 +887,7 @@ class TodosController < ApplicationController
def get_todo_from_params
# TODO: this was a :append_before but was removed to tune performance per
# method. Reconsider re-enabling it
@todo = current_user.todos.find(params['id'])
@todo = current_user.todos.find_by_id(params['id'])
end
def find_and_activate_ready
@ -898,7 +902,7 @@ class TodosController < ApplicationController
def with_feed_query_scope(&block)
unless TodosController.is_feed_request(request)
Todo.send(:with_scope, :find => {:conditions => ['todos.state = ?', 'active']}) do
Todo.send(:where, ['todos.state = ?', 'active']) do
yield
return
end
@ -939,7 +943,7 @@ class TodosController < ApplicationController
condition_builder.add('taggings.tag_id = ?', tag.id)
end
Todo.send :with_scope, :find => {:conditions => condition_builder.to_conditions} do
Todo.send :where, condition_builder.to_conditions do
yield
end
@ -950,14 +954,14 @@ class TodosController < ApplicationController
if (params[:context_id])
@context = current_user.contexts.find_by_params(params)
@feed_title = @feed_title + t('todos.feed_title_in_context', :context => @context.name)
Todo.send :with_scope, :find => {:conditions => ['todos.context_id = ?', @context.id]} do
Todo.send :where, ['todos.context_id = ?', @context.id] do
yield
end
elsif (params[:project_id])
@project = current_user.projects.find_by_params(params)
@feed_title = @feed_title + t('todos.feed_title_in_project', :project => @project.name)
@project_feed = true
Todo.send :with_scope, :find => {:conditions => ['todos.project_id = ?', @project.id]} do
Todo.send :where, ['todos.project_id = ?', @project.id] do
yield
end
else
@ -995,13 +999,13 @@ class TodosController < ApplicationController
# current_users.todos.find but that broke with_scope for :limit
# Exclude hidden projects from count on home page
@todos = current_user.todos.find(:all, :include => Todo::DEFAULT_INCLUDES)
@todos = current_user.todos.includes(Todo::DEFAULT_INCLUDES)
# Exclude hidden projects from the home page
@not_done_todos = current_user.todos.find(:all,
:conditions => ['contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', false, 'active'],
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:include => Todo::DEFAULT_INCLUDES)
@not_done_todos = current_user.todos.
where('contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', false, 'active').
order("todos.due IS NULL, todos.due ASC, todos.created_at ASC").
includes(Todo::DEFAULT_INCLUDES)
end
end
@ -1014,10 +1018,10 @@ class TodosController < ApplicationController
# but that broke with_scope for :limit
# Exclude hidden projects from the home page
@not_done_todos = current_user.todos.find(:all,
:conditions => ['todos.state = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', 'active', false, 'active'],
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:include => [ :project, :context, :tags ])
@not_done_todos = current_user.todos.
where('todos.state = ? AND contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', 'active', false, 'active').
order("todos.due IS NULL, todos.due ASC, todos.created_at ASC").
includes(:project, :context, :tags)
end
def tag_title(tag_expr)
@ -1079,23 +1083,23 @@ class TodosController < ApplicationController
end
from.context do
context_id = @original_item_context_id || @todo.context_id
todos = current_user.contexts.find(context_id).todos.not_completed
todos = current_user.contexts.find_by_id(context_id).todos.not_completed
if @todo.context.hide?
# include hidden todos
@down_count = todos.count(:all)
@down_count = todos.count
else
# exclude hidden_todos
@down_count = todos.not_hidden.count(:all)
@down_count = todos.not_hidden.count
end
end
from.project do
unless @todo.project_id == nil
@down_count = current_user.projects.find(@todo.project_id).todos.active_or_hidden.count
@down_count = current_user.projects.find_by_id(@todo.project_id).todos.active_or_hidden.count
end
end
from.deferred do
@down_count = current_user.todos.deferred_or_blocked.count(:all)
@down_count = current_user.todos.deferred_or_blocked.count
end
from.tag do
@tag_name = params['_tag_name']
@ -1112,8 +1116,8 @@ class TodosController < ApplicationController
source_view do |from|
from.deferred {
# force reload to todos to get correct count and not a cached one
@remaining_in_context = current_user.contexts.find(context_id).todos.deferred_or_blocked.count
@target_context_count = current_user.contexts.find(@todo.context_id).todos.deferred_or_blocked.count
@remaining_in_context = current_user.contexts.find_by_id(context_id).todos.deferred_or_blocked.count
@target_context_count = current_user.contexts.find_by_id(@todo.context_id).todos.deferred_or_blocked.count
}
from.tag {
tag = Tag.find_by_name(params['_tag_name'])
@ -1121,27 +1125,27 @@ class TodosController < ApplicationController
tag = Tag.new(:name => params['tag'])
end
@remaining_deferred_or_pending_count = current_user.todos.with_tag(tag.id).deferred_or_blocked.count
@remaining_in_context = current_user.contexts.find(context_id).todos.active.not_hidden.with_tag(tag.id).count
@target_context_count = current_user.contexts.find(@todo.context_id).todos.active.not_hidden.with_tag(tag.id).count
@remaining_in_context = current_user.contexts.find_by_id(context_id).todos.active.not_hidden.with_tag(tag.id).count
@target_context_count = current_user.contexts.find_by_id(@todo.context_id).todos.active.not_hidden.with_tag(tag.id).count
@remaining_hidden_count = current_user.todos.hidden.with_tag(tag.id).count
}
from.project {
project_id = @project_changed ? @original_item_project_id : @todo.project_id
@remaining_deferred_or_pending_count = current_user.projects.find(project_id).todos.deferred_or_blocked.count
@remaining_deferred_or_pending_count = current_user.projects.find_by_id(project_id).todos.deferred_or_blocked.count
if @todo_was_completed_from_deferred_or_blocked_state
@remaining_in_context = @remaining_deferred_or_pending_count
else
@remaining_in_context = current_user.projects.find(project_id).todos.active_or_hidden.count
@remaining_in_context = current_user.projects.find_by_id(project_id).todos.active_or_hidden.count
end
@target_context_count = current_user.projects.find(project_id).todos.active.count
@target_context_count = current_user.projects.find_by_id(project_id).todos.active.count
}
from.calendar {
@target_context_count = @new_due_id.blank? ? 0 : count_old_due_empty(@new_due_id)
}
from.context {
context = current_user.contexts.find(context_id)
context = current_user.contexts.find_by_id(context_id)
@remaining_deferred_or_pending_count = context.todos.deferred_or_blocked.count
remaining_actions_in_context = context.todos(true).active
@ -1149,7 +1153,7 @@ class TodosController < ApplicationController
@remaining_in_context = remaining_actions_in_context.count
if @todo_was_deferred_or_blocked
actions_in_target = current_user.contexts.find(@todo.context_id).todos(true).active
actions_in_target = current_user.contexts.find_by_id(@todo.context_id).todos(true).active
actions_in_target = actions_in_target.not_hidden if !context.hide?
else
actions_in_target = @todo.context.todos.deferred_or_blocked
@ -1157,8 +1161,8 @@ class TodosController < ApplicationController
@target_context_count = actions_in_target.count
}
end
@remaining_in_context = current_user.contexts.find(context_id).todos(true).active.not_hidden.count if !@remaining_in_context
@target_context_count = current_user.contexts.find(@todo.context_id).todos(true).active.not_hidden.count if !@target_context_count
@remaining_in_context = current_user.contexts.find_by_id(context_id).todos(true).active.not_hidden.count if !@remaining_in_context
@target_context_count = current_user.contexts.find_by_id(@todo.context_id).todos(true).active.not_hidden.count if !@target_context_count
end
def determine_completed_count
@ -1167,13 +1171,13 @@ class TodosController < ApplicationController
@completed_count = current_user.todos.not_hidden.completed.count
end
from.context do
todos = current_user.contexts.find(@todo.context_id).todos.completed
todos = current_user.contexts.find_by_id(@todo.context_id).todos.completed
todos = todos.not_hidden if !@todo.context.hidden?
@completed_count = todos.count
end
from.project do
unless @todo.project_id == nil
todos = current_user.projects.find(@todo.project_id).todos.completed
todos = current_user.projects.find_by_id(@todo.project_id).todos.completed
todos = todos.not_hidden if !@todo.project.hidden?
@completed_count = todos.count
end
@ -1197,7 +1201,7 @@ class TodosController < ApplicationController
# If you've set no_completed to zero, the completed items box isn't shown
# on the home page
max_completed = current_user.prefs.show_number_completed
@done = current_user.todos.completed.find(:all, :limit => max_completed, :include => Todo::DEFAULT_INCLUDES) unless max_completed == 0
@done = current_user.todos.completed.limit(max_completed).includes(Todo::DEFAULT_INCLUDES) unless max_completed == 0
# Set count badge to number of not-done, not hidden context items
@count = current_user.todos.active.not_hidden.count(:all)
@ -1212,7 +1216,7 @@ class TodosController < ApplicationController
@home = true
max_completed = current_user.prefs.show_number_completed
@done = current_user.todos.completed.find(:all, :limit => max_completed, :include => Todo::DEFAULT_INCLUDES) unless max_completed == 0
@done = current_user.todos.completed.limit(max_completed).includes(Todo::DEFAULT_INCLUDES) unless max_completed == 0
cookies[:mobile_url]= { :value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
determine_down_count
@ -1349,20 +1353,15 @@ class TodosController < ApplicationController
due_this_month_date = Time.zone.now.end_of_month
case id
when "due_today"
return current_user.todos.not_completed.count(:all,
:conditions => ['todos.due <= ?', due_today_date])
return current_user.todos.not_completed.where('todos.due <= ?', due_today_date).count
when "due_this_week"
return current_user.todos.not_completed.count(:all,
:conditions => ['todos.due > ? AND todos.due <= ?', due_today_date, due_this_week_date])
return current_user.todos.not_completed.where('todos.due > ? AND todos.due <= ?', due_today_date, due_this_week_date).count
when "due_next_week"
return current_user.todos.not_completed.count(:all,
:conditions => ['todos.due > ? AND todos.due <= ?', due_this_week_date, due_next_week_date])
return current_user.todos.not_completed.where('todos.due > ? AND todos.due <= ?', due_this_week_date, due_next_week_date).count
when "due_this_month"
return current_user.todos.not_completed.count(:all,
:conditions => ['todos.due > ? AND todos.due <= ?', due_next_week_date, due_this_month_date])
return current_user.todos.not_completed.where('todos.due > ? AND todos.due <= ?', due_next_week_date, due_this_month_date).count
when "due_after_this_month"
return current_user.todos.not_completed.count(:all,
:conditions => ['todos.due > ?', due_this_month_date])
return current_user.todos.not_completed.where('todos.due > ?', due_this_month_date).count
else
raise Exception.new, "unknown due id for calendar: '#{id}'"
end
@ -1402,7 +1401,7 @@ class TodosController < ApplicationController
def update_todo_state_if_project_changed
if ( @project_changed ) then
@todo.update_state_from_project
@remaining_undone_in_project = current_user.projects.find(@original_item_project_id).todos.active.count if source_view_is :project
@remaining_undone_in_project = current_user.projects.find_by_id(@original_item_project_id).todos.active.count if source_view_is :project
end
end

View file

@ -18,7 +18,7 @@ class UsersController < ApplicationController
store_location
end
format.xml do
@users = User.find(:all, :order => 'login')
@users = User.order('login').all
render :xml => @users.to_xml(:except => [ :password ])
end
end
@ -139,7 +139,7 @@ class UsersController < ApplicationController
def destroy
@deleted_user = User.find_by_id(params[:id])
@saved = @deleted_user.destroy
@total_users = User.find(:all).size
@total_users = User.all.size
respond_to do |format|
format.html do

View file

@ -110,7 +110,7 @@ module TodosHelper
def successors_span(todo=@todo)
unless todo.pending_successors.empty?
pending_count = todo.pending_successors.length
pending_count = todo.pending_successors.count
title = "#{t('todos.has_x_pending', :count => pending_count)}: #{todo.pending_successors.map(&:description).join(', ')}"
image_tag( 'successor_off.png', :width=>'10', :height=>'16', :border=>'0', :title => title )
end
@ -272,12 +272,12 @@ module TodosHelper
end
def default_contexts_for_autocomplete
projects = current_user.projects.uncompleted.find(:all, :include => [:default_context], :conditions => ['NOT(default_context_id IS NULL)'])
projects = current_user.projects.uncompleted.includes(:default_context).where('NOT(default_context_id IS NULL)')
Hash[*projects.map{ |p| [escape_javascript(p.name), escape_javascript(p.default_context.name)] }.flatten].to_json
end
def default_tags_for_autocomplete
projects = current_user.projects.uncompleted.find(:all, :conditions => ["default_tags != ''"])
projects = current_user.projects.uncompleted.where("NOT(default_tags = '')")
Hash[*projects.map{ |p| [escape_javascript(p.name), p.default_tags] }.flatten].to_json
end

View file

@ -295,14 +295,14 @@ class Todo < ActiveRecord::Base
# activate todos that should be activated if the current todo is completed
def activate_pending_todos
pending_todos = successors.find_all {|t| t.uncompleted_predecessors.empty?}
pending_todos = successors.select {|t| t.uncompleted_predecessors.empty?}
pending_todos.each {|t| t.activate! }
return pending_todos
end
# Return todos that should be blocked if the current todo is undone
def block_successors
active_successors = successors.find_all {|t| t.active? or t.deferred?}
active_successors = successors.select {|t| t.active? or t.deferred?}
active_successors.each {|t| t.block!}
return active_successors
end
@ -320,7 +320,7 @@ class Todo < ActiveRecord::Base
# value will be a string. In that case convert to array
deps = [deps] unless deps.class == Array
deps.each { |dep| self.add_predecessor(self.user.todos.find(dep.to_i)) unless dep.blank? }
deps.each { |dep| self.add_predecessor(self.user.todos.find_by_id(dep.to_i)) unless dep.blank? }
end
alias_method :original_context=, :context=

View file

@ -10,7 +10,7 @@ class User < ActiveRecord::Base
:order => 'position ASC',
:dependent => :delete_all do
def find_by_params(params)
find(params['id'] || params['context_id']) || nil
find_by_id(params['id'] || params['context_id']) || nil
end
def update_positions(context_ids)
context_ids.each_with_index {|id, position|
@ -24,7 +24,7 @@ class User < ActiveRecord::Base
:order => 'projects.position ASC',
:dependent => :delete_all do
def find_by_params(params)
find(params['id'] || params['project_id'])
find_by_id(params['id'] || params['project_id'])
end
def update_positions(project_ids)
project_ids.each_with_index {|id, position|
@ -34,7 +34,7 @@ class User < ActiveRecord::Base
}
end
def projects_in_state_by_position(state)
self.sort{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
self.sort{ |a,b| a.position <=> b.position }.select{ |p| p.state == state }
end
def next_from(project)
self.offset_from(project, 1)
@ -49,29 +49,29 @@ class User < ActiveRecord::Base
projects.at( position + offset)
end
def cache_note_counts
project_note_counts = Note.count(:group => 'project_id')
project_note_counts = Note.group(:project_id).count
self.each do |project|
project.cached_note_count = project_note_counts[project.id] || 0
end
end
def alphabetize(scope_conditions = {})
projects = find(:all, :conditions => scope_conditions)
projects = where(scope_conditions)
projects.sort!{ |x,y| x.name.downcase <=> y.name.downcase }
self.update_positions(projects.map{ |p| p.id })
return projects
end
def actionize(scope_conditions = {})
todos_in_project = find(:all, :conditions => scope_conditions, :include => [:todos])
todos_in_project = where(scope_conditions).includes(:todos)
todos_in_project.sort!{ |x, y| -(x.todos.active.count <=> y.todos.active.count) }
todos_in_project.reject{ |p| p.todos.active.count > 0 }
sorted_project_ids = todos_in_project.map {|p| p.id}
all_project_ids = find(:all).map {|p| p.id}
all_project_ids = all.map {|p| p.id}
other_project_ids = all_project_ids - sorted_project_ids
update_positions(sorted_project_ids + other_project_ids)
return find(:all, :conditions => scope_conditions)
return where(scope_conditions)
end
end
has_many :todos,
@ -85,7 +85,7 @@ class User < ActiveRecord::Base
:conditions => [ 'state = ?', 'deferred' ],
:order => 'show_from ASC, todos.created_at DESC' do
def find_and_activate_ready
find(:all, :conditions => ['show_from <= ?', Time.zone.now ]).collect { |t| t.activate! }
where('show_from <= ?', Time.zone.now).collect { |t| t.activate! }
end
end
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
@ -119,7 +119,7 @@ class User < ActiveRecord::Base
def self.authenticate(login, pass)
return nil if login.blank?
candidate = find(:first, :conditions => ["login = ?", login])
candidate = where("login = ?", login).first
return nil if candidate.nil?
if Tracks::Config.auth_schemes.include?('database')

View file

@ -6,7 +6,7 @@
</div>
<div id="context_new" class="context_new" style="display:block">
<% form_for(@new_context, :html => {:id => 'context-form',:name=>'context',:class => "inline-form", :method => :post }) do -%>
<%= form_for(@new_context, :html => {:id => 'context-form',:name=>'context',:class => "inline-form", :method => :post }) do -%>
<div id="error_status"><%= error_messages_for('context') %></div>

View file

@ -8,7 +8,7 @@
<p>F&uuml;gen Sie den Inhalt der kopierten YAML Datei in das untenstehende Formular ein:</p>
</div>
<p>
<% form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %>
<%= form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %>
<%= f.text_area :yaml %><br />
<input type="submit" value="Daten importieren">
<% end %>

View file

@ -1,14 +1,14 @@
<div id="display_box">
<div id="feeds">
<div id="feedlegend">
<p><b>Beware</b>: all your current data will be destroyed before importing
the YAML file, so if you have access to the database, we strongly recommend
<p><b>Beware</b>: all your current data will be destroyed before importing
the YAML file, so if you have access to the database, we strongly recommend
backing up the database right now in case that anything goes wrong.
</p>
<p>Paste the contents of the YAML file you exported into the text box below:</p>
</div>
<p>
<% form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %>
<%= form_for :import, @import, :url => {:controller => 'data', :action => 'yaml_import'} do |f| %>
<%= f.text_area :yaml %><br />
<input type="submit" value="Import data">
<% end %>

View file

@ -11,21 +11,21 @@
<h3><%= t('login.please_login') %>:</h3>
<% if show_database_form %>
<div id="database_auth_form" style="display:<%=(@prefered_auth.eql?('database')) ? "block" : "none"%>">
<% form_tag :action=> 'login' do %>
<%= form_tag :action=> 'login' do %>
<table>
<tr>
<td><label for="user_login"><%= User.human_attribute_name('login') %>:</label></td>
<td><input type="text" name="user_login" id="user_login" value="" class="login_text" /></td>
</tr>
<tr>
<tr>
<td><label for="user_password"><%= User.human_attribute_name('password') %>:</label></td>
<td><input type="password" name="user_password" id="user_password" class="login_text" /></td>
</tr>
<tr>
<tr>
<td><label for="user_noexpiry"><%= t('login.user_no_expiry') %>:</label></td>
<td><input type="checkbox" name="user_noexpiry" id="user_noexpiry" checked /></td>
</tr>
<tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="<%= t('login.sign_in') %> &#187;" class="primary" /></td>
</tr>
@ -36,17 +36,17 @@
<% if show_openid_form %>
<div id="openid_auth_form" style="display:<%=(@prefered_auth.eql?('openid')) ? "block" : "none"%>">
<% form_tag :action=> 'login' do %>
<%= form_tag :action=> 'login' do %>
<table>
<tr>
<td><label for="openid_url"><%= User.human_attribute_name('open_id_url') %>:</label></td>
<td><input type="text" name="openid_url" id="openid_url" value="<%= @openid_url %>" class="login_text open_id" /></td>
</tr>
<tr>
<tr>
<td><label for="user_noexpiry"><%= t('login.user_no_expiry') %>:</label></td>
<td><input type="checkbox" name="user_noexpiry" id="user_noexpiry" checked /></td>
</tr>
<tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="<%= t('login.sign_in') %> &#187;" class="primary" /></td>
</tr>
@ -59,7 +59,7 @@
<div id="cas_auth_form" style="display:<%=(@prefered_auth.eql?('cas')) ? "block" : "none"%>">
<table>
<tr>
<td>
<td>
<% if @username && @user%>
<p><%= t('login.cas_logged_in_greeting', :username => @username) %></p>
<% elsif @username %>

View file

@ -11,21 +11,21 @@
<% if show_database_form %>
<div id="database_auth_form">
<% form_tag login_path(:format => 'm') do %>
<%= form_tag login_path(:format => 'm') do %>
<table>
<tr>
<td><label for="user_login"><%= User.human_attribute_name('login') %>:</label></td>
<td><input type="text" name="user_login" id="user_login" value="" class="login_text" /></td>
</tr>
<tr>
<tr>
<td><label for="user_password"><%= User.human_attribute_name('password') %>:</label></td>
<td><input type="password" name="user_password" id="user_password" class="login_text" /></td>
</tr>
<tr>
<tr>
<td><label for="user_noexpiry"><%= t('login.user_no_expiry') %>:</label></td>
<td><input type="checkbox" name="user_noexpiry" id="user_noexpiry" checked="checked" /></td>
</tr>
<tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="login" value="<%= t('login.sign_in') %> &#187;" class="primary" /></td>
</tr>
@ -34,28 +34,4 @@
</div>
<% end %>
<% if show_openid_form %>
<h4><%= t('login.mobile_use_openid') %>:</h4>
<div id="openid_auth_form">
<% form_tag login_path(:format => 'm') do %>
<table>
<tr>
<td width="100px"><label for="openid_url"><%= User.human_attribute_name('open_id_url') %>:</label></td>
<td width="100px"><input type="text" name="openid_url" id="openid_url" value="<%= @openid_url %>" class="login_text open_id" /></td>
</tr>
<tr>
<td width="100px"><label for="user_noexpiry"><%= t('login.user_no_expiry') %>:</label></td>
<td width="100px"><input type="checkbox" name="user_noexpiry" id="user_noexpiry" checked /></td>
</tr>
<tr>
<td width="100px"></td>
<td><input type="submit" name="login" value="<%= t('login.sign_in') %> &#187;" class="primary" /></td>
</tr>
</table>
<% end %>
</div>
<% end %>
</div>

View file

@ -2,7 +2,7 @@
<div id="edit_error_status"><%= error_messages_for(:user) + error_messages_for(:prefs) %></div>
<% form_tag :action => 'update' do %>
<%= form_tag :action => 'update' do %>
<div id="tabs">
<ul>
<li><a href="#tabs-1"><%= t('preferences.tabs.profile')%></a></li>

View file

@ -6,7 +6,7 @@
</div>
<div id="project_new" class="project_new" style="display:block">
<% form_for(@new_project, :html => {:id => 'project_form',:name=>'project',:class => "inline-form", :method => :post }) do -%>
<%= form_for(@new_project, :html => {:id => 'project_form',:name=>'project',:class => "inline-form", :method => :post }) do -%>
<div id="error_status"><%= error_messages_for("project") %></div>
<label for="project_name"><%= Project.human_attribute_name(:name) %>:</label><br />

View file

@ -1,5 +1,5 @@
<div class="recurring_container">
<% form_for(@recurring_todo, :html=> { :id=>'recurring-todo-form-edit-action', :name=>'recurring_todo', :class => 'inline-form' }) do |f| -%>
<%= form_for(@recurring_todo, :html=> { :id=>'recurring-todo-form-edit-action', :name=>'recurring_todo', :class => 'inline-form' }) do |f| -%>
<div id="edit_error_status"><%= error_messages_for("item", :object_name => 'action') %></div>
<div id="recurring_todo_form_container">

View file

@ -1,6 +1,6 @@
<%- reset_tab_index %>
<div class="recurring_container">
<% form_for(@new_recurring_todo, :html=> { :id=>'recurring-todo-form-new-action', :name=>'recurring_todo', :class => 'inline-form' }) do -%>
<%= form_for(@new_recurring_todo, :html=> { :id=>'recurring-todo-form-new-action', :name=>'recurring_todo', :class => 'inline-form' }) do -%>
<div id="error_status"><%= error_messages_for("item", :object_name => 'action') %></div>
<div id="recurring_todo_form_container">

View file

@ -1,5 +1,5 @@
<div id="display_box_search">
<% form_tag({:action => :results}, :id => 'search-form') do %>
<%= form_tag({:action => :results}, :id => 'search-form') do %>
<%= text_field_tag(:search, params[:search]) %>
<%= submit_tag t('common.search') %>
<% end %>

View file

@ -1,4 +1,4 @@
<% form_tag todo_path(@todo, :format => 'm'), :name => 'mobileEdit', :method => :put do %>
<%= form_tag todo_path(@todo, :format => 'm'), :name => 'mobileEdit', :method => :put do %>
<%= render :partial => 'edit_mobile_form', :locals => { :parent_container_type => "show_mobile" } %>
<p><input type="submit" value="<%= t('common.update') %>" tabindex="6" accesskey="#" /></p>
<% end -%>

View file

@ -1,4 +1,4 @@
<% form_tag todos_path(:format => 'm'), :method => :post do %>
<%= form_tag todos_path(:format => 'm'), :method => :post do %>
<%= render :partial => 'edit_mobile_form' %>
<p><input type="submit" value="<%= t('common.create') %>" tabindex="12" accesskey="#" /></p>
<% end -%>

View file

@ -6,7 +6,7 @@
<p><%= t('users.select_authentication_type') %></p>
<% form_tag :action => 'update_auth_type' do %>
<%= form_tag :action => 'update_auth_type' do %>
<div><label for="user_auth_type"><%= t('users.label_auth_type') %>:</label> <%= select('user', 'auth_type', Tracks::Config.auth_schemes.collect {|p| [ p, p ] }) %></div>
<div id="open_id" style="display:<%= current_user.auth_type == 'open_id' ? 'block' : 'none' %>"><label for="openid_url"><%= t('users.identity_url') %>:</label> <input type="text" name="openid_url" value="<%= current_user.open_id_url %>" class="open_id" /></div>
<div class="actions"><%= submit_tag t('users.auth_change_submit') %> <%= link_to t('common.cancel'), preferences_path %></div>

View file

@ -6,7 +6,7 @@
<p><%= t('users.change_password_prompt') %></p>
<% form_tag :action => 'update_password' do %>
<%= form_tag :action => 'update_password' do %>
<%= render :partial => 'update_password' %>
<br/>
<%= link_to t('common.cancel'), preferences_path %>

View file

@ -1,5 +1,5 @@
<div title="<%= t('users.account_signup') %>" id="signupform" class="form">
<% form_tag :action=> "create" do %>
<%= form_tag :action=> "create" do %>
<%= error_messages_for 'user' %><br/>