mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Ading a sort by number of tasks option
This commit is contained in:
parent
0673d67b62
commit
ee5c730f44
4 changed files with 30 additions and 1 deletions
|
|
@ -186,6 +186,13 @@ class ProjectsController < ApplicationController
|
|||
init_not_done_counts(['project'])
|
||||
end
|
||||
|
||||
def actionize
|
||||
@state = params['state']
|
||||
@projects = current_user.projects.actionize(:state => @state) if @state
|
||||
@contexts = current_user.contexts
|
||||
init_not_done_counts(['project'])
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def render_projects_html
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@ class User < ActiveRecord::Base
|
|||
self.update_positions(projects.map{ |p| p.id })
|
||||
return projects
|
||||
end
|
||||
def actionize(scope_conditions = {})
|
||||
projects = find(:all, :conditions => scope_conditions)
|
||||
projects.sort!{ |x,y| y.todos.count(:state == 'active') <=> x.todos.count(:state == 'active') }
|
||||
self.update_positions(projects.map{ |p| p.id })
|
||||
return projects
|
||||
end
|
||||
end
|
||||
has_many :active_projects,
|
||||
:class_name => 'Project',
|
||||
|
|
|
|||
|
|
@ -11,9 +11,21 @@
|
|||
end
|
||||
end
|
||||
%></div>
|
||||
|
||||
<div class="tasks_sort">
|
||||
<%= link_to("Sort 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 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>
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue