Skip to content

Commit

Permalink
get the done view on a context and a project
Browse files Browse the repository at this point in the history
  • Loading branch information
lrbalt committed Jul 9, 2011
1 parent 35fe362 commit a58e832
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 15 deletions.
18 changes: 18 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,24 @@ def self.prefered_auth?
def prefered_auth?
self.class.prefered_auth?
end

def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_day = Time.zone.now.beginning_of_day
completed_todos.completed_after(start_of_this_day).all(includes)
end

def get_done_this_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_week = Time.zone.now.beginning_of_week
start_of_this_day = Time.zone.now.beginning_of_day
completed_todos.completed_after(start_of_this_week).completed_before(start_of_this_day).all(includes)
end

def get_done_this_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_month = Time.zone.now.beginning_of_month
start_of_this_week = Time.zone.now.beginning_of_week
completed_todos.completed_after(start_of_this_month).completed_before(start_of_this_week).all(includes)
end


private

Expand Down
23 changes: 23 additions & 0 deletions app/controllers/contexts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ def order
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

@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')

@done = current_user.contexts.find(params[:id]).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
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,29 @@ def actionize
@contexts = current_user.contexts
end

def done_todos
@source_view = 'project'
@page_title = t('project.completed_tasks_title')

completed_todos = current_user.projects.find(params[:id]).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')

@done = current_user.projects.find(params[:id]).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
Expand Down
13 changes: 4 additions & 9 deletions app/controllers/todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,10 @@ def done
@page_title = t('todos.completed_tasks_title')

completed_todos = current_user.todos.completed
start_of_this_day = Time.zone.now.beginning_of_day
start_of_this_week = Time.zone.now.beginning_of_week
start_of_this_month = Time.zone.now.beginning_of_month
start_of_previous_month = (Time.zone.now.beginning_of_month - 1.day).beginning_of_month
includes = {:include => Todo::DEFAULT_INCLUDES}

@done_today = completed_todos.completed_after(start_of_this_day).all(includes)
@done_this_week = completed_todos.completed_after(start_of_this_week).completed_before(start_of_this_day).all(includes)
@done_this_month = completed_todos.completed_after(start_of_this_month).completed_before(start_of_this_week).all(includes)

@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
end

Expand Down
22 changes: 22 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,27 @@ def javascript_tag_for_i18n_datepicker
javascript_include_tag("i18n/jquery.ui.datepicker-#{locale}.js")
end
end

def determine_done_path
case @controller.controller_name
when "contexts"
done_todos_context_path(@context)
when "projects"
done_todos_project_path(@project)
else
done_todos_path
end
end

def determine_all_done_path
case @controller.controller_name
when "contexts"
all_done_todos_context_path(@context)
when "projects"
all_done_todos_project_path(@project)
else
all_done_todos_path
end
end

end
2 changes: 1 addition & 1 deletion app/models/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Todo < ActiveRecord::Base
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } }

STARRED_TAG_NAME = "starred"
DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :pending_successors, :successors, :predecessors, :recurring_todo ]
DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :recurring_todo ]

# regular expressions for dependencies
RE_TODO = /[^']+/
Expand Down
2 changes: 1 addition & 1 deletion app/views/todos/_completed.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
suppress_project ||= false
-%>
<div class="container completed" id="completed_container">
<div class=add_note_link><%= link_to "Show all", done_todos_path%></div>
<div class=add_note_link><%= link_to "Show all", determine_done_path%></div>
<h2>
<% if collapsible %>
<a href="#" class="container_toggle" id="toggle_completed"><%= image_tag("collapse.png") %></a>
Expand Down
2 changes: 1 addition & 1 deletion app/views/todos/done.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
<% end -%>
</div>

<p>You can see all completed actions <%= link_to "here", all_done_todos_path %></p>
<p>You can see all completed actions <%= link_to "here", determine_all_done_path %></p>

</div><!-- End of display_box -->
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
users.signup 'signup', :action => "new"
end

map.resources :contexts, :collection => {:order => :post} do |contexts|
map.resources :contexts, :collection => {:order => :post}, :member => {:done_todos => :get, :all_done_todos => :get} do |contexts|
contexts.resources :todos, :name_prefix => "context_"
end

map.with_options :controller => :contexts do |contexts|
contexts.done_contexts 'contexts/done', :action => 'done'
end

map.resources :projects, :collection => {:order => :post, :alphabetize => :post, :actionize => :post} do |projects|
map.resources :projects, :collection => {:order => :post, :alphabetize => :post, :actionize => :post},
:member => {:done_todos => :get, :all_done_todos => :get} do |projects|
projects.resources :todos, :name_prefix => "project_"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tracks/todo_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def done_todo_count
def deferred_todo_count
self.todos.count_in_state(:deferred)
end

end
end

0 comments on commit a58e832

Please sign in to comment.