Skip to content

Commit

Permalink
Sort issues bt "real" position
Browse files Browse the repository at this point in the history
meaning, in order
* sprint (or backlog)
* story, on position
* tasks, after the story it belongs to, on order within story tree
  • Loading branch information
friflaj committed Aug 10, 2010
1 parent ccbb183 commit 8c9211b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
8 changes: 4 additions & 4 deletions app/controllers/backlogs_controller.rb
Expand Up @@ -60,17 +60,17 @@ def select_issues
@query.add_filter("status_id", '*', ['']) # All statuses
@query.add_filter("fixed_version_id", '=', [params[:sprint_id]])
@query.add_filter("backlogs_issue_type", '=', ['any'])
@query.sort_criteria = [['parent_id', 'desc']]
else
@query.add_filter("status_id", 'o', ['']) # only open
@query.add_filter("fixed_version_id", '!*', ['']) # only unassigned
@query.add_filter("backlogs_issue_type", '=', ['story'])
@query.sort_criteria = [['position', 'asc']]
end

session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
column_names = @query.columns.collect{|col| col.name}
column_names = column_names + ['position'] unless column_names.include?('position')

redirect_to :controller => 'issues', :action => 'index', :project_id => @project.id
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :column_names => column_names}
redirect_to :controller => 'issues', :action => 'index', :project_id => @project.id, :sort => 'position'
end

def select_product_backlog
Expand Down
46 changes: 16 additions & 30 deletions lib/backlogs_query_patch.rb
Expand Up @@ -11,12 +11,26 @@ def self.included(base) # :nodoc:
unloadable # Send unloadable so it will not be unloaded in development
base.add_available_column(QueryColumn.new(:story_points, :sortable => "#{Issue.table_name}.story_points"))
base.add_available_column(QueryColumn.new(:remaining_hours, :sortable => "#{Issue.table_name}.remaining_hours"))
base.add_available_column(QueryColumn.new(:position, :sortable => "#{Issue.table_name}.position"))
base.add_available_column(QueryColumn.new(:velocity_based_estimate))

base.add_available_column(QueryColumn.new(:position,
:sortable => [
# sprint startdate
"coalesce((select sprint_start_date from versions where versions.id = issues.fixed_version_id), '1900-01-01')",
# sprint name, in case start dates are the same
"(select name from versions where versions.id = issues.fixed_version_id)",
# story position
"(select root.position from issues root where issues.root_id = root.id)",
# story ID, in case positions are the same (SHOULD NOT HAPPEN!)
"issues.root_id",
# order in task tree
"issues.lft"
],
:default_order => 'asc'))


alias_method_chain :available_filters, :backlogs_issue_type
alias_method_chain :sql_for_field, :backlogs_issue_type
alias_method_chain :columns, :backlogs_story_columns
end

end
Expand All @@ -38,32 +52,6 @@ def available_filters_with_backlogs_issue_type
return @available_filters.merge(backlogs_filters)
end

def columns_with_backlogs_story_columns
cols = columns_without_backlogs_story_columns

return cols if not has_default_columns?

return cols if ! self.filters["backlogs_issue_type"]

[ [:parent, :before, (self.filters["backlogs_issue_type"][:values] == ['any'])],
[:story_points, :after, true],
[:position, :after, true],
[:estimated_hours, :after, true]]. each {|col, pos, use|

next if !use
col = available_columns.select{|c| c.name == col}[0]
if cols.include? col
# pass
elsif pos == :before
cols = [col] + cols
else
cols = cols + [col]
end
}

return cols
end

def sql_for_field_with_backlogs_issue_type(field, operator, v, db_table, db_field, is_custom_filter=false)
if field == "backlogs_issue_type"
db_table = Issue.table_name
Expand All @@ -79,8 +67,6 @@ def sql_for_field_with_backlogs_issue_type(field, operator, v, db_table, db_fiel
sql << "(#{db_table}.tracker_id in (" + Story.trackers.collect{|val| "#{val}"}.join(",") + ") and #{db_table}.parent_id is NULL)"
when "task"
sql << "(#{db_table}.tracker_id = #{Task.tracker} and not #{db_table}.parent_id is NULL)"
when "any"
sql << "1 = 1"
end
}

Expand Down

0 comments on commit 8c9211b

Please sign in to comment.