start modifying done view and do some refactoring

This commit is contained in:
Reinier Balt 2011-05-01 12:48:32 +02:00
parent de7b8e329d
commit 01057af684
19 changed files with 160 additions and 202 deletions

View file

@ -212,14 +212,14 @@ class ContextsController < ApplicationController
def render_contexts_rss_feed
lambda do
render_rss_feed_for current_user.contexts.all, :feed => feed_options,
:item => { :description => lambda { |c| c.summary(count_undone_todos_phrase(c)) } }
:item => { :description => lambda { |c| @template.summary(c, count_undone_todos_phrase(c)) } }
end
end
def render_contexts_atom_feed
lambda do
render_atom_feed_for current_user.contexts.all, :feed => feed_options,
:item => { :description => lambda { |c| c.summary(count_undone_todos_phrase(c)) },
:item => { :description => lambda { |c| @template.summary(c, count_undone_todos_phrase(c)) },
:author => lambda { |c| nil } }
end
end

View file

@ -48,8 +48,8 @@ class ProjectsController < ApplicationController
@page_title = t('projects.page_title', :project => @project.name)
@not_done = @project.todos.active_or_hidden(:include => [:tags, :context, :predecessors])
@deferred = @project.deferred_todos(:include => [:tags, :context, :predecessors])
@pending = @project.pending_todos(:include => [:tags, :context, :predecessors])
@deferred = @project.todos.deferred(:include => [:tags, :context, :predecessors])
@pending = @project.todos.pending(:include => [:tags, :context, :predecessors])
@done = @project.todos.find_in_state(:all, :completed,
:order => "todos.completed_at DESC", :limit => current_user.prefs.show_number_completed, :include => [:context, :tags, :predecessors])
@ -274,14 +274,14 @@ class ProjectsController < ApplicationController
lambda do
render_rss_feed_for @projects, :feed => feed_options,
:title => :name,
:item => { :description => lambda { |p| summary(p) } }
:item => { :description => lambda { |p| @template.summary(p) } }
end
end
def render_atom_feed
lambda do
render_atom_feed_for @projects, :feed => feed_options,
:item => { :description => lambda { |p| summary(p) },
:item => { :description => lambda { |p| @template.summary(p) },
:title => :name,
:author => lambda { |p| nil } }
end
@ -319,13 +319,4 @@ class ProjectsController < ApplicationController
end
end
def summary(project)
project_description = ''
project_description += sanitize(markdown( project.description )) unless project.description.blank?
project_description += "<p>#{count_undone_todos_phrase(p)}. "
project_description += t('projects.project_state', :state => project.state)
project_description += "</p>"
project_description
end
end

View file

@ -7,9 +7,9 @@ class TodosController < ApplicationController
append_before_filter :find_and_activate_ready, :only => [:index, :list_deferred]
# TODO: replace :except with :only
append_before_filter :init, :except => [ :tag, :tags, :destroy, :completed,
:completed_archive, :check_deferred, :toggle_check, :toggle_star,
:edit, :update, :defer, :create, :calendar, :auto_complete_for_predecessor, :remove_predecessor, :add_predecessor]
append_before_filter :init, :except => [ :tag, :tags, :destroy, :done,
:check_deferred, :toggle_check, :toggle_star, :edit, :update, :defer, :create,
:calendar, :auto_complete_for_predecessor, :remove_predecessor, :add_predecessor]
protect_from_forgery :except => :check_deferred
@ -349,7 +349,7 @@ class TodosController < ApplicationController
determine_remaining_in_context_count(@original_item_context_id)
respond_to do |format|
format.js {render :action => :update }
format.js { render :action => :update }
format.xml { render :xml => @todo.to_xml( :except => :user_id ) }
end
end
@ -468,21 +468,16 @@ class TodosController < ApplicationController
end
end
def completed
def done
@source_view = 'done'
@page_title = t('todos.completed_tasks_title')
@done = current_user.completed_todos
@done_today = @done.completed_within Time.zone.now - 1.day
@done_this_week = @done.completed_within Time.zone.now - 1.week
@done_this_month = @done.completed_within Time.zone.now - 4.week
completed_todos = current_user.todos.completed
@done_today = completed_todos.completed_after(Time.zone.now.beginning_of_day)
@done_this_week = completed_todos.completed_after(Time.zone.now.beginning_of_week)-@done_today
@done_this_month = completed_todos.completed_after(Time.zone.now.beginning_of_month)-@done_this_week
@done_previous_month = completed_todos.completed_after( (Time.zone.now.beginning_of_month - 1.day).beginning_of_month)-@done_this_month
@count = @done_today.size + @done_this_week.size + @done_this_month.size
end
def completed_archive
@page_title = t('todos.archived_tasks_title')
@done = current_user.completed_todos
@count = @done.size
@done_archive = @done.completed_more_than Time.zone.now - 28.days
end
def list_deferred
@source_view = 'deferred'
@ -490,7 +485,7 @@ class TodosController < ApplicationController
@contexts_to_show = @contexts = current_user.contexts.find(:all)
@not_done_todos = current_user.deferred_todos(:include => [:tags, :taggings, :projects]) + current_user.pending_todos(:include => [:tags, :taggings, :projects])
@not_done_todos = current_user.todos.deferred(:include => [:tags, :taggings, :projects]) + current_user.todos.pending(:include => [:tags, :taggings, :projects])
@down_count = @count = @not_done_todos.size
respond_to do |format|

View file

@ -1,25 +1,30 @@
module ContextsHelper
def get_listing_sortable_options
{
:tag => 'div',
:handle => 'handle',
:complete => visual_effect(:highlight, 'list-contexts'),
:url => order_contexts_path
}
end
def get_listing_sortable_options
{
:tag => 'div',
:handle => 'handle',
:complete => visual_effect(:highlight, 'list-contexts'),
:url => order_contexts_path
}
end
def link_to_delete_context(context, descriptor = sanitize(context.name))
link_to(
descriptor,
context_path(context, :format => 'js'),
{
:id => "delete_context_#{context.id}",
:class => "delete_context_button",
:x_confirm_message => t('contexts.delete_context_confirmation', :name => context.name),
:title => t('contexts.delete_context_title')
}
)
end
def summary(context, undone_todo_count)
content_tag(:p, "#{undone_todo_count}. Context is #{context.hidden? ? 'Hidden' : 'Active'}.")
end
def link_to_delete_context(context, descriptor = sanitize(context.name))
link_to(
descriptor,
context_path(context, :format => 'js'),
{
:id => "delete_context_#{context.id}",
:class => "delete_context_button",
:x_confirm_message => t('contexts.delete_context_confirmation', :name => context.name),
:title => t('contexts.delete_context_title')
}
)
end
end

View file

@ -57,5 +57,14 @@ module ProjectsHelper
}
)
end
def summary(project)
project_description = ''
project_description += sanitize(markdown( project.description )) unless project.description.blank?
project_description += content_tag(:p,
"#{count_undone_todos_phrase(p)}. " + t('projects.project_state', :state => project.state)
)
project_description
end
end

