aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/stop_areas_controller.rb
diff options
context:
space:
mode:
authorcedricnjanga2018-03-08 20:42:28 -0800
committerAlban Peignier2018-03-15 10:01:04 +0100
commita6991d329d754aa8dff4c1e7a07119123148b61d (patch)
treee38d6351786da7c24934c0dd51002c3addde49e1 /app/controllers/stop_areas_controller.rb
parentae282e2eac8dedde62a957912dcb0b4e5e4bc7c6 (diff)
downloadchouette-core-a6991d329d754aa8dff4c1e7a07119123148b61d.tar.bz2
Refs #6033 Changes for StopArea#index and StopArea#show
Diffstat (limited to 'app/controllers/stop_areas_controller.rb')
-rw-r--r--app/controllers/stop_areas_controller.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index 41a1a8c6d..c3da92265 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -133,7 +133,9 @@ class StopAreasController < ChouetteController
end
def collection
- @q = parent.present? ? parent.stop_areas.search(params[:q]) : referential.stop_areas.search(params[:q])
+ scope = parent.present? ? parent.stop_areas : referential.stop_areas
+ scope = ransack_status(scope)
+ @q = scope.search(params[:q])
if sort_column && sort_direction
@stop_areas ||=
@@ -206,4 +208,35 @@ class StopAreasController < ChouetteController
)
end
+ # Fake ransack filter
+ def ransack_status scope
+ return scope unless params[:q].try(:[], :status)
+ return scope if params[:q][:status].values.uniq.length == 1
+
+ @status = {
+ in_creation: params[:q][:status]['in_creation'] == 'true',
+ activated: params[:q][:status]['activated'] == 'true',
+ deactivated: params[:q][:status]['deactivated'] == 'true',
+ }
+
+ scope = Chouette::StopArea.where(
+ "confirmed_at #{@status[:activated] ? "IS NOT NULL" : "IS NULL"}
+ AND deleted_at #{@status[:deactivated] ? "IS NOT NULL" : "IS NULL"}"
+ )
+
+ params[:q].delete :status
+ scope
+ end
+
+ # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope
+ # We clone params[:q] so we can delete fake ransack filter arguments before calling search method,
+ # which will allow us to preserve params[:q] for sorting
+ def ransack_params
+ copy_params = params[:q].clone
+ copy_params.delete('associated_lines_id_eq')
+ copy_params.delete('archived_at_not_null')
+ copy_params.delete('archived_at_null')
+ copy_params
+ end
+
end