aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorZog2018-01-03 16:31:33 +0100
committerZog2018-01-08 08:18:57 +0100
commit913d6935727ace3ac94c08adb4e1ec378741fb19 (patch)
tree1c8f0c63693ef4fbe7e20f7af3e6731395c855ad /app/controllers
parentfa63d6e3d51ccc0b3a38616747fcd91b5fdfbba5 (diff)
downloadchouette-core-913d6935727ace3ac94c08adb4e1ec378741fb19.tar.bz2
Refs #5455 @6h; Add time and distance between stops in Journey Patterns
- Adds a `JSON` attribute in the model - Adds the fields in the editor
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/journey_patterns_collections_controller.rb62
1 files changed, 36 insertions, 26 deletions
diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb
index 5fe78766c..6b661da0c 100644
--- a/app/controllers/journey_patterns_collections_controller.rb
+++ b/app/controllers/journey_patterns_collections_controller.rb
@@ -17,35 +17,45 @@ class JourneyPatternsCollectionsController < ChouetteController
alias_method :vehicle_journey, :resource
def show
- @q = route.journey_patterns.search(params[:q]).result(distinct: true).includes(:stop_points)
+ @q = route.journey_patterns
+ if params[:q].present?
+ ids = @q.search(params[:q]).result(distinct: true).pluck(:id)
+ @q = @q.where(id: ids)
+ end
+ @q = @q.includes(:stop_points)
+ # @q = route.journey_patterns.search(params[:q]).result().includes(:stop_points)
@ppage = 10
@journey_patterns ||= @q.paginate(page: params[:page], per_page: @ppage).order(:name)
-
- @stop_points_list = []
- route.stop_points.each do |sp|
- @stop_points_list << {
- :id => sp.stop_area.id,
- :route_id => sp.try(:route_id),
- :object_id => sp.try(:objectid),
- :position => sp.try(:position),
- :for_boarding => sp.try(:for_boarding),
- :for_alighting => sp.try(:for_alighting),
- :name => sp.stop_area.try(:name),
- :zip_code => sp.stop_area.try(:zip_code),
- :city_name => sp.stop_area.try(:city_name),
- :comment => sp.stop_area.try(:comment),
- :area_type => sp.stop_area.try(:area_type),
- :registration_number => sp.stop_area.try(:registration_number),
- :nearest_topic_name => sp.stop_area.try(:nearest_topic_name),
- :fare_code => sp.stop_area.try(:fare_code),
- :longitude => sp.stop_area.try(:longitude),
- :latitude => sp.stop_area.try(:latitude),
- :long_lat_type => sp.stop_area.try(:long_lat_type),
- :country_code => sp.stop_area.try(:country_code),
- :street_name => sp.stop_area.try(:street_name)
- }
+ respond_to do |format|
+ format.json
+ format.html do
+ @stop_points_list = []
+ route.stop_points.each do |sp|
+ @stop_points_list << {
+ :id => sp.stop_area.id,
+ :route_id => sp.try(:route_id),
+ :object_id => sp.try(:objectid),
+ :position => sp.try(:position),
+ :for_boarding => sp.try(:for_boarding),
+ :for_alighting => sp.try(:for_alighting),
+ :name => sp.stop_area.try(:name),
+ :zip_code => sp.stop_area.try(:zip_code),
+ :city_name => sp.stop_area.try(:city_name),
+ :comment => sp.stop_area.try(:comment),
+ :area_type => sp.stop_area.try(:area_type),
+ :registration_number => sp.stop_area.try(:registration_number),
+ :nearest_topic_name => sp.stop_area.try(:nearest_topic_name),
+ :fare_code => sp.stop_area.try(:fare_code),
+ :longitude => sp.stop_area.try(:longitude),
+ :latitude => sp.stop_area.try(:latitude),
+ :long_lat_type => sp.stop_area.try(:long_lat_type),
+ :country_code => sp.stop_area.try(:country_code),
+ :street_name => sp.stop_area.try(:street_name)
+ }
+ end
+ @stop_points_list = @stop_points_list.sort_by {|a| a[:position] }
+ end
end
- @stop_points_list = @stop_points_list.sort_by {|a| a[:position] }
end
def user_permissions