View file

@ -19,6 +19,7 @@ class Context < ActiveRecord::Base
validates_does_not_contain :name, :string => ',', :message => "cannot contain the comma (',') character"
def self.feed_options(user)
# TODO: move to view or helper
{
:title => 'Tracks Contexts',
:description => "Lists all the contexts for #{user.display_name}"
@ -36,14 +37,7 @@ class Context < ActiveRecord::Base
def title
name
end
def summary(undone_todo_count)
s = "<p>#{undone_todo_count}. "
s += "Context is #{hidden? ? 'Hidden' : 'Active'}."
s += "</p>"
s
end
def new_record_before_save?
@new_record_before_save
end

View file

@ -1,28 +1,5 @@
class Project < ActiveRecord::Base
has_many :todos, :dependent => :delete_all
# TODO: remove these scopes. Can be replaced by the named scopes on the todo relation
has_many :not_done_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:conditions => ["todos.state = ?", 'active']
has_many :done_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:conditions => ["todos.state = ?", 'completed']
has_many :deferred_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:conditions => ["todos.state = ? ", "deferred"],
:order => "show_from"
has_many :pending_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:conditions => ["todos.state = ? ", "pending"],
:order => "show_from"
has_many :notes, :dependent => :delete_all, :order => "created_at DESC"
has_many :recurring_todos

View file

@ -1,5 +1,8 @@
class Todo < ActiveRecord::Base
after_save :save_predecessors
# relations
belongs_to :context
belongs_to :project
belongs_to :user
@ -13,20 +16,17 @@ class Todo < ActiveRecord::Base
:source => :predecessor, :conditions => ['NOT (todos.state = ?)', 'completed']
has_many :pending_successors, :through => :predecessor_dependencies,
:source => :successor, :conditions => ['todos.state = ?', 'pending']
after_save :save_predecessors
# scopes for states of this todo
named_scope :active, :conditions => { :state => 'active' }
named_scope :active_or_hidden, :conditions => ["todos.state = ? OR todos.state = ?", 'active', 'project_hidden']
named_scope :not_completed, :conditions => ['NOT (todos.state = ? )', 'completed']
named_scope :completed, :conditions => ["NOT(todos.completed_at IS NULL)"]
named_scope :are_due, :conditions => ['NOT (todos.due IS NULL)']
named_scope :deferred, :conditions => ["todos.completed_at IS NULL AND NOT(todos.show_from IS NULL)"]
named_scope :not_completed, :conditions => ['NOT (todos.state = ?)', 'completed']
named_scope :completed, :conditions => ["NOT (todos.completed_at IS NULL)"]
named_scope :deferred, :conditions => ["todos.completed_at IS NULL AND NOT (todos.show_from IS NULL)"]
named_scope :blocked, :conditions => ['todos.state = ?', 'pending']
named_scope :pending, :conditions => ['todos.state = ?', 'pending']
named_scope :deferred_or_blocked, :conditions => ["(todos.completed_at IS NULL AND NOT(todos.show_from IS NULL)) OR (todos.state = ?)", "pending"]
named_scope :not_deferred_or_blocked, :conditions => ["todos.completed_at IS NULL AND todos.show_from IS NULL AND NOT(todos.state = ?)", "pending"]
named_scope :with_tag, lambda { |tag| {:joins => :taggings, :conditions => ["taggings.tag_id = ? ", tag.id] } }
named_scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } }
named_scope :hidden,
:joins => :context,
:conditions => ["todos.state = ? OR (contexts.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))",
@ -36,6 +36,13 @@ class Todo < ActiveRecord::Base
:conditions => ['NOT(todos.state = ? OR (contexts.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))',
'project_hidden', true, 'active', 'deferred', 'pending']
# other scopes
named_scope :are_due, :conditions => ['NOT (todos.due IS NULL)']
named_scope :with_tag, lambda { |tag| {:joins => :taggings, :conditions => ["taggings.tag_id = ? ", tag.id] } }
named_scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } }
named_scope :completed_after, lambda { |date| {:conditions => ["todos.completed_at > ? ", date] } }
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } }
STARRED_TAG_NAME = "starred"
# regular expressions for dependencies
@ -302,7 +309,7 @@ class Todo < ActiveRecord::Base
context_id = default_context_id
unless(context.nil?)
found_context = user.active_contexts.find_by_namepart(context)
found_context = user.contexts.active.find_by_namepart(context)
found_context = user.contexts.find_by_namepart(context) if found_context.nil?
context_id = found_context.id unless found_context.nil?
end
@ -318,7 +325,7 @@ class Todo < ActiveRecord::Base
found_project.name = project[4..255+4].strip
found_project.save!
else
found_project = user.active_projects.find_by_namepart(project)
found_project = user.projects.active.find_by_namepart(project)
found_project = user.projects.find_by_namepart(project) if found_project.nil?
end
project_id = found_project.id unless found_project.nil?

