diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 27 | ||||
| -rw-r--r-- | app/helpers/stop_areas_helper.rb | 21 | ||||
| -rw-r--r-- | app/views/stop_areas/_filters.html.slim | 36 | 
3 files changed, 34 insertions, 50 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 diff --git a/app/helpers/stop_areas_helper.rb b/app/helpers/stop_areas_helper.rb index 314154fb7..d3e7dd2a4 100644 --- a/app/helpers/stop_areas_helper.rb +++ b/app/helpers/stop_areas_helper.rb @@ -75,16 +75,17 @@ module StopAreasHelper      t "formtastic.hints.stop_area.registration_number"    end -  def stop_area_status(stop_area) -    if stop_area.activated? -      content_tag(:span, nil, class: 'fa fa-check-circle fa-lg text-success') + -      t('activerecord.attributes.stop_area.confirmed') -    elsif stop_area.deactivated? -      content_tag(:span, nil, class: 'fa fa-exclamation-circle fa-lg text-danger') + -      t('activerecord.attributes.stop_area.deactivated') -    else -      content_tag(:span, nil, class: 'fa fa-pencil fa-lg text-info') + -      t('activerecord.attributes.stop_area.in_creation') +  def stop_area_status(status) +    case status +      when :confirmed +        content_tag(:span, nil, class: 'fa fa-check-circle fa-lg text-success') + +        t('activerecord.attributes.stop_area.confirmed') +      when :deactivated +        content_tag(:span, nil, class: 'fa fa-exclamation-circle fa-lg text-danger') + +        t('activerecord.attributes.stop_area.deactivated') +      else +        content_tag(:span, nil, class: 'fa fa-pencil fa-lg text-info') + +        t('activerecord.attributes.stop_area.in_creation')      end    end diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim index cca48bb17..2bc59ce75 100644 --- a/app/views/stop_areas/_filters.html.slim +++ b/app/views/stop_areas/_filters.html.slim @@ -9,38 +9,16 @@            span.fa.fa-search    .ffg-row -    = f.input :zip_code_cont, placeholder: t('.zip_code'), label: Chouette::StopArea.human_attribute_name(:zip_code), required: false, wrapper_html: {class: filter_item_class(params[:q], :zip_code_cont)} -    = f.input :city_name_cont, placeholder: t('.city_name'), label: Chouette::StopArea.human_attribute_name(:city_name), required: false, wrapper_html: {class: filter_item_class(params[:q], :city_name_cont)} +    = f.input :zip_code_cont, placeholder: t('.zip_code'), label: Chouette::StopArea.tmf('zip_code'), required: false, wrapper_html: {class: filter_item_class(params[:q], :zip_code_cont)} +    = f.input :city_name_cont, placeholder: t('.city_name'), label: Chouette::StopArea.tmf('city_name'), required: false, wrapper_html: {class: filter_item_class(params[:q], :city_name_cont)}      .form-group.togglable class=filter_item_class(params[:q], :area_type_eq_any) -      = f.label Chouette::StopArea.human_attribute_name(:area_type), required: false, class: 'control-label' +      = f.label Chouette::StopArea.tmf('area_type'), required: false, class: 'control-label'        = f.input :area_type_eq_any, checked: params[:q] && params[:q][:area_type_eq_any], collection: Chouette::AreaType.options, as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + w[0] + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' } -       -    .form-group.togglable class=filter_item_class(params[:q], :status) -      = f.label Chouette::StopArea.tmf('status'), required: false, class: 'control-label' -      .form-group.checkbox_list -        = f.simple_fields_for :status do |p| -          = p.input :in_creation, -            label: ("<span>#{t('activerecord.attributes.stop_area.in_creation')}<span class='fa fa-pencil text-info'></span></span>").html_safe, -            as: :boolean, -            wrapper_html: { class: 'checkbox-wrapper' }, -            checked_value: true, -            unchecked_value: false, -            input_html: { checked: @status.try(:[], :in_creation) } -          = p.input :confirmed, -            label: ("<span>#{t('activerecord.attributes.stop_area.confirmed')}<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.stop_area.deleted')}<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) } + +    .form-group.togglable class=filter_item_class(@status, :status_eq_any) +      = f.label Chouette::StopArea.tmf('state'), required: false, class: 'control-label' +      = f.input :status_eq_any, checked: lambda { |w| @status.try(:[], :status_eq_any).try(:[], w)}, collection: [:in_creation, :confirmed, :deactivated], as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + stop_area_status(w) + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }    .actions      = link_to t('actions.erase'), @workbench, class: 'btn btn-link' | 
