diff options
| author | Xinhui | 2017-07-03 16:23:00 +0200 |
|---|---|---|
| committer | Xinhui | 2017-07-03 16:35:51 +0200 |
| commit | adc8e323d6f76baf50d649b47bf83f08468681c0 (patch) | |
| tree | f7b01912df37e67e522f3c86f5ec6c7e0a548616 /app | |
| parent | 69723fff92b21b4fff722cefe1ca169ed308f5b2 (diff) | |
| download | chouette-core-adc8e323d6f76baf50d649b47bf83f08468681c0.tar.bz2 | |
Refactoring workbench_controller ransack_status
refs #3936
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index d03841356..a53e21269 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -13,8 +13,10 @@ class WorkbenchesController < BreadcrumbController # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope # We clone params[:q] so we can delete fake ransack filter arguments before calling search method, # which will allow us to preserve params[:q] for sorting - ransack_params = params[:q].merge(archived_at_not_null: nil, archived_at_null: nil).clone + ransack_params = params[:q].clone ransack_params.delete('associated_lines_id_eq') + ransack_params.delete('archived_at_not_null') + ransack_params.delete('archived_at_null') @q = scope.ransack(ransack_params) @wbench_refs = sort_result(@q.result).paginate(page: params[:page], per_page: 30) @@ -55,16 +57,13 @@ class WorkbenchesController < BreadcrumbController end 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 + params[:q] ||= {} + params[:q].delete_if { |query, value| value.blank? } end # Fake ransack filter def ransack_associated_lines scope - if params[:q] && params[:q]['associated_lines_id_eq'] + if params[:q]['associated_lines_id_eq'] scope = scope.include_metadatas_lines([params[:q]['associated_lines_id_eq']]) end scope @@ -89,29 +88,17 @@ class WorkbenchesController < BreadcrumbController scope end - # Fake (again) ransack filter + # Fake 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 + archived = !params[:q]['archived_at_not_null'].to_i.zero? + unarchived = !params[:q]['archived_at_null'].to_i.zero? - 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 + # Both status checked, means no filter + return scope unless archived || unarchived + return scope if archived && unarchived + scope = scope.where(archived_at: nil) if unarchived + scope = scope.where("archived_at is not null") if archived scope end end |