View file

@ -79,19 +79,9 @@ class User < ActiveRecord::Base
return find(:all, :conditions => scope_conditions)
end
end
has_many :active_projects,
:class_name => 'Project',
:order => 'projects.position ASC',
:conditions => [ 'state = ?', 'active' ]
has_many :active_contexts,
:class_name => 'Context',
:order => 'position ASC',
:conditions => [ 'hide = ?', false ]
has_many :todos,
:order => 'todos.completed_at DESC, todos.created_at DESC',
:dependent => :delete_all
has_many :project_hidden_todos,
:conditions => ['(state = ? OR state = ?)', 'project_hidden', 'active']
has_many :recurring_todos,
:order => 'recurring_todos.completed_at DESC, recurring_todos.created_at DESC',
:dependent => :delete_all
@ -103,23 +93,6 @@ class User < ActiveRecord::Base
find(:all, :conditions => ['show_from <= ?', Time.zone.now ]).collect { |t| t.activate! }
end
end
has_many :pending_todos,
:class_name => 'Todo',
:conditions => [ 'state = ?', 'pending' ],
:order => 'show_from ASC, todos.created_at DESC'
has_many :completed_todos,
:class_name => 'Todo',
:conditions => ['todos.state = ? AND NOT(todos.completed_at IS NULL)', 'completed'],
:order => 'todos.completed_at DESC',
:include => [ :project, :context ] do
def completed_within( date )
reject { |x| x.completed_at < date }
end
def completed_more_than( date )
reject { |x| x.completed_at > date }
end
end
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
has_one :preference, :dependent => :destroy

