mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Update how the sorting is done in the User model
Use the `sort_by` method to do the sorting rather than converting to an array and then calling `sort` Co-Authored-By: Dan Rice <dnrce@users.noreply.github.com>
This commit is contained in:
parent
859701a81f
commit
6e70fcbe5e
1 changed files with 2 additions and 2 deletions
|
|
@ -56,13 +56,13 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
def alphabetize(scope_conditions = {})
|
||||
projects = where(scope_conditions)
|
||||
projects.to_a.sort!{ |x,y| x.name.downcase <=> y.name.downcase }
|
||||
projects = projects.sort_by { |project| project.name.downcase }
|
||||
self.update_positions(projects.map{ |p| p.id })
|
||||
return projects
|
||||
end
|
||||
def actionize(scope_conditions = {})
|
||||
todos_in_project = where(scope_conditions).includes(:todos)
|
||||
todos_in_project.to_a.sort_by!{ |x| [-x.todos.active.count, -x.id] }
|
||||
todos_in_project = todos_in_project.sort_by { |x| [-x.todos.active.count, -x.id] }
|
||||
todos_in_project.reject{ |p| p.todos.active.count > 0 }
|
||||
sorted_project_ids = todos_in_project.map {|p| p.id}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue