mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-01 23:08:49 +01:00
Added ability to sort projects alphabetically on the project listing page. Closes #461 (Ability to alphabetically sort projects as an alternative to drag/drop)
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@524 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
3946dbf0c1
commit
2d73602d98
8 changed files with 67 additions and 2 deletions
|
|
@ -127,6 +127,11 @@ class ProjectsController < ApplicationController
|
|||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def alphabetize
|
||||
@state = params['state']
|
||||
@projects = @user.projects.alphabetize(:state => @state) if @state
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def render_projects_html
|
||||
|
|
|
|||
|
|
@ -42,6 +42,12 @@ class User < ActiveRecord::Base
|
|||
project.cached_note_count = project_note_counts[project.id] || 0
|
||||
end
|
||||
end
|
||||
def alphabetize(scope_conditions = {})
|
||||
projects = find(:all, :conditions => scope_conditions)
|
||||
projects.sort!{ |x,y| x.name <=> y.name }
|
||||
self.update_positions(projects.map{ |p| p.id })
|
||||
return projects
|
||||
end
|
||||
end
|
||||
has_many :todos,
|
||||
:order => 'completed_at DESC, todos.created_at DESC',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,15 @@
|
|||
<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="alpha_sort">
|
||||
<%= link_to("Sort Alphabetically", alphabetize_projects_path(:state => state),
|
||||
:class => "alphabetize_link", :title => "Sort these projects alphabetically") %>
|
||||
<% apply_behavior '.alphabetize_link:click', :prevent_default => true do |page|
|
||||
page << "if (confirm('Are you sure that you want to sort these projects alphabetically? This will replace the existing sort order.')) {"
|
||||
page << " new Ajax.Request(this.href, { asynchronous : true, evalScripts : true, method : 'post' })"
|
||||
page << "}"
|
||||
end
|
||||
%></div>
|
||||
|
||||
<div id="list-<%= state %>-projects">
|
||||
<%= render :partial => 'project_listing', :collection => project_state_group %>
|
||||
</div>
|
||||
|
|
|
|||
3
tracks/app/views/projects/alphabetize.rjs
Normal file
3
tracks/app/views/projects/alphabetize.rjs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
page.replace_html "list-#{@state}-projects",
|
||||
:partial => 'project_listing',
|
||||
:collection => @projects
|
||||
|
|
@ -19,7 +19,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
end
|
||||
|
||||
# Projects Routes
|
||||
map.resources :projects, :collection => {:order => :post} do |projects|
|
||||
map.resources :projects, :collection => {:order => :post, :alphabetize => :post} do |projects|
|
||||
projects.resources :todos, :name_prefix => "project_"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -526,8 +526,15 @@ div.buttons, div.buttons a, div.buttons a:hover {
|
|||
}
|
||||
|
||||
div#list-active-projects, div#list-hidden-projects, div#list-completed-projects, div#list-contexts, div#projects-empty-nd {
|
||||
border: 1px solid #999;
|
||||
clear:right;
|
||||
border: 1px solid #999;
|
||||
}
|
||||
|
||||
div.alpha_sort {
|
||||
margin-top:-20px;
|
||||
float:right;
|
||||
}
|
||||
|
||||
|
||||
.container td {
|
||||
border: none;
|
||||
|
|
|
|||
|
|
@ -214,6 +214,31 @@ class ProjectsControllerTest < TodoContainerControllerTestBase
|
|||
get :index, { :format => "txt", :token => users(:admin_user).word }
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
def test_alphabetize_sorts_active_projects_alphabetically
|
||||
u = users(:admin_user)
|
||||
@request.session['user_id'] = u.id
|
||||
post :alphabetize, { :state => "active" }
|
||||
assert_equal 1, projects(:timemachine).position
|
||||
assert_equal 2, projects(:gardenclean).position
|
||||
assert_equal 3, projects(:moremoney).position
|
||||
end
|
||||
|
||||
def test_alphabetize_assigns_state
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
post :alphabetize, { :state => "active" }
|
||||
assert_equal "active", assigns['state']
|
||||
end
|
||||
|
||||
def test_alphabetize_assigns_projects
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
post :alphabetize, { :state => "active" }
|
||||
exposed_projects = assigns['projects']
|
||||
assert_equal 3, exposed_projects.length
|
||||
assert_equal projects(:timemachine), exposed_projects[0]
|
||||
assert_equal projects(:gardenclean), exposed_projects[1]
|
||||
assert_equal projects(:moremoney), exposed_projects[2]
|
||||
end
|
||||
|
||||
private
|
||||
def show(project)
|
||||
|
|
|
|||
|
|
@ -269,5 +269,14 @@ class UserTest < Test::Unit::TestCase
|
|||
todos = @admin_user.completed_todos.completed_more_than(@admin_user.time - 1.day)
|
||||
assert_equal 1, todos.length
|
||||
end
|
||||
|
||||
def test_sort_active_projects_alphabetically
|
||||
u = users(:admin_user)
|
||||
u.projects.alphabetize(:state => "active")
|
||||
assert_equal 1, projects(:timemachine).position
|
||||
assert_equal 2, projects(:gardenclean).position
|
||||
assert_equal 3, projects(:moremoney).position
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue