aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-10-04 23:20:41 +0200
committercedricnjanga2017-10-04 23:23:00 +0200
commit9a642d186ec8ca9016dba59d925c1bdb079eb23f (patch)
tree180007030010d0fdea1b52a7149d53b9ecd27410
parent458b841fbeed0fee9a1f6db981c3b18f47a84905 (diff)
downloadchouette-core-9a642d186ec8ca9016dba59d925c1bdb079eb23f.tar.bz2
Refs 4517 Add some modification to the two modules to add methods to list the sorted transport modes and submodes
-rw-r--r--app/helpers/lines_helper.rb8
-rw-r--r--app/models/concerns/stif_transport_mode_enumerations.rb7
-rw-r--r--app/models/concerns/stif_transport_submode_enumerations.rb7
-rw-r--r--app/views/compliance_control_blocks/_form.html.slim4
-rw-r--r--app/views/lines/_filters.html.slim4
-rw-r--r--spec/models/line_referential_spec.rb2
6 files changed, 17 insertions, 15 deletions
diff --git a/app/helpers/lines_helper.rb b/app/helpers/lines_helper.rb
index e5062e43f..e9a4bd3c5 100644
--- a/app/helpers/lines_helper.rb
+++ b/app/helpers/lines_helper.rb
@@ -5,14 +5,6 @@ module LinesHelper
line.number
end
- def sorted_transport_submode
- Chouette::Line.transport_submodes.sort_by{|m| t("enumerize.transport_submode.#{m}").parameterize }
- end
-
- def sorted_transport_mode
- Chouette::Line.transport_modes.sort_by{|m| t("enumerize.transport_mode.#{m}").parameterize }
- end
-
def colors?(line)
line.text_color.present? || line.color.present?
end
diff --git a/app/models/concerns/stif_transport_mode_enumerations.rb b/app/models/concerns/stif_transport_mode_enumerations.rb
index dc573b3a0..676154f73 100644
--- a/app/models/concerns/stif_transport_mode_enumerations.rb
+++ b/app/models/concerns/stif_transport_mode_enumerations.rb
@@ -1,10 +1,15 @@
module StifTransportModeEnumerations
extend ActiveSupport::Concern
extend Enumerize
+ extend self
enumerize :transport_mode, in: %w(air bus coach ferry metro rail trolleyBus tram water cableway funicular other)
def transport_modes
- StifTransportModeEnumerations.transport_mode.options.map(&:first)
+ StifTransportModeEnumerations.transport_mode.values
+ end
+
+ def sorted_transport_modes
+ self.transport_modes.sort_by{|m| I18n.t("enumerize.transport_mode.#{m}").parameterize }
end
end
diff --git a/app/models/concerns/stif_transport_submode_enumerations.rb b/app/models/concerns/stif_transport_submode_enumerations.rb
index a150381f3..6322b2dae 100644
--- a/app/models/concerns/stif_transport_submode_enumerations.rb
+++ b/app/models/concerns/stif_transport_submode_enumerations.rb
@@ -1,10 +1,15 @@
module StifTransportSubmodeEnumerations
extend ActiveSupport::Concern
extend Enumerize
+ extend self
enumerize :transport_submode, in: %w(unknown undefined internationalFlight domesticFlight intercontinentalFlight domesticScheduledFlight shuttleFlight intercontinentalCharterFlight internationalCharterFlight roundTripCharterFlight sightseeingFlight helicopterService domesticCharterFlight SchengenAreaFlight airshipService shortHaulInternationalFlight canalBarge localBus regionalBus expressBus nightBus postBus specialNeedsBus mobilityBus mobilityBusForRegisteredDisabled sightseeingBus shuttleBus highFrequencyBus dedicatedLaneBus schoolBus schoolAndPublicServiceBus railReplacementBus demandAndResponseBus airportLinkBus internationalCoach nationalCoach shuttleCoach regionalCoach specialCoach schoolCoach sightseeingCoach touristCoach commuterCoach metro tube urbanRailway local highSpeedRail suburbanRailway regionalRail interregionalRail longDistance intermational sleeperRailService nightRail carTransportRailService touristRailway railShuttle replacementRailService specialTrain crossCountryRail rackAndPinionRailway cityTram localTram regionalTram sightseeingTram shuttleTram trainTram internationalCarFerry nationalCarFerry regionalCarFerry localCarFerry internationalPassengerFerry nationalPassengerFerry regionalPassengerFerry localPassengerFerry postBoat trainFerry roadFerryLink airportBoatLink highSpeedVehicleService highSpeedPassengerService sightseeingService schoolBoat cableFerry riverBus scheduledFerry shuttleFerryService telecabin cableCar lift chairLift dragLift telecabinLink funicular streetCableCar allFunicularServices undefinedFunicular)
def transport_submodes
- StifTransportSubmodeEnumerations.transport_submode.options.map(&:first)
+ StifTransportSubmodeEnumerations.transport_submode.values
+ end
+
+ def sorted_transport_submodes
+ self.transport_submodes.sort_by{|m| I18n.t("enumerize.transport_submode.#{m}").parameterize }
end
end
diff --git a/app/views/compliance_control_blocks/_form.html.slim b/app/views/compliance_control_blocks/_form.html.slim
index 88fa7e98b..2e87a877e 100644
--- a/app/views/compliance_control_blocks/_form.html.slim
+++ b/app/views/compliance_control_blocks/_form.html.slim
@@ -2,8 +2,8 @@
.row
.col-lg-12
.form-group
- = f.input :transport_mode, as: :select, collection: ComplianceControlBlock.transport_modes, label: t('activerecord.attributes.compliance_control_blocks.transport_mode')
- = f.input :transport_submode, as: :select, collection: ComplianceControlBlock.transport_submodes, label: t('activerecord.attributes.compliance_control_blocks.transport_submode')
+ = f.input :transport_mode, as: :select, collection: ComplianceControlBlock.sorted_transport_modes, label: t('activerecord.attributes.compliance_control_blocks.transport_mode'), label_method: lambda {|t| ("<span>" + t("enumerize.transport_mode.#{t}") + "</span>").html_safe }
+ = f.input :transport_submode, as: :select, collection: ComplianceControlBlock.sorted_transport_submodes, label: t('activerecord.attributes.compliance_control_blocks.transport_submode'), label_method: lambda {|t| ("<span>" + t("enumerize.transport_submode.#{t}") + "</span>").html_safe }
.separator
diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim
index 01c2da58f..7662c41b5 100644
--- a/app/views/lines/_filters.html.slim
+++ b/app/views/lines/_filters.html.slim
@@ -17,11 +17,11 @@
.form-group.togglable
= f.label Chouette::Line.human_attribute_name(:transport_mode), required: false, class: 'control-label'
- = f.input :transport_mode_eq_any, collection: sorted_transport_mode, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_mode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
+ = f.input :transport_mode_eq_any, collection: Chouette::Line.sorted_transport_modes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_mode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable
= f.label Chouette::Line.human_attribute_name(:transport_submode), required: false, class: 'control-label'
- = f.input :transport_submode_eq_any, collection: sorted_transport_submode, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
+ = f.input :transport_submode_eq_any, collection: Chouette::Line.sorted_transport_submodes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.actions
= link_to 'Effacer', @workbench, class: 'btn btn-link'
diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb
index c156a3d5c..8c6cb018b 100644
--- a/spec/models/line_referential_spec.rb
+++ b/spec/models/line_referential_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe LineReferential, :type => :model do
describe "#transport_modes" do
it 'returns a list of all transport modes' do
- expect(FactoryGirl.create(:line_referential).class.transport_modes).to match_array(StifTransportModeEnumerations.transport_mode.options.map(&:first) )
+ expect(FactoryGirl.create(:line_referential).class.transport_modes).to match_array(StifTransportModeEnumerations.transport_modes )
end
end
end