diff options
| author | Luc Donnet | 2018-03-15 15:35:55 +0100 |
|---|---|---|
| committer | GitHub | 2018-03-15 15:35:55 +0100 |
| commit | d3d3c0f40c37d716cfccbf9297bfbdc98c692521 (patch) | |
| tree | ad64c5c06322894491a2740d14e30bb1b693561e /app/controllers/lines_controller.rb | |
| parent | 499a46cabdf2ee1aab830f27c3aa3e896ded24e3 (diff) | |
| parent | e93784cba5e7f07d7ff4e20622088d9506816436 (diff) | |
| download | chouette-core-d3d3c0f40c37d716cfccbf9297bfbdc98c692521.tar.bz2 | |
Merge pull request #372 from af83/6146-line-states
6146 Line state update
Diffstat (limited to 'app/controllers/lines_controller.rb')
| -rw-r--r-- | app/controllers/lines_controller.rb | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 27a9bf9be..ae8c9ed0c 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -83,18 +83,23 @@ class LinesController < ChouetteController end def collection - %w(network_id company_id group_of_lines_id comment_id transport_mode).each do |filter| - if params[:q] && params[:q]["#{filter}_eq"] == '-1' - params[:q]["#{filter}_eq"] = '' - params[:q]["#{filter}_blank"] = '1' + @lines ||= begin + %w(network_id company_id group_of_lines_id comment_id transport_mode).each do |filter| + if params[:q] && params[:q]["#{filter}_eq"] == '-1' + params[:q]["#{filter}_eq"] = '' + params[:q]["#{filter}_blank"] = '1' + end end - end - @q = line_referential.lines.search(params[:q]) - if sort_column && sort_direction - @lines ||= @q.result(:distinct => true).order(sort_column + ' ' + sort_direction).paginate(:page => params[:page]).includes([:network, :company]) - else - @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company]) + scope = ransack_status line_referential.lines + @q = scope.search(params[:q]) + + if sort_column && sort_direction + lines ||= @q.result(:distinct => true).order(sort_column + ' ' + sort_direction).paginate(:page => params[:page]).includes([:network, :company]) + else + lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company]) + end + lines end end @@ -145,4 +150,17 @@ class LinesController < ChouetteController ) end + # 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 = { + activated: params[:q][:status]['activated'] == 'true', + deactivated: params[:q][:status]['deactivated'] == 'true', + } + + scope.where(deactivated: @status[:deactivated]) +end + end |
