diff options
| author | jpl | 2017-04-25 16:05:38 +0200 | 
|---|---|---|
| committer | jpl | 2017-04-25 16:05:44 +0200 | 
| commit | 4d88dfa88facab8ca4ac367288c4987cde131827 (patch) | |
| tree | 0b2cc2a7ec10f4edfd501590885155a3d285b4b7 | |
| parent | 5848e03e9655d74cdea84eb66286cf7696ee2ee4 (diff) | |
| download | chouette-core-4d88dfa88facab8ca4ac367288c4987cde131827.tar.bz2 | |
Refs #3172: fix bouding_dates filter on tt#index
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 19 | ||||
| -rw-r--r-- | app/helpers/newapplication_helper.rb | 2 | ||||
| -rw-r--r-- | app/views/time_tables/_filter.html.slim | 4 | ||||
| -rw-r--r-- | app/views/time_tables/index.html.slim | 2 | 
4 files changed, 23 insertions, 4 deletions
| diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index eedfef07c..b23345607 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -99,6 +99,7 @@ class TimeTablesController < ChouetteController        params[:q].delete("tag_search")        scope = select_time_tables.tagged_with(tags, :wild => true, :any => true) if tags.any?      end +    scope = ransack_periode(scope)      @q = scope.search(params[:q])      if sort_column && sort_direction @@ -126,6 +127,24 @@ class TimeTablesController < ChouetteController    end    private +  # Fake ransack filter +  def ransack_periode scope +    return scope unless params[:q] +    periode = params[:q] +    return scope if periode['end_date_lteq(1i)'].empty? || periode['start_date_gteq(1i)'].empty? + +    begin_range = Date.civil(periode["start_date_gteq(1i)"].to_i, periode["start_date_gteq(2i)"].to_i, periode["start_date_gteq(3i)"].to_i) +    end_range   = Date.civil(periode["end_date_lteq(1i)"].to_i, periode["end_date_lteq(2i)"].to_i, periode["end_date_lteq(3i)"].to_i) + +    if begin_range > end_range +      flash.now[:error] = t('referentials.errors.validity_period') +    else +      @begin_range = begin_range +      @end_range   = end_range +    end +    scope +  end +    def sort_column      referential.time_tables.column_names.include?(params[:sort]) ? params[:sort] : 'comment'    end diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb index 42fca489f..804f6dab4 100644 --- a/app/helpers/newapplication_helper.rb +++ b/app/helpers/newapplication_helper.rb @@ -16,7 +16,7 @@ module NewapplicationHelper          end          columns.map do |k, v| -          if ["ID Codif", "Oid", "OiD", "ID Reflex", "Arrêt de départ", "Arrêt d'arrivée", "Période de validité englobante"].include? k +          if ["ID Codif", "Oid", "OiD", "ID Reflex", "Arrêt de départ", "Arrêt d'arrivée", "Période de validité englobante", "Période englobante"].include? k              hcont << content_tag(:th, k)            else              hcont << content_tag(:th, sortable_columns(collection, k)) diff --git a/app/views/time_tables/_filter.html.slim b/app/views/time_tables/_filter.html.slim index b5d8185f0..d29c628a9 100644 --- a/app/views/time_tables/_filter.html.slim +++ b/app/views/time_tables/_filter.html.slim @@ -17,8 +17,8 @@      .form-group.togglable        = f.label @time_tables.human_attribute_name(:bounding_dates), required: false, class: 'control-label'        .filter_menu -        = f.input :start_date_gteq, as: :date, label: t('simple_form.from'), wrapper_html: { class: 'date filter_menu-item' } -        = f.input :end_date_lteq, as: :date, label: t('simple_form.to'), wrapper_html: { class: 'date filter_menu-item' } +        = f.input :start_date_gteq, as: :date, label: t('simple_form.from'), wrapper_html: { class: 'date filter_menu-item' }, default: @begin_range, include_blank: @begin_range ? false : true +        = f.input :end_date_lteq, as: :date, label: t('simple_form.to'), wrapper_html: { class: 'date filter_menu-item' }, default: @end_range, include_blank: @end_range ? false : true    .actions diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim index 4e803e18f..5ca3c7569 100644 --- a/app/views/time_tables/index.html.slim +++ b/app/views/time_tables/index.html.slim @@ -16,7 +16,7 @@          .col-lg-12            = table_builder @time_tables,              { :comment => 'comment', :color => Proc.new{|tt| tt.color ? content_tag(:span, '', class: 'fa fa-circle', style: "color:#{tt.color}") : '-' }, -              "Période de validité englobante" => Proc.new{ |tt| tt.bounding_dates.empty? ? '-' : t('bounding_dates', debut: l(tt.bounding_dates.min), end: l(tt.bounding_dates.max)) }, :calendar => Proc.new{ |tt| tt.calendar ? tt.calendar.try(:name) : '-' }, :updated_at => Proc.new {|tt| l(tt.updated_at, format: :short)} }, +              "Période englobante" => Proc.new{ |tt| tt.bounding_dates.empty? ? '-' : t('bounding_dates', debut: l(tt.bounding_dates.min), end: l(tt.bounding_dates.max)) }, :calendar => Proc.new{ |tt| tt.calendar ? tt.calendar.try(:name) : '-' }, :updated_at => Proc.new {|tt| l(tt.updated_at, format: :short)} },              [:show, :edit, :duplicate, :delete],              [],              'table has-search' | 
