aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorTeddy Wing2018-04-19 13:59:41 +0200
committerJohan Van Ryseghem2018-04-26 09:16:15 +0200
commite5215f229e3dfa5d84a43bcf75e2edf8c99667a3 (patch)
treef4d18422ecbcda411e7382eff94fea677ce4f606 /app/controllers
parent37cef4eca7eec2dbfc4be10334c787ce207b466e (diff)
downloadchouette-core-e5215f229e3dfa5d84a43bcf75e2edf8c99667a3.tar.bz2
ReferentialVehicleJourneys: Show selected line in drop-down
Previously we weren't showing the currently-selected line filter in the drop-down label. If a line is selected, get its ID and name and use those to pre-fill the select. Using Select2's `initSelection` option to configure this instead of putting `selected: ` in the Rails field definition. That would have looked like this: collection: [[@filtered_line.name, @filtered_line.id]], selected: params[:q] && params[:q][:route_line_id_eq], But doing it that way wasn't possible because this is an AJAX-populated Select2. Since we already have a way to use `initSelection`, this was the quickest and easiest way to go, but apparently Select2 v4.0 deprecated this option, instead doing it with a data adapter. Couldn't really be bothered right now to figure out how to set that up as it seemed like a lot of work for not much payoff right now. Also, I was a little disappointed in Select2's docs regarding this. From what I understood, it looks like you basically need to create your own custom data adapter to do this, which sounds like a pain, and I'm not sure if I would have to mess with the rest of our existing Select2 configuration setup in order to integrate that. Refs #5889
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/referential_vehicle_journeys_controller.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/controllers/referential_vehicle_journeys_controller.rb b/app/controllers/referential_vehicle_journeys_controller.rb
index b07d6c600..c35a06087 100644
--- a/app/controllers/referential_vehicle_journeys_controller.rb
+++ b/app/controllers/referential_vehicle_journeys_controller.rb
@@ -12,6 +12,16 @@ class ReferentialVehicleJourneysController < ChouetteController
requires_feature :referential_vehicle_journeys
+ def index
+ if params[:q] && params[:q][:route_line_id_eq].present?
+ @filtered_line = Chouette::Line
+ .select(:id, :name)
+ .find(params[:q][:route_line_id_eq])
+ end
+
+ index!
+ end
+
private
def collection