add done view to tag pages and add more tests

This commit is contained in:
Reinier Balt 2011-06-26 23:05:33 +02:00
parent 6e97541ab3
commit 601736de2d
14 changed files with 1106 additions and 869 deletions

View file

@ -11,7 +11,7 @@ class ContextsController < ApplicationController
def index
# #true is passed here to force an immediate load so that size and empty?
# checks later don't result in separate SQL queries
@active_contexts = current_user.contexts.active(true)
@active_contexts = current_user.contexts.active(true)
@hidden_contexts = current_user.contexts.hidden(true)
@new_context = current_user.contexts.build
@ -34,7 +34,7 @@ class ContextsController < ApplicationController
format.autocomplete { render :text => for_autocomplete(@active_contexts + @hidden_contexts, params[:term])}
end
end
def show
@contexts = current_user.contexts(true)
if @context.nil?
@ -51,7 +51,7 @@ class ContextsController < ApplicationController
end
end
end
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type:
# application/xml'
# -u username:password
@ -86,14 +86,14 @@ class ContextsController < ApplicationController
end
end
end
# Edit the details of the context
#
def update
params['context'] ||= {}
success_text = if params['field'] == 'name' && params['value']
params['context']['id'] = params['id']
params['context']['name'] = params['value']
params['context']['id'] = params['id']
params['context']['name'] = params['value']
end
@original_context_hidden = @context.hidden?
@ -110,7 +110,7 @@ class ContextsController < ApplicationController
end
# TODO is this param ever used? is this dead code?
elsif boolean_param('update_context_name')
@contexts = current_user.projects
render :template => 'contexts/update_context_name.js.rjs'
@ -120,10 +120,10 @@ class ContextsController < ApplicationController
end
else
respond_to do |format|
format.js
format.js
format.xml {
if @saved
render :xml => @context.to_xml( :except => :user_id )
render :xml => @context.to_xml( :except => :user_id )
else
render :text => "Error on update: #{@context.errors.full_messages.inject("") {|v, e| v + e + " " }}", :status => 409
end
@ -145,7 +145,7 @@ class ContextsController < ApplicationController
def destroy
# make sure the deleted recurring patterns are removed from associated todos
@context.recurring_todos.each { |rt| rt.clear_todos_association } unless @context.recurring_todos.nil?
@context.destroy
respond_to do |format|
format.js do
@ -166,26 +166,28 @@ class ContextsController < ApplicationController
notify :error, $!
redirect_to :action => 'index'
end
def done_todos
@source_view = 'context'
@page_title = t('context.completed_tasks_title')
completed_todos = current_user.contexts.find(params[:id]).todos.completed
@context = current_user.contexts.find(params[:id])
@page_title = t('contexts.completed_tasks_title', :context_name => @context.name)
completed_todos = @context.todos.completed
@done_today = get_done_today(completed_todos)
@done_this_week = get_done_this_week(completed_todos)
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
render :template => 'todos/done'
end
def all_done_todos
@source_view = 'context'
@page_title = t('context.completed_tasks_title')
@context = current_user.contexts.find(params[:id])
@page_title = t('contexts.all_completed_tasks_title', :context_name => @context.name)
@done = current_user.contexts.find(params[:id]).todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@done = @context.todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@count = @done.size
render :template => 'todos/all_done'
end
@ -209,23 +211,23 @@ class ContextsController < ApplicationController
render
end
end
def render_contexts_mobile
lambda do
@page_title = "TRACKS::List Contexts"
@active_contexts = current_user.contexts.active
@hidden_contexts = current_user.contexts.hidden
@down_count = @active_contexts.size + @hidden_contexts.size
@down_count = @active_contexts.size + @hidden_contexts.size
cookies[:mobile_url]= {:value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
render :action => 'index_mobile'
end
end
def render_context_mobile
lambda do
@page_title = "TRACKS::List actions in "+@context.name
@not_done = @not_done_todos.select {|t| t.context_id == @context.id }
@down_count = @not_done.size
@not_done = @not_done_todos.select {|t| t.context_id == @context.id }
@down_count = @not_done.size
cookies[:mobile_url]= {:value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
@mobile_from_context = @context.id
render :action => 'mobile_show_context'
@ -246,7 +248,7 @@ class ContextsController < ApplicationController
:author => lambda { |c| nil } }
end
end
def feed_options
Context.feed_options(current_user)
end
@ -256,7 +258,7 @@ class ContextsController < ApplicationController
rescue
@context = nil
end
def init
@source_view = params['_source_view'] || 'context'
init_data_for_sidebar
@ -270,13 +272,13 @@ class ContextsController < ApplicationController
end
@max_completed = current_user.prefs.show_number_completed
# @not_done_todos = @context.not_done_todos TODO: Temporarily doing this
# search manually until I can work out a way to do the same thing using
# not_done_todos acts_as_todo_container method Hides actions in hidden
# projects from context.
@not_done_todos = @context.todos.active(
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:include => Todo::DEFAULT_INCLUDES)
@projects = current_user.projects

View file

@ -12,7 +12,7 @@ class ProjectsController < ApplicationController
@new_project = current_user.projects.build
if params[:projects_and_actions]
projects_and_actions
else
else
@contexts = current_user.contexts.all
init_not_done_counts(['project'])
init_project_hidden_todo_counts(['project'])
@ -32,18 +32,18 @@ class ProjectsController < ApplicationController
end
end
end
def done
@source_view = params['_source_view'] || 'project_list'
@page_title = t('projects.list_completed_projects')
page = params[:page] || 1
projects_per_page = 20
@projects = current_user.projects.completed.paginate :page => page, :per_page => projects_per_page
@count = @projects.count
@total = current_user.projects.completed.count
@no_projects = @projects.empty?
@range_low = (page.to_i-1) * projects_per_page + 1
@range_high = @range_low + @projects.size - 1
@ -54,7 +54,7 @@ class ProjectsController < ApplicationController
def projects_and_actions
@projects = current_user.projects.active
respond_to do |format|
format.text {
format.text {
render :action => 'index_text_projects_and_actions', :layout => false, :content_type => Mime::TEXT
}
end
@ -64,7 +64,7 @@ class ProjectsController < ApplicationController
@max_completed = current_user.prefs.show_number_completed
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)
@ -85,7 +85,7 @@ class ProjectsController < ApplicationController
format.xml { render :xml => @project.to_xml( :except => :user_id ) }
end
end
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type:
# application/xml'
# -u username:password
@ -138,8 +138,8 @@ class ProjectsController < ApplicationController
params['project'].delete('state')
end
success_text = if params['field'] == 'name' && params['value']
params['project']['id'] = params['id']
params['project']['name'] = params['value']
params['project']['id'] = params['id']
params['project']['name'] = params['value']
end
@project.attributes = params['project']
@ -165,7 +165,7 @@ class ProjectsController < ApplicationController
elsif boolean_param('update_status')
template = 'projects/update_status.js.rjs'
elsif boolean_param('update_default_context')
@initial_context_name = @project.default_context.name
@initial_context_name = @project.default_context.name
template = 'projects/update_default_context.js.rjs'
elsif boolean_param('update_default_tags')
template = 'projects/update_default_tags.js.rjs'
@ -184,23 +184,23 @@ class ProjectsController < ApplicationController
respond_to do |format|
format.js { render :template => template }
format.html { redirect_to :action => 'index'}
format.xml {
format.xml {
if @saved
render :xml => @project.to_xml( :except => :user_id )
render :xml => @project.to_xml( :except => :user_id )
else
render :text => "Error on update: #{@project.errors.full_messages.inject("") {|v, e| v + e + " " }}", :status => 409
end
}
end
end
def edit
respond_to do |format|
format.js
end
end
def destroy
@project.recurring_todos.each {|rt| rt.remove_from_project!}
@project.destroy
@ -213,7 +213,7 @@ class ProjectsController < ApplicationController
format.xml { render :text => "Deleted project #{@project.name}" }
end
end
def order
project_ids = params["container_project"]
@projects = current_user.projects.update_positions( project_ids )
@ -222,44 +222,46 @@ class ProjectsController < ApplicationController
notify :error, $!
redirect_to :action => 'index'
end
def alphabetize
@state = params['state']
@projects = current_user.projects.alphabetize(:state => @state) if @state
@contexts = current_user.contexts
init_not_done_counts(['project'])
end
def actionize
@state = params['state']
@projects = current_user.projects.actionize(:state => @state) if @state
@contexts = current_user.contexts
init_not_done_counts(['project'])
end
def done_todos
@source_view = 'project'
@page_title = t('project.completed_tasks_title')
completed_todos = current_user.projects.find(params[:id]).todos.completed
@project = current_user.projects.find(params[:id])
@page_title = t('projects.completed_tasks_title', :project_name => @project.name)
completed_todos = @project.todos.completed
@done_today = get_done_today(completed_todos)
@done_this_week = get_done_this_week(completed_todos)
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
render :template => 'todos/done'
end
def all_done_todos
@source_view = 'project'
@page_title = t('project.completed_tasks_title')
@project = current_user.projects.find(params[:id])
@page_title = t('projects.all_completed_tasks_title', :project_name => @project.name)
@done = current_user.projects.find(params[:id]).todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@done = @project.todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@count = @done.size
render :template => 'todos/all_done'
end
protected
def update_state_counts
@ -291,12 +293,12 @@ class ProjectsController < ApplicationController
@active_projects = current_user.projects.active
@hidden_projects = current_user.projects.hidden
@completed_projects = current_user.projects.completed
@down_count = @active_projects.size + @hidden_projects.size + @completed_projects.size
@down_count = @active_projects.size + @hidden_projects.size + @completed_projects.size
cookies[:mobile_url]= {:value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
render :action => 'index_mobile'
end
end
def render_project_mobile
lambda do
if @project.default_context.nil?
@ -326,7 +328,7 @@ class ProjectsController < ApplicationController
:author => lambda { |p| nil } }
end
end
def feed_options
Project.feed_options(current_user)
end
@ -336,15 +338,15 @@ class ProjectsController < ApplicationController
render :action => 'index', :layout => false, :content_type => Mime::TEXT
end
end
def set_project_from_params
@project = current_user.projects.find_by_params(params)
end
def set_source_view
@source_view = params['_source_view'] || 'project'
end
def default_context_filter
p = params['project']
p = params['request']['project'] if p.nil? && params['request']

View file

@ -22,7 +22,7 @@ class TodosController < ApplicationController
@contexts = current_user.contexts.find(:all)
@contexts_to_show = current_user.contexts.active
respond_to do |format|
format.html &render_todos_html
format.m &render_todos_mobile
@ -33,7 +33,7 @@ class TodosController < ApplicationController
format.ics &render_ical_feed
end
end
def new
@projects = current_user.projects.active
@contexts = current_user.contexts.find(:all)
@ -47,16 +47,16 @@ class TodosController < ApplicationController
# we have a project but not a context -> use the default context
@mobile_from_context = @mobile_from_project.default_context
end
render :action => "new"
render :action => "new"
}
end
end
def create
@source_view = params['_source_view'] || 'todo'
@default_context = current_user.contexts.find_by_name(params['default_context_name'])
@default_project = current_user.projects.find_by_name(params['default_project_name']) unless params['default_project_name'].blank?
@tag_name = params['_tag_name']
is_multiple = params[:todo] && params[:todo][:multiple_todos] && !params[:todo][:multiple_todos].nil?
@ -67,7 +67,7 @@ class TodosController < ApplicationController
p.parse_dates() unless mobile?
tag_list = p.tag_list
predecessor_list = p.predecessor_list
@todo = current_user.todos.build(p.attributes)
if p.project_specified_by_name?
@ -75,7 +75,7 @@ class TodosController < ApplicationController
@new_project_created = project.new_record_before_save?
@todo.project_id = project.id
end
if p.context_specified_by_name?
context = current_user.contexts.find_or_create_by_name(p.context_name)
@new_context_created = context.new_record_before_save?
@ -210,7 +210,7 @@ class TodosController < ApplicationController
end
end
end
def edit
@todo = current_user.todos.find(params['id'], :include => Todo::DEFAULT_INCLUDES)
@source_view = params['_source_view'] || 'todo'
@ -219,7 +219,7 @@ class TodosController < ApplicationController
format.js
end
end
def show
@todo = current_user.todos.find(params['id'])
respond_to do |format|
@ -233,7 +233,7 @@ class TodosController < ApplicationController
format.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ) }
end
end
def add_predecessor
@source_view = params['_source_view'] || 'todo'
@predecessor = current_user.todos.find(params['predecessor'])
@ -251,7 +251,7 @@ class TodosController < ApplicationController
@saved = false
end
respond_to do |format|
format.js
format.js
end
end
@ -278,18 +278,18 @@ class TodosController < ApplicationController
@original_item_context_id = @todo.context_id
@original_item_project_id = @todo.project_id
@saved = @todo.toggle_completion!
# check if this todo has a related recurring_todo. If so, create next todo
@new_recurring_todo = check_for_next_todo(@todo) if @saved
if @saved
if @todo.completed?
@pending_to_activate = @todo.activate_pending_todos
@pending_to_activate = @todo.activate_pending_todos
else
@active_to_block = @todo.block_successors
end
end
respond_to do |format|
format.js do
if @saved
@ -318,7 +318,7 @@ class TodosController < ApplicationController
end
end
end
def toggle_star
@todo = current_user.todos.find(params['id'])
@todo.toggle_star!
@ -357,18 +357,18 @@ class TodosController < ApplicationController
cache_attributes_from_before_update
update_tags
update_project
update_context
update_project
update_context
update_due_and_show_from_dates
update_completed_state
update_dependencies
update_attributes_of_todo
@saved = @todo.save
# this is set after save and cleared after reload, so save it here
@removed_predecessors = @todo.removed_predecessors
@todo.reload # refresh context and project object too (not only their id's)
update_dependency_state
@ -401,7 +401,7 @@ class TodosController < ApplicationController
end
end
end
def destroy
@source_view = params['_source_view'] || 'todo'
@todo = current_user.todos.find(params['id'])
@ -428,9 +428,9 @@ class TodosController < ApplicationController
# check if this todo has a related recurring_todo. If so, create next todo
@new_recurring_todo = check_for_next_todo(@todo) if @saved
respond_to do |format|
format.html do
if @saved
message = t('todos.action_deleted_success')
@ -444,7 +444,7 @@ class TodosController < ApplicationController
redirect_to :action => 'index'
end
end
format.js do
if @saved
determine_down_count
@ -457,16 +457,16 @@ class TodosController < ApplicationController
end
render
end
format.xml { render :text => '200 OK. Action deleted.', :status => 200 }
end
end
def done
@source_view = 'done'
@page_title = t('todos.completed_tasks_title')
completed_todos = current_user.todos.completed
@done_today = get_done_today(completed_todos)
@ -474,7 +474,7 @@ class TodosController < ApplicationController
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
end
def all_done
@source_view = 'done'
@page_title = t('todos.completed_tasks_title')
@ -482,25 +482,25 @@ class TodosController < ApplicationController
@done = current_user.todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@count = @done.size
end
def list_deferred
@source_view = 'deferred'
@page_title = t('todos.deferred_tasks_title')
@contexts_to_show = @contexts = current_user.contexts.find(:all)
includes = params[:format]=='xml' ? [:context, :project] : Todo::DEFAULT_INCLUDES
@not_done_todos = current_user.todos.deferred(:include => includes) + current_user.todos.pending(:include => includes)
@down_count = @count = @not_done_todos.size
respond_to do |format|
format.html
format.m { render :action => 'mobile_list_deferred' }
format.xml { render :xml => @not_done_todos.to_xml( :except => :user_id ) }
end
end
# Check for any due tickler items, activate them Called by
# periodically_call_remote
def check_deferred
@ -510,46 +510,47 @@ class TodosController < ApplicationController
format.js
end
end
def filter_to_context
context = current_user.contexts.find(params['context']['id'])
redirect_to context_todos_path(context, :format => 'm')
end
def filter_to_project
project = current_user.projects.find(params['project']['id'])
redirect_to project_todos_path(project, :format => 'm')
end
# /todos/tag/[tag_name] shows all the actions tagged with tag_name
def tag
init_data_for_sidebar unless mobile?
@source_view = params['_source_view'] || 'tag'
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
@page_title = t('todos.tagged_page_title', :tag_name => @tag_name)
# mobile tags are routed with :name ending on .m. So we need to chomp it
@tag_name = @tag_name.chomp('.m') if mobile?
@tag = Tag.find_by_name(@tag_name)
@tag = Tag.new(:name => @tag_name) if @tag.nil?
@not_done_todos = current_user.todos.with_tag(@tag).active.not_hidden.find(:all,
:order => 'todos.due IS NULL, todos.due ASC, todos.created_at ASC', :include => [:context])
:order => 'todos.due IS NULL, todos.due ASC, todos.created_at ASC', :include => Todo::DEFAULT_INCLUDES)
@hidden_todos = current_user.todos.with_tag(@tag).hidden.find(:all,
:include => [:taggings, :tags, :context],
:include => Todo::DEFAULT_INCLUDES,
:order => 'todos.completed_at DESC, todos.created_at DESC')
@deferred = current_user.todos.with_tag(@tag).deferred.find(:all,
:order => 'show_from ASC, todos.created_at DESC', :include => [:context])
:order => 'show_from ASC, todos.created_at DESC', :include => Todo::DEFAULT_INCLUDES)
@pending = current_user.todos.with_tag(@tag).blocked.find(:all,
:order => 'show_from ASC, todos.created_at DESC', :include => [:context])
:order => 'show_from ASC, todos.created_at DESC', :include => Todo::DEFAULT_INCLUDES)
# If you've set no_completed to zero, the completed items box isn't shown on
# the tag page
max_completed = current_user.prefs.show_number_completed
@done = current_user.todos.with_tag(@tag).completed.find(:all,
:limit => max_completed,
:order => 'todos.completed_at DESC')
:order => 'todos.completed_at DESC',
:include => Todo::DEFAULT_INCLUDES)
@projects = current_user.projects
@contexts = current_user.contexts
@ -560,7 +561,7 @@ class TodosController < ApplicationController
unless @not_done_todos.empty?
@context = current_user.contexts.find_by_id(@not_done_todos[0].context_id)
end
# Set count badge to number of items with this tag
@not_done_todos.empty? ? @count = 0 : @count = @not_done_todos.size
@down_count = @count
@ -574,13 +575,42 @@ class TodosController < ApplicationController
end
end
def done_tag
@source_view = params['_source_view'] || 'tag'
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
@page_title = t('todos.completed_tagged_page_title', :tag_name => @tag_name)
@tag = Tag.find_by_name(@tag_name)
@tag = Tag.new(:name => @tag_name) if @tag.nil?
completed_todos = current_user.todos.completed.with_tag(@tag)
@done_today = get_done_today(completed_todos)
@done_this_week = get_done_this_week(completed_todos)
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
render :template => 'todos/done'
end
def all_done_tag
@source_view = params['_source_view'] || 'tag'
@tag_name = sanitize(params[:name]) # sanitize to prevent XSS vunerability!
@page_title = t('todos.all_completed_tagged_page_title', :tag_name => @tag_name)
@tag = Tag.find_by_name(@tag_name)
@tag = Tag.new(:name => @tag_name) if @tag.nil?
@done = current_user.todos.completed.with_tag(@tag).paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES
@count = @done.size
render :template => 'todos/all_done'
end
def tags
@tags = Tag.find(:all, :conditions =>['name like ?', '%'+params[:term]+'%'])
respond_to do |format|
format.autocomplete { render :text => for_autocomplete(@tags, params[:term]) }
end
end
def defer
@source_view = params['_source_view'] || 'todo'
numdays = params['days'].to_i
@ -621,13 +651,13 @@ class TodosController < ApplicationController
@page_title = t('todos.calendar_page_title')
@projects = current_user.projects.find(:all)
due_today_date = Time.zone.now
due_this_week_date = Time.zone.now.end_of_week
due_next_week_date = due_this_week_date + 7.days
due_this_month_date = Time.zone.now.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],
@ -648,7 +678,7 @@ class TodosController < ApplicationController
:include => included_tables,
:conditions => ['todos.due > ?', due_this_month_date],
:order => "due")
@count = current_user.todos.not_completed.are_due.count
respond_to do |format|
@ -659,7 +689,7 @@ class TodosController < ApplicationController
}
end
end
def auto_complete_for_predecessor
unless params['id'].nil?
get_todo_from_params
@ -723,13 +753,13 @@ class TodosController < ApplicationController
end
private
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'])
end
def find_and_activate_ready
current_user.deferred_todos.find_and_activate_ready
end
@ -774,7 +804,7 @@ class TodosController < ApplicationController
@title << t('todos.next_actions_title_additions.completed')
@description << t('todos.next_actions_description_additions.completed', :count => done_in_last.to_s)
end
if params.key?('tag')
tag = Tag.find_by_name(params['tag'])
if tag.nil?
@ -782,11 +812,11 @@ class TodosController < ApplicationController
end
condition_builder.add('taggings.tag_id = ?', tag.id)
end
Todo.send :with_scope, :find => {:conditions => condition_builder.to_conditions} do
yield
end
end
def with_parent_resource_scope(&block)
@ -830,11 +860,11 @@ class TodosController < ApplicationController
with_feed_query_scope do
with_parent_resource_scope do # @context or @project may get defined here
with_limit_scope do
if mobile?
init_todos_for_mobile_view
else
# Note: these next two finds were previously using
# current_users.todos.find but that broke with_scope for :limit
@ -852,18 +882,18 @@ class TodosController < ApplicationController
end
end
end
def init_todos_for_mobile_view
# Note: these next two finds were previously using current_users.todos.find
# 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 ])
end
def determine_down_count
source_view do |from|
from.todo do
@ -890,7 +920,7 @@ class TodosController < ApplicationController
end
end
end
def determine_remaining_in_context_count(context_id = @todo.context_id)
source_view do |from|
from.deferred {
@ -931,7 +961,7 @@ class TodosController < ApplicationController
@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
end
def determine_completed_count
source_view do |from|
from.todo do
@ -972,7 +1002,7 @@ class TodosController < ApplicationController
# Set count badge to number of not-done, not hidden context items
@count = current_user.todos.active.not_hidden.count(:all)
render
end
end
@ -983,11 +1013,11 @@ class TodosController < ApplicationController
@home = true
cookies[:mobile_url]= { :value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
determine_down_count
render :action => 'index'
end
end
def render_rss_feed
lambda do
render_rss_feed_for @todos, :feed => todo_feed_options,
@ -999,7 +1029,7 @@ class TodosController < ApplicationController
}
end
end
def todo_feed_options
options = Todo.feed_options(current_user)
options[:title] = @feed_title
@ -1049,7 +1079,7 @@ class TodosController < ApplicationController
def self.is_feed_request(req)
['rss','atom','txt','ics'].include?(req.parameters[:format])
end
def check_for_next_todo(todo)
# check if this todo has a related recurring_todo. If so, create next todo
new_recurring_todo = nil
@ -1060,15 +1090,15 @@ class TodosController < ApplicationController
# check if there are active todos belonging to this recurring todo. only
# add new one if all active todos are completed
if recurring_todo.todos.active.count == 0
# check for next todo either from the due date or the show_from date
date_to_check = todo.due.nil? ? todo.show_from : todo.due
# if both due and show_from are nil, check for a next todo from now
date_to_check = Time.zone.now if date_to_check.nil?
if recurring_todo.active? && recurring_todo.has_next_todo(date_to_check)
# shift the reference date to yesterday if date_to_check is furher in
# the past. This is to make sure we do not get older todos for overdue
# todos. I.e. checking a daily todo that is overdue with 5 days will
@ -1084,7 +1114,7 @@ class TodosController < ApplicationController
end
return new_recurring_todo
end
def get_due_id_for_calendar(due)
return "" if due.nil?
due_today_date = Time.zone.now
@ -1104,7 +1134,7 @@ class TodosController < ApplicationController
end
return new_due_id
end
def is_old_due_empty(id)
return 0 == count_old_due_empty(id)
end
@ -1255,7 +1285,7 @@ class TodosController < ApplicationController
source_view do |page|
page.calendar do
@old_due_empty = is_old_due_empty(@original_item_due_id)
@new_due_id = get_due_id_for_calendar(@todo.due)
@new_due_id = get_due_id_for_calendar(@todo.due)
end
page.tag do
@tag_name = params['_tag_name']
@ -1276,14 +1306,14 @@ class TodosController < ApplicationController
return false if context_name.blank?
true
end
def determine_non_uniq_todo
# for calendar view. TODO: unused
all_list_uniq_ids = (@due_today.map(&:id) + @due_this_week.map(&:id) +
@due_next_week.map(&:id) + @due_this_month.map(&:id) + @due_after_this_month.map(&:id)).uniq
all_list_count = @due_today.count + @due_this_week.count +
@due_next_week.count + @due_this_month.count + @due_after_this_month.count
return !( all_list_uniq_ids.length == all_list_count )
end
@ -1311,54 +1341,54 @@ class TodosController < ApplicationController
@prefs = prefs
@attributes = params['request'] && params['request']['todo'] || params['todo']
end
def attributes
@attributes
end
def show_from
@attributes['show_from']
end
def due
@attributes['due']
end
def project_name
@params['project_name'].strip unless @params['project_name'].nil?
end
def context_name
@params['context_name'].strip unless @params['context_name'].nil?
end
def tag_list
@params['tag_list']
end
def predecessor_list
@params['predecessor_list']
end
def parse_dates()
@attributes['show_from'] = @prefs.parse_date(show_from)
@attributes['due'] = @prefs.parse_date(due)
@attributes['due'] ||= ''
end
def project_specified_by_name?
return false unless @attributes['project_id'].blank?
return false if project_name.blank?
return false if project_name == 'None'
true
end
def context_specified_by_name?
return false unless @attributes['context_id'].blank?
return false if context_name.blank?
true
end
end
end

View file

@ -282,6 +282,12 @@ module ApplicationHelper
done_todos_context_path(@context)
when "projects"
done_todos_project_path(@project)
when "todos"
if source_view_is(:tag)
done_tag_path(@tag_name)
else
done_todos_path
end
else
done_todos_path
end
@ -293,6 +299,12 @@ module ApplicationHelper
all_done_todos_context_path(@context)
when "projects"
all_done_todos_project_path(@project)
when "todos"
if source_view_is(:tag)
all_done_tag_path(@tag_name)
else
all_done_todos_path
end
else
all_done_todos_path
end

View file

@ -18,8 +18,8 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
<% unless todo.completed? || todo.deferred? -%>
<li><%= remote_defer_menu_item(1, todo) %></li>
<li><%= remote_defer_menu_item(7, todo) %></li>
<li><%= remote_promote_to_project_menu_item(todo) %></li>
<% end -%>
<li><%= remote_promote_to_project_menu_item(todo) %></li>
</ul>
</li>
</ul>