diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/chouette/stop_area.rb | 30 | ||||
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 2 | ||||
| -rw-r--r-- | app/models/import/message_export.rb | 48 | ||||
| -rw-r--r-- | app/models/import/resource.rb | 2 | ||||
| -rw-r--r-- | app/models/line_referential.rb | 1 | ||||
| -rw-r--r-- | app/models/merge.rb | 1 | ||||
| -rw-r--r-- | app/models/stop_area_referential.rb | 1 | ||||
| -rw-r--r-- | app/models/workgroup.rb | 2 |
8 files changed, 82 insertions, 5 deletions
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/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index 46522c354..b3987060a 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -62,7 +62,7 @@ module Chouette scope :with_ordered_stop_area_ids, ->(first, second){ if first.present? && second.present? joins(journey_pattern: :stop_points). - joins('INNER JOIN "journey_patterns" ON "journey_patterns"."id" = "vehicle_journeys"."journey_pattern_id" INNER JOIN "journey_patterns_stop_points" ON "journey_patterns_stop_points"."journey_pattern_id" = "journey_patterns"."id" INNER JOIN "stop_points" as "second_stop_points" ON "stop_points"."id" = "journey_patterns_stop_points"."stop_point_id"'). + joins('INNER JOIN "journey_patterns" ON "journey_patterns"."id" = "vehicle_journeys"."journey_pattern_id" INNER JOIN "journey_patterns_stop_points" ON "journey_patterns_stop_points"."journey_pattern_id" = "journey_patterns"."id" INNER JOIN "stop_points" as "second_stop_points" ON "second_stop_points"."id" = "journey_patterns_stop_points"."stop_point_id"'). where('stop_points.stop_area_id = ?', first). where('second_stop_points.stop_area_id = ? and stop_points.position < second_stop_points.position', second) else diff --git a/app/models/import/message_export.rb b/app/models/import/message_export.rb new file mode 100644 index 000000000..7a7add08c --- /dev/null +++ b/app/models/import/message_export.rb @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +require "csv" +require "zip" + +class Import::MessageExport + include ActiveModel::Validations + include ActiveModel::Conversion + extend ActiveModel::Naming + + attr_accessor :import_messages + + def initialize(attributes = {}) + attributes.each { |name, value| send("#{name}=", value) } + end + + def persisted? + false + end + + def label(name) + I18n.t "vehicle_journey_exports.label.#{name}" + end + + def column_names + ["criticity", "message key", "message", "file name", "line", "column"] + end + + def to_csv(options = {}) + csv_string = CSV.generate(options) do |csv| + csv << column_names + import_messages.each do |import_message| + csv << [import_message.criticity, import_message.message_attributes['test_id'], I18n.t("import_messages.#{import_message.message_key}", import_message.message_attributes.deep_symbolize_keys), *import_message.resource_attributes.values_at("filename", "line_number", "column_number") ] + end + end + # We add a BOM to indicate we use UTF-8 + "\uFEFF" + csv_string + end + + def to_zip(temp_file,options = {}) + ::Zip::OutputStream.open(temp_file) { |zos| } + ::Zip::File.open(temp_file.path, ::Zip::File::CREATE) do |zipfile| + zipfile.get_output_stream(label("vj_filename")+route.id.to_s+".csv") { |f| f.puts to_csv(options) } + zipfile.get_output_stream(label("tt_filename")+".csv") { |f| f.puts time_tables_to_csv(options) } + zipfile.get_output_stream(label("ftn_filename")+".csv") { |f| f.puts footnotes_to_csv(options) } + end + end + +end diff --git a/app/models/import/resource.rb b/app/models/import/resource.rb index 73be04d0e..5bd011039 100644 --- a/app/models/import/resource.rb +++ b/app/models/import/resource.rb @@ -4,5 +4,5 @@ class Import::Resource < ActiveRecord::Base include IevInterfaces::Resource belongs_to :import, class_name: Import::Base - has_many :messages, class_name: "ImportMessage", foreign_key: :resource_id + has_many :messages, class_name: "Import::Message", foreign_key: :resource_id end diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 15b2f6276..0d2ed39b1 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -10,6 +10,7 @@ class LineReferential < ActiveRecord::Base has_many :networks, class_name: 'Chouette::Network' has_many :line_referential_syncs, -> { order created_at: :desc } has_many :workbenches + has_one :workgroup def add_member(organisation, options = {}) attributes = options.merge organisation: organisation diff --git a/app/models/merge.rb b/app/models/merge.rb index d42d882ac..e72c794fe 100644 --- a/app/models/merge.rb +++ b/app/models/merge.rb @@ -159,7 +159,6 @@ class Merge < ActiveRecord::Base route_id: nil, objectid: objectid, ) - new_route.stop_points.build attributes end diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index 9e9e02d80..a9d3cc9b1 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -8,6 +8,7 @@ class StopAreaReferential < ActiveRecord::Base has_many :stop_areas, class_name: 'Chouette::StopArea' has_many :stop_area_referential_syncs, -> {order created_at: :desc} has_many :workbenches + has_one :workgroup def add_member(organisation, options = {}) attributes = options.merge organisation: organisation diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 3af20ae23..708225a2a 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -11,6 +11,8 @@ class Workgroup < ActiveRecord::Base validates_presence_of :line_referential_id validates_presence_of :stop_area_referential_id + validates_uniqueness_of :stop_area_referential_id + validates_uniqueness_of :line_referential_id has_many :custom_fields |
