From e02ada352a0b204783fbc67d7c2a4266d2551082 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Mon, 12 Mar 2018 06:17:02 -0700 Subject: Refs #5146 Line state update --- app/controllers/lines_controller.rb | 20 +++++++++++++++++++- app/helpers/referentials_helper.rb | 6 +++--- app/views/lines/_filters.html.slim | 20 ++++++++++++++++++++ app/views/lines/index.html.slim | 4 ++-- config/locales/lines.en.yml | 3 +++ config/locales/lines.fr.yml | 3 +++ 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| ("" + t("enumerize.transport_submode.#{l}") + "").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: ("#{t('activerecord.attributes.line.activated')}").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: ("#{t('activerecord.attributes.line.deactivated')}").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 -- cgit v1.2.3 From 08895521dd1587c460ffc4ed335d7129b1b53de1 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 14 Mar 2018 09:21:03 +0100 Subject: Refs #6146; Fix "activated/deactivated" filter --- app/controllers/lines_controller.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 6b002e4f6..ae8c9ed0c 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -83,20 +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 - scope = ransack_status line_referential.lines - @q = scope.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]) - else - @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company]) + 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 @@ -157,10 +160,7 @@ class LinesController < ChouetteController deactivated: params[:q][:status]['deactivated'] == 'true', } - scope = Chouette::Line.where(deactivated: @status[@status.key(true)]) - - params[:q].delete :status - scope + scope.where(deactivated: @status[:deactivated]) end end -- cgit v1.2.3 From c8d685984e8d9513e586b4bbc04ccf8e33be8ca3 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 14 Mar 2018 09:21:15 +0100 Subject: Refs #6146; Fix typo --- app/views/lines/_filters.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim index c221a02a1..da0539bd0 100644 --- a/app/views/lines/_filters.html.slim +++ b/app/views/lines/_filters.html.slim @@ -33,7 +33,7 @@ wrapper_html: { class: 'checkbox-wrapper' }, checked_value: true, unchecked_value: false, - input_html: { checked: @status.try(:[], :confirmed) } + input_html: { checked: @status.try(:[], :activated) } = p.input :deactivated, label: ("#{t('activerecord.attributes.line.deactivated')}").html_safe, as: :boolean, -- cgit v1.2.3 From 2339663e4a6092b320826aec424103f32dd90035 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 14 Mar 2018 09:21:24 +0100 Subject: Refs #6146; Add specs --- spec/features/lines_spec.rb | 48 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/spec/features/lines_spec.rb b/spec/features/lines_spec.rb index 459c065cb..87e865798 100644 --- a/spec/features/lines_spec.rb +++ b/spec/features/lines_spec.rb @@ -47,14 +47,48 @@ describe "Lines", type: :feature do 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) + context "when filtered by status" do + it 'supports displaying only activated lines' 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) + find('#q_status_activated').set(true) + click_button 'search-btn' + expect(page).to_not have_content(lines.first.name) + expect(page).to have_content(lines.last.name) + end + + it 'supports displaying only deactivated lines' do + lines.first.update_attribute(:deactivated, true) + lines.last.update_attribute(:deactivated, false) + + find('#q_status_deactivated').set(true) + click_button 'search-btn' + expect(page).to have_content(lines.first.name) + expect(page).to_not have_content(lines.last.name) + end + + it 'supports displaying all lines' do + lines.first.update_attribute(:deactivated, true) + lines.last.update_attribute(:deactivated, false) + + find('#q_status_activated').set(true) + find('#q_status_deactivated').set(true) + click_button 'search-btn' + expect(page).to have_content(lines.first.name) + expect(page).to have_content(lines.last.name) + end + + it 'supports displaying all lines (with all filters disabled)' do + lines.first.update_attribute(:deactivated, true) + lines.last.update_attribute(:deactivated, false) + + find('#q_status_activated').set(false) + find('#q_status_deactivated').set(false) + click_button 'search-btn' + expect(page).to have_content(lines.first.name) + expect(page).to have_content(lines.last.name) + end end end end -- cgit v1.2.3 From b1b32c0c0adccedcfa198e6f65e8b6c83056946e Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 14 Mar 2018 09:41:46 +0100 Subject: Refs #6146; Fix display in tables --- app/assets/stylesheets/components/_tables.sass | 3 ++- app/helpers/table_builder_helper.rb | 24 ++++++++++++++---------- app/helpers/table_builder_helper/column.rb | 9 +++++++++ app/views/lines/index.html.slim | 1 + spec/helpers/table_builder_helper_spec.rb | 24 ++++++++++++------------ 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass index ef19bd538..5360f0625 100644 --- a/app/assets/stylesheets/components/_tables.sass +++ b/app/assets/stylesheets/components/_tables.sass @@ -222,6 +222,8 @@ background: url( image-path('map/lda.png') ) no-repeat left 50% padding-left: 30px + tr.line td.state + white-space: nowrap // select_toolbox .select_toolbox @@ -307,7 +309,6 @@ font-style: italic font-size: 0.85em - //-----------------------------// // Tables (column by column) // //-----------------------------// diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index d16858678..63125b161 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -208,7 +208,7 @@ module TableBuilderHelper end def tr item, columns, selectable, links, overhead, model_name, action - klass = "#{model_name}-#{item.id}" + klass = "#{model_name} #{model_name}-#{item.id}" content_tag :tr, class: klass do bcont = [] if selectable @@ -221,13 +221,14 @@ module TableBuilderHelper columns.each do |column| value = column.value(item) + extra_class = column.td_class(item) if column.linkable? path = column.link_to(item) link = value.present? && path.present? ? link_to(value, path) : "" if overhead.empty? - bcont << content_tag(:td, link, title: 'Voir') + bcont << content_tag(:td, link, title: 'Voir', class: extra_class) else i = columns.index(column) @@ -236,22 +237,22 @@ module TableBuilderHelper if (i > 0) && (overhead[i - 1][:width] > 1) clsArrayAlt = overhead[i - 1][:cls].split - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt, extra_class)) else - bcont << content_tag(:td, link, title: 'Voir') + bcont << content_tag(:td, link, title: 'Voir', class: extra_class) end else clsArray = overhead[columns.index(column)][:cls].split - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray, extra_class)) end end else if overhead.empty? - bcont << content_tag(:td, value) + bcont << content_tag(:td, value, class: extra_class) else i = columns.index(column) @@ -260,10 +261,10 @@ module TableBuilderHelper if (i > 0) && (overhead[i - 1][:width] > 1) clsArrayAlt = overhead[i - 1][:cls].split - bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) + bcont << content_tag(:td, value, class: td_cls(clsArrayAlt, extra_class)) else - bcont << content_tag(:td, value) + bcont << content_tag(:td, value, class: extra_class) end else @@ -299,12 +300,15 @@ module TableBuilderHelper end end - def td_cls(a) + def td_cls(a, extra_class="") + out = [extra_class] if a.include? 'full-border' a.slice!(a.index('full-border')) - return a.join(' ') + out += a end + out = out.select(&:present?).join(' ') + out.present? ? out : nil end def build_links(item, links, action) diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb index ff6f2f36f..f930eb9fd 100644 --- a/app/helpers/table_builder_helper/column.rb +++ b/app/helpers/table_builder_helper/column.rb @@ -13,6 +13,7 @@ module TableBuilderHelper @sortable = sortable @link_to = link_to @condition = opts[:if] + @extra_class = opts[:class] end def value(obj) @@ -50,6 +51,14 @@ module TableBuilderHelper end !!condition_val end + + def td_class(obj) + out = [] + out << @attribute if @attribute.is_a?(String) || @attribute.is_a?(Symbol) + out << @extra_class + out = out.compact.join ' ' + out.present? ? out : nil + end end diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim index e77518d57..9d491ace4 100644 --- a/app/views/lines/index.html.slim +++ b/app/views/lines/index.html.slim @@ -30,6 +30,7 @@ ), \ TableBuilderHelper::Column.new( \ name: t('activerecord.attributes.line.state'), \ + class: :state, \ attribute: Proc.new { |n| line_status(n.deactivated) } \ ), \ TableBuilderHelper::Column.new( \ diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index b0c17859f..6cb7929ac 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -68,11 +68,11 @@ describe TableBuilderHelper, type: :helper do - +
- #{referential.name} + #{referential.name}
En préparation
@@ -229,12 +229,12 @@ describe TableBuilderHelper, type: :helper do - + #{company.get_objectid.local_id} - #{company.name} - - - + #{company.name} + + +
@@ -344,12 +344,12 @@ describe TableBuilderHelper, type: :helper do - + #{company.get_objectid.local_id} - #{company.name} - - - + #{company.name} + + +
-- cgit v1.2.3 From e93784cba5e7f07d7ff4e20622088d9506816436 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 15 Mar 2018 15:22:16 +0100 Subject: Small fixes for i18n state Refs #6146 @1 --- app/views/referentials/show.html.slim | 2 +- config/locales/lines.en.yml | 1 - config/locales/lines.fr.yml | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index 289e802d7..b2a079ab4 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -40,7 +40,7 @@ end \ ), \ TableBuilderHelper::Column.new( \ - key: :deactivated, \ + key: :state, \ attribute: Proc.new { |n| line_status(n.deactivated?) } \ ), \ TableBuilderHelper::Column.new( \ diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml index 94b34a63b..e61013725 100644 --- a/config/locales/lines.en.yml +++ b/config/locales/lines.en.yml @@ -83,7 +83,6 @@ en: name: "Name" published_name: "Published name" registration_number: "Short name" - deactivated: "Activated" number: "Number" transport_mode: "Transport mode" transport_submode: "Transport Submode" diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml index 5f2110db8..d3069f1d1 100644 --- a/config/locales/lines.fr.yml +++ b/config/locales/lines.fr.yml @@ -81,7 +81,6 @@ fr: companies: name: "Transporteur principal" registration_number: "Nom court" - deactivated: "Activé" name: "Nom de la ligne" published_name: "Nom public" number: "Numéro" -- cgit v1.2.3