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/imports_controller.rb | |
| parent | b611a84ed724036c4929bd4c3eaa7e23ea314f45 (diff) | |
| parent | 51a1ea5b141032121913f807a162d305828bec54 (diff) | |
| download | chouette-core-f480ad0739e5c0ec2c0c8bb890344b9c4777ba35.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'app/controllers/imports_controller.rb')
| -rw-r--r-- | app/controllers/imports_controller.rb | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 3333dc535..3c52dc935 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -1,7 +1,9 @@ class ImportsController < BreadcrumbController + include PolicyChecker + include RansackDateFilter + before_action only: [:index] { set_date_time_params("started_at", DateTime) } skip_before_action :authenticate_user!, only: [:download] defaults resource_class: Import, collection_name: 'imports', instance_name: 'import' - before_action :ransack_started_at_params, only: [:index] before_action :ransack_status_params, only: [:index] respond_to :html belongs_to :workbench @@ -47,7 +49,8 @@ class ImportsController < BreadcrumbController protected def collection scope = parent.imports.where(type: "WorkbenchImport") - scope = ransack_period scope + + scope = self.ransack_period_range(scope: scope, error_message: t('imports.filters.error_period_filter'), query: :where_started_at_in) @q = scope.search(params[:q]) @@ -60,33 +63,6 @@ class ImportsController < BreadcrumbController private - def ransack_started_at_params - start_date = [] - end_date = [] - - if params[:q] && params[:q][:started_at] && !params[:q][:started_at].has_value?(nil) && !params[:q][:started_at].has_value?("") - [1, 2, 3].each do |key| - start_date << params[:q][:started_at]["begin(#{key}i)"].to_i - end_date << params[:q][:started_at]["end(#{key}i)"].to_i - end - params[:q].delete([:started_at]) - @begin_range = DateTime.new(*start_date,0,0,0) rescue nil - @end_range = DateTime.new(*end_date,23,59,59) rescue nil - end - end - - # Fake ransack filter - def ransack_period scope - return scope unless !!@begin_range && !!@end_range - - if @begin_range > @end_range - flash.now[:error] = t('imports.filters.error_period_filter') - else - scope = scope.where_started_at_between(@begin_range, @end_range) - end - scope - end - def ransack_status_params if params[:q] return params[:q].delete(:status_eq_any) if params[:q][:status_eq_any].empty? || ( (Import.status.values & params[:q][:status_eq_any]).length >= 4 ) |
