mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-20 09:10:12 +01:00
get the done view on a context and a project
This commit is contained in:
parent
35fe362b93
commit
a58e832945
10 changed files with 96 additions and 14 deletions
|
|
@ -225,6 +225,24 @@ class ApplicationController < ActionController::Base
|
||||||
self.class.prefered_auth?
|
self.class.prefered_auth?
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def parse_date_per_user_prefs( s )
|
def parse_date_per_user_prefs( s )
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,29 @@ class ContextsController < ApplicationController
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
end
|
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
|
protected
|
||||||
|
|
||||||
def update_state_counts
|
def update_state_counts
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,29 @@ class ProjectsController < ApplicationController
|
||||||
@contexts = current_user.contexts
|
@contexts = current_user.contexts
|
||||||
end
|
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
|
protected
|
||||||
|
|
||||||
def update_state_counts
|
def update_state_counts
|
||||||
|
|
|
||||||
|
|
@ -472,15 +472,10 @@ class TodosController < ApplicationController
|
||||||
@page_title = t('todos.completed_tasks_title')
|
@page_title = t('todos.completed_tasks_title')
|
||||||
|
|
||||||
completed_todos = current_user.todos.completed
|
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_today = get_done_today(completed_todos)
|
||||||
@done_this_week = completed_todos.completed_after(start_of_this_week).completed_before(start_of_this_day).all(includes)
|
@done_this_week = get_done_this_week(completed_todos)
|
||||||
@done_this_month = completed_todos.completed_after(start_of_this_month).completed_before(start_of_this_week).all(includes)
|
@done_this_month = get_done_this_month(completed_todos)
|
||||||
@count = @done_today.size + @done_this_week.size + @done_this_month.size
|
@count = @done_today.size + @done_this_week.size + @done_this_month.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -276,4 +276,26 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class Todo < ActiveRecord::Base
|
||||||
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } }
|
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } }
|
||||||
|
|
||||||
STARRED_TAG_NAME = "starred"
|
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
|
# regular expressions for dependencies
|
||||||
RE_TODO = /[^']+/
|
RE_TODO = /[^']+/
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
suppress_project ||= false
|
suppress_project ||= false
|
||||||
-%>
|
-%>
|
||||||
<div class="container completed" id="completed_container">
|
<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>
|
<h2>
|
||||||
<% if collapsible %>
|
<% if collapsible %>
|
||||||
<a href="#" class="container_toggle" id="toggle_completed"><%= image_tag("collapse.png") %></a>
|
<a href="#" class="container_toggle" id="toggle_completed"><%= image_tag("collapse.png") %></a>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,6 @@
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</div>
|
</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 -->
|
</div><!-- End of display_box -->
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
users.signup 'signup', :action => "new"
|
users.signup 'signup', :action => "new"
|
||||||
end
|
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_"
|
contexts.resources :todos, :name_prefix => "context_"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -16,7 +16,8 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
contexts.done_contexts 'contexts/done', :action => 'done'
|
contexts.done_contexts 'contexts/done', :action => 'done'
|
||||||
end
|
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_"
|
projects.resources :todos, :name_prefix => "project_"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue