From 18fbb9be2993bcffa4183d4e45b4759088a19075 Mon Sep 17 00:00:00 2001
From: cedricnjanga
Date: Thu, 8 Mar 2018 20:39:59 -0800
Subject: Refs #6033 Add confirmed_at attribute to Chouette::StopArea
---
 db/migrate/20180307202627_add_confirmed_at_to_stop_areas.rb | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 db/migrate/20180307202627_add_confirmed_at_to_stop_areas.rb
diff --git a/db/migrate/20180307202627_add_confirmed_at_to_stop_areas.rb b/db/migrate/20180307202627_add_confirmed_at_to_stop_areas.rb
new file mode 100644
index 000000000..602d3afdc
--- /dev/null
+++ b/db/migrate/20180307202627_add_confirmed_at_to_stop_areas.rb
@@ -0,0 +1,5 @@
+class AddConfirmedAtToStopAreas < ActiveRecord::Migration
+  def change
+    add_column :stop_areas, :confirmed_at, :datetime
+  end
+end
-- 
cgit v1.2.3
From ae282e2eac8dedde62a957912dcb0b4e5e4bc7c6 Mon Sep 17 00:00:00 2001
From: cedricnjanga
Date: Thu, 8 Mar 2018 20:40:45 -0800
Subject: Refs #6033 Update all StopArea#confirmed_at
---
 .../20180308063549_update_stop_areas_confirmed_at_attribute.rb   | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 db/migrate/20180308063549_update_stop_areas_confirmed_at_attribute.rb
diff --git a/db/migrate/20180308063549_update_stop_areas_confirmed_at_attribute.rb b/db/migrate/20180308063549_update_stop_areas_confirmed_at_attribute.rb
new file mode 100644
index 000000000..7bc0471f7
--- /dev/null
+++ b/db/migrate/20180308063549_update_stop_areas_confirmed_at_attribute.rb
@@ -0,0 +1,9 @@
+class UpdateStopAreasConfirmedAtAttribute < ActiveRecord::Migration
+   def up
+    Chouette::StopArea.where(deleted_at: nil).update_all(confirmed_at: Time.now)
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
-- 
cgit v1.2.3
From a6991d329d754aa8dff4c1e7a07119123148b61d Mon Sep 17 00:00:00 2001
From: cedricnjanga
Date: Thu, 8 Mar 2018 20:42:28 -0800
Subject: Refs #6033 Changes for StopArea#index and StopArea#show
---
 app/controllers/stop_areas_controller.rb | 35 +++++++++++++++++++++++++++++++-
 app/helpers/stop_areas_helper.rb         | 14 +++++++++++++
 app/views/stop_areas/_filters.html.slim  | 26 ++++++++++++++++++++++++
 app/views/stop_areas/index.html.slim     |  4 ++--
 app/views/stop_areas/show.html.slim      |  2 +-
 config/locales/stop_areas.en.yml         |  9 ++++----
 config/locales/stop_areas.fr.yml         |  9 ++++----
 7 files changed, 87 insertions(+), 12 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| ("" + w[0] + "").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: ("#{t('activerecord.attributes.stop_area.in_creation')}").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: ("#{t('activerecord.attributes.stop_area.confirmed')}").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.stop_area.deleted')}").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
diff --git a/config/locales/stop_areas.en.yml b/config/locales/stop_areas.en.yml
index 33722b60b..389f70c0c 100644
--- a/config/locales/stop_areas.en.yml
+++ b/config/locales/stop_areas.en.yml
@@ -110,8 +110,11 @@ en:
         name: "Name"
         registration_number: "Registration number"
         published_name: "Published name"
-        deleted: "Deleted"
-        deleted_at: "Deleted at"
+        in_creation: "In creation"
+        confirmed: "Activated"
+        confirmed_at: "Activated at"
+        deleted: "Deactivated"
+        deleted_at: "Deactivated at"
         comment: "Description"
         stop_area_type: "Area type"
         area_type: "Area type"
@@ -143,8 +146,6 @@ en:
         coordinates: "Coordinates (lat,lng) WGS84"
         zip_code: "Zip code"
         city_name: "City"
-        created_at: Created at
-        updated_at: Updated at
         waiting_time: Waiting time (minutes)
         state: State
   formtastic:
diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml
index 605e6158e..da977d79c 100644
--- a/config/locales/stop_areas.fr.yml
+++ b/config/locales/stop_areas.fr.yml
@@ -112,8 +112,11 @@ fr:
         kind: "Catégorie"
         registration_number: "Numéro d'enregistrement"
         published_name: "Nom public"
-        deleted: "Supprimé"
-        deleted_at: "Activé"
+        in_creation: "En création"
+        confirmed: "Actif"
+        confirmed_at: "Activé le"
+        deleted: "Désactivé"
+        deleted_at: "Désactivé le"
         comment: "Commentaire"
         stop_area_type: "Type d'arrêt"
         area_type: "Type d'arrêt"
@@ -145,8 +148,6 @@ fr:
         coordinates: "Coordonnées (lat,lng) WGS84"
         zip_code: "Code postal"
         city_name: "Commune"
-        created_at: "Créé le"
-        updated_at: "Edité le"
         waiting_time: Temps de desserte (minutes)
         state: État
   formtastic:
-- 
cgit v1.2.3
From 2104fa747e813e7a829de0d081d0fdca138e796f Mon Sep 17 00:00:00 2001
From: cedricnjanga
Date: Thu, 8 Mar 2018 20:42:49 -0800
Subject: Refs #6033 Update Stop Area schema
---
 db/schema.rb | 1 +
 1 file changed, 1 insertion(+)
diff --git a/db/schema.rb b/db/schema.rb
index cf0a32a3b..7f774478c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -841,6 +841,7 @@ ActiveRecord::Schema.define(version: 20180308095116) do
     t.integer  "waiting_time"
     t.string   "kind"
     t.jsonb    "localized_names"
+    t.datetime "confirmed_at"
   end
 
   add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree
-- 
cgit v1.2.3
From 0a81b6a94eeabe481e0ef7473a13b1847539adb5 Mon Sep 17 00:00:00 2001
From: cedricnjanga
Date: Thu, 8 Mar 2018 20:43:07 -0800
Subject: Refs #6033 add specs
---
 spec/features/stop_areas_spec.rb | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff --git a/spec/features/stop_areas_spec.rb b/spec/features/stop_areas_spec.rb
index 668eb2fa3..0e1f6f3a9 100644
--- a/spec/features/stop_areas_spec.rb
+++ b/spec/features/stop_areas_spec.rb
@@ -30,6 +30,34 @@ describe "StopAreas", :type => :feature do
         expect(page).to have_content(stop_areas.first.name)
         expect(page).not_to have_content(stop_areas.last.name)
       end
+
+      context 'filtering by status' do
+        before do
+          stop_areas.first.activate!
+          stop_areas.last.deactivate!
+        end
+        
+        xit 'should filter stop areas in creation' do
+          find("#q_status_in_creation").set(true)
+          click_button 'search-btn'
+          expect(page).not_to have_content(stop_areas.first.name)
+          expect(page).not_to have_content(stop_areas.last.name)
+        end
+
+        xit 'should filter confirmed stop areas' do
+          find("#q_status_confirmed").set(true)
+          click_button 'search-btn'
+          expect(page).to have_content(stop_areas.first.name)
+          expect(page).not_to have_content(stop_areas.last.name)
+        end
+
+        xit 'should filter deactivated stop areas' do
+          find("#q_status_deactivated").set(true)
+          click_button 'search-btn'
+          expect(page).not_to have_content(stop_areas.first.name)
+          expect(page).to have_content(stop_areas.last.name)
+        end
+      end
     end
   end
 
-- 
cgit v1.2.3
From 5227184b20e720d6643802b187a4c07c692283cb Mon Sep 17 00:00:00 2001
From: cedricnjanga
Date: Thu, 8 Mar 2018 20:43:38 -0800
Subject: Refs #6033 Update activate and deactivate methods
---
 app/models/chouette/stop_area.rb | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index 0a27b2f39..d9d2facfe 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -383,26 +383,30 @@ 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
 
-- 
cgit v1.2.3
From 01cf341348eaec620a296a3435131798f4f17f6d Mon Sep 17 00:00:00 2001
From: cedricnjanga
Date: Thu, 15 Mar 2018 00:11:01 -0700
Subject: Refs #6033 Fix stop areas spec feature
---
 app/controllers/stop_areas_controller.rb | 17 ++---------
 spec/features/stop_areas_spec.rb         | 48 ++++++++++++++++++++------------
 2 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index c3da92265..e94f64e14 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
