add done views to projects and recurring todos

This commit is contained in:
Reinier Balt 2011-06-20 06:50:25 +02:00
parent 5496b84642
commit 35f947ec57
13 changed files with 166 additions and 20 deletions

View file

@ -32,6 +32,24 @@ 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
init_not_done_counts(['project'])
render
end
def projects_and_actions
@projects = current_user.projects.active
@ -259,7 +277,8 @@ 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
@completed_projects = current_user.projects.completed.find(:all, :limit => 10)
@completed_count = current_user.projects.completed.count
@no_projects = current_user.projects.empty?
current_user.projects.cache_note_counts
@new_project = current_user.projects.build

View file

@ -10,7 +10,7 @@ class RecurringTodosController < ApplicationController
find_and_inactivate
@recurring_todos = current_user.recurring_todos.active
@completed_recurring_todos = current_user.recurring_todos.completed
@completed_recurring_todos = current_user.recurring_todos.completed.find(:all, :limit => 10)
@no_recurring_todos = @recurring_todos.size == 0
@no_completed_recurring_todos = @completed_recurring_todos.size == 0
@ -24,6 +24,16 @@ class RecurringTodosController < ApplicationController
def show
end
def done
@page_title = t('todos.completed_recurring_actions_title')
items_per_page = 20
page = params[:page] || 1
@completed_recurring_todos = current_user.recurring_todos.completed.paginate :page => params[:page], :per_page => items_per_page
@total = @count = current_user.recurring_todos.completed.count
@range_low = (page.to_i-1) * items_per_page + 1
@range_high = @range_low + @completed_recurring_todos.size - 1
end
def edit
respond_to do |format|

View file

@ -1,5 +1,12 @@
<%-
total_count ||= -1
total_count_string = total_count!=-1 ? " / #{total_count}" : ""
-%>
<div class="project-state-group" id="list-<%= state %>-projects-container" <%= " style=\"display:none\"" if project_state_group.empty? %>>
<h2><span id="<%= state %>-projects-count" class="badge"><%= project_state_group.length %></span><%= t('states.'+state+'_plural' )%> <%= t('common.projects') %></h2>
<h2>
<span id="<%= state %>-projects-count" class="badge"><%= project_state_group.length%><%= total_count_string%></span>
<%= t('common.last' )%> <%= t('states.'+state+'_plural' )%> <%= t('common.projects') %><%= total_count==-1 ? "" : " ("+link_to("Show all", done_projects_path)+")"%>
</h2>
<div class="menu_sort"><span class="sort_separator"><%= t('common.sort.sort') %>&nbsp;</span>
<div class="alpha_sort">
<%= link_to(t("common.sort.alphabetically"), alphabetize_projects_path(:state => state),

View file

@ -0,0 +1,37 @@
<%
paginate_options = {
:class => :add_note_link,
:previous_label => '&laquo; '+ t('common.previous'),
:next_label => t('common.next')+' &raquo;',
:inner_window => 2
}
%>
<div id="display_box">
<div id="projects-empty-nd" style="<%= @no_projects ? 'display:block' : 'display:none'%>">
<div class="message"><p><%= t('projects.no_projects') %></p></div>
</div>
<div class="project-state-group" id="list-completed-projects-container" <%= " style=\"display:none\"" if @no_projects %>>
<%= will_paginate @projects, paginate_options %>
<h2>
<span id="completed-projects-count" class="badge"><%= "#{@total} (#{@range_low}-#{@range_high})" %></span>
<%= t('states.completed_plural' )%> <%= t('common.projects') %>
</h2>
<div id="list-completed-projects" class="project-list">
<%= render :partial => 'project_listing', :collection => @projects %>
</div>
</div>
<%= will_paginate @projects, paginate_options %>
</div>
<div id="input_box">
<div class="menu_sort"><h2><br/><%= t('common.sort.sort') %>&nbsp;<%= t('states.completed_plural' )%> <%= t('common.projects') %></h2>
<div class="alpha_sort">
<%= link_to(t("common.sort.alphabetically"), alphabetize_projects_path(:state => :completed),
:id => "completed_alphabetize_link", :class => "alphabetize_link", :title => t('common.sort.alphabetically_title'), :x_confirm_message => t('common.sort.alphabetically_confirm')) %>
</div><span class="sort_separator">&nbsp;|&nbsp;</span><div class="tasks_sort">
<%= link_to(t("common.sort.by_task_count"), actionize_projects_path(:state => :completed),
:id => "completed_actionize_link", :class => "actionize_link", :title => t('common.sort.by_task_count_title'), :x_confirm_message => t('common.sort.by_task_count_title_confirm')) %>
</div>
</div>
</div>

View file

@ -4,7 +4,7 @@
</div>
<%= render :partial => 'project_state_group', :object => @active_projects, :locals => { :state => 'active'} %>
<%= render :partial => 'project_state_group', :object => @hidden_projects, :locals => { :state => 'hidden'} %>
<%= render :partial => 'project_state_group', :object => @completed_projects, :locals => { :state => 'completed'} %>
<%= render :partial => 'project_state_group', :object => @completed_projects, :locals => { :state => 'completed', :total_count => @completed_count} %>
</div>
<div id="input_box">

View file

@ -0,0 +1,24 @@
<%
paginate_options = {
:class => :add_note_link,
:previous_label => '&laquo; '+ t('common.previous'),
:next_label => t('common.next')+' &raquo;',
:inner_window => 2
}
%>
<div id="display_box">
<div class="container" id="completed_recurring_todos_container">
<%= will_paginate @completed_recurring_todos, paginate_options %>
<h2>
<span id="completed-projects-count" class="badge"><%= "#{@total} (#{@range_low}-#{@range_high})" %></span>
<%= t('todos.completed_recurring') %>
</h2>
<div id="completed_recurring_todos_container">
<div id="completed-empty-nd" style="<%= @no_completed_recurring_todos ? 'display:block' : 'display:none'%>">
<div class="message"><p><%= t('todos.no_completed_recurring') %></p></div>
</div>
<%= render :partial => @completed_recurring_todos %>
</div>
<%= will_paginate @completed_recurring_todos, paginate_options %>
</div>
</div>

View file

@ -10,7 +10,8 @@
</div>
<div class="container" id="completed_recurring_todos_container">
<h2><%= t('todos.completed_recurring') %></h2>
<div class=add_note_link><%= link_to "Show all", done_recurring_todos_path%></div>
<h2><%= t('common.last') %> <%= t('todos.completed_recurring') %></h2>
<div id="completed_recurring_todos_container">
<div id="completed-empty-nd" style="<%= @no_completed_recurring_todos ? 'display:block' : 'display:none'%>">
<div class="message"><p><%= t('todos.no_completed_recurring') %></p></div>

View file

@ -1,2 +0,0 @@
<h1>RecurringTodo#show</h1>
<p>Find me in app/views/recurring_todo/show.html.erb</p>

View file

@ -8,23 +8,15 @@ ActionController::Routing::Routes.draw do |map|
users.signup 'signup', :action => "new"
end
map.resources :contexts, :collection => {:order => :post}, :member => {:done_todos => :get, :all_done_todos => :get} do |contexts|
map.resources :contexts, :collection => {:order => :post, :done => :get}, :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},
map.resources :projects, :collection => {:order => :post, :alphabetize => :post, :actionize => :post, :done => :get},
:member => {:done_todos => :get, :all_done_todos => :get} do |projects|
projects.resources :todos, :name_prefix => "project_"
end
map.with_options :controller => :projects do |projects|
projects.done_projects 'projects/done', :action => 'done'
end
map.resources :notes
map.resources :todos,
@ -62,11 +54,10 @@ ActionController::Routing::Routes.draw do |map|
end
map.root :controller => 'todos' # Make OpenID happy because it needs #root_url defined
map.resources :recurring_todos,
map.resources :recurring_todos, :collection => {:done => :get},
:member => {:toggle_check => :put, :toggle_star => :put}
map.with_options :controller => :recurring_todos do |rt|
rt.recurring_todos 'recurring_todos', :action => 'index'
rt.done_recurring_todos 'recurring_todos/done', :action => 'done'
end
map.with_options :controller => :login do |login|

