diff options
| author | cedricnjanga | 2017-09-12 16:54:25 +0200 | 
|---|---|---|
| committer | cedricnjanga | 2017-09-12 17:04:19 +0200 | 
| commit | 0222139b23393937bf32586ca00cbf7f2a4cb88e (patch) | |
| tree | 17d74dbcb7831d3e3c961ebed8c57691abe3fd48 /app/controllers/imports_controller.rb | |
| parent | 515b7eb4bfd1623c443cd89b11320a1864ed6306 (diff) | |
| download | chouette-core-0222139b23393937bf32586ca00cbf7f2a4cb88e.tar.bz2 | |
Change the import status filter to include all of the statuses and not just running successful warning and failed.
The Import model has seven statuses and we wanted to filter them all so we added a method in the controller that will be called before_action :index to change the params and include the other statuses and include them in the ransack query (witout having duplicates in the checkboxes)
Diffstat (limited to 'app/controllers/imports_controller.rb')
| -rw-r--r-- | app/controllers/imports_controller.rb | 15 | 
1 files changed, 12 insertions, 3 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 2bd8cc6f4..fa8919f20 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -2,6 +2,7 @@ class ImportsController < BreadcrumbController    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 @@ -45,11 +46,10 @@ class ImportsController < BreadcrumbController    protected    def collection -      scope = parent.imports.where(type: "WorkbenchImport")      scope = ransack_period scope -    @q = scope.search(params[:q].try(:except, :started_at)) +    @q = scope.search(params[:q])      if sort_column && sort_direction        @imports ||= @q.result(distinct: true).order(sort_column + ' ' + sort_direction).paginate(page: params[:page], per_page: 10) @@ -64,7 +64,7 @@ class ImportsController < BreadcrumbController      start_date = []      end_date = [] -    if params[:q] && params[:q][:started_at] && !params[:q][:started_at].has_value?(nil) +    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 @@ -87,6 +87,15 @@ class ImportsController < BreadcrumbController      scope    end +  def ransack_status_params +    if params[:q] +      binding.pry +      return params[:q].delete(:status_eq_any) if params[:q][:status_eq_any].empty? || ( (Import.status.values & params[:q][:status_eq_any]).length >= 4 ) +      params[:q][:status_eq_any].push("new", "running") if params[:q][:status_eq_any].include?("pending") +      params[:q][:status_eq_any].push("aborted", "canceled") if params[:q][:status_eq_any].include?("failed") +    end +  end +    def build_resource      @import ||= WorkbenchImport.new(*resource_params) do |import|        import.workbench = parent  | 
