aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-01-29 16:25:08 +0100
committerZog2018-02-01 14:40:24 +0100
commit82de76f0efce7558a3fe240edf4e2293a8788ee1 (patch)
tree3c9c70b904d989a4b8e0d8b2d0db03314465a410
parentd896ba8753f9877dfd29a97cf1310d54d0b25874 (diff)
downloadchouette-core-82de76f0efce7558a3fe240edf4e2293a8788ee1.tar.bz2
Refs #5758 @1h; Add localized names to StopAreas
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock3
-rw-r--r--app/assets/stylesheets/application.sass2
-rw-r--r--app/controllers/stop_areas_controller.rb1
-rw-r--r--app/helpers/stop_areas_helper.rb6
-rw-r--r--app/models/chouette/stop_area.rb7
-rw-r--r--app/views/stop_areas/_form.html.slim6
-rw-r--r--app/views/stop_areas/show.html.slim6
-rw-r--r--config/initializers/countries.rb3
-rw-r--r--db/migrate/20180129141656_add_localized_names_to_stop_areas.rb5
-rw-r--r--db/schema.rb1
11 files changed, 36 insertions, 5 deletions
diff --git a/Gemfile b/Gemfile
index e1943e659..bb1a42df0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -102,6 +102,7 @@ gem 'font-awesome-sass', '~> 4.7'
gem 'will_paginate-bootstrap'
gem 'gretel'
gem 'country_select'
+gem 'flag-icons-rails'
# Format Output
gem 'json'
diff --git a/Gemfile.lock b/Gemfile.lock
index 3a2314857..ffa63b535 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -236,6 +236,8 @@ GEM
ffi (1.9.18)
ffi-geos (1.2.0)
ffi (>= 1.0.0)
+ flag-icons-rails (2.5.0)
+ sass (~> 3.2)
font-awesome-sass (4.7.0)
sass (>= 3.2)
formtastic (3.1.5)
@@ -625,6 +627,7 @@ DEPENDENCIES
faraday (~> 0.9.1)
faraday_middleware (~> 0.9.1)
ffaker (~> 2.1.0)
+ flag-icons-rails
font-awesome-sass (~> 4.7)
formtastic (= 3.1.5)
georuby (= 2.3.0)
diff --git a/app/assets/stylesheets/application.sass b/app/assets/stylesheets/application.sass
index 50f8b64cb..3f8467efe 100644
--- a/app/assets/stylesheets/application.sass
+++ b/app/assets/stylesheets/application.sass
@@ -19,3 +19,5 @@
@import 'modules/vj_collection'
@import 'modules/timetables'
@import 'modules/import_messages'
+
+@import 'flag-icon'
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index 076de922c..41a1a8c6d 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -202,6 +202,7 @@ class StopAreasController < ChouetteController
:waiting_time,
:zip_code,
:kind,
+ localized_names: Chouette::StopArea::AVAILABLE_LOCALIZATIONS
)
end
diff --git a/app/helpers/stop_areas_helper.rb b/app/helpers/stop_areas_helper.rb
index 3e04fac7d..05ae042f5 100644
--- a/app/helpers/stop_areas_helper.rb
+++ b/app/helpers/stop_areas_helper.rb
@@ -11,6 +11,10 @@ module StopAreasHelper
( "<img src='#{stop_area_picture_url(stop_area)}'/>" + " <span style='height:25px; line-height:25px; margin-left: 5px; '>" + name + " <small style='height:25px; line-height:25px; margin-left: 10px; color: #555;'>" + localization + "</small></span>").html_safe
end
+ def label_for_country country, txt=nil
+ "#{txt} <span title='#{ISO3166::Country[country]&.translation(I18n.locale)}' class='flag-icon flag-icon-#{country}'></span>".html_safe
+ end
+
def genealogical_title
return t("stop_areas.genealogical.genealogical_routing") if @stop_area.stop_area_type == 'itl'
t("stop_areas.genealogical.genealogical")
@@ -33,12 +37,10 @@ module StopAreasHelper
@stop_area.stop_area_type == 'stop_place' || @stop_area.stop_area_type == 'commercial_stop_point'
end
-
def pair_key(access_link)
"#{access_link.access_point.id}-#{access_link.stop_area.id}"
end
-
def geo_data(sa, sar)
if sa.long_lat_type.nil?
content_tag :span, '-'
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index c6feaf940..bb8747faa 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -12,6 +12,8 @@ module Chouette
enumerize :area_type, in: Chouette::AreaType::ALL
enumerize :kind, in: %i(commercial non_commercial)
+ AVAILABLE_LOCALIZATIONS = %i(gb nl de fr it es)
+
with_options dependent: :destroy do |assoc|
assoc.has_many :stop_points
assoc.has_many :access_points
@@ -50,6 +52,11 @@ module Chouette
:nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone]
end
+ def localized_names
+ val = read_attribute(:localized_names) || {}
+ Hash[*AVAILABLE_LOCALIZATIONS.map{|k| [k, val[k.to_s]]}.flatten]
+ end
+
def parent_area_type_must_be_greater
return unless self.parent
diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim
index 1bc3e77ef..c2b9a7f4f 100644
--- a/app/views/stop_areas/_form.html.slim
+++ b/app/views/stop_areas/_form.html.slim
@@ -6,8 +6,12 @@
/= @map.to_html
= f.input :id, as: :hidden
= f.input :name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.name")}
+ .form-group
+ .col-sm-3.col-xs-5
+ .col-sm-9.col-xs-7
+ - f.object.localized_names.each do |k, v|
+ .col-md-6= f.input "localized_names[#{k}]", input_html: {value: v}, label: label_for_country(k)
= f.input :kind, as: :radio_buttons, checked: @stop_area.kind, :input_html => {:disabled => !@stop_area.new_record?}, :include_blank => false, item_wrapper_class: 'radio-inline', wrapper: :horizontal_form, disabled: !@stop_area.new_record?
-
.slave data-master="[name='stop_area[kind]']" data-value="commercial"
= f.input :parent_id, as: :select, :collection => [f.object.parent_id], input_html: { data: { select2_ajax: 'true', url: autocomplete_stop_area_referential_stop_areas_path(@stop_area_referential), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}}
- %i(non_commercial commercial).each do |kind|
diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim
index b0896c1e0..67f309cef 100644
--- a/app/views/stop_areas/show.html.slim
+++ b/app/views/stop_areas/show.html.slim
@@ -7,10 +7,12 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
- attributes = { t('id_reflex') => @stop_area.get_objectid.short_id }
+ - @stop_area.localized_names.each do |k, v|
+ - attributes.merge!({label_for_country(k, @stop_area.human_attribute_name(:name)) => v }) if v.present?
- attributes.merge!({ @stop_area.human_attribute_name(:parent) => @stop_area.parent ? link_to(@stop_area.parent.name, stop_area_referential_stop_area_path(@stop_area_referential, @stop_area.parent)) : "-" }) if @stop_area.commercial?
- attributes.merge!({ @stop_area.human_attribute_name(:stop_area_type) => Chouette::AreaType.find(@stop_area.area_type).try(:label),
- @stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number,
- })
+ @stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number
+ })
- attributes.merge!(@stop_area.human_attribute_name(:waiting_time) => @stop_area.waiting_time_text) if has_feature?(:stop_area_waiting_time)
- attributes.merge!({ "Coordonnées" => geo_data(@stop_area, @stop_area_referential),
@stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code,
diff --git a/config/initializers/countries.rb b/config/initializers/countries.rb
new file mode 100644
index 000000000..7f2b5c9db
--- /dev/null
+++ b/config/initializers/countries.rb
@@ -0,0 +1,3 @@
+ISO3166.configure do |config|
+ config.locales = (I18n.available_locales + Chouette::StopArea::AVAILABLE_LOCALIZATIONS).uniq
+end
diff --git a/db/migrate/20180129141656_add_localized_names_to_stop_areas.rb b/db/migrate/20180129141656_add_localized_names_to_stop_areas.rb
new file mode 100644
index 000000000..320ce739a
--- /dev/null
+++ b/db/migrate/20180129141656_add_localized_names_to_stop_areas.rb
@@ -0,0 +1,5 @@
+class AddLocalizedNamesToStopAreas < ActiveRecord::Migration
+ def change
+ add_column :stop_areas, :localized_names, :jsonb
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5356c9909..d54a40feb 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -789,6 +789,7 @@ ActiveRecord::Schema.define(version: 20180124124215) do
t.string "stif_type"
t.integer "waiting_time"
t.string "kind"
+ t.jsonb "localized_names"
end
add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree