diff options
Diffstat (limited to 'app/controllers/workbenches_controller.rb')
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index ecf70805d..1424fe03c 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -5,10 +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) - @q = ransack_periode(scope).ransack(params[:q]) - @wbench_refs = sort_result(@q.result).paginate(page: params[:page], per_page: 30) + scope = ransack_periode(scope) + scope = ransack_status(scope) + + # 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 @@ -42,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 @@ -72,4 +81,30 @@ class WorkbenchesController < BreadcrumbController 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 |
