diff options
| author | Luc Donnet | 2017-10-16 23:52:06 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-10-16 23:52:06 +0200 |
| commit | f480ad0739e5c0ec2c0c8bb890344b9c4777ba35 (patch) | |
| tree | a19bc6b43449b8b978a53c33476fb3eb571d4dda /app/controllers/time_tables_controller.rb | |
| parent | b611a84ed724036c4929bd4c3eaa7e23ea314f45 (diff) | |
| parent | 51a1ea5b141032121913f807a162d305828bec54 (diff) | |
| download | chouette-core-f480ad0739e5c0ec2c0c8bb890344b9c4777ba35.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'app/controllers/time_tables_controller.rb')
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 0054963c9..2d24d5aa6 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -1,5 +1,7 @@ class TimeTablesController < ChouetteController include TimeTablesHelper + include RansackDateFilter + before_action only: [:index] { set_date_time_params("bounding_dates", Date) } defaults :resource_class => Chouette::TimeTable respond_to :html respond_to :xml @@ -131,7 +133,7 @@ class TimeTablesController < ChouetteController params[:q].delete("tag_search") scope = select_time_tables.tagged_with(tags, :any => true) if tags.any? end - scope = ransack_periode(scope) + scope = self.ransack_period_range(scope: scope, error_message: t('referentials.errors.validity_period'), query: :overlapping) @q = scope.search(params[:q]) if sort_column && sort_direction @@ -159,28 +161,6 @@ class TimeTablesController < ChouetteController end private - def ransack_periode scope - return scope unless params[:q] - return scope unless params[:q]['end_date_lteq(1i)'].present? - - begin_range = flatten_date('start_date_gteq') - end_range = flatten_date('end_date_lteq') - - if begin_range > end_range - flash.now[:error] = t('referentials.errors.validity_period') - else - scope = scope.overlapping(begin_range, end_range) - params[:q] = params[:q].slice('comment_cont', 'color_cont_any') - @begin_range = begin_range - @end_range = end_range - end - scope - end - - def flatten_date key - date_int = %w(1 2 3).map {|e| params[:q]["#{key}(#{e}i)"].to_i } - Date.new(*date_int) - end def sort_column referential.time_tables.column_names.include?(params[:sort]) ? params[:sort] : 'comment' |
