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:
Matt Rogers 2018-10-27 10:20:58 -05:00
parent 859701a81f
commit 6e70fcbe5e
No known key found for this signature in database
GPG key ID: 605D017C07EB4316

View file

@ -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}