diff options
| author | Xinhui | 2016-11-16 14:23:36 +0100 | 
|---|---|---|
| committer | Xinhui | 2016-11-16 14:23:36 +0100 | 
| commit | d5469a07545b21da81b1ccfbdb65378c187d7bef (patch) | |
| tree | bf94d46a83c25e19db4e4160f988f89ab4ebb00c /app | |
| parent | 27863346ac69845de01f3b75de67303226181e31 (diff) | |
| download | chouette-core-d5469a07545b21da81b1ccfbdb65378c187d7bef.tar.bz2 | |
Model CleanUp add end_date
Refs #1934
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/clean_ups_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/time_table.rb | 7 | ||||
| -rw-r--r-- | app/models/clean_up.rb | 13 | ||||
| -rw-r--r-- | app/views/referentials/_clean.html.slim | 3 | 
4 files changed, 14 insertions, 11 deletions
| diff --git a/app/controllers/clean_ups_controller.rb b/app/controllers/clean_ups_controller.rb index c6e4ecd44..1e4835775 100644 --- a/app/controllers/clean_ups_controller.rb +++ b/app/controllers/clean_ups_controller.rb @@ -14,6 +14,6 @@ class CleanUpsController < ChouetteController    end    def clean_up_params -    params.require(:clean_up).permit(:keep_lines, :keep_stops, :keep_companies, :keep_networks, :keep_group_of_lines, :expected_date) +    params.require(:clean_up).permit(:keep_lines, :keep_stops, :keep_companies, :keep_networks, :keep_group_of_lines, :begin_date, :end_date)    end  end diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 9af80fbb7..abe6186a7 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -4,8 +4,8 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord    self.primary_key = "id"    acts_as_taggable -   -  attr_accessor :monday,:tuesday,:wednesday,:thursday,:friday,:saturday,:sunday   + +  attr_accessor :monday,:tuesday,:wednesday,:thursday,:friday,:saturday,:sunday    attr_accessor :tag_search    def self.ransackable_attributes auth_object = nil @@ -70,6 +70,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord      return false unless self.end_date      self.end_date <= expected_date    end +    def validity_out_between?(starting_date, ending_date)      return false unless self.start_date      starting_date < self.end_date  && @@ -414,7 +415,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord    # remove dates form tt which aren't in another_tt    def intersect!(another_tt)      transaction do -       +        # transform tt as effective dates and get common ones        days = another_tt.intersects(self.effective_days) & self.intersects(another_tt.effective_days)        self.dates.clear diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb index 607362682..a44bb46a4 100644 --- a/app/models/clean_up.rb +++ b/app/models/clean_up.rb @@ -3,7 +3,7 @@ class CleanUp < ActiveRecord::Base    belongs_to :referential    has_one :clean_up_result -  validates :expected_date, presence: true +  validates :begin_date, presence: true    after_commit :perform_cleanup, :on => :create    def perform_cleanup @@ -12,15 +12,16 @@ class CleanUp < ActiveRecord::Base    def clean      result = {} -    tms = Chouette::TimeTable.validity_out_from_on?(expected_date) -    tms.each.map(&:delete) - -    result['time_table_count']      = tms.size +    result['time_table_count']      = self.clean_time_tables      result['vehicle_journey_count'] = self.clean_vehicle_journeys      result['journey_pattern_count'] = self.clean_journey_patterns      result    end +  def clean_time_tables +    Chouette::TimeTable.validity_out_between?(begin_date, end_date).delete_all +  end +    def clean_vehicle_journeys      ids = Chouette::VehicleJourney.includes(:time_tables).where(:time_tables => {id: nil}).pluck(:id)      Chouette::VehicleJourney.where(id: ids).delete_all @@ -61,6 +62,6 @@ class CleanUp < ActiveRecord::Base    def log_failed message_attributs      update_attribute(:ended_at, Time.now) -    # self.clean_up_result.create(message_key: :failed, message_attributs: message_attributs) +    CleanUpResult.create(clean_up: self, message_key: :failed, message_attributs: message_attributs)    end  end diff --git a/app/views/referentials/_clean.html.slim b/app/views/referentials/_clean.html.slim index cf79da8a6..a962d5417 100644 --- a/app/views/referentials/_clean.html.slim +++ b/app/views/referentials/_clean.html.slim @@ -1,6 +1,7 @@  #clean_up    = semantic_form_for [@referential, CleanUp.new] do |form|      = form.inputs do -      = form.input :expected_date, as: :date_picker, :wrapper_html => { class: 'date', title: t('titles.clean_up.expected_date') } +      = form.input :begin_date, as: :date_picker, :wrapper_html => { class: 'date', title: t('titles.clean_up.begin_date') } +      = form.input :end_date, as: :date_picker, :wrapper_html => { class: 'date', title: t('titles.clean_up.end_date') }      = form.actions do        = form.action :submit, as: :button, label: t('clean_ups.actions.clean_up') , :button_html => { data: { confirm: t('clean_ups.actions.confirm') } } | 
