aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorteddywing2018-04-20 15:40:51 +0200
committerGitHub2018-04-20 15:40:51 +0200
commitb51eab242753ecac8154714f2467395b6d9ee86c (patch)
treeb86c495ff253c7f20316b2e3cdd28f6e40821ca3 /app/controllers
parente6567cbfc987d8488492e2b1ce66a03db3a3d37d (diff)
parent1962a33393f5cd0c206dc560e5d3116344393036 (diff)
downloadchouette-core-b51eab242753ecac8154714f2467395b6d9ee86c.tar.bz2
Merge pull request #468 from af83/6493-fix-stop_areas-sort
6493 Sort StopAreas on the type label, instead of the internal key
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/stop_areas_controller.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index b2634467d..76732afd7 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -126,7 +126,18 @@ class StopAreasController < ChouetteController
if sort_column && sort_direction
@stop_areas ||=
begin
- stop_areas = @q.result.order(sort_column + ' ' + sort_direction)
+ if sort_column == "area_type"
+ sorted_area_type_labels = Chouette::AreaType.options(:all, I18n.locale).sort.transpose.last
+ sorted_area_type_labels = sorted_area_type_labels.reverse if sort_direction != 'asc'
+ order_by = ["CASE"]
+ sorted_area_type_labels.each_with_index do |area_type, index|
+ order_by << "WHEN area_type='#{area_type}' THEN #{index}"
+ end
+ order_by << "END"
+ stop_areas = @q.result.order(order_by.join(" "))
+ else
+ stop_areas = @q.result.order(sort_column + ' ' + sort_direction)
+ end
stop_areas = stop_areas.paginate(:page => params[:page], :per_page => @per_page) if @per_page.present?
stop_areas
end