mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +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'])
|
init_not_done_counts(['project'])
|
||||||
end
|
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
|
protected
|
||||||
|
|
||||||
def render_projects_html
|
def render_projects_html
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,12 @@ class User < ActiveRecord::Base
|
||||||
self.update_positions(projects.map{ |p| p.id })
|
self.update_positions(projects.map{ |p| p.id })
|
||||||
return projects
|
return projects
|
||||||
end
|
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
|
end
|
||||||
has_many :active_projects,
|
has_many :active_projects,
|
||||||
:class_name => 'Project',
|
:class_name => 'Project',
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,18 @@
|
||||||
end
|
end
|
||||||
%></div>
|
%></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">
|
<div id="list-<%= state %>-projects" class="project-list">
|
||||||
<%= render :partial => 'project_listing', :collection => project_state_group %>
|
<%= render :partial => 'project_listing', :collection => project_state_group %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
projects.resources :todos, :name_prefix => "project_"
|
projects.resources :todos, :name_prefix => "project_"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
map.resources :projects, :collection => {:order => :post, :actionize => :post} do |projects|
|
||||||
|
projects.resources :todos, :name_prefix => "project_"
|
||||||
|
end
|
||||||
|
|
||||||
map.resources :todos,
|
map.resources :todos,
|
||||||
:member => {:toggle_check => :put, :toggle_star => :put},
|
:member => {:toggle_check => :put, :toggle_star => :put},
|
||||||
:collection => {:check_deferred => :post, :filter_to_context => :post, :filter_to_project => :post}
|
:collection => {:check_deferred => :post, :filter_to_context => :post, :filter_to_project => :post}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue