diff options
| author | Bruno Perles | 2015-11-10 15:38:48 +0100 |
|---|---|---|
| committer | Bruno Perles | 2015-11-10 15:39:21 +0100 |
| commit | 9772ead99ea485b03113885c96115922e81712b6 (patch) | |
| tree | 1b56ba97fca65db7c3c58070663f0cf55700c04f /app/controllers | |
| parent | eb1fb75584a78d392e29cc5f7e98f5f6fefe4165 (diff) | |
| download | chouette-core-9772ead99ea485b03113885c96115922e81712b6.tar.bz2 | |
Add autocomplete on Timeband
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/autocomplete_time_tables_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/autocomplete_timebands_controller.rb | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/app/controllers/autocomplete_time_tables_controller.rb b/app/controllers/autocomplete_time_tables_controller.rb index d7e6ec885..ee0f8a0cb 100644 --- a/app/controllers/autocomplete_time_tables_controller.rb +++ b/app/controllers/autocomplete_time_tables_controller.rb @@ -4,7 +4,7 @@ class AutocompleteTimeTablesController < InheritedResources::Base before_action :switch_referential def switch_referential - Apartment::Database.switch(referential.slug) + Apartment::Tenant.switch!(referential.slug) end def referential diff --git a/app/controllers/autocomplete_timebands_controller.rb b/app/controllers/autocomplete_timebands_controller.rb new file mode 100644 index 000000000..3915bd69f --- /dev/null +++ b/app/controllers/autocomplete_timebands_controller.rb @@ -0,0 +1,31 @@ +class AutocompleteTimebandsController < InheritedResources::Base + respond_to :json, :only => [:index] + + before_action :switch_referential + + def switch_referential + Apartment::Tenant.switch!(referential.slug) + end + + def referential + @referential ||= current_organisation.referentials.find params[:referential_id] + end + + protected + + def select_timebands + if params[:route_id] + referential.timebands.joins( vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})") + else + referential.timebands + end + end + + def referential_timebands + @referential_timebands ||= select_timebands + end + + def collection + @timebands = referential_timebands.select{ |p| p.fullname =~ /#{params[:q]}/i } + end +end |