@@ -215,28 +216,16 @@ class StopAreasController < ChouetteController
 
     @status = {
       in_creation: params[:q][:status]['in_creation'] == 'true',
-      activated: params[:q][:status]['activated'] == 'true',
+      confirmed: params[:q][:status]['confirmed'] == 'true',
       deactivated: params[:q][:status]['deactivated'] == 'true',
     }
 
     scope = Chouette::StopArea.where(
-      "confirmed_at #{@status[:activated] ? "IS NOT NULL" : "IS NULL"} 
+      "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
-
-  # 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/spec/features/stop_areas_spec.rb b/spec/features/stop_areas_spec.rb
index 0e1f6f3a9..02e853999 100644
--- a/spec/features/stop_areas_spec.rb
+++ b/spec/features/stop_areas_spec.rb
@@ -36,26 +36,38 @@ describe "StopAreas", :type => :feature do
           stop_areas.first.activate!
           stop_areas.last.deactivate!
         end
-        
-        xit 'should filter stop areas in creation' do
-          find("#q_status_in_creation").set(true)
-          click_button 'search-btn'
-          expect(page).not_to have_content(stop_areas.first.name)
-          expect(page).not_to have_content(stop_areas.last.name)
-        end
 
-        xit 'should filter confirmed stop areas' do
-          find("#q_status_confirmed").set(true)
-          click_button 'search-btn'
-          expect(page).to have_content(stop_areas.first.name)
-          expect(page).not_to have_content(stop_areas.last.name)
-        end
+        describe 'updated stop areas in before block' do
+
+          it 'supports displaying only stop areas in creation' do
+            find("#q_status_in_creation").set(true)
+            click_button 'search-btn'
+            expect(page).not_to have_content(stop_areas.first.name)
+            expect(page).not_to have_content(stop_areas.last.name)
+          end
+
+          it 'supports displaying only confirmed stop areas' do
+            find("#q_status_confirmed").set(true)
+            click_button 'search-btn'
+            expect(page).to have_content(stop_areas.first.name)
+            expect(page).not_to have_content(stop_areas.last.name)
+          end
+
+          it 'supports displaying only deactivated stop areas' do
+            find("#q_status_deactivated").set(true)
+            click_button 'search-btn'
+            expect(page).not_to have_content(stop_areas.first.name)
+            expect(page).to have_content(stop_areas.last.name)
+          end
 
-        xit 'should filter deactivated stop areas' do
-          find("#q_status_deactivated").set(true)
-          click_button 'search-btn'
-          expect(page).not_to have_content(stop_areas.first.name)
-          expect(page).to have_content(stop_areas.last.name)
+          it 'should display all stop areas if all filters are checked' do
+            find("#q_status_in_creation").set(true)
+            find("#q_status_confirmed").set(true)
+            find("#q_status_deactivated").set(true)
+            click_button 'search-btn'
+            expect(page).to have_content(stop_areas.first.name)
+            expect(page).to have_content(stop_areas.last.name)
+          end
         end
       end
     end
-- 
cgit v1.2.3
From 8c9ae9bf75a148e3080acb6d60d0523793d555c7 Mon Sep 17 00:00:00 2001
From: Alban Peignier
Date: Thu, 15 Mar 2018 09:56:46 +0100
Subject: Defines StopArea deactivated i18n. Refs #6033
---
 config/locales/stop_areas.fr.yml | 1 +
 1 file changed, 1 insertion(+)
diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml
index da977d79c..aee112be7 100644
--- a/config/locales/stop_areas.fr.yml
+++ b/config/locales/stop_areas.fr.yml
@@ -116,6 +116,7 @@ fr:
         confirmed: "Actif"
         confirmed_at: "Activé le"
         deleted: "Désactivé"
+        deactivated: "Désactivé"
         deleted_at: "Désactivé le"
         comment: "Commentaire"
         stop_area_type: "Type d'arrêt"
-- 
cgit v1.2.3
From 7cef201f206f1b95ece9b28a07b384a3fb88d7c9 Mon Sep 17 00:00:00 2001
From: Alban Peignier
Date: Thu, 15 Mar 2018 10:00:02 +0100
Subject: Keep schema.rb clean
---
 db/schema.rb | 53 ++++++-----------------------------------------------
 1 file changed, 6 insertions(+), 47 deletions(-)
diff --git a/db/schema.rb b/db/schema.rb
index 7f774478c..2f9ffa840 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -298,58 +298,18 @@ ActiveRecord::Schema.define(version: 20180308095116) do
 
   add_index "custom_fields", ["resource_type"], name: "index_custom_fields_on_resource_type", using: :btree
 
-  create_table "export_messages", id: :bigserial, force: :cascade do |t|
-    t.string   "criticity"
-    t.string   "message_key"
-    t.hstore   "message_attributes"
-    t.integer  "export_id",           limit: 8
-    t.integer  "resource_id",         limit: 8
-    t.datetime "created_at"
-    t.datetime "updated_at"
-    t.hstore   "resource_attributes"
-  end
-
-  add_index "export_messages", ["export_id"], name: "index_export_messages_on_export_id", using: :btree
-  add_index "export_messages", ["resource_id"], name: "index_export_messages_on_resource_id", using: :btree
-
-  create_table "export_resources", id: :bigserial, force: :cascade do |t|
-    t.integer  "export_id",     limit: 8
-    t.string   "status"
-    t.datetime "created_at"
-    t.datetime "updated_at"
-    t.string   "resource_type"
-    t.string   "reference"
-    t.string   "name"
-    t.hstore   "metrics"
-  end
-
-  add_index "export_resources", ["export_id"], name: "index_export_resources_on_export_id", using: :btree
-
   create_table "exports", id: :bigserial, force: :cascade do |t|
+    t.integer  "referential_id",  limit: 8
     t.string   "status"
-    t.string   "current_step_id"
-    t.float    "current_step_progress"
-    t.integer  "workbench_id",          limit: 8
-    t.integer  "referential_id",        limit: 8
-    t.string   "name"
+    t.string   "type"
+    t.string   "options"
     t.datetime "created_at"
     t.datetime "updated_at"
-    t.string   "file"
-    t.datetime "started_at"
-    t.datetime "ended_at"
-    t.string   "token_upload"
-    t.string   "type"
-    t.integer  "parent_id",             limit: 8
-    t.string   "parent_type"
-    t.datetime "notified_parent_at"
-    t.integer  "current_step",                    default: 0
-    t.integer  "total_steps",                     default: 0
-    t.string   "creator"
-    t.hstore   "options"
+    t.string   "references_type"
+    t.string   "reference_ids"
   end
 
   add_index "exports", ["referential_id"], name: "index_exports_on_referential_id", using: :btree
-  add_index "exports", ["workbench_id"], name: "index_exports_on_workbench_id", using: :btree
 
   create_table "facilities", id: :bigserial, force: :cascade do |t|
     t.integer  "stop_area_id",       limit: 8
@@ -460,9 +420,9 @@ ActiveRecord::Schema.define(version: 20180308095116) do
     t.string   "type"
     t.integer  "parent_id",             limit: 8
     t.string   "parent_type"
-    t.datetime "notified_parent_at"
     t.integer  "current_step",                    default: 0
     t.integer  "total_steps",                     default: 0
+    t.datetime "notified_parent_at"
     t.string   "creator"
   end
 
@@ -805,7 +765,6 @@ ActiveRecord::Schema.define(version: 20180308095116) do
     t.datetime "created_at"
     t.datetime "updated_at"
     t.string   "objectid_format"
-    t.string   "registration_number_format"
   end
 
   create_table "stop_areas", id: :bigserial, force: :cascade do |t|
-- 
cgit v1.2.3
From 3036b52aea082c12dec82d463936dae29643cb22 Mon Sep 17 00:00:00 2001
From: Alban Peignier
Date: Thu, 15 Mar 2018 09:57:53 +0100
Subject: Add StopArea#status in stop_areas#_form. Refs #6033
---
 app/controllers/stop_areas_controller.rb |  3 ++-
 app/helpers/stop_areas_helper.rb         |  6 ++++++
 app/models/chouette/stop_area.rb         | 22 ++++++++++++++++++++++
 app/views/stop_areas/_form.html.slim     |  2 ++
 4 files changed, 32 insertions(+), 1 deletion(-)
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")
 
-- 
cgit v1.2.3