diff options
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 3 | ||||
| -rw-r--r-- | app/helpers/stop_areas_helper.rb | 6 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 22 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 2 |
4 files changed, 32 insertions, 1 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index e94f64e14..c77500132 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -205,6 +205,7 @@ class StopAreasController < ChouetteController :waiting_time, :zip_code, :kind, + :status, localized_names: Chouette::StopArea::AVAILABLE_LOCALIZATIONS ) end @@ -221,7 +222,7 @@ class StopAreasController < ChouetteController } scope = Chouette::StopArea.where( - "confirmed_at #{@status[:confirmed] ? "IS NOT NULL" : "IS NULL"} + "confirmed_at #{@status[:confirmed] ? "IS NOT NULL" : "IS NULL"} AND deleted_at #{@status[:deactivated] ? "IS NOT NULL" : "IS NULL"}" ) diff --git a/app/helpers/stop_areas_helper.rb b/app/helpers/stop_areas_helper.rb index 631dbfc3c..1c9d974a1 100644 --- a/app/helpers/stop_areas_helper.rb +++ b/app/helpers/stop_areas_helper.rb @@ -84,4 +84,10 @@ module StopAreasHelper 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 d9d2facfe..1918c90d1 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -410,6 +410,28 @@ module Chouette 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/_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") |
