aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/companies_controller.rb1
-rw-r--r--app/controllers/stop_areas_controller.rb2
-rw-r--r--app/helpers/referentials_helper.rb15
-rw-r--r--app/javascript/helpers/CustomFieldsInputs.js6
-rw-r--r--app/models/chouette/line.rb4
-rw-r--r--app/models/chouette/trident_active_record.rb6
-rw-r--r--app/models/concerns/custom_fields_support.rb42
-rw-r--r--app/models/concerns/line_referential_support.rb4
-rw-r--r--app/models/concerns/stop_area_referential_support.rb4
-rw-r--r--app/models/custom_field.rb10
-rw-r--r--app/models/referential_metadata.rb4
-rw-r--r--app/views/companies/_form.html.slim2
-rw-r--r--app/views/lines/_filters.html.slim10
-rw-r--r--app/views/lines/index.html.slim4
-rw-r--r--app/views/lines/show.html.slim2
-rw-r--r--app/views/referential_lines/show.html.slim2
-rw-r--r--app/views/referential_stop_areas/show.html.slim14
-rw-r--r--app/views/referentials/show.html.slim4
-rw-r--r--app/views/routes/show.html.slim5
-rw-r--r--app/views/stop_areas/_filters.html.slim2
-rw-r--r--app/views/stop_areas/_form.html.slim4
-rw-r--r--app/views/stop_areas/index.html.slim2
-rw-r--r--app/views/stop_areas/show.html.slim20
-rw-r--r--config/locales/lines.en.yml2
-rw-r--r--config/locales/lines.fr.yml2
-rw-r--r--config/locales/referentials.en.yml2
-rw-r--r--config/locales/referentials.fr.yml2
-rw-r--r--config/locales/stop_areas.en.yml6
-rw-r--r--config/locales/stop_areas.fr.yml7
-rw-r--r--spec/models/custom_field_spec.rb43
-rw-r--r--spec/models/referential_metadata_spec.rb2
31 files changed, 150 insertions, 85 deletions
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb
index a09cab783..2c32ed3a5 100644
--- a/app/controllers/companies_controller.rb
+++ b/app/controllers/companies_controller.rb
@@ -37,6 +37,7 @@ class CompaniesController < ChouetteController
protected
+
def collection
scope = line_referential.companies
@q = scope.search(params[:q])
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index 76732afd7..734152c64 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -203,7 +203,7 @@ class StopAreasController < ChouetteController
:kind,
:status,
localized_names: Chouette::StopArea::AVAILABLE_LOCALIZATIONS
- ] + permitted_custom_fields_params(Chouette::StopArea.custom_fields) # XXX filter on the workgroup
+ ] + permitted_custom_fields_params(Chouette::StopArea.custom_fields(stop_area_referential.workgroup))
params.require(:stop_area).permit(fields)
end
diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb
index a01d901e6..9b5b13ace 100644
--- a/app/helpers/referentials_helper.rb
+++ b/app/helpers/referentials_helper.rb
@@ -1,15 +1,14 @@
module ReferentialsHelper
# Outputs a green check icon and the text "Oui" or a red exclamation mark
# icon and the text "Non" based on `status`
- def line_status(status, verbose=true)
- if status
- out = content_tag(:span, nil, class: 'fa fa-exclamation-circle fa-lg text-danger')
- out += t('activerecord.attributes.line.deactivated') if verbose
- out
+ def line_status(status)
+ case status
+ when :deactivated
+ content_tag(:span, nil, class: 'fa fa-exclamation-circle fa-lg text-danger') +
+ Chouette::Line.tmf('deactivated')
else
- out = content_tag(:span, nil, class: 'fa fa-check-circle fa-lg text-success')
- out += t('activerecord.attributes.line.activated') if verbose
- out
+ content_tag(:span, nil, class: 'fa fa-check-circle fa-lg text-success') +
+ Chouette::Line.tmf('activated')
end
end
diff --git a/app/javascript/helpers/CustomFieldsInputs.js b/app/javascript/helpers/CustomFieldsInputs.js
index abc8097d5..9547021eb 100644
--- a/app/javascript/helpers/CustomFieldsInputs.js
+++ b/app/javascript/helpers/CustomFieldsInputs.js
@@ -16,7 +16,7 @@ export default class CustomFieldsInputs extends Component {
})}
ref={'custom_fields.' + cf.code}
className='form-control'
- defaultValue={cf.value}
+ defaultValue={cf.value || cf.options.default}
disabled={this.props.disabled}
options={{
theme: 'bootstrap',
@@ -34,7 +34,7 @@ export default class CustomFieldsInputs extends Component {
ref={'custom_fields.' + cf.code}
className='form-control'
disabled={this.props.disabled}
- value={cf.value}
+ value={cf.value || cf.options.default}
onChange={(e) => {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} }
/>
)
@@ -47,7 +47,7 @@ export default class CustomFieldsInputs extends Component {
ref={'custom_fields.' + cf.code}
className='form-control'
disabled={this.props.disabled}
- value={cf.value}
+ value={cf.value || cf.options.default}
onChange={(e) => {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} }
/>
)
diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb
index 4b5d1a68d..3ef2d8e1d 100644
--- a/app/models/chouette/line.rb
+++ b/app/models/chouette/line.rb
@@ -114,5 +114,9 @@ module Chouette
def activated?
!deactivated
end
+
+ def status
+ activated? ? :activated : :deactivated
+ end
end
end
diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb
index 18b7bbf9b..475589e13 100644
--- a/app/models/chouette/trident_active_record.rb
+++ b/app/models/chouette/trident_active_record.rb
@@ -7,6 +7,10 @@ module Chouette
@referential ||= Referential.where(:slug => Apartment::Tenant.current).first!
end
+ def workgroup
+ referential&.workgroup
+ end
+
def hub_restricted?
referential.data_format == "hub"
end
@@ -16,4 +20,4 @@ module Chouette
end
end
-end \ No newline at end of file
+end
diff --git a/app/models/concerns/custom_fields_support.rb b/app/models/concerns/custom_fields_support.rb
index c39dfd1fc..6e744d550 100644
--- a/app/models/concerns/custom_fields_support.rb
+++ b/app/models/concerns/custom_fields_support.rb
@@ -5,18 +5,19 @@ module CustomFieldsSupport
validate :custom_fields_values_are_valid
after_initialize :initialize_custom_fields
- def self.custom_fields workgroup=:all
+ def self.custom_fields workgroup
+ return [] unless workgroup
fields = CustomField.where(resource_type: self.name.split("::").last)
- fields = fields.where(workgroup_id: workgroup&.id) if workgroup != :all
+ fields = fields.where(workgroup_id: workgroup.id)
fields
end
- def self.custom_fields_definitions workgroup=:all
+ def self.custom_fields_definitions workgroup
Hash[*custom_fields(workgroup).map{|cf| [cf.code, cf]}.flatten]
end
def method_missing method_name, *args
- if method_name =~ /custom_field_*/ && method_name.to_sym != :custom_field_values && !@custom_fields_initialized
+ if !@custom_fields_initialized && method_name =~ /custom_field_*/ && method_name.to_sym != :custom_field_values
initialize_custom_fields
send method_name, *args
else
@@ -24,8 +25,9 @@ module CustomFieldsSupport
end
end
- def custom_fields workgroup=:all
- CustomField::Collection.new self, workgroup
+ def custom_fields deprecated_workgroup=nil
+ _workgroup = deprecated_workgroup || self.workgroup
+ CustomField::Collection.new self, _workgroup
end
def custom_fields_checksum
@@ -33,21 +35,37 @@ module CustomFieldsSupport
end
def custom_field_values= vals
- out = {}
- custom_fields.each do |code, field|
- out[code] = field.preprocess_value_for_assignment(vals.symbolize_keys[code.to_sym])
+ if custom_fields_initialized?
+ out = {}
+ custom_fields.each do |code, field|
+ out[code] = field.preprocess_value_for_assignment(vals.symbolize_keys[code.to_sym])
+ end
+ @custom_fields_values_initialized = true
+ else
+ out = vals
end
write_attribute :custom_field_values, out
end
+ def custom_fields_initialized?
+ !!@custom_fields_initialized
+ end
+
+ def custom_fields_values_initialized?
+ !!@custom_fields_values_initialized
+ end
+
def initialize_custom_fields
+ return if custom_fields_initialized?
return unless self.attributes.has_key?("custom_field_values")
+ return unless self.workgroup.present?
self.custom_field_values ||= {}
- custom_fields(:all).values.each &:initialize_custom_field
- custom_fields(:all).each do |k, v|
+ custom_fields.values.each &:initialize_custom_field
+ custom_fields.each do |k, v|
custom_field_values[k] ||= v.default_value
end
@custom_fields_initialized = true
+ self.custom_field_values = self.custom_field_values unless custom_fields_values_initialized?
end
def custom_field_value key
@@ -56,7 +74,7 @@ module CustomFieldsSupport
private
def custom_fields_values_are_valid
- custom_fields(:all).values.all?{|cf| cf.valid?}
+ custom_fields.values.all?{|cf| cf.valid?}
end
end
end
diff --git a/app/models/concerns/line_referential_support.rb b/app/models/concerns/line_referential_support.rb
index 5eade3557..b77a178eb 100644
--- a/app/models/concerns/line_referential_support.rb
+++ b/app/models/concerns/line_referential_support.rb
@@ -7,6 +7,10 @@ module LineReferentialSupport
alias_method :referential, :line_referential
end
+ def workgroup
+ line_referential&.workgroup
+ end
+
def hub_restricted?
false
end
diff --git a/app/models/concerns/stop_area_referential_support.rb b/app/models/concerns/stop_area_referential_support.rb
index f29397b3a..fb9edd7d5 100644
--- a/app/models/concerns/stop_area_referential_support.rb
+++ b/app/models/concerns/stop_area_referential_support.rb
@@ -7,6 +7,10 @@ module StopAreaReferentialSupport
alias_method :referential, :stop_area_referential
end
+ def workgroup
+ stop_area_referential&.workgroup
+ end
+
def hub_restricted?
false
end
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 88783b5b4..15aee9a41 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -8,7 +8,7 @@ class CustomField < ApplicationModel
validates :code, uniqueness: {scope: [:resource_type, :workgroup_id], case_sensitive: false}, presence: true
class Collection < HashWithIndifferentAccess
- def initialize object, workgroup=:all
+ def initialize object, workgroup=nil
vals = object.class.custom_fields(workgroup).map do |v|
[v.code, CustomField::Instance.new(object, v, object.custom_field_value(v.code))]
end
@@ -147,6 +147,10 @@ class CustomField < ApplicationModel
@raw_value&.to_i
end
+ def preprocess_value_for_assignment val
+ val&.to_i
+ end
+
def validate
@valid = true
return if @raw_value.is_a?(Fixnum) || @raw_value.is_a?(Float)
@@ -167,6 +171,10 @@ class CustomField < ApplicationModel
end
end
+ def preprocess_value_for_assignment val
+ val
+ end
+
def display_value
return unless value
k = options["list_values"].is_a?(Hash) ? value.to_s : value.to_i
diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb
index 7a8a01774..a4e6333d7 100644
--- a/app/models/referential_metadata.rb
+++ b/app/models/referential_metadata.rb
@@ -44,8 +44,8 @@ class ReferentialMetadata < ApplicationModel
validate :check_end_greather_than_begin
def check_end_greather_than_begin
- if self.begin and self.end and self.begin >= self.end
- errors.add(:base, I18n.t('referentials.errors.short_period'))
+ if self.begin and self.end and self.begin > self.end
+ errors.add(:base, I18n.t('referentials.errors.invalid_period'))
end
end
diff --git a/app/views/companies/_form.html.slim b/app/views/companies/_form.html.slim
index e8b3fcede..ec003b836 100644
--- a/app/views/companies/_form.html.slim
+++ b/app/views/companies/_form.html.slim
@@ -12,7 +12,7 @@
= f.input :time_zone, include_blank: true
= f.input :url
= f.input :registration_number, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.registration_number")}
- - if resource.custom_fields(current_referential.workgroup).any?
+ - if resource.custom_fields.present?
- resource.custom_fields.each do |code, field|
= field.input(f).to_s
.separator
diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim
index f745d10a4..992d163fe 100644
--- a/app/views/lines/_filters.html.slim
+++ b/app/views/lines/_filters.html.slim
@@ -8,23 +8,23 @@
.ffg-row
.form-group.togglable class=filter_item_class(params[:q], :network_id_eq_any)
- = f.label Chouette::Line.human_attribute_name(:network_id), required: false, class: 'control-label'
+ = f.label Chouette::Line.tmf(:network_id), required: false, class: 'control-label'
= f.input :network_id_eq_any, collection: @line_referential.networks.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable class=filter_item_class(params[:q], :company_id_eq_any)
- = f.label Chouette::Line.human_attribute_name(:company_id), required: false, class: 'control-label'
+ = f.label Chouette::Line.tmf(:company_id), required: false, class: 'control-label'
= f.input :company_id_eq_any, collection: @line_referential.companies.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
.form-group.togglable class=filter_item_class(params[:q], :transport_mode_eq_any)
- = f.label Chouette::Line.human_attribute_name(:transport_mode), required: false, class: 'control-label'
+ = f.label Chouette::Line.tmf(:transport_mode), required: false, class: 'control-label'
= f.input :transport_mode_eq_any, collection: StifTransportModeEnumerations.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 class=filter_item_class(params[:q], :transport_submode_eq_any)
- = f.label Chouette::Line.human_attribute_name(:transport_submode), required: false, class: 'control-label'
+ = f.label Chouette::Line.tmf(:transport_submode), required: false, class: 'control-label'
= f.input :transport_submode_eq_any, collection: StifTransportSubmodeEnumerations.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'}
.form-group.togglable class=filter_item_class(params[:q], :status)
- = f.label Chouette::Line.human_attribute_name(:state), required: false, class: 'control-label'
+ = f.label Chouette::Line.tmf(:status), required: false, class: 'control-label'
.form-group.checkbox_list
= f.simple_fields_for :status do |p|
= p.input :activated,
diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim
index 4d4ba938d..02bb5ec6e 100644
--- a/app/views/lines/index.html.slim
+++ b/app/views/lines/index.html.slim
@@ -29,9 +29,9 @@
end \
), \
TableBuilderHelper::Column.new( \
- name: t('activerecord.attributes.line.state'), \
+ key: :status, \
class: :state, \
- attribute: Proc.new { |n| line_status(n.deactivated) } \
+ attribute: Proc.new { |n| line_status(n.status) } \
), \
TableBuilderHelper::Column.new( \
key: 'networks.name', \
diff --git a/app/views/lines/show.html.slim b/app/views/lines/show.html.slim
index b683b9be6..fae32fb5d 100644
--- a/app/views/lines/show.html.slim
+++ b/app/views/lines/show.html.slim
@@ -7,7 +7,7 @@
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
{ t('objectid') => @line.get_objectid.short_id,
- Chouette::Line.tmf(:state) => line_status(@line.deactivated),
+ Chouette::Line.tmf(:status) => line_status(@line.status),
Chouette::Line.tmf(:network_id) => (@line.network.nil? ? t('lines.index.unset') : @line.network.name),
Chouette::Line.tmf(:company_id) => (@line.company.nil? ? t('lines.index.unset') : @line.company.name),
Chouette::Line.tmf(:secondary_companies) => (@line.secondary_companies.nil? ? t('lines.index.unset') : array_to_html_list(@line.secondary_companies.collect(&:name))),
diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim
index 4804da527..e387146d7 100644
--- a/app/views/referential_lines/show.html.slim
+++ b/app/views/referential_lines/show.html.slim
@@ -7,7 +7,7 @@
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
{ t('id_codif') => @line.get_objectid.short_id,
- Chouette::Line.tmf('state') => line_status(@line.deactivated),
+ Chouette::Line.tmf('status') => line_status(@line.status),
Chouette::Line.tmf('network_id') => (@line.network.nil? ? t('lines.index.unset') : link_to(@line.network.name, [@referential, @line.network]) ),
Chouette::Line.tmf('company') => (@line.company.nil? ? t('lines.index.unset') : link_to(@line.company.name, [@referential, @line.company]) ),
Chouette::Line.tmf('secondary_companies') => (@line.secondary_companies.nil? ? t('lines.index.unset') : @line.secondary_companies.collect(&:name).join(', ')),
diff --git a/app/views/referential_stop_areas/show.html.slim b/app/views/referential_stop_areas/show.html.slim
index cb04ab7a6..beee0383f 100644
--- a/app/views/referential_stop_areas/show.html.slim
+++ b/app/views/referential_stop_areas/show.html.slim
@@ -7,10 +7,10 @@
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
{ t('id_reflex') => @stop_area.try(:user_objectid),
- 'Activé' => (@stop_area.deleted_at ? t('false') : t('true')),
- @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment),
- @stop_area.human_attribute_name(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"),
- @stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number,
- 'Coordonnées' => geo_data(@stop_area, @stop_area_referential),
- @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code,
- @stop_area.human_attribute_name(:city_name) => @stop_area.city_name }
+ Chouette::StopArea.tmf(:status) => stop_area_status(@stop_area),
+ Chouette::StopArea.tmf(:comment) => @stop_area.try(:comment),
+ Chouette::StopArea.tmf(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"),
+ Chouette::StopArea.tmf(:registration_number) => @stop_area.registration_number,
+ Chouette::StopArea.tmf(:coordinates) => geo_data(@stop_area, @stop_area_referential),
+ Chouette::StopArea.tmf(:zip_code) => @stop_area.zip_code,
+ Chouette::StopArea.tmf(:city_name) => @stop_area.city_name } \ No newline at end of file
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index b2a079ab4..3cdcff63b 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -40,8 +40,8 @@
end \
), \
TableBuilderHelper::Column.new( \
- key: :state, \
- attribute: Proc.new { |n| line_status(n.deactivated?) } \
+ key: :status, \
+ attribute: Proc.new { |n| line_status(n.status) } \
), \
TableBuilderHelper::Column.new( \
key: :transport_mode, \
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index d4571c173..aea824a89 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -34,8 +34,9 @@
end \
), \
TableBuilderHelper::Column.new( \
- name: Chouette::Line.tmf('activated'), \
- attribute: Proc.new { |s| line_status(s.try(:stop_area).deleted_at) } \
+ key: :status, \
+ name: Chouette::StopArea.tmf('status'), \
+ attribute: Proc.new { |s| stop_area_status(s.try(:stop_area)) } \
), \
TableBuilderHelper::Column.new( \
key: :zip_code, \
diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim
index c698eaaa5..caa264d5e 100644
--- a/app/views/stop_areas/_filters.html.slim
+++ b/app/views/stop_areas/_filters.html.slim
@@ -15,7 +15,7 @@
= 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'
+ = f.label Chouette::StopArea.tmf('status'), required: false, class: 'control-label'
.form-group.checkbox_list
= f.simple_fields_for :status do |p|
= p.input :in_creation,
diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim
index 00f2ad8bb..220097a69 100644
--- a/app/views/stop_areas/_form.html.slim
+++ b/app/views/stop_areas/_form.html.slim
@@ -62,10 +62,10 @@
= f.input :stairs_availability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true
= f.input :lift_availability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true
- - if resource.custom_fields(resource.stop_area_referential.workgroup).any?
+ - if resource.custom_fields.present?
.custom_fields
h3 = t("stop_areas.stop_area.custom_fields")
- - resource.custom_fields(resource.stop_area_referential.workgroup).each do |code, field|
+ - resource.custom_fields.each do |code, field|
= field.input(f).to_s
.separator
diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim
index fbdb54e02..62b873c36 100644
--- a/app/views/stop_areas/index.html.slim
+++ b/app/views/stop_areas/index.html.slim
@@ -32,7 +32,7 @@
attribute: 'registration_number' \
), \
TableBuilderHelper::Column.new( \
- name: Chouette::StopArea.tmf('state'), \
+ key: :status, \
attribute: Proc.new { |s| stop_area_status(s) } \
), \
TableBuilderHelper::Column.new( \
diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim
index 851bd9b82..c4d06f61d 100644
--- a/app/views/stop_areas/show.html.slim
+++ b/app/views/stop_areas/show.html.slim
@@ -10,18 +10,18 @@
- if has_feature?(:stop_area_localized_names)
- @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,
+ - attributes.merge!({label_for_country(k, Chouette::StopArea.tmf('name')) => v }) if v.present?
+ - attributes.merge!({ Chouette::StopArea.tmf('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!({ Chouette::StopArea.tmf('stop_area_type') => Chouette::AreaType.find(@stop_area.area_type).try(:label),
+ Chouette::StopArea.tmf('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!(Chouette::StopArea.tmf('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,
- @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_status(@stop_area),
- @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment),
+ Chouette::StopArea.tmf('zip_code') => @stop_area.zip_code,
+ Chouette::StopArea.tmf('city_name') => @stop_area.city_name,
+ Chouette::StopArea.tmf('country_code') => @stop_area.country_code.presence || '-',
+ Chouette::StopArea.tmf('status') => stop_area_status(@stop_area),
+ Chouette::StopArea.tmf('comment') => @stop_area.try(:comment),
})
- @stop_area.custom_fields.each do |code, field|
- attributes.merge!(field.name => field.display_value)
diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml
index c1f9063a7..6501faa57 100644
--- a/config/locales/lines.en.yml
+++ b/config/locales/lines.en.yml
@@ -118,7 +118,7 @@ en:
creator_id: "Created by"
footnotes: "Footnotes"
stable_id: External permanent idenifier"
- state: Status
+ status: Status
activated: Activated
deactivated: Deactivated
formtastic:
diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml
index 487cae35c..587453e83 100644
--- a/config/locales/lines.fr.yml
+++ b/config/locales/lines.fr.yml
@@ -118,7 +118,7 @@ fr:
creator_id: "Créé par"
footnotes: "Notes de bas de page"
stable_id: "Identifiant externe pérenne"
- state: État
+ status: État
activated: Activée
deactivated: Désactivée
formtastic:
diff --git a/config/locales/referentials.en.yml b/config/locales/referentials.en.yml
index 1381d5ddd..f52eaa1cb 100644
--- a/config/locales/referentials.en.yml
+++ b/config/locales/referentials.en.yml
@@ -47,7 +47,7 @@ en:
user_excluded: "%{user} is a reserved value"
overlapped_referential: "%{referential} cover the same perimeter"
overlapped_period: "Another period is on the same period"
- short_period: Min period length is two days
+ invalid_period: The begin date must be before end date
overview:
head:
dates: Dates
diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml
index cf012ef8e..c4633014b 100644
--- a/config/locales/referentials.fr.yml
+++ b/config/locales/referentials.fr.yml
@@ -47,7 +47,7 @@ fr:
user_excluded: "%{user} est une valeur réservée"
overlapped_referential: "%{referential} couvre le même périmètre d'offre"
overlapped_period: "Une autre période chevauche cette période"
- short_period: "La durée minimum d'une période est de deux jours"
+ invalid_period: La date de début doit être antérieure à la date de fin
overview:
head:
dates: Dates
diff --git a/config/locales/stop_areas.en.yml b/config/locales/stop_areas.en.yml
index 4d19a77e9..7f460381c 100644
--- a/config/locales/stop_areas.en.yml
+++ b/config/locales/stop_areas.en.yml
@@ -71,9 +71,6 @@ en:
access_managment: "Access Points and Links managment"
access_points: "Access Points"
not_editable: "The area type is not editable"
- state:
- active: Active
- deactivated: Deactivated
genealogical:
genealogical: "Links between stop area"
genealogical_routing: "Routing constraint's links"
@@ -115,6 +112,7 @@ en:
confirmed: "Activated"
confirmed_at: "Activated at"
deleted: "Deactivated"
+ deactivated: "Deactivated"
deleted_at: "Deactivated at"
comment: "Description"
stop_area_type: "Area type"
@@ -148,7 +146,7 @@ en:
zip_code: "Zip code"
city_name: "City"
waiting_time: Waiting time (minutes)
- state: Status
+ status: Status
formtastic:
titles:
stop_area:
diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml
index 6a5fbf24b..c85faaf7d 100644
--- a/config/locales/stop_areas.fr.yml
+++ b/config/locales/stop_areas.fr.yml
@@ -72,9 +72,6 @@ fr:
access_managment: "Gestion des accès et liens associés"
access_points: "Points d'accès"
not_editable: "Le type d'arrêt est non modifiable"
- state:
- active: Actif
- deactivated: Désactivé
genealogical:
genealogical: "Lien entre arrêts"
genealogical_routing: "Liens de l'ITL"
@@ -114,7 +111,7 @@ fr:
registration_number: "Numéro d'enregistrement"
published_name: "Nom public"
in_creation: "En création"
- confirmed: "Actif"
+ confirmed: "Activé"
confirmed_at: "Activé le"
deleted: "Désactivé"
deactivated: "Désactivé"
@@ -151,7 +148,7 @@ fr:
zip_code: "Code postal"
city_name: "Commune"
waiting_time: Temps de desserte (minutes)
- state: État
+ status: État
formtastic:
titles:
stop_area:
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index ce6ce9fa5..54fd4f9d8 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -3,6 +3,11 @@ require 'rails_helper'
RSpec.describe CustomField, type: :model do
let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
+ let(:referential){ create :workbench_referential }
+ let(:workgroup){ referential.workgroup }
+ before do
+ referential.switch
+ end
context "validates" do
it { should validate_uniqueness_of(:name).scoped_to(:resource_type, :workgroup_id) }
@@ -18,14 +23,14 @@ RSpec.describe CustomField, type: :model do
end
context "custom fields for a resource" do
- let!( :fields ){ [create(:custom_field), create(:custom_field, code: :energy)] }
+ let!( :fields ){ [create(:custom_field, workgroup: workgroup), create(:custom_field, code: :energy, workgroup: workgroup)] }
let!( :instance_fields ){
{
fields[0].code => fields[0].slice(:code, :name, :field_type, :options).update(value: nil),
"energy" => fields[1].slice(:code, :name, :field_type, :options).update(value: 99)
}
}
- it { expect(Chouette::VehicleJourney.custom_fields).to eq(fields) }
+ it { expect(Chouette::VehicleJourney.custom_fields(workgroup)).to eq(fields) }
it {
instance_fields.each do |code, cf|
cf.each do |k, v|
@@ -37,14 +42,36 @@ RSpec.describe CustomField, type: :model do
context "custom field_values for a resource" do
before do
- create :custom_field, field_type: :integer, code: :energy, name: :energy
+ create :custom_field, field_type: :integer, code: :energy, name: :energy, workgroup: workgroup
end
it { expect(vj.custom_field_value("energy")).to eq(99) }
+
+ context "given different workgroups" do
+ let(:ref1){ create :workbench_referential }
+ let(:ref2){ create :workbench_referential }
+ before do
+ create :custom_field, field_type: :integer, code: :ref1_energy, name: :energy, workgroup: ref1.workgroup, options: {default: 12}
+ create :custom_field, field_type: :integer, code: :ref1_energy, name: :energy, workgroup: ref1.workgroup, options: {default: 12}, resource_type: "Company"
+ create :custom_field, field_type: :integer, code: :ref2_energy, name: :energy, workgroup: ref2.workgroup
+ end
+ it "should only initialize fields from the right workgroup" do
+ ref1.switch
+ expect(Chouette::VehicleJourney.new.custom_fields.keys).to eq ["ref1_energy"]
+ expect(Chouette::VehicleJourney.new.custom_field_values["ref1_energy"]).to eq 12
+ expect(Chouette::VehicleJourney.new(custom_field_values: {ref1_energy: 13}).custom_field_values["ref1_energy"]).to eq 13
+ line_referential = create(:line_referential, workgroup: ref1.workgroup)
+ expect(line_referential.companies.build(custom_field_values: {ref1_energy: "13"}).custom_field_values["ref1_energy"]).to eq 13
+
+ ref2.switch
+ expect(Chouette::VehicleJourney.new.custom_fields.keys).to eq ["ref2_energy"]
+ expect(Chouette::VehicleJourney.new.custom_field_values).to_not have_key "ref1_energy"
+ end
+ end
end
context "with a 'list' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'list', options: {list_values: %w(foo bar baz)})] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'list', options: {list_values: %w(foo bar baz)}, workgroup: workgroup)] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "1"} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq 1
@@ -75,7 +102,7 @@ RSpec.describe CustomField, type: :model do
end
context "with an 'integer' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'integer')] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'integer', workgroup: workgroup)] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: "99"} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq 99
@@ -101,7 +128,7 @@ RSpec.describe CustomField, type: :model do
end
context "with a 'string' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'string')] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'string', workgroup: workgroup)] }
let!( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value).to eq '99'
@@ -109,7 +136,7 @@ RSpec.describe CustomField, type: :model do
end
context "with a 'attachment' field_type" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment')] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment', workgroup: workgroup)] }
let( :vj ){ create :vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'users.json'))} }
it "should cast the value" do
expect(vj.custom_fields[:energy].value.class).to be CustomFieldAttachmentUploader
@@ -129,7 +156,7 @@ RSpec.describe CustomField, type: :model do
end
context "with a whitelist" do
- let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment', options: {extension_whitelist: %w(zip)})] }
+ let!(:field){ [create(:custom_field, code: :energy, field_type: 'attachment', options: {extension_whitelist: %w(zip)}, workgroup: workgroup)] }
it "should validate extension" do
expect(build(:vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'users.json'))})).to_not be_valid
expect(build(:vehicle_journey, custom_field_values: {energy: File.open(Rails.root.join('spec', 'fixtures', 'nozip.zip'))})).to be_valid
diff --git a/spec/models/referential_metadata_spec.rb b/spec/models/referential_metadata_spec.rb
index 88a12b2bb..210f95e14 100644
--- a/spec/models/referential_metadata_spec.rb
+++ b/spec/models/referential_metadata_spec.rb
@@ -100,7 +100,7 @@ RSpec.describe ReferentialMetadata, :type => :model do
it "should validate that end is greather than or equlals to begin" do
expect(period(begin: "2016-11-21", end: "2016-11-22")).to be_valid
- expect(period(begin: "2016-11-21", end: "2016-11-21")).to_not be_valid
+ expect(period(begin: "2016-11-21", end: "2016-11-21")).to be_valid
expect(period(begin: "2016-11-22", end: "2016-11-21")).to_not be_valid
end