mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-19 15:36:10 +01:00
fix #1157 and fix #1158 by changing the way empty projects are included in the sorting and by fixing the dutch translation for sorting titles
This commit is contained in:
parent
29ee5f9d1c
commit
e57ee2aaa7
3 changed files with 23 additions and 19 deletions
|
|
@ -60,19 +60,23 @@ class User < ActiveRecord::Base
|
|||
return projects
|
||||
end
|
||||
def actionize(user_id, scope_conditions = {})
|
||||
@state = scope_conditions[:state]
|
||||
query_state = ""
|
||||
query_state = "AND project.state = '" + @state +"' "if @state
|
||||
projects = Project.find_by_sql([
|
||||
"SELECT project.id, count(todo.id) as p_count " +
|
||||
"FROM projects as project " +
|
||||
"LEFT OUTER JOIN todos as todo ON todo.project_id = project.id "+
|
||||
"WHERE project.user_id = ? AND NOT (todo.state='completed') " +
|
||||
query_state = scope_conditions[:state] ? "AND projects.state = '#{scope_conditions[:state]}' " : ""
|
||||
projects_with_active_todos = Project.find_by_sql([
|
||||
"SELECT projects.id, count(todos.id) as p_count " +
|
||||
"FROM projects " +
|
||||
"LEFT OUTER JOIN todos ON todos.project_id = projects.id "+
|
||||
"WHERE projects.user_id = ? AND " +
|
||||
"NOT (todos.state='completed' OR todos.state='deferred' OR todos.state='pending') " +
|
||||
query_state +
|
||||
" GROUP BY project.id ORDER by p_count DESC",user_id])
|
||||
self.update_positions(projects.map{ |p| p.id })
|
||||
projects = find(:all, :conditions => scope_conditions)
|
||||
return projects
|
||||
" GROUP BY projects.id ORDER by p_count DESC",user_id])
|
||||
all_project_ids = Project.find_by_sql([
|
||||
"SELECT id FROM projects WHERE projects.user_id = ? " + query_state, user_id
|
||||
])
|
||||
ids_in_new_positions = projects_with_active_todos.map{|p| p.id}
|
||||
ids_of_unselected_projects = all_project_ids.map{|p| p.id} - ids_in_new_positions
|
||||
self.update_positions(ids_in_new_positions + ids_of_unselected_projects)
|
||||
|
||||
return find(:all, :conditions => scope_conditions)
|
||||
end
|
||||
end
|
||||
has_many :active_projects,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue