diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/chouette/journey_frequency.rb | 35 | ||||
| -rw-r--r-- | app/models/chouette/timeband.rb | 28 | ||||
| -rw-r--r-- | app/models/concerns/custom_fields_support.rb | 2 | ||||
| -rw-r--r-- | app/models/referential.rb | 3 | ||||
| -rw-r--r-- | app/models/stop_area_copy.rb | 95 | 
5 files changed, 1 insertions, 162 deletions
| diff --git a/app/models/chouette/journey_frequency.rb b/app/models/chouette/journey_frequency.rb deleted file mode 100644 index 1b4efe96e..000000000 --- a/app/models/chouette/journey_frequency.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Chouette -  class JourneyFrequencyValidator < ActiveModel::Validator -    def validate(record) -      timeband = record.timeband -      if timeband -        first_departure_time = record.first_departure_time.utc.strftime( "%H%M%S%N" ) -        last_departure_time  = record.last_departure_time.utc.strftime( "%H%M%S%N" ) -        timeband_start_time  = timeband.start_time.utc.strftime( "%H%M%S%N" ) -        timeband_end_time    = timeband.end_time.utc.strftime( "%H%M%S%N" ) - -        unless first_departure_time.between? timeband_start_time, timeband_end_time -          record.errors[:first_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.start_must_be_after_timeband') -        end -        unless last_departure_time.between? timeband_start_time, timeband_end_time -          record.errors[:last_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.end_must_be_before_timeband') -        end -      end -      if record.first_departure_time == record.last_departure_time -        record.errors[:last_departure_time] << I18n.t('activerecord.errors.models.journey_frequency.end_must_be_different_from_first') -      end -      if record.scheduled_headway_interval.blank? || (record.scheduled_headway_interval.strftime( "%H%M%S%N" ) == Time.current.midnight.strftime( "%H%M%S%N" )) -        record.errors[:scheduled_headway_interval] << I18n.t('activerecord.errors.models.journey_frequency.scheduled_headway_interval_greater_than_zero') -      end -    end -  end - -  class JourneyFrequency < ActiveRecord -    belongs_to :vehicle_journey_frequency, foreign_key: 'vehicle_journey_id' -    belongs_to :timeband -    validates :first_departure_time, presence: true -    validates :last_departure_time,  presence: true -    validates :scheduled_headway_interval, presence: true -    validates_with Chouette::JourneyFrequencyValidator -  end -end
\ No newline at end of file diff --git a/app/models/chouette/timeband.rb b/app/models/chouette/timeband.rb deleted file mode 100644 index 38260b755..000000000 --- a/app/models/chouette/timeband.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Chouette -  class TimebandValidator < ActiveModel::Validator -    def validate(record) -      if record.end_time <= record.start_time -        record.errors[:end_time] << I18n.t('activerecord.errors.models.timeband.start_must_be_before_end') -      end -    end -  end - -  class Timeband < Chouette::TridentActiveRecord -    include ObjectidSupport -    has_metadata - -    validates :start_time, :end_time, presence: true -    validates_with Chouette::TimebandValidator - -    default_scope { order(:start_time) } - -    def self.object_id_key -      "Timeband" -    end - -    def fullname -      fullname = "#{I18n.l(self.start_time, format: :hour)}-#{I18n.l(self.end_time, format: :hour)}" -      "#{self.name} (#{fullname})" if self.name -    end -  end -end diff --git a/app/models/concerns/custom_fields_support.rb b/app/models/concerns/custom_fields_support.rb index f5a76f324..f55ff923b 100644 --- a/app/models/concerns/custom_fields_support.rb +++ b/app/models/concerns/custom_fields_support.rb @@ -31,7 +31,7 @@ module CustomFieldsSupport      end      def custom_fields_checksum -      custom_fields.values.map(&:checksum) +      custom_fields.values.sort_by(&:code).map(&:checksum)      end      def custom_field_values= vals diff --git a/app/models/referential.rb b/app/models/referential.rb index 0c6e71d47..ea75274d0 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -192,9 +192,6 @@ class Referential < ApplicationModel      Chouette::TimeTableDate.all    end -  def timebands -    Chouette::Timeband.all -  end    def connection_links      Chouette::ConnectionLink.all diff --git a/app/models/stop_area_copy.rb b/app/models/stop_area_copy.rb deleted file mode 100644 index d3eb78557..000000000 --- a/app/models/stop_area_copy.rb +++ /dev/null @@ -1,95 +0,0 @@ -class StopAreaCopy -  include ActiveModel::Validations -  include ActiveModel::Conversion -  extend  ActiveModel::Naming - -  attr_accessor :source_id, :hierarchy, :area_type, :source, :copy - -  validates_presence_of :source_id, :hierarchy, :area_type - -  validates :hierarchy, inclusion: { in: %w(child parent) } - - -  def initialize(attributes = {}) -    attributes.each { |name, value| send("#{name}=", value) } if attributes -    if self.area_type.blank? && self.source != nil -      self.source_id = self.source.id -      if self.hierarchy == "child" -        if self.source.area_type.underscore == "stop_place" -          self.area_type="commercial_stop_point" -        else -          self.area_type="boarding_position" -        end -      else -        if self.source.area_type.underscore == "stop_place" || self.source.area_type.underscore == "commercial_stop_point" -          self.area_type="stop_place" -        else -          self.area_type="commercial_stop_point" -        end -      end -    end -  end - -  def persisted? -    false -  end -   -  def source -    @source ||= Chouette::StopArea.find self.source_id -  end - -  def copy -    @copy ||= self.source.duplicate -  end - -  def copy_is_source_parent? -    self.hierarchy == "parent" -  end - -  def copy_is_source_child? -    self.hierarchy == "child" -  end - -  def copy_modfied_attributes -    { :name => self.source.name, # TODO: change ninoxe to avoid that !!! -      :area_type => self.area_type.camelcase, -      :registration_number => nil, -      :parent_id => copy_is_source_child? ? self.source_id : nil -    } -  end - -  def source_modified_attributes -    return {} unless copy_is_source_parent? -    { :parent_id => self.copy.id -    } -  end - -  def save -    begin -      if self.valid? -        Chouette::StopArea.transaction do -          copy.update_attributes copy_modfied_attributes -          if copy.valid? -            unless source_modified_attributes.empty? -              source.update_attributes source_modified_attributes -            end -            true -          else -            copy.errors.full_messages.each do |m|  -              errors.add :base, m -            end -            false -          end   -        end -      else -        false -      end -    rescue Exception => exception -      Rails.logger.error(exception.message) -      Rails.logger.error(exception.backtrace.join("\n")) -      errors.add :base, I18n.t("stop_area_copies.errors.exception") -      false -    end -  end -   -end | 
