diff options
| author | Alban Peignier | 2018-03-15 10:17:57 +0100 |
|---|---|---|
| committer | GitHub | 2018-03-15 10:17:57 +0100 |
| commit | ec7b83ebc22ea7355d49c4b4fac32ef3104a9622 (patch) | |
| tree | 5fb93f87993eacdbac52ac57325a79066ae7b171 /app | |
| parent | 9e1ad7402881a0ef47b949a3ad95ba39e6e65008 (diff) | |
| parent | 3036b52aea082c12dec82d463936dae29643cb22 (diff) | |
| download | chouette-core-ec7b83ebc22ea7355d49c4b4fac32ef3104a9622.tar.bz2 | |
Merge pull request #365 from af83/6033-stop-area-states
Enable stop area states. Refs #6033
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 25 | ||||
| -rw-r--r-- | app/helpers/stop_areas_helper.rb | 20 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 30 | ||||
| -rw-r--r-- | app/views/stop_areas/_filters.html.slim | 26 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/index.html.slim | 4 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 2 |
7 files changed, 103 insertions, 6 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 41a1a8c6d..c77500132 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -53,6 +53,7 @@ class StopAreasController < ChouetteController index! do |format| format.html { + # binding.pry if collection.out_of_bounds? redirect_to params.merge(:page => 1) end @@ -133,7 +134,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 ||= @@ -202,8 +205,28 @@ class StopAreasController < ChouetteController :waiting_time, :zip_code, :kind, + :status, localized_names: Chouette::StopArea::AVAILABLE_LOCALIZATIONS ) 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', + confirmed: params[:q][:status]['confirmed'] == 'true', + deactivated: params[:q][:status]['deactivated'] == 'true', + } + + scope = Chouette::StopArea.where( + "confirmed_at #{@status[:confirmed] ? "IS NOT NULL" : "IS NULL"} + AND deleted_at #{@status[: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 fa99f1b4c..1c9d974a1 100644 --- a/app/helpers/stop_areas_helper.rb +++ b/app/helpers/stop_areas_helper.rb @@ -70,4 +70,24 @@ 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 + + def stop_area_status_options + Chouette::StopArea.statuses.map do |status| + [ t(status, scope: 'activerecord.attributes.stop_area'), status ] + end + end + end diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 0a27b2f39..1918c90d1 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -383,29 +383,55 @@ module Chouette end def activated? - deleted_at.nil? + deleted_at.nil? && confirmed_at end def deactivated? - !activated? + deleted_at && confirmed_at.nil? end def activate + self.confirmed_at = Time.now self.deleted_at = nil end def deactivate + self.confirmed_at = nil self.deleted_at = Time.now end def activate! + update_attribute :confirmed_at, Time.now update_attribute :deleted_at, nil end def deactivate! + update_attribute :confirmed_at, nil update_attribute :deleted_at, Time.now end + def status + return :deleted if deleted_at + return :confirmed if confirmed_at + + :in_creation + end + + def status=(status) + case status&.to_sym + when :deleted + deactivate + when :confirmed + activate + when :in_creation + self.confirmed_at = self.deleted_at = nil + end + end + + def self.statuses + %i{in_creation confirmed deleted} + end + def time_zone_offset return 0 unless time_zone.present? ActiveSupport::TimeZone[time_zone]&.utc_offset 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/_form.html.slim b/app/views/stop_areas/_form.html.slim index c63e95c89..d6682ef70 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -27,6 +27,8 @@ .slave data-master="[name='stop_area[kind]']" data-value=kind = f.input :area_type, as: :select, :input_html => {id: kind, :disabled => !@stop_area.new_record?}, :collection => Chouette::AreaType.options(kind), :include_blank => false, disabled: !@stop_area.new_record? + = f.input :status, as: :select, :collection => stop_area_status_options, :include_blank => false + .location_info h3 = t("stop_areas.stop_area.localisation") 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 |
