diff options
| -rw-r--r-- | app/controllers/lines_controller.rb | 20 | ||||
| -rw-r--r-- | app/helpers/referentials_helper.rb | 6 | ||||
| -rw-r--r-- | app/views/lines/_filters.html.slim | 20 | ||||
| -rw-r--r-- | app/views/lines/index.html.slim | 4 | ||||
| -rw-r--r-- | config/locales/lines.en.yml | 3 | ||||
| -rw-r--r-- | config/locales/lines.fr.yml | 3 | ||||
| -rw-r--r-- | spec/features/lines_spec.rb | 10 |
7 files changed, 60 insertions, 6 deletions
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 27a9bf9be..6b002e4f6 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -89,7 +89,9 @@ class LinesController < ChouetteController params[:q]["#{filter}_blank"] = '1' end end - @q = line_referential.lines.search(params[:q]) + + 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]) @@ -145,4 +147,20 @@ 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 = Chouette::Line.where(deactivated: @status[@status.key(true)]) + + params[:q].delete :status + scope +end + end diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb index e464ec8a5..9c3852322 100644 --- a/app/helpers/referentials_helper.rb +++ b/app/helpers/referentials_helper.rb @@ -2,12 +2,12 @@ module ReferentialsHelper # Outputs a green check icon and the text "Oui" or a red exclamation mark # icon and the text "Non" based on `status` def line_status(status) - if status + if status content_tag(:span, nil, class: 'fa fa-exclamation-circle fa-lg text-danger') + - t('false') + t('activerecord.attributes.line.deactivated') else content_tag(:span, nil, class: 'fa fa-check-circle fa-lg text-success') + - t('true') + t('activerecord.attributes.line.activated') end end diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim index 67ba297cf..c221a02a1 100644 --- a/app/views/lines/_filters.html.slim +++ b/app/views/lines/_filters.html.slim @@ -23,6 +23,26 @@ = f.label Chouette::Line.human_attribute_name(:transport_submode), required: false, class: 'control-label' = f.input :transport_submode_eq_any, collection: StifTransportSubmodeEnumerations.sorted_transport_submodes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'} + .form-group.togglable class=filter_item_class(params[:q], :status) + = f.label Chouette::Line.human_attribute_name(:state), required: false, class: 'control-label' + .form-group.checkbox_list + = f.simple_fields_for :status do |p| + = p.input :activated, + label: ("<span>#{t('activerecord.attributes.line.activated')}<span class='fa fa-check-circle text-success'></span></span>").html_safe, + as: :boolean, + wrapper_html: { class: 'checkbox-wrapper' }, + checked_value: true, + unchecked_value: false, + input_html: { checked: @status.try(:[], :confirmed) } + = p.input :deactivated, + label: ("<span>#{t('activerecord.attributes.line.deactivated')}<span class='fa fa-exclamation-circle text-danger'></span></span>").html_safe, + as: :boolean, + wrapper_html: { class: 'checkbox-wrapper' }, + checked_value: true, + unchecked_value: false, + input_html: { checked: @status.try(:[], :deactivated) } + + .actions = link_to 'Effacer', @workbench, class: 'btn btn-link' = f.submit 'Filtrer', class: 'btn btn-default' diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim index 2d64e5f73..e77518d57 100644 --- a/app/views/lines/index.html.slim +++ b/app/views/lines/index.html.slim @@ -29,8 +29,8 @@ end \ ), \ TableBuilderHelper::Column.new( \ - key: :deactivated, \ - attribute: Proc.new { |n| line_status(n.deactivated?) } \ + name: t('activerecord.attributes.line.state'), \ + attribute: Proc.new { |n| line_status(n.deactivated) } \ ), \ TableBuilderHelper::Column.new( \ key: 'networks.name', \ diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml index 8e0189bd8..94b34a63b 100644 --- a/config/locales/lines.en.yml +++ b/config/locales/lines.en.yml @@ -116,6 +116,9 @@ en: creator_id: "Created by" footnotes: "Footnotes" stable_id: External permanent idenifier" + state: State + activated: Activated + deactivated: Deactivated formtastic: titles: line: diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml index 2159f06ab..5f2110db8 100644 --- a/config/locales/lines.fr.yml +++ b/config/locales/lines.fr.yml @@ -116,6 +116,9 @@ fr: creator_id: "Créé par" footnotes: "Notes de bas de page" stable_id: "Identifiant externe pérenne" + state: État + activated: Activée + deactivated: Désactivée formtastic: titles: line: diff --git a/spec/features/lines_spec.rb b/spec/features/lines_spec.rb index f176e34fe..459c065cb 100644 --- a/spec/features/lines_spec.rb +++ b/spec/features/lines_spec.rb @@ -46,6 +46,16 @@ describe "Lines", type: :feature do expect(page).to have_content(lines.first.name) expect(page).not_to have_content(lines.last.name) end + + xit 'supports filtering by status' do + lines.first.update_attribute(:deactivated, true) + lines.last.update_attribute(:deactivated, false) + + find('#q_status_activated').set(true) + click_button 'search-btn' + expect(page).to have_content(lines.first.name) + expect(page).not_to have_content(lines.last.name) + end end end |
