aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/vehicle_journeys_controller.rb
diff options
context:
space:
mode:
authorTeddy Wing2017-05-12 16:53:00 +0200
committerTeddy Wing2017-05-12 17:56:27 +0200
commit7bf94bc6e6ce6558252252e68419e89a23213573 (patch)
tree9eb150d5cd41b8dbfad6b50b8610485c519a9d48 /app/controllers/vehicle_journeys_controller.rb
parent0898f39c35f2f853e051269ae0945eafa475d483 (diff)
downloadchouette-core-7bf94bc6e6ce6558252252e68419e89a23213573.tar.bz2
VehicleJourneysController#collection: Integrate .departure_time_between
Add our custom departure time range filter to the query. We pass the times sent from the frontend into the query in order to get the correct vehicle journeys back. Copied the `if params[:q]` check from `#ransack_periode_filter`, but added an additional condition on the existence of `:vehicle_journey_at_stops_departure_time_lteq` instead of blatantly assuming it's there just because its `..._gteq` counterpart is. Adding the filter necessitated some modifications to the `VehicleJourneys.departure_time_between` method. We needed to remove the `SELECT DISTINCT` and join parts of the query, reducing it to a simple "where" condition. These removals were due to the nature of the combination of this method with `VehicleJourneys.with_stops`. The `.with_stops` method already does a join on `vehicle_journey_at_stops`, and there's already a `SELECT DISTINCT` applied to the controller's query. Made the decision to limit this method's use to this specific use-case, and thus expect DISTINCT and the necessary join to already be defined on the `ActiveRecord` query object. We modify the test to implement this requirement. Finally, rename `.departure_time_between` to `.where_departure_time_between` to further indicate that this is a simple `where` condition, without the required extras. Refs #3370
Diffstat (limited to 'app/controllers/vehicle_journeys_controller.rb')
-rw-r--r--app/controllers/vehicle_journeys_controller.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index cca75af5b..c78613e99 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -78,6 +78,16 @@ class VehicleJourneysController < ChouetteController
protected
def collection
scope = route.vehicle_journeys.with_stops
+
+ if params[:q] &&
+ params[:q][:vehicle_journey_at_stops_departure_time_gteq] &&
+ params[:q][:vehicle_journey_at_stops_departure_time_lteq]
+ scope = scope.where_departure_time_between(
+ params[:q][:vehicle_journey_at_stops_departure_time_gteq],
+ params[:q][:vehicle_journey_at_stops_departure_time_lteq]
+ )
+ end
+
@q = scope.search filtered_ransack_params
# Fixme 3358