aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/workbenches_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/workbenches_controller.rb')
-rw-r--r--app/controllers/workbenches_controller.rb45
1 files changed, 40 insertions, 5 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index 7f108b266..1424fe03c 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -5,12 +5,17 @@ class WorkbenchesController < BreadcrumbController
respond_to :html, only: [:show]
def show
- scope = params[:q] ? resource.all_referentials : resource.referentials.ready
+ scope = resource.all_referentials
scope = ransack_associated_lines(scope)
+ scope = ransack_periode(scope)
+ scope = ransack_status(scope)
- @q = ransack_periode(scope).ransack(params[:q])
- @q.organisation_name_eq_any ||= current_organisation.name unless params[:q]
- @wbench_refs = sort_result(@q.result).paginate(page: params[:page], per_page: 30)
+ # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope
+ q_for_result =
+ scope.ransack(params[:q].merge(archived_at_not_null: nil, archived_at_null: nil))
+ @wbench_refs = sort_result(q_for_result.result).paginate(page: params[:page], per_page: 30)
+
+ @q = scope.ransack(params[:q])
show! do
build_breadcrumb :show
end
@@ -44,6 +49,8 @@ class WorkbenchesController < BreadcrumbController
def query_params
if params[:q].present?
params[:q].delete_if { |query, value| value.blank? }
+ else
+ params[:q] = { "archived_at_not_null"=>"1", "archived_at_null"=>"1" }
end
end
@@ -68,8 +75,36 @@ class WorkbenchesController < BreadcrumbController
if begin_range > end_range
flash.now[:error] = t('referentials.errors.validity_period')
else
- scope = scope.in_periode(begin_range..end_range)
+ scope = scope.in_periode(begin_range..end_range)
+ @begin_range = begin_range
+ @end_range = end_range
+ end
+ scope
+ end
+
+ # Fake (again) ransack filter
+ def ransack_status scope
+ return scope unless params[:q]
+
+ archived_at_not_null = params[:q]['archived_at_not_null'] == '1'
+ archived_at_null = params[:q]['archived_at_null'] == '1'
+
+ if !archived_at_not_null and !archived_at_null
+ return scope.none
end
+
+ if archived_at_not_null and archived_at_null
+ return scope
+ end
+
+ if archived_at_null
+ return scope.where(archived_at: nil)
+ end
+
+ if archived_at_not_null
+ return scope.where("archived_at is not null")
+ end
+
scope
end
end