diff options
| author | cedricnjanga | 2018-04-09 23:56:16 -0700 | 
|---|---|---|
| committer | Johan Van Ryseghem | 2018-05-28 12:48:49 +0200 | 
| commit | cd3c110893a7b1845e5ff420f7f28d30b0b78825 (patch) | |
| tree | 46a2b6069111008fbb08542a354efbccd0c9cf43 /app/controllers | |
| parent | a14ab8ed2c24ae52b8227c49b0b8e2126b46765c (diff) | |
| download | chouette-core-cd3c110893a7b1845e5ff420f7f28d30b0b78825.tar.bz2 | |
Refs #6433 Add changes to stop areas status filter
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 27 | 
1 files changed, 16 insertions, 11 deletions
| diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 734152c64..c3d27cc6c 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -120,7 +120,7 @@ class StopAreasController < ChouetteController    def collection      scope = parent.present? ? parent.stop_areas : referential.stop_areas -    scope = ransack_status(scope) +    scope = ransack_status(scope) if params[:q] && params[:q][:status_eq_any]      @q = scope.search(params[:q])      if sort_column && sort_direction @@ -209,21 +209,26 @@ class StopAreasController < ChouetteController     # Fake ransack filter    def ransack_status scope -    return scope unless params[:q].try(:[], :status) -    return scope if params[:q][:status].values.uniq.length == 1 +    status_param = params[:q][:status_eq_any].reject(&:blank?) +    params[:q].delete :status_eq_any -    @status = { -      in_creation: params[:q][:status]['in_creation'] == 'true', -      confirmed: params[:q][:status]['confirmed'] == 'true', -      deactivated: params[:q][:status]['deactivated'] == 'true', -    } +    return scope unless status_param +    return scope if status_param.empty? || status_param.length == 3 + +    @status = Hash.new do |hash| +      hash[:status_eq_any] = { +        in_creation: status_param.include?('in_creation'), +        confirmed: status_param.include?('confirmed'), +        deactivated: status_param.include?('deactivated'), +      } +    end +            scope = Chouette::StopArea.where( -      "confirmed_at #{(@status[:confirmed] || @status[:deactivated]) ? "IS NOT NULL" : "IS NULL"} -      AND deleted_at #{@status[:deactivated] ? "IS NOT NULL" : "IS NULL"}" +      "confirmed_at #{(@status[:status_eq_any][:confirmed] || @status[:status_eq_any][:deactivated]) ? "IS NOT NULL" : "IS NULL"} +      AND deleted_at #{@status[:status_eq_any][:deactivated] ? "IS NOT NULL" : "IS NULL"}"        ) -    params[:q].delete :status      scope    end  end | 
