Skip to content

Commit

Permalink
add done views to projects and recurring todos
Browse files Browse the repository at this point in the history
  • Loading branch information
lrbalt committed Jul 9, 2011
1 parent 5496b84 commit 35f947e
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 20 deletions.
21 changes: 20 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ def index
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
Expand Down Expand Up @@ -259,7 +277,8 @@ def render_projects_html
@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
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/recurring_todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index

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
Expand All @@ -24,6 +24,16 @@ def new

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|
Expand Down
9 changes: 8 additions & 1 deletion app/views/projects/_project_state_group.rhtml
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
37 changes: 37 additions & 0 deletions app/views/projects/done.html.erb
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
24 changes: 24 additions & 0 deletions app/views/recurring_todos/done.html.erb
Original file line number Diff line number Diff line change
@@ -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>
3 changes: 2 additions & 1 deletion app/views/recurring_todos/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 0 additions & 2 deletions app/views/recurring_todos/show.html.erb

This file was deleted.

15 changes: 3 additions & 12 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@
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,
Expand Down Expand Up @@ -62,11 +54,10 @@
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|
Expand Down
13 changes: 13 additions & 0 deletions features/step_definitions/project_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
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
Expand Down
6 changes: 6 additions & 0 deletions features/step_definitions/recurring_todo_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
@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
Expand Down
3 changes: 2 additions & 1 deletion features/step_definitions/todo_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
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|
Expand Down
39 changes: 39 additions & 0 deletions features/view_done.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 35f947e

Please sign in to comment.