From af05b9d9832ab3b74b1a810246ea7d499010d5c9 Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Tue, 23 Dec 2014 11:11:23 +0100 Subject: isolation of calendar autocomplete. Mantis 31068 --- .../autocomplete_time_tables_controller.rb | 33 ++++++ app/helpers/time_tables_helper.rb | 54 --------- app/inputs/search_time_table_input.rb | 5 +- app/views/autocomplete_time_tables/index.rabl | 10 ++ .../time_table_combinations/_combine_form.html.erb | 2 +- app/views/time_tables/_properties_show.html.erb | 127 +++++++++++++++++++++ app/views/time_tables/_show_time_table.html.erb | 14 +-- app/views/time_tables/_time_table.html.erb | 14 +-- app/views/time_tables/index.html.erb | 12 +- app/views/vehicle_journeys/_form.html.erb | 8 +- app/views/vehicle_journeys/_show_popover.html.erb | 12 +- app/views/vehicle_journeys/_time_filter.html.erb | 13 --- app/views/vehicle_journeys/_time_table.html.erb | 7 -- .../_timeless_vehicle_journey.html.erb | 15 --- app/views/vehicle_journeys/index.html.erb | 27 +++-- 15 files changed, 220 insertions(+), 133 deletions(-) create mode 100644 app/controllers/autocomplete_time_tables_controller.rb create mode 100644 app/views/autocomplete_time_tables/index.rabl create mode 100644 app/views/time_tables/_properties_show.html.erb delete mode 100644 app/views/vehicle_journeys/_time_filter.html.erb delete mode 100644 app/views/vehicle_journeys/_time_table.html.erb delete mode 100644 app/views/vehicle_journeys/_timeless_vehicle_journey.html.erb (limited to 'app') diff --git a/app/controllers/autocomplete_time_tables_controller.rb b/app/controllers/autocomplete_time_tables_controller.rb new file mode 100644 index 000000000..c556bb71c --- /dev/null +++ b/app/controllers/autocomplete_time_tables_controller.rb @@ -0,0 +1,33 @@ +class AutocompleteTimeTablesController < InheritedResources::Base + respond_to :json, :only => [:index] + + before_filter :switch_referential + + def switch_referential + Apartment::Database.switch(referential.slug) + end + + def referential + @referential ||= current_organisation.referentials.find params[:referential_id] + end + + protected + + def select_time_tables + if params[:route_id] + referential.time_tables.joins( vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})") + else + referential.time_tables + end + end + + def referential_time_tables + @referential_time_tables ||= select_time_tables + end + + def collection + comment_selection = referential_time_tables.select{ |p| p.comment =~ /#{params[:q]}/i } + tag_selection = referential_time_tables.tagged_with( params[:q], :wild => true) + @time_tables = (comment_selection + tag_selection).uniq + end +end diff --git a/app/helpers/time_tables_helper.rb b/app/helpers/time_tables_helper.rb index e0c1fc2db..9fdb791b1 100644 --- a/app/helpers/time_tables_helper.rb +++ b/app/helpers/time_tables_helper.rb @@ -1,57 +1,3 @@ module TimeTablesHelper - def time_table_state_code(time_table) - if time_table.validity_out_from_on?(Date.today) - "validity_out" - elsif time_table.validity_out_between?(Date.today,Date.today+7.day) - "validity_out_soon" - else - "validity_regular" - end - end - def tag_list_shortened(time_table) - time_table.tags.join(', ').truncate(30, separator: ',') - end - def bounding_info(time_table) - return t('time_tables.time_table.empty') if time_table.bounding_dates.empty? - t('time_tables.time_table.bounding', - :start => l(time_table.bounding_dates.min), - :end => l(time_table.bounding_dates.max)) - end - def bounding_short_info(dates) - return t('time_tables.time_table.empty') if dates.empty? - "#{l(dates.min)} #{l(dates.max)}" - end - def time_table_bounding( time_table) - bounding_short_info( time_table.bounding_dates) - end - def time_tables_shortest_info( vehicle) - bounding_short_info( vehicle.bounding_dates) - end - def time_tables_info( vehicle) - vehicle.time_tables.map do |time_table| - "#{time_table_bounding( time_table)} - #{composition_info(time_table)}" - end.join( "\n") - end - - def composition_info(time_table) - return if time_table.bounding_dates.empty? - if time_table.dates.empty? - t('time_tables.time_table.periods_count', :count => time_table.periods.count) - elsif time_table.periods.empty? - t('time_tables.time_table.dates_count', :count => time_table.dates.count) - else - t('time_tables.time_table.periods_dates_count', - :dates_count => time_table.dates.count, - :periods_count => time_table.periods.count) - end - end - - def time_table_description(time_table) - if time_table.bounding_dates.empty? - "#{time_table.comment} (vide)" - else - "#{time_table.comment} : #{time_table_bounding( time_table)} - #{composition_info(time_table)}" - end - end end diff --git a/app/inputs/search_time_table_input.rb b/app/inputs/search_time_table_input.rb index 877333592..c64280e6d 100644 --- a/app/inputs/search_time_table_input.rb +++ b/app/inputs/search_time_table_input.rb @@ -25,12 +25,11 @@ class SearchTimeTableInput < Formtastic::Inputs::SearchInput minChars: 2, propertyToSearch: 'comment', preventDuplicates: true, - queryParam: 'q[comment_cont]', hintText: '#{options[:hint_text]}', noResultsText: '#{options[:no_result_text]}', searchingText: '#{options[:searching_text]}', resultsFormatter: time_table_formatter, - tokenFormatter: time_table_formatter, + tokenFormatter: time_table_formatter, }); });").html_safe) end @@ -49,7 +48,7 @@ class SearchTimeTableInput < Formtastic::Inputs::SearchInput :required => nil, :autofocus => nil, :class => 'token-input', - 'data-model-name' => object.class.model_name.human + 'data-model-name' => object.class.model_name.human }) end diff --git a/app/views/autocomplete_time_tables/index.rabl b/app/views/autocomplete_time_tables/index.rabl new file mode 100644 index 000000000..0389c26b0 --- /dev/null +++ b/app/views/autocomplete_time_tables/index.rabl @@ -0,0 +1,10 @@ +collection @time_tables, :object_root => false + +node do |time_table| + { :id => time_table.id, :comment => time_table.comment, + :time_table_bounding => time_table.presenter.time_table_bounding, + :composition_info => time_table.presenter.composition_info, + :tags => time_table.tags.join(','), + :day_types => %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| time_table.send(d) }.map{ |d| time_table.human_attribute_name(d).first(2)}.join('')} +end + diff --git a/app/views/time_table_combinations/_combine_form.html.erb b/app/views/time_table_combinations/_combine_form.html.erb index aad31a218..dd9cd9b92 100644 --- a/app/views/time_table_combinations/_combine_form.html.erb +++ b/app/views/time_table_combinations/_combine_form.html.erb @@ -3,7 +3,7 @@ <%= render "shared/flash_messages" %> <%= form.inputs do %> <%= form.input :operation, :as => :radio, :collection => Hash[TimeTableCombination.operations.map {|b| [t( b, :scope => "time_table_combinations.operations"),b]}] %> - <%= form.input :combined_id, :label => t('.time_tables'), :as => :search_time_table, :json => referential_time_tables_path(@referential, :format => :json), :hint_text => t('search_hint'), :no_result_text => t('no_result_text'), :searching_text => t('searching_term'), :tokenLimit => 1 %> + <%= form.input :combined_id, :label => t('.time_tables'), :as => :search_time_table, :json => referential_autocomplete_time_tables_path(@referential, :format => :json), :hint_text => t('search_hint'), :no_result_text => t('no_result_text'), :searching_text => t('searching_term'), :tokenLimit => 1 %> <% end %>
<%= @time_table.version %> @@ -62,15 +62,15 @@ <% if @time_table.int_day_types & 508 == 0 %> - <% else %> + <% else %> <% %w(monday tuesday wednesday thursday friday saturday sunday).each do |day_type| %> "> <%= @time_table.human_attribute_name(day_type) %> <% end %> - <% end %> -
- + <% end %> + +- <%= vehicle_journey.time_tables.size %> <%= Chouette::TimeTable.model_name.human.pluralize %> <%= time_tables_shortest_info( vehicle_journey ) %> : + <%= vehicle_journey.time_tables.size %> <%= Chouette::TimeTable.model_name.human.pluralize %> <%= vehicle_journey.presenter.time_tables_shortest_info %> :