aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/autocomplete_lines_controller.rb24
-rw-r--r--app/models/chouette/vehicle_journey.rb1
-rw-r--r--app/views/autocomplete_lines/index.rabl8
-rw-r--r--app/views/referential_vehicle_journeys/_filters.html.slim11
-rw-r--r--config/routes.rb1
5 files changed, 40 insertions, 5 deletions
diff --git a/app/controllers/autocomplete_lines_controller.rb b/app/controllers/autocomplete_lines_controller.rb
new file mode 100644
index 000000000..945736ab9
--- /dev/null
+++ b/app/controllers/autocomplete_lines_controller.rb
@@ -0,0 +1,24 @@
+class AutocompleteLinesController < ChouetteController
+ include ReferentialSupport
+
+ respond_to :json, only: :index
+
+ protected
+
+ def collection
+ @lines = referential.line_referential.lines
+
+ filter = <<~SQL
+ number LIKE ?
+ OR name LIKE ?
+ SQL
+ @lines = @lines
+ .where(
+ filter,
+ *Array.new(2, "#{params[:q]}%")
+ )
+ .search(params[:q])
+ .result
+ .paginate(page: params[:page])
+ end
+end
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 60279422c..cdeac56dd 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -409,6 +409,7 @@ module Chouette
.where('"time_tables_vehicle_journeys"."vehicle_journey_id" IS NULL')
end
+ # TODO: delete this
def self.lines
lines_query = joins(:route).select("routes.line_id").reorder(nil).except(:group).pluck(:'routes.line_id')
Chouette::Line.where(id: lines_query)
diff --git a/app/views/autocomplete_lines/index.rabl b/app/views/autocomplete_lines/index.rabl
new file mode 100644
index 000000000..1d235ef94
--- /dev/null
+++ b/app/views/autocomplete_lines/index.rabl
@@ -0,0 +1,8 @@
+collection @lines
+
+node do |line|
+ {
+ id: line.id,
+ text: line.display_name
+ }
+end
diff --git a/app/views/referential_vehicle_journeys/_filters.html.slim b/app/views/referential_vehicle_journeys/_filters.html.slim
index 5f102ae1b..d650225b2 100644
--- a/app/views/referential_vehicle_journeys/_filters.html.slim
+++ b/app/views/referential_vehicle_journeys/_filters.html.slim
@@ -24,14 +24,15 @@
= f.input :route_line_id_eq,
as: :select,
include_blank: t(".all"),
- collection: @vehicle_journeys.lines,
- selected: params[:q] && params[:q][:route_line_id_eq],
input_html: { \
- 'data-select2ed': 'true',
- 'data-select2ed-placeholder': t('referentials.filters.line') \
+ data: { \
+ 'select2-ajax': 'true',
+ 'select2ed-placeholder': t('referentials.filters.line'),
+ url: referential_autocomplete_lines_path(@referential, format: :json),
+ 'select2ed-allow-clear': true \
+ } \
},
label: false,
- label_method: :display_name,
wrapper_html: { class: 'filter_menu-item select2ed' }
.form-group.togglable.name-filter class=filter_item_class(params[:q], :published_journey_name_gteq)
diff --git a/config/routes.rb b/config/routes.rb
index a3a21511c..dc75bec11 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -41,6 +41,7 @@ ChouetteIhm::Application.routes.draw do
post :validate
end
+ resources :autocomplete_lines, only: :index
resources :autocomplete_stop_areas, only: [:show, :index] do
get 'around', on: :member
end