aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/chouette/journey_pattern.rb8
-rw-r--r--app/models/chouette/stop_area.rb13
-rw-r--r--app/models/chouette/vehicle_journey.rb8
-rw-r--r--app/models/custom_field.rb7
-rw-r--r--app/models/merge.rb2
-rw-r--r--app/models/referential.rb16
-rw-r--r--app/models/referential_cloning.rb9
-rw-r--r--app/models/workbench.rb1
-rw-r--r--app/models/workgroup.rb14
9 files changed, 67 insertions, 11 deletions
diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb
index 366fde188..1ddf7c9fb 100644
--- a/app/models/chouette/journey_pattern.rb
+++ b/app/models/chouette/journey_pattern.rb
@@ -58,14 +58,14 @@ module Chouette
{
name: item['name'],
published_name: item['published_name'],
- registration_number: item['registration_number']
+ registration_number: item['registration_number'],
+ costs: item['costs']
}
end
def self.state_create_instance route, item
# Flag new record, so we can unset object_id if transaction rollback
jp = route.journey_patterns.create(state_permited_attributes(item))
-
# FIXME
# DefaultAttributesSupport will trigger some weird validation on after save
# wich will call to valid?, wich will populate errors
@@ -146,5 +146,9 @@ module Chouette
vjas.destroy
end
end
+
+ def costs
+ read_attribute(:costs) || {}
+ end
end
end
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index 4f1359ff8..52602be9f 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -49,8 +49,10 @@ module Chouette
def parent_area_type_must_be_greater
return unless self.parent
- if Chouette::AreaType.find(self.area_type) >= Chouette::AreaType.find(self.parent.area_type)
- errors.add(:parent_id, I18n.t('stop_areas.errors.parent_area_type', area_type: self.parent.area_type))
+
+ parent_area_type = Chouette::AreaType.find(self.parent.area_type)
+ if Chouette::AreaType.find(self.area_type) >= parent_area_type
+ errors.add(:parent_id, I18n.t('stop_areas.errors.parent_area_type', area_type: parent_area_type.label))
end
end
@@ -355,5 +357,12 @@ module Chouette
def deactivate!
update_attribute :deleted_at, Time.now
end
+
+ def country_name
+ return unless country_code
+
+ country = ISO3166::Country[country_code]
+ country.translations[I18n.locale.to_s] || country.name
+ end
end
end
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index d4dc82a56..11da77948 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -243,6 +243,14 @@ module Chouette
end
end
+ def custom_fields
+ CustomField.where(resource_type: self.class.name.split("::").last)
+ end
+
+ def custom_field_value key
+ (custom_field_values || {})[key.to_s]
+ end
+
def self.matrix(vehicle_journeys)
Hash[*VehicleJourneyAtStop.where(vehicle_journey_id: vehicle_journeys.pluck(:id)).map do |vjas|
[ "#{vjas.vehicle_journey_id}-#{vjas.stop_point_id}", vjas]
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
new file mode 100644
index 000000000..e8e76c6b5
--- /dev/null
+++ b/app/models/custom_field.rb
@@ -0,0 +1,7 @@
+class CustomField < ActiveRecord::Base
+
+ extend Enumerize
+ enumerize :field_type, in: %i{list}
+
+ validates :name, uniqueness: {scope: :resource_type}
+end
diff --git a/app/models/merge.rb b/app/models/merge.rb
index 4cbbd18ab..8051eed4d 100644
--- a/app/models/merge.rb
+++ b/app/models/merge.rb
@@ -17,7 +17,7 @@ class Merge < ActiveRecord::Base
end
def name
- "Dummy" # FIXME
+ referentials.first(3).map { |r| r.name.truncate(10) }.join(',')
end
attr_reader :new
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 932000174..3eb5d3283 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -360,8 +360,18 @@ class Referential < ActiveRecord::Base
Apartment::Tenant.create slug
end
- Rails.logger.info("Schema create benchmark: '#{slug}'\t#{report}")
- Rails.logger.error( "Schema migrations count for Referential #{slug} " + Referential.connection.select_value("select count(*) from #{slug}.schema_migrations;").to_s )
+ check_migration_count(report)
+ end
+ end
+
+ def check_migration_count(report)
+ Rails.logger.info("Schema create benchmark: '#{slug}'\t#{report}")
+ Rails.logger.info("Schema migrations count for Referential #{slug}: #{migration_count || '-'}")
+ end
+
+ def migration_count
+ if self.class.connection.table_exists?("#{slug}.schema_migrations")
+ self.class.connection.select_value("select count(*) from #{slug}.schema_migrations;")
end
end
@@ -451,7 +461,7 @@ class Referential < ActiveRecord::Base
# No explicit unlock is needed as it will be released at the end of the
# transaction.
ActiveRecord::Base.connection.execute(
- 'LOCK referentials IN ACCESS EXCLUSIVE MODE'
+ 'LOCK public.referentials IN ACCESS EXCLUSIVE MODE'
)
end
end
diff --git a/app/models/referential_cloning.rb b/app/models/referential_cloning.rb
index a2b23e819..d4b74bd52 100644
--- a/app/models/referential_cloning.rb
+++ b/app/models/referential_cloning.rb
@@ -19,9 +19,12 @@ class ReferentialCloning < ActiveRecord::Base
end
def clone!
- AF83::SchemaCloner
- .new(source_referential.slug, target_referential.slug)
- .clone_schema
+ report = Benchmark.measure do
+ AF83::SchemaCloner
+ .new(source_referential.slug, target_referential.slug)
+ .clone_schema
+ end
+ target_referential.check_migration_count(report)
end
private
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index 3190246ae..f49f4e7cf 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -4,6 +4,7 @@ class Workbench < ActiveRecord::Base
belongs_to :line_referential
belongs_to :stop_area_referential
belongs_to :output, class_name: 'ReferentialSuite'
+ belongs_to :workgroup
has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential
has_many :networks, through: :line_referential
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
new file mode 100644
index 000000000..995917fac
--- /dev/null
+++ b/app/models/workgroup.rb
@@ -0,0 +1,14 @@
+class Workgroup < ActiveRecord::Base
+ belongs_to :line_referential
+ belongs_to :stop_area_referential
+
+ has_many :workbenches
+ has_many :organisations, through: :workbenches
+
+ validates_uniqueness_of :name
+
+ validates_presence_of :line_referential_id
+ validates_presence_of :stop_area_referential_id
+
+ has_many :custom_fields
+end