diff options
| author | Teddy Wing | 2017-05-22 14:05:54 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-05-22 14:10:03 +0200 | 
| commit | fc9ff386b1961949e2ba742ef226935ec3c389cd (patch) | |
| tree | 688915f470e69a5ce10329a7b8b07ef90637a462 /app/controllers/vehicle_journeys_controller.rb | |
| parent | d0544404ffd77d276a5db5e8cacc85e26bc5a272 (diff) | |
| download | chouette-core-fc9ff386b1961949e2ba742ef226935ec3c389cd.tar.bz2 | |
VehicleJourneysController: Move departure time filter to a new method
Like we did in d0544404ffd77d276a5db5e8cacc85e26bc5a272 with
`filter_without_time_tables`, add a similar method to extract the
departure time filter from `#collection`. This allows us to keep the
`#collection` method a little cleaner.
Add `maybe_` prefixes to both aforementioned new filter methods because
we aren't guaranteed to be filtering. It depends on the contents of the
request parameters received.
Remove the comment describing the date range filter now that it has a
method name.
Refs #3427
Diffstat (limited to 'app/controllers/vehicle_journeys_controller.rb')
| -rw-r--r-- | app/controllers/vehicle_journeys_controller.rb | 25 | 
1 files changed, 14 insertions, 11 deletions
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index 84500bd0c..e72145c1e 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -83,8 +83,19 @@ class VehicleJourneysController < ChouetteController    protected    def collection      scope = route.vehicle_journeys.with_stops +    scope = maybe_filter_by_departure_time(scope) +    scope = maybe_filter_without_time_tables(scope) -    # Apply departure time range filter +    @q = scope.search filtered_ransack_params + +    @ppage = 20 +    @vehicle_journeys = @q.result.paginate(:page => params[:page], :per_page => @ppage) +    @footnotes = route.line.footnotes.to_json +    @matrix    = resource_class.matrix(@vehicle_journeys) +    @vehicle_journeys +  end + +  def maybe_filter_by_departure_time(scope)      if params[:q] &&          params[:q][:vehicle_journey_at_stops_departure_time_gteq] &&          params[:q][:vehicle_journey_at_stops_departure_time_lteq] @@ -96,18 +107,10 @@ class VehicleJourneysController < ChouetteController        )      end -    scope = filter_without_time_tables(scope) - -    @q = scope.search filtered_ransack_params - -    @ppage = 20 -    @vehicle_journeys = @q.result.paginate(:page => params[:page], :per_page => @ppage) -    @footnotes = route.line.footnotes.to_json -    @matrix    = resource_class.matrix(@vehicle_journeys) -    @vehicle_journeys +    scope    end -  def filter_without_time_tables(scope) +  def maybe_filter_without_time_tables(scope)      if params[:q] &&          params[:q][:vehicle_journey_without_time_table] == 'false'        return scope  | 
