Merge branch 'sort_projects_by_todos' of git://github.com/waltercruz/tracks

This commit is contained in:
Reinier Balt 2008-10-28 20:59:07 +01:00
commit 76d72b54bf
7 changed files with 59 additions and 3 deletions

View file

@ -186,6 +186,13 @@ class ProjectsController < ApplicationController
init_not_done_counts(['project'])
end
def actionize
@state = params['state']
@projects = current_user.projects.actionize(current_user.id, :state => @state) if @state
@contexts = current_user.contexts
init_not_done_counts(['project'])
end
protected
def render_projects_html

View file

@ -51,6 +51,21 @@ class User < ActiveRecord::Base
self.update_positions(projects.map{ |p| p.id })
return projects
end
def actionize(user_id, scope_conditions = {})
@state = scope_conditions[:state]
query_state = ''
query_state = 'AND project.state = "' + @state +'" 'if @state
projects = Project.find_by_sql([
"SELECT project.id, count(todo.id) as p_count " +
"FROM projects as project " +
"LEFT OUTER JOIN todos as todo ON todo.project_id = project.id "+
"WHERE project.user_id = ? AND NOT todo.state='completed' " +
query_state +
" GROUP BY project.id ORDER by p_count DESC",user_id])
self.update_positions(projects.map{ |p| p.id })
projects = find(:all, :conditions => scope_conditions)
return projects
end
end
has_many :active_projects,
:class_name => 'Project',

View file

@ -1,7 +1,8 @@
<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><%= state.titlecase %> Projects</h2>
<div class="menu_sort"><span class="sort_separator">Sort&nbsp;</span>
<div class="alpha_sort">
<%= link_to("Sort Alphabetically", alphabetize_projects_path(:state => state),
<%= link_to("Alphabetically", alphabetize_projects_path(:state => state),
:class => "alphabetize_link", :title => "Sort these projects alphabetically") %>
<% apply_behavior '.alphabetize_link:click', :prevent_default => true do |page, element|
page.confirming 'Are you sure that you want to sort these projects alphabetically? This will replace the existing sort order.' do
@ -10,10 +11,21 @@
page << remote_to_href(:complete => "alphaSort.stopWaiting()")
end
end
%></div><span class="sort_separator">&nbsp;|&nbsp;</span><div class="tasks_sort">
<%= link_to("By number of tasks", actionize_projects_path(:state => state),
:class => "actionize_link", :title => "Sort these projects by number of tasks") %>
<% apply_behavior '.actionize_link:click', :prevent_default => true do |page, element|
page.confirming 'Are you sure that you want to sort these projects by the number of tasks? This will replace the existing sort order.' do
page << "tasksSort = this.up('.tasks_sort');
tasksSort.startWaiting();"
page << remote_to_href(:complete => "tasksSort.stopWaiting()")
end
end
%></div>
</div>
<div id="list-<%= state %>-projects" class="project-list">
<%= render :partial => 'project_listing', :collection => project_state_group %>
</div>
<%= sortable_element "list-#{state}-projects", get_listing_sortable_options("list-#{state}-projects") %>
</div>
</div>

View file

@ -0,0 +1,6 @@
list_id = "list-#{@state}-projects"
page.replace_html list_id,
:partial => 'project_listing',
:collection => @projects
page.sortable list_id, get_listing_sortable_options(list_id)

View file

@ -28,6 +28,10 @@ ActionController::Routing::Routes.draw do |map|
projects.resources :todos, :name_prefix => "project_"
end
map.resources :projects, :collection => {:order => :post, :actionize => :post} do |projects|
projects.resources :todos, :name_prefix => "project_"
end
map.resources :todos,
:member => {:toggle_check => :put, :toggle_star => :put},
:collection => {:check_deferred => :post, :filter_to_context => :post, :filter_to_project => :post}

View file

@ -692,11 +692,14 @@ div#list-active-projects, div#list-hidden-projects, div#list-completed-projects,
margin:20px 0px 8px 13px
}
div.alpha_sort {
div.menu_sort {
margin-top:-20px;
float:right;
}
div.alpha_sort, div.tasks_sort,span.sort_separator {
float:left;
}
.container td {
border: none;

View file

@ -218,6 +218,15 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
get :index, { :format => "txt", :token => users(:admin_user).token }
assert_response :ok
end
def test_actionize_sorts_active_projects_by_number_of_tasks
login_as :admin_user
u = users(:admin_user)
post :actionize, :state => "active", :format => 'js'
assert_equal 1, projects(:gardenclean).position
assert_equal 2, projects(:timemachine).position
assert_equal 3, projects(:moremoney).position
end
def test_alphabetize_sorts_active_projects_alphabetically
login_as :admin_user