aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorteddywing2018-02-20 15:42:11 +0100
committerGitHub2018-02-20 15:42:11 +0100
commit7fcf0598427f879451cda8dbb414c6362735a7f9 (patch)
tree359ec1f46caf135ca1734e09848b20e084f3fea0
parent338a4df2491bebe0acd30c384665dd420899910c (diff)
parent05a60eb3e91915ae7192d67599cb3d47a2790507 (diff)
downloadchouette-core-7fcf0598427f879451cda8dbb414c6362735a7f9.tar.bz2
Merge pull request #304 from af83/5901-fix-calendar-autocompletion
5901 Makes TimeTable search accent-insensitive
-rw-r--r--app/controllers/autocomplete_time_tables_controller.rb2
-rw-r--r--app/javascript/vehicle_journeys/components/Filters.js2
-rw-r--r--app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js2
-rw-r--r--app/models/chouette/time_table.rb4
-rw-r--r--app/models/chouette/time_table_date.rb2
-rw-r--r--app/views/time_table_combinations/_form.html.slim2
-rw-r--r--spec/controllers/autocomplete_time_tables_controller_spec.rb37
7 files changed, 46 insertions, 5 deletions
diff --git a/app/controllers/autocomplete_time_tables_controller.rb b/app/controllers/autocomplete_time_tables_controller.rb
index 0a9f51ced..dded24a36 100644
--- a/app/controllers/autocomplete_time_tables_controller.rb
+++ b/app/controllers/autocomplete_time_tables_controller.rb
@@ -23,7 +23,7 @@ class AutocompleteTimeTablesController < ChouetteController
end
def split_params! search
- params[:q][search] = params[:q][search].split(" ") if params[:q][search]
+ params[:q][search] = params[:q][search].split(" ") if params[:q] && params[:q][search]
end
def collection
diff --git a/app/javascript/vehicle_journeys/components/Filters.js b/app/javascript/vehicle_journeys/components/Filters.js
index f8697c930..ae3ab3476 100644
--- a/app/javascript/vehicle_journeys/components/Filters.js
+++ b/app/javascript/vehicle_journeys/components/Filters.js
@@ -36,7 +36,7 @@ export default function Filters({filters, pagination, missions, onFilter, onRese
onSelect2Timetable={onSelect2Timetable}
hasRoute={true}
chunkURL={("/autocomplete_time_tables.json?route_id=" + String(window.route_id))}
- searchKey={"comment_or_objectid_cont_any"}
+ searchKey={"unaccented_comment_or_objectid_cont_any"}
filters={filters}
isFilter={true}
/>
diff --git a/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js
index e2fcd27d5..f21480563 100644
--- a/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js
+++ b/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js
@@ -99,7 +99,7 @@ export default class TimetablesEditVehicleJourney extends Component {
<TimetableSelect2
onSelect2Timetable={this.props.onSelect2Timetable}
chunkURL={'/autocomplete_time_tables.json'}
- searchKey={"comment_or_objectid_cont_any"}
+ searchKey={"unaccented_comment_or_objectid_cont_any"}
isFilter={false}
/>
</div>
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index b76de852a..20d6e69ac 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -17,6 +17,10 @@ module Chouette
(column_names + ['tag_search']) + _ransackers.keys
end
+ ransacker :unaccented_comment, formatter: ->(val){ val.parameterize } do
+ Arel.sql('unaccent(comment)')
+ end
+
has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney'
has_many :dates, -> {order(:date)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTableDate", :dependent => :destroy
diff --git a/app/models/chouette/time_table_date.rb b/app/models/chouette/time_table_date.rb
index b3b2fd561..98d8fa765 100644
--- a/app/models/chouette/time_table_date.rb
+++ b/app/models/chouette/time_table_date.rb
@@ -20,4 +20,4 @@ module Chouette
self.slice(*attrs).values
end
end
-end \ No newline at end of file
+end
diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim
index 426624ee3..6a0fda01e 100644
--- a/app/views/time_table_combinations/_form.html.slim
+++ b/app/views/time_table_combinations/_form.html.slim
@@ -7,7 +7,7 @@
abbr title='Champ requis' *
= f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8 col-xs-7' }
- = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_or_objectid_cont_any', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}
+ = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'unaccented_comment_or_objectid_cont_any', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}
= f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''}
diff --git a/spec/controllers/autocomplete_time_tables_controller_spec.rb b/spec/controllers/autocomplete_time_tables_controller_spec.rb
new file mode 100644
index 000000000..85a8eb714
--- /dev/null
+++ b/spec/controllers/autocomplete_time_tables_controller_spec.rb
@@ -0,0 +1,37 @@
+require 'rails_helper'
+
+RSpec.describe AutocompleteTimeTablesController, type: :controller do
+ login_user
+
+ let(:referential) { Referential.first }
+ let(:other_referential) { create :referential }
+ let!(:time_table) { create :time_table, comment: 'écolà militaire' }
+ let!(:blargh) { create :time_table, comment: 'écolàë militaire' }
+ let!(:other_time_table) { create :time_table, comment: 'foo bar baz' }
+
+ describe 'GET #index' do
+ it 'should be successful' do
+ get :index, referential_id: referential.id
+ expect(response).to be_success
+ end
+
+ context 'search by name' do
+ it 'should be successful' do
+ get :index, referential_id: referential.id, q: {unaccented_comment_or_objectid_cont_any: 'écolà'}, :format => :json
+ expect(response).to be_success
+ expect(assigns(:time_tables)).to include(time_table)
+ expect(assigns(:time_tables)).to include(blargh)
+ expect(assigns(:time_tables)).to_not include(other_time_table)
+ end
+
+ it 'should be accent insensitive' do
+ get :index, referential_id: referential.id, q: {unaccented_comment_or_objectid_cont_any: 'ecola'}, :format => :json
+ expect(response).to be_success
+ expect(assigns(:time_tables)).to include(time_table)
+ expect(assigns(:time_tables)).to include(blargh)
+ expect(assigns(:time_tables)).to_not include(other_time_table)
+ end
+ end
+ end
+
+end