View file

@ -37,6 +37,19 @@ Given /^I have the following projects:$/ do |table|
end
end
Given /^I have a completed project called "([^"]*)"$/ do |project_name|
Given "I have a project called \"#{project_name}\""
@project.complete!
@project.reload
assert @project.completed?
end
Given /^I have (\d+) completed projects$/ do |number_of_projects|
1.upto number_of_projects.to_i do |i|
Given "I have a completed project called \"Project #{i}\""
end
end
Given /^I have no projects$/ do
Project.delete_all
end

View file

@ -26,6 +26,12 @@ Given /^I have a completed repeat pattern "([^"]*)"$/ do |pattern_name|
@recurring_todo.completed?.should be_true
end
Given /^I have (\d+) completed repeat patterns$/ do |number_of_patterns|
1.upto number_of_patterns.to_i do |i|
Given "I have a completed repeat pattern \"Repeating Todo #{i}\""
end
end
When /^I select "([^\"]*)" recurrence pattern$/ do |recurrence_period|
selenium.click("recurring_todo_recurring_period_#{recurrence_period.downcase}")
end

View file

@ -68,7 +68,8 @@ Given /^I have ([0-9]+) completed todos in context "([^"]*)"$/ do |count, contex
end
Given /^I have ([0-9]+) completed todos$/ do |count|
Given "I have #{count} completed todos in the context \"context D\""
Given "I have a context called \"context D\""
Given "I have #{count} completed todos in context \"context D\""
end
Given /^I have ([0-9]+) completed todos with a note$/ do |count|

View file

@ -71,3 +71,42 @@ Feature: Show done
And I should see "Show all"
When I follow "Show all"
Then I should be on the done actions page for project "test"
Scenario: The projects page shows a link to all completed projects
Given I have a completed project called "finished"
When I go to the projects page
Then I should see "finished"
And I should see "Show all"
When I follow "Show all"
Then I should be on the done projects page
And I should see "finished"
Scenario: I can browse all completed projects by page
Given I have 40 completed projects
When I go to the projects page
Then I should see "10 / 40"
When I follow "Show all"
Then I should see the page selector
And I should see "40 (1-20)"
When I follow "2"
Then I should be on the done projects page
And the page should be "2"
Scenario: The recurring todos page shows a link to all completed recurring todos
Given I have a completed repeat pattern "finished"
When I go to the recurring todos page
Then I should see "finished"
And I should see "Show all"
When I follow "Show all"
Then I should be on the done recurring todos page
And I should see "finished"
Scenario: I can browse all completed recurring todos by page
Given I have 40 completed repeat patterns
When I go to the recurring todos page
And I follow "Show all"
Then I should see the page selector
And I should see "40 (1-20)"
When I follow "2"
Then I should be on the done recurring todos page
And the page should be "2"