Refactor how headings are ordered

This commit is contained in:
Marko Lovic
2018-07-23 20:31:41 +02:00
committed by Javi Martín
parent 375fbf775f
commit 997db67104

View File

@@ -17,7 +17,7 @@ module Budgets
@headings = @headings.where(filter_investment_by_latest_milestone, params[:status]) @headings = @headings.where(filter_investment_by_latest_milestone, params[:status])
end end
@headings = reorder_with_city_heading_first(@headings) @headings = reorder_alphabetically_with_city_heading_first(@headings)
end end
private private
@@ -33,17 +33,15 @@ module Budgets
SQL SQL
end end
def reorder_with_city_heading_first(original_headings) def reorder_alphabetically_with_city_heading_first(headings)
headings = original_headings.to_a.dup headings.sort do |a, b|
if a.name == 'Toda la ciudad'
city_heading_index = headings.find_index do |heading| -1
heading.name == "Toda la ciudad" elsif b.name == 'Toda la ciudad'
end 1
else
if city_heading_index a.name <=> b.name
headings.insert(0, headings.delete_at(city_heading_index)) end
else
headings
end end
end end
end end