aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-09-12 16:54:25 +0200
committercedricnjanga2017-09-12 17:04:19 +0200
commit0222139b23393937bf32586ca00cbf7f2a4cb88e (patch)
tree17d74dbcb7831d3e3c961ebed8c57691abe3fd48
parent515b7eb4bfd1623c443cd89b11320a1864ed6306 (diff)
downloadchouette-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)
-rw-r--r--app/controllers/imports_controller.rb15
-rw-r--r--app/views/imports/_filters.html.slim2
2 files changed, 13 insertions, 4 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
diff --git a/app/views/imports/_filters.html.slim b/app/views/imports/_filters.html.slim
index a5488b275..85099b99a 100644
--- a/app/views/imports/_filters.html.slim
+++ b/app/views/imports/_filters.html.slim
@@ -9,7 +9,7 @@
.ffg-row
.form-group.togglable
= f.label Import.human_attribute_name(:status), required: false, class: 'control-label'
- = f.input :status_eq_any, collection: @imports.map(&:status).uniq.compact, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + import_status(l) + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}, input_html: { checked: true}
+ = f.input :status_eq_any, collection: %w(pending successful warning failed), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + import_status(l) + "</span>").html_safe}, required: false, wrapper_html: { class: "checkbox_list"}
.form-group.togglable
= f.label Import.human_attribute_name(:started_at), required: false, class: 'control-label'