diff options
| author | cedricnjanga | 2018-03-08 20:42:28 -0800 | 
|---|---|---|
| committer | Alban Peignier | 2018-03-15 10:01:04 +0100 | 
| commit | a6991d329d754aa8dff4c1e7a07119123148b61d (patch) | |
| tree | e38d6351786da7c24934c0dd51002c3addde49e1 /app | |
| parent | ae282e2eac8dedde62a957912dcb0b4e5e4bc7c6 (diff) | |
| download | chouette-core-a6991d329d754aa8dff4c1e7a07119123148b61d.tar.bz2 | |
Refs #6033 Changes for StopArea#index and StopArea#show
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 35 | ||||
| -rw-r--r-- | app/helpers/stop_areas_helper.rb | 14 | ||||
| -rw-r--r-- | app/views/stop_areas/_filters.html.slim | 26 | ||||
| -rw-r--r-- | app/views/stop_areas/index.html.slim | 4 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 2 | 
5 files changed, 77 insertions, 4 deletions
| diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 41a1a8c6d..c3da92265 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -133,7 +133,9 @@ class StopAreasController < ChouetteController    end    def collection -    @q = parent.present? ? parent.stop_areas.search(params[:q]) : referential.stop_areas.search(params[:q]) +    scope = parent.present? ? parent.stop_areas : referential.stop_areas +    scope = ransack_status(scope) +    @q = scope.search(params[:q])      if sort_column && sort_direction        @stop_areas ||= @@ -206,4 +208,35 @@ class StopAreasController < 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 = { +      in_creation: params[:q][:status]['in_creation'] == 'true', +      activated: params[:q][:status]['activated'] == 'true', +      deactivated: params[:q][:status]['deactivated'] == 'true', +    } + +    scope = Chouette::StopArea.where( +      "confirmed_at #{@status[:activated] ? "IS NOT NULL" : "IS NULL"}  +      AND deleted_at #{@status[:deactivated] ? "IS NOT NULL" : "IS NULL"}" +      ) + +    params[:q].delete :status +    scope +  end + +  # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope +  # We clone params[:q] so we can delete fake ransack filter arguments before calling search method, +  # which will allow us to preserve params[:q] for sorting +  def ransack_params +    copy_params = params[:q].clone +    copy_params.delete('associated_lines_id_eq') +    copy_params.delete('archived_at_not_null') +    copy_params.delete('archived_at_null') +    copy_params +  end +  end diff --git a/app/helpers/stop_areas_helper.rb b/app/helpers/stop_areas_helper.rb index fa99f1b4c..631dbfc3c 100644 --- a/app/helpers/stop_areas_helper.rb +++ b/app/helpers/stop_areas_helper.rb @@ -70,4 +70,18 @@ module StopAreasHelper    def stop_area_registration_number_value stop_area      stop_area&.registration_number || stop_area&.stop_area_referential&.generate_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') +    end +  end +  end diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim index 00369d3ed..a32638567 100644 --- a/app/views/stop_areas/_filters.html.slim +++ b/app/views/stop_areas/_filters.html.slim @@ -13,6 +13,32 @@      .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.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.human_attribute_name(:state), 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) }    .actions      = link_to 'Effacer', @workbench, class: 'btn btn-link' diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index 71c7f995c..587efbdaa 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -32,8 +32,8 @@                  attribute: 'registration_number' \                ), \                TableBuilderHelper::Column.new( \ -                key: :deleted_at, \ -                attribute: Proc.new { |s| line_status(s.deleted_at) } \ +                name: t('activerecord.attributes.stop_area.state'), \ +                attribute: Proc.new { |s| stop_area_status(s) } \                ), \                TableBuilderHelper::Column.new( \                  key: :zip_code, \ diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index 34b872e91..a6147b86d 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -20,7 +20,7 @@              @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code,              @stop_area.human_attribute_name(:city_name) => @stop_area.city_name,              @stop_area.human_attribute_name(:country_code) => @stop_area.country_code.presence || '-', -            t('activerecord.attributes.stop_area.state') => (@stop_area.deleted_at ? t('stop_areas.show.state.deactivated') : t('stop_areas.show.state.active')), +            t('activerecord.attributes.stop_area.state') => stop_area_status(@stop_area),              @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment),              })          = definition_list t('metadatas'), attributes | 
