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 | |
| 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
| -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 | ||||
| -rw-r--r-- | config/locales/stop_areas.en.yml | 9 | ||||
| -rw-r--r-- | config/locales/stop_areas.fr.yml | 10 | ||||
| -rw-r--r-- | db/migrate/20180307202627_add_confirmed_at_to_stop_areas.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20180308063549_update_stop_areas_confirmed_at_attribute.rb | 9 | ||||
| -rw-r--r-- | db/schema.rb | 54 | ||||
| -rw-r--r-- | spec/features/stop_areas_spec.rb | 40 |
13 files changed, 175 insertions, 61 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 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..aee112be7 100644 --- a/config/locales/stop_areas.fr.yml +++ b/config/locales/stop_areas.fr.yml @@ -112,8 +112,12 @@ 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é" + deactivated: "Désactivé" + deleted_at: "Désactivé le" comment: "Commentaire" stop_area_type: "Type d'arrêt" area_type: "Type d'arrêt" @@ -145,8 +149,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: 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 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 diff --git a/db/schema.rb b/db/schema.rb index cf0a32a3b..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| @@ -841,6 +800,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 diff --git a/spec/features/stop_areas_spec.rb b/spec/features/stop_areas_spec.rb index 668eb2fa3..02e853999 100644 --- a/spec/features/stop_areas_spec.rb +++ b/spec/features/stop_areas_spec.rb @@ -30,6 +30,46 @@ 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 + + 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 + + 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 end |