View file

@ -1,25 +0,0 @@
<div id="display_box_projects">
<p><%= t('todos.completed_today', :count => @due_tickles.nil? ? 0 : @due_tickles.length) %></p>
<div class="container">
<h2><%= t('todos.completed_last_day') %></h2>
<table class="next_actions" border="0">
<%= render :partial => "done", :collection => @done_today %>
</table>
</div>
<div class="container">
<h2><%= t('todos.completed_last_x_days', :count => 7) %></h2>
<table class="next_actions" border="0">
<%= render :partial => "done", :collection => @done_this_week %>
</table>
</div>
<div class="container">
<h2><%= t('todos.completed_last_x_days', :count => 28) %></h2>
<table class="next_actions" border="0">
<%= render :partial => "done", :collection => @done_this_month %>
</table>
</div>
<p><%= t('todos.older_completed_items') %>: <%= link_to( t('todos.older_than_days', :count => 31), done_archive_path ) %></p>
</div><!-- End of display_box -->

View file

@ -1,11 +0,0 @@
<div id="display_box_projects">
<p><%= t('todos.completed_in_archive', :count => @done_archive.length) %></p>
<div class="container">
<h2><%= t('todos.completed_more_than_x_days_ago', :count => 31) %></h2>
<table class="next_actions" cellspacing="5" cellpadding="0" border="0">
<%= render :partial => "done", :collection => @done_archive %>
</table>
</div>
</div><!-- End of display_box -->

View file

@ -0,0 +1,39 @@
<div id="display_box_projects">
<div class="container">
<h2><%= t('todos.completed_today') %></h2>
<% if @done_today.empty? -%>
<div class="message"><p><%= t('todos.no_completed_actions') %></p></div>
<% else -%>
<%= render :partial => "todos/todo", :collection => @done_today, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %>
<% end -%>
</div>
<div class="container">
<h2><%= t('todos.completed_rest_of_week') %></h2>
<% if @done_this_week.empty? -%>
<div class="message"><p><%= t('todos.no_completed_actions') %></p></div>
<% else -%>
<%= render :partial => "todos/todo", :collection => @done_this_week, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %>
<% end -%>
</div>
<div class="container">
<h2><%= t('todos.completed_rest_of_month', :month_name => 'TODO') %></h2>
<% if @done_this_month.empty? -%>
<div class="message"><p><%= t('todos.no_completed_actions') %></p></div>
<% else -%>
<%= render :partial => "todos/todo", :collection => @done_this_month, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %>
<% end -%>
</div>
<div class="container">
<h2><%= t('todos.completed_rest_of_previous_month', :month_name => 'TODO2') %></h2>
<% if @done_previous_month.empty? -%>
<div class="message"><p><%= t('todos.no_completed_actions') %></p></div>
<% else -%>
<%= render :partial => "todos/todo", :collection => @done_previous_month, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %>
<% end -%>
</div>
</div><!-- End of display_box -->