aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2017-12-22 15:44:00 +0100
committerZog2017-12-22 16:42:47 +0100
commitb342f126e58fc940ac40fc13c27799a047e1336b (patch)
tree07999657bc06f723db7f419530b40a68d817aa80
parent8091f1ecd1f712dcb50344e6b4839b820e6e94ab (diff)
downloadchouette-core-b342f126e58fc940ac40fc13c27799a047e1336b.tar.bz2
Speed VehicleJourneys#index view up
-rw-r--r--app/controllers/vehicle_journeys_controller.rb70
-rw-r--r--app/views/vehicle_journeys/show.rabl6
2 files changed, 39 insertions, 37 deletions
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index f44553098..454f9c3dd 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -40,42 +40,46 @@ class VehicleJourneysController < ChouetteController
end
def index
- @stop_points_list = []
- @stop_points_list = route.stop_points.joins(:stop_area).map do |sp|
- {
- :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
- @transport_mode = route.line['transport_mode']
- @transport_submode = route.line['transport_submode']
-
- if params[:jp]
- @jp_origin = Chouette::JourneyPattern.find_by(objectid: params[:jp])
- @jp_origin_stop_points = @jp_origin.stop_points
- end
-
- index! do
+ index! do |format|
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
end
+ format.json do
+ @vehicle_journeys = @vehicle_journeys.includes({stop_points: :stop_area})
+ end
+ format.html do
+ @stop_points_list = []
+ @stop_points_list = route.stop_points.joins(:stop_area).map do |sp|
+ {
+ :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
+ @transport_mode = route.line['transport_mode']
+ @transport_submode = route.line['transport_submode']
+
+ if params[:jp]
+ @jp_origin = Chouette::JourneyPattern.find_by(objectid: params[:jp])
+ @jp_origin_stop_points = @jp_origin.stop_points
+ end
+ end
end
end
diff --git a/app/views/vehicle_journeys/show.rabl b/app/views/vehicle_journeys/show.rabl
index 830dee8bd..a39a53b05 100644
--- a/app/views/vehicle_journeys/show.rabl
+++ b/app/views/vehicle_journeys/show.rabl
@@ -49,11 +49,9 @@ child(:vehicle_journey_at_stops_matrix, :object_root => false) do |vehicle_stops
vehicle_stop.stop_point.stop_area.city_name
end
- [:id, :connecting_service_id, :boarding_alighting_possibility].map do |att|
- node(att) { vehicle_stop.send(att) ? vehicle_stop.send(att) : nil }
- end
+ attributes :id, :connecting_service_id, :boarding_alighting_possibility
- [:arrival_time, :departure_time].map do |att|
+ [:arrival_time, :departure_time].each do |att|
node(att) do |vs|
{
hour: vs.send(att).try(:strftime, '%H'),