diff options
41 files changed, 185 insertions, 217 deletions
| diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPatterns.js b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPatterns.js index f7a84cc22..23473ae52 100644 --- a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPatterns.js +++ b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPatterns.js @@ -95,7 +95,15 @@ class JourneyPatterns extends Component{              { _.some(this.props.journeyPatterns, 'errors') && (                <div className="alert alert-danger mt-sm">                  <strong>Erreur : </strong> -                une erreur bloque la validation des modifications. +                {this.props.journeyPatterns.map((jp, index) => +                  jp.errors.map((err, i) => { +                    return ( +                      <ul key={i}> +                        <li>{err}</li> +                      </ul> +                    ) +                  }) +                )}                </div>              )} diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js b/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js index f1b999cff..a1f41a693 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js @@ -49,9 +49,9 @@ class TagsSelect2 extends React.Component{                };              },              processResults: function(data, params) { - +              let items = _.filter(data, ({name}) => name.includes(params.term) )                return { -                results: data.map( +                results: items.map(                    item => _.assign(                      {},                      item, @@ -62,7 +62,7 @@ class TagsSelect2 extends React.Component{              },              cache: true            }, -          minimumInputLength: 3, +          minimumInputLength: 1,            templateResult: formatRepo          }}        /> diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourneys.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourneys.js index 8575c076f..e8673a25a 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourneys.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourneys.js @@ -96,7 +96,15 @@ class VehicleJourneys extends Component{              { _.some(this.props.vehicleJourneys, 'errors') && (                <div className="alert alert-danger mt-sm">                  <strong>Erreur : </strong> -                une erreur bloque la validation des modifications. +                {this.props.vehicleJourneys.map((vj, index) => +                  vj.errors.map((err, i) => { +                    return ( +                      <ul key={i}> +                        <li>{err}</li> +                      </ul> +                    ) +                  }) +                )}                </div>              )} diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/MissionSelect2.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/MissionSelect2.js index c04a1d642..922a1e5ee 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/MissionSelect2.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/MissionSelect2.js @@ -34,7 +34,7 @@ class BSelect4 extends React.Component{              delay: '500',              data: function(params) {                return { -                q: {published_name_or_objectid_or_registration_number_cont: params.term}, +                q: {published_name_cont_or_short_id_or_registration_number_cont: params.term},                };              },              processResults: function(data, params) { @@ -43,7 +43,7 @@ class BSelect4 extends React.Component{                    item => _.assign(                      {},                      item, -                    { text: "<strong>" + item.published_name + _.last(_.split(item.object_id, ':')) + "</strong><br/><small>" + item.registration_number + "</small>" } +                    { text: "<strong>" + item.published_name + " - " + item.short_id + "</strong><br/><small>" + item.registration_number + "</small>" }                    )                  )                }; diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js index 3e81290f5..0183aac43 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js @@ -34,7 +34,7 @@ class BSelect4 extends React.Component{              delay: '500',              data: function(params) {                return { -                q: {comment_cont: params.term}, +                q: {short_id_or_comment_cont: params.term},                };              },              processResults: function(data, params) { @@ -43,7 +43,7 @@ class BSelect4 extends React.Component{                    item => _.assign(                      {},                      item, -                    {text: '<strong>' + (item.color ? "<span class='fa fa-circle' style='color:" + item.color + "'></span> " : '') + item.comment + ' - ' + item.short_id + '</strong><br/><small>' + item.day_types.match(/[A-Z]?[a-z]+/g).join(', ') + '</small>'} +                    {text: '<strong>' + "<span class='fa fa-circle' style='color:" + (item.color ? item.color : '#4B4B4B') + "'></span> " + item.comment + ' - ' + item.short_id + '</strong><br/><small>' + (item.day_types ? item.day_types.match(/[A-Z]?[a-z]+/g).join(', ') : "") + '</small>'}                    )                  )                }; diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee index 1c03fe451..2e3884d7f 100644 --- a/app/assets/javascripts/select2.coffee +++ b/app/assets/javascripts/select2.coffee @@ -25,6 +25,8 @@ bind_select2_ajax = (el, cfg = {}) ->        item.text      templateSelection: (item) ->        item.text +    escapeMarkup: (markup) -> +      markup    bind_select2(el, cfg) diff --git a/app/assets/javascripts/time_table.coffee b/app/assets/javascripts/time_table.coffee new file mode 100644 index 000000000..8789cb226 --- /dev/null +++ b/app/assets/javascripts/time_table.coffee @@ -0,0 +1,14 @@ + $(document).on("click", "#time_table_filter_btn", (e) -> +   dates = [1, 2, 3].reduce (arr, key) -> +     arr.push $("#q_start_date_gteq_#{key}i").val(), $("#q_end_date_lteq_#{key}i").val() +     arr +   , [] + +   validDate = dates.every (date) -> !!date + +   noDate = dates.every (date) -> !date + +   unless (validDate || noDate) +     e.preventDefault() +     alert(window.I18n.fr.time_tables.error_period_filter) + ) diff --git a/app/assets/javascripts/workbench.coffee b/app/assets/javascripts/workbench.coffee new file mode 100644 index 000000000..971462e98 --- /dev/null +++ b/app/assets/javascripts/workbench.coffee @@ -0,0 +1,14 @@ + $(document).on("click", "#referential_filter_btn", (e) -> +   dates = [1, 2, 3].reduce (arr, key) -> +     arr.push $("#q_validity_period_begin_gteq_#{key}i").val(), $("#q_validity_period_end_gteq__#{key}i").val() +     arr +   , [] + +   validDate = dates.every (date) -> !!date + +   noDate = dates.every (date) -> !date + +   unless (validDate || noDate) +     e.preventDefault() +     alert(window.I18n.fr.referentials.error_period_filter) + ) diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index 6541eb492..78cd0e209 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -55,7 +55,7 @@ class RoutingConstraintZonesController < ChouetteController    alias_method :line, :parent    def collection -    @q = current_referential.routing_constraint_zones.search(params[:q]) +    @q = line.routing_constraint_zones.search(params[:q])      @routing_constraint_zones ||= begin        routing_constraint_zones = sort_collection diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 0054963c9..2ff7a2c3a 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -161,7 +161,6 @@ class TimeTablesController < ChouetteController    private    def ransack_periode scope      return scope unless params[:q] -    return scope unless params[:q]['end_date_lteq(1i)'].present?      begin_range = flatten_date('start_date_gteq')      end_range   = flatten_date('end_date_lteq') diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 897e842a8..375697bec 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -175,12 +175,11 @@ module TableBuilderHelper      sort_on,      sort_direction    ) -    if !table_is_sortable + +    if !table_is_sortable || !column.sortable        return column.header_label(collection_model)      end -    return column.name if !column.sortable -      direction =        if column.key.to_s == sort_on && sort_direction == 'desc'          'asc' diff --git a/app/models/calendar.rb b/app/models/calendar.rb index fb575515a..bb38e74df 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -31,6 +31,7 @@ class Calendar < ActiveRecord::Base        self.periods.each do |p|          tt.periods << Chouette::TimeTablePeriod.new(period_start: p.begin, period_end: p.end)        end +      tt.int_day_types = 508      end    end diff --git a/app/models/chouette/access_point.rb b/app/models/chouette/access_point.rb index da1f9524a..476f13c08 100644 --- a/app/models/chouette/access_point.rb +++ b/app/models/chouette/access_point.rb @@ -1,9 +1,10 @@  require 'geokit'  require 'geo_ruby' -class Chouette::AccessPoint < Chouette::TridentActiveRecord +class Chouette::AccessPoint < Chouette::ActiveRecord    # FIXME http://jira.codehaus.org/browse/JRUBY-6358    self.primary_key = "id" +  include StifReflexAttributesSupport    include Geokit::Mappable    include ProjectionFields @@ -29,6 +30,10 @@ class Chouette::AccessPoint < Chouette::TridentActiveRecord    before_save :coordinates_to_lat_lng +  def referential +    @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! +  end +    def combine_lat_lng      if self.latitude.nil? || self.longitude.nil?        "" diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 713ce0b21..1753cbed5 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -297,7 +297,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord    end    def display_day_types -    %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| self.send(d) }.map{ |d| self.human_attribute_name(d).first(2)}.join('') +    %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| self.send(d) }.map{ |d| self.human_attribute_name(d).first(2)}.join(', ')    end    def day_by_mask(flag) @@ -461,59 +461,6 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord      optimized.sort { |a,b| a.period_start <=> b.period_start}    end -  def continuous_periods -    periods = self.periods.sort_by(&:period_start) -    chunk = {} -    group = nil -    periods.each_with_index do |period, index| -      group ||= index -      group = (period.period_start - 1.day == periods[index - 1].period_end) ? group : group + 1 -      chunk[group] ||= [] -      chunk[group] << period -    end -    chunk.values.delete_if {|periods| periods.count < 2} -  end - -  def convert_continuous_periods_into_one -    chunks = self.continuous_periods - -    transaction do -      chunks.each do |chunk| -        self.periods.create!(period_start: chunk.first.period_start, period_end: chunk.last.period_end) -        self.periods.delete chunk -      end -    end -  end - -  #update a period if a in_day is just before or after -  def optimize_continuous_dates_and_periods -    return self.periods if self.included_days.empty? || periods.empty? - -    periods = self.clone_periods -    optimized = [] - -    i = 0 -    while i < periods.length -      period = periods[i] -      j = 0 -      in_days = self.reload.dates.where(in_out: true).sort_by(&:date) -      while j < in_days.length -        day = in_days[j] -        if period.period_start - 1.day === day.date -          period.period_start = day.date -          self.dates.delete day -        elsif period.period_end + 1.day === day.date -          period.period_end = day.date -          self.dates.delete day -        end -        j += 1 -      end -      i += 1 -      optimized << period -    end -    optimized -  end -    # add a peculiar day or switch it from excluded to included    def add_included_day(d)      if self.excluded_date?(d) @@ -530,28 +477,20 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord    # merge effective days from another timetable    def merge!(another_tt)      transaction do -      self.periods = another_tt.clone_periods + self.periods - -      # For included dates -      another_tt.included_days.map{ |d| add_included_day(d) } - -      # For excluded dates -      self.dates.where(in_out: false).each do |d| -        self.dates.delete d if another_tt.include_in_periods?(d.date) && !another_tt.excluded_date?(d.date) +      days = [].tap do |array| +        array.push(*self.included_days_in_dates_and_periods, *another_tt.effective_days) +        array.uniq!        end -      another_tt.excluded_days.each do |d| -        unless self.reload.excluded_date?(d) -          self.dates << Chouette::TimeTableDate.new(date: d, in_out: false) -        end -        self.save! -      end +      self.dates.clear +      self.periods.clear -      self.convert_continuous_dates_to_periods -      self.periods = self.optimize_continuous_dates_and_periods -      self.convert_continuous_periods_into_one -      self.periods = self.optimize_overlapping_periods +      days.each do |day| +        self.dates << Chouette::TimeTableDate.new(date: day, in_out: true) +      end +      self.save!      end +    self.convert_continuous_dates_to_periods    end    def included_days_in_dates_and_periods @@ -564,12 +503,18 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord      days    end -  # remove dates form tt which aren't in another_tt +  # keep common dates with another_tt    def intersect!(another_tt)      transaction do -      days = self.included_days_in_dates_and_periods & another_tt.included_days_in_dates_and_periods +      days = [].tap do |array| +        array.push(*self.included_days_in_dates_and_periods) +        array.delete_if {|day| !another_tt.effective_days.include?(day) } +        array.uniq! +      end +        self.dates.clear        self.periods.clear +        days.sort.each do |d|          self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true)        end @@ -578,12 +523,18 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord      self.convert_continuous_dates_to_periods    end -  # remove days from another calendar +  # remove common dates with another_tt    def disjoin!(another_tt)      transaction do -      days = self.included_days_in_dates_and_periods - another_tt.included_days_in_dates_and_periods +      days = [].tap do |array| +        array.push(*self.included_days_in_dates_and_periods) +        array.delete_if {|day| another_tt.effective_days.include?(day) } +        array.uniq! +      end +        self.dates.clear        self.periods.clear +        days.sort.each do |d|          self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true)        end diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index bc2713973..5e86a4897 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -23,11 +23,11 @@ module Chouette      validates_presence_of :route      validates_presence_of :journey_pattern -    validates :vehicle_journey_at_stops, +    # validates :vehicle_journey_at_stops,        # Validation temporarily removed for day offsets        # :vjas_departure_time_must_be_before_next_stop_arrival_time, -      vehicle_journey_at_stops_are_in_increasing_time_order: true +      # vehicle_journey_at_stops_are_in_increasing_time_order: false      validates_presence_of :number      has_many :vehicle_journey_at_stops, -> { includes(:stop_point).order("stop_points.position") }, :dependent => :destroy diff --git a/app/models/concerns/stif_codifligne_attributes_support.rb b/app/models/concerns/stif_codifligne_attributes_support.rb index d4370e505..0cd2cccc4 100644 --- a/app/models/concerns/stif_codifligne_attributes_support.rb +++ b/app/models/concerns/stif_codifligne_attributes_support.rb @@ -16,6 +16,6 @@ module StifCodifligneAttributesSupport    end    def objectid -    Chouette::StifCodifligneObjectid.new read_attribute(:objectid).to_s +    Chouette::StifCodifligneObjectid.new read_attribute(:objectid)    end  end diff --git a/app/models/concerns/stif_reflex_attributes_support.rb b/app/models/concerns/stif_reflex_attributes_support.rb index e6236a146..9dfd21f94 100644 --- a/app/models/concerns/stif_reflex_attributes_support.rb +++ b/app/models/concerns/stif_reflex_attributes_support.rb @@ -16,6 +16,6 @@ module StifReflexAttributesSupport    end    def objectid -    Chouette::StifReflexObjectid.new read_attribute(:objectid).to_s +    Chouette::StifReflexObjectid.new read_attribute(:objectid)    end  end diff --git a/app/views/api/v1/journey_patterns/show.rabl b/app/views/api/v1/journey_patterns/show.rabl index 21f25e480..7c3af52fc 100644 --- a/app/views/api/v1/journey_patterns/show.rabl +++ b/app/views/api/v1/journey_patterns/show.rabl @@ -5,6 +5,13 @@ extends "api/v1/trident_objects/show"    attributes attr, :unless => lambda { |m| m.send( attr).nil?}  end +node do |jp| +  { +    short_id: jp.objectid.parts.try(:third) +  } + +end +  node(:route_short_description) do |journey_pattern|    partial("api/v1/routes/short_description", :object => journey_pattern.route)  end @@ -18,4 +25,3 @@ child :stop_points => :stop_area_short_descriptions do |stop_points|      partial("api/v1/stop_areas/short_description", :object => stop_point.stop_area)    end  end - diff --git a/app/views/autocomplete_calendars/autocomplete.rabl b/app/views/autocomplete_calendars/autocomplete.rabl index 9aba2c37b..3a7703c53 100644 --- a/app/views/autocomplete_calendars/autocomplete.rabl +++ b/app/views/autocomplete_calendars/autocomplete.rabl @@ -1,5 +1,6 @@  collection @calendars, :object_root => false  attribute :id, :name, :short_name, :shared +  node :text do |cal| -  "#{cal.id} - #{cal.name}" +  "<strong>" + cal.name + " - " + cal.id.to_s + "</strong>"  end diff --git a/app/views/autocomplete_time_tables/index.rabl b/app/views/autocomplete_time_tables/index.rabl index 80e3f8684..7aafdca16 100644 --- a/app/views/autocomplete_time_tables/index.rabl +++ b/app/views/autocomplete_time_tables/index.rabl @@ -2,14 +2,15 @@ collection @time_tables, :object_root => false  node do |time_table|    { -    :id => time_table.id, :comment => time_table.comment, :objectid => time_table.objectid, +    :id => time_table.id, +    :comment => time_table.comment, +    :objectid => time_table.objectid,      :time_table_bounding => time_table.presenter.time_table_bounding,      :composition_info => time_table.presenter.composition_info,      :tags => time_table.tags.join(','), -    :text => "#{time_table.comment} - #{time_table.display_day_types} - #{time_table.objectid.parts.try(:third)}",      :color => time_table.color,      :day_types => time_table.display_day_types, -    :short_id => time_table.objectid.parts.try(:third) +    :short_id => time_table.objectid.parts.try(:third), +    :text => "<strong><span class='fa fa-circle' style='color:" + (time_table.color ? time_table.color : '#4b4b4b') + "'></span> " + time_table.comment + " - " + time_table.objectid.parts.try(:third) + "</strong><br/><small>" + time_table.display_day_types + "</small>"    }  end - diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index f2f8f1a9d..ec9719355 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -37,8 +37,7 @@              [ \                TableBuilderHelper::Column.new( \                  name: 'ID Reflex', \ -                attribute: Proc.new { |s| s.try(:stop_area).try(:user_objectid) }, \ -                sortable: false \ +                attribute: Proc.new { |s| s.try(:stop_area).try(:user_objectid) } \                ), \                TableBuilderHelper::Column.new( \                  key: :name, \ @@ -46,7 +45,7 @@                ), \                TableBuilderHelper::Column.new( \                  key: :deleted_at, \ -                attribute: Proc.new { |s| s.try(:stop_area).deleted_at ? t('false') : t('true') } \ +                attribute: Proc.new { |s| s.try(:stop_area).deleted_at ? t('false') : t('true') }, \                ), \                TableBuilderHelper::Column.new( \                  key: :zip_code, \ @@ -63,14 +62,11 @@                TableBuilderHelper::Column.new( \                  key: :for_alighting, \                  attribute: Proc.new { |s| t("stop_points.stop_point.for_alighting.#{s.for_alighting}") } \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :position, \ -                attribute: 'position' \ -              ), \ +              ) \              ],              links: [:show], -            cls: 'table' +            sortable: false, +            cls: 'table has-stoppoints'          - else            = replacement_msg t('stop_areas.search_no_results') diff --git a/app/views/time_tables/_filter.html.slim b/app/views/time_tables/_filter.html.slim index 392dc4f50..043aa87d0 100644 --- a/app/views/time_tables/_filter.html.slim +++ b/app/views/time_tables/_filter.html.slim @@ -20,4 +20,4 @@    .actions      = link_to 'Effacer', @workbench, class: 'btn btn-link' -    = f.submit 'Filtrer', class: 'btn btn-default' +    = f.submit 'Filtrer', class: 'btn btn-default', id: 'time_table_filter_btn' diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim index 72c025bc1..5ee854c58 100644 --- a/app/views/time_tables/index.html.slim +++ b/app/views/time_tables/index.html.slim @@ -62,3 +62,6 @@        .row.mt-xs          .col-lg-12            = replacement_msg t('time_tables.search_no_results') + += javascript_tag do +  | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; diff --git a/app/views/workbenches/_filters.html.slim b/app/views/workbenches/_filters.html.slim index 8da7ecf51..8da629e9c 100644 --- a/app/views/workbenches/_filters.html.slim +++ b/app/views/workbenches/_filters.html.slim @@ -30,4 +30,4 @@    .actions      = link_to t('actions.erase'), @workbench, class: 'btn btn-link' -    = f.submit t('actions.filter'), class: 'btn btn-default' +    = f.submit t('actions.filter'), class: 'btn btn-default', id: 'referential_filter_btn' diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index 6a41ca569..2f845ed96 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -71,3 +71,6 @@        .row.mt-xs          .col-lg-12            = replacement_msg t('referentials.search_no_results') + += javascript_tag do +  | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; diff --git a/config/locales/referentials.en.yml b/config/locales/referentials.en.yml index e29df7cf4..9ae6bfe35 100644 --- a/config/locales/referentials.en.yml +++ b/config/locales/referentials.en.yml @@ -5,6 +5,7 @@ en:        name: 'Search by name'        line: 'Seach by associated lines'      search_no_results: 'No data space matching your query' +    error_period_filter: "The period filter must have valid bounding dates"      index:        title: 'Data spaces'      edit: diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml index 643295c0e..a201ccadd 100644 --- a/config/locales/referentials.fr.yml +++ b/config/locales/referentials.fr.yml @@ -5,6 +5,7 @@ fr:        name: 'Indiquez un nom de référentiel...'        line: 'Indiquez une ligne...'      search_no_results: 'Aucun jeu de données ne correspond à votre recherche' +    error_period_filter: "Le filtre par période doit contenir une date de début et de fin valides"      index:        title: 'Jeux de données'      edit: diff --git a/config/locales/time_tables.en.yml b/config/locales/time_tables.en.yml index 24750f0af..ed2f9758e 100644 --- a/config/locales/time_tables.en.yml +++ b/config/locales/time_tables.en.yml @@ -2,6 +2,7 @@ en:    time_tables:      duplicate_success: "duplication succeded"      search_no_results: 'No calendar matching your query' +    error_period_filter: "The period filter must have valid bounding dates"      time_table:        empty: "empty"        bounding: "from %{start} to %{end}" diff --git a/config/locales/time_tables.fr.yml b/config/locales/time_tables.fr.yml index 886aaa263..cf6888d0f 100644 --- a/config/locales/time_tables.fr.yml +++ b/config/locales/time_tables.fr.yml @@ -2,6 +2,7 @@ fr:    time_tables:      duplicate_success: "duplication terminée"      search_no_results: 'Aucun calendrier ne correspond à votre recherche' +    error_period_filter: "Le filtre par période doit contenir une date de début et de fin valides"      time_table:        empty: "vide"        bounding: "du %{start} au %{end}" diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 675486265..63270a986 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -123,7 +123,7 @@ module Stif        end        def create_or_update_access_point entry, stop_area -        access = Chouette::AccessPoint.find_or_create_by(objectid: "dummy:AccessPoint:#{entry['id'].tr(':', '')}") +        access = Chouette::AccessPoint.find_or_create_by(objectid: entry['id'])          # Hack, on save object_version will be incremented by 1          entry['version']   = entry['version'].to_i + 1  if access.persisted?          access.access_type = self.access_point_access_type(entry) diff --git a/lib/tasks/generate.rake b/lib/tasks/generate.rake index f02a75cc2..a9b1a3454 100644 --- a/lib/tasks/generate.rake +++ b/lib/tasks/generate.rake @@ -2,8 +2,15 @@ namespace :generate do    desc "Create model diagrams for Chouette"    task :model_diagram  => :environment do -    sh "bundle exec rake erd only='Calendar,Referential,Chouette::Line,Chouette::Route,Chouette::JourneyPattern,Chouette::VehicleJourney,Chouette::VehicleJourneyAtStop,Chouette::TimeTable,Chouette::TimeTableDate,Chouette::TimeTablePeriod,Chouette::Footnote,Chouette::Network,Chouette::Company,Chouette::StopPoint,Chouette::StopArea' filename='offer_datas' title='Offer Datas'"      sh "bundle exec rake erd only='Organisation,Referential,User,Workbench' filename='organisation' title='Organisation'" +    sh "bundle exec rake erd only='Calendar,Referential,Chouette::Line,Chouette::Route,Chouette::JourneyPattern,Chouette::VehicleJourney,Chouette::VehicleJourneyAtStop,Chouette::TimeTable,Chouette::TimeTableDate,Chouette::TimeTablePeriod,Chouette::Footnote,Chouette::Network,Chouette::Company,Chouette::StopPoint,Chouette::StopArea' filename='offer_datas' title='Offer Datas'" +    sh "bundle exec rake erd only='Organisation,StopAreaReferential,StopAreaReferentialSync,StopAreaReferentialSyncMessage,StopAreaReferentialMembership,LineReferential,LineReferentialSync,LineReferentialSyncMessage,LineReferentialMembership' filename='referentiels_externes' title='Référentiels externes'" +    sh "bundle exec rake erd only='NetexImport,Import,WorkbenchImport,ImportResource,ImportMessage' filename='import' title='Import'" +    #sh "bundle exec rake erd only='' filename='validation' title='Validation'" +    #sh "bundle exec rake erd only='VehicleJourney,VehicleJourneyExport' filename='export' title='Export'" +    #sh "bundle exec rake erd only='' filename='intégration' title='Integration'" +    #sh "bundle exec rake erd only='' filename='fusion' title='Fusion'" +    #sh "bundle exec rake erd only='' filename='publication' title='Publication'"    end  end diff --git a/spec/factories/chouette_access_points.rb b/spec/factories/chouette_access_points.rb index 06d1da779..38ad76363 100644 --- a/spec/factories/chouette_access_points.rb +++ b/spec/factories/chouette_access_points.rb @@ -5,7 +5,7 @@ FactoryGirl.define do      longitude {10.0 * rand}      sequence(:name) { |n| "AccessPoint #{n}" }      access_type "InOut" -    sequence(:objectid) { |n| "test:AccessPoint:#{n}" } +    sequence(:objectid) { |n| "FR:#{n}:ADL:#{n}:STIF" }      association :stop_area, :factory => :stop_area    end diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb index 24b182b83..423ab99f2 100644 --- a/spec/factories/chouette_lines.rb +++ b/spec/factories/chouette_lines.rb @@ -2,7 +2,7 @@ FactoryGirl.define do    factory :line, :class => Chouette::Line do      sequence(:name) { |n| "Line #{n}" } -    sequence(:objectid) { |n| "chouette:test:Line:#{n}" } +    sequence(:objectid) { |n| "STIF:CODIFLIGNE:Line:#{n}" }      sequence(:transport_mode) { |n| "bus" }      sequence(:number, 1) diff --git a/spec/factories/chouette_stop_areas.rb b/spec/factories/chouette_stop_areas.rb index 8e92b024b..8b64c227b 100644 --- a/spec/factories/chouette_stop_areas.rb +++ b/spec/factories/chouette_stop_areas.rb @@ -1,6 +1,6 @@  FactoryGirl.define do    factory :stop_area, :class => Chouette::StopArea do -    sequence(:objectid) { |n| "test:StopArea:#{n}" } +    sequence(:objectid) { |n| "FR:#{n}:ZDE:#{n}:STIF" }      sequence(:name) { |n| "stop_area_#{n}" }      sequence(:registration_number) { |n| "test-#{n}" }      area_type { Chouette::StopArea.area_type.values.sample } diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb index 02b1621e3..e0f4b1501 100644 --- a/spec/models/chouette/access_point_spec.rb +++ b/spec/models/chouette/access_point_spec.rb @@ -1,10 +1,11 @@  require 'spec_helper'  describe Chouette::AccessPoint, :type => :model do +  subject { create(:access_point) }    describe '#objectid' do      subject { super().objectid } -    it { is_expected.to be_kind_of(Chouette::ObjectId) } +    it { is_expected.to be_kind_of(Chouette::StifReflexObjectid) }    end    it { is_expected.to validate_presence_of :name } @@ -109,7 +110,6 @@ describe Chouette::AccessPoint, :type => :model do    end    describe "#to_lat_lng" do -      it "should return nil if latitude is nil" do        subject.latitude = nil        expect(subject.to_lat_lng).to be_nil @@ -123,12 +123,13 @@ describe Chouette::AccessPoint, :type => :model do    end    describe "#geometry" do +    let(:access_point) { create(:access_point) }      it "should be nil when to_lat_lng is nil" do -      allow(subject).to receive_messages :to_lat_lng => nil -      expect(subject.geometry).to be_nil +      allow(access_point).to receive_messages :longitude => nil +      allow(access_point).to receive_messages :latitude => nil +      expect(access_point.geometry).to be_nil      end -    end    describe "#generic_access_link_matrix" do diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index 293ae5202..a3a398bfb 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -1,9 +1,9 @@  require 'spec_helper'  describe Chouette::StopArea, :type => :model do -  # FIXME !!!!!!!! +  subject { create(:stop_area) } +    let!(:quay) { create :stop_area, :area_type => "zdep" } -  # let!(:boarding_position) { create :stop_area, :area_type => "BoardingPosition" }    let!(:commercial_stop_point) { create :stop_area, :area_type => "lda" }    let!(:stop_place) { create :stop_area, :area_type => "zdlp" } diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 304cb0184..f13e13d52 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -52,20 +52,19 @@ describe Chouette::TimeTable, :type => :model do        expect(subject.int_day_types).to eq int_day_types      end -    it 'should merge date in_out false' do +    it 'should not merge date in_out false' do        another_tt.dates.last.in_out = false        another_tt.save        subject.merge!(another_tt) -      expect(subject.dates.map(&:date)).to include(another_tt.dates.last.date) +      expect(subject.dates.map(&:date)).not_to include(another_tt.dates.last.date)      end -    it 'should remove date in_out false if other tt doesnt have them' do +    it 'should remove all date in_out false' do        subject.dates.create(in_out: false, date: Date.today + 5.day + 1.year) - -      expect { -        subject.merge!(another_tt) -      }.to change {subject.reload.excluded_days.count}.by(-1) +      another_tt.dates.last.in_out = false +      subject.merge!(another_tt) +      expect(subject.reload.excluded_days.count).to eq(0)      end    end diff --git a/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb index c30e0dbd8..d0a15788d 100644 --- a/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb @@ -13,7 +13,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do          subject.vehicle_journey_at_stops[1].departure_time      end -    it "should make instance invalid if departure time exceeds gap" do +    it "should make instance invalid if departure time exceeds gap", :skip => "Time gap validation is in pending status" do        subject.validate        expect( @@ -31,7 +31,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do      let(:vjas2) { vehicle_journey.vehicle_journey_at_stops[1] }      context "when vjas#arrival_time exceeds gap" do -      it "should add errors on arrival_time" do +      it "should add errors on arrival_time", :skip => "Time gap validation is in pending status" do          vjas1.arrival_time = vjas2.arrival_time - 5.hour          expect(            Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator @@ -43,7 +43,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do      end      context "when vjas#departure_time exceeds gap" do -      it "should add errors on departure_time" do +      it "should add errors on departure_time", :skip => "Time gap validation is in pending status" do          vjas1.departure_time = vjas2.departure_time - 5.hour          expect(            Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator @@ -55,7 +55,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do      end      context "when vjas doesn't exceed gap" do -      it "should not add errors" do +      it "should not add errors", :skip => "Time gap validation is in pending status" do          expect(            Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator              .validate_at_stop_times_must_increase(vjas2, vjas1) diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 645513735..3c04a77cc 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -558,18 +558,18 @@ describe Chouette::VehicleJourney, :type => :model do              "0"=>{"id" => subject.vehicle_journey_at_stops[0].id ,"arrival_time" => 1.minutes.ago,"departure_time" => 1.minutes.ago},              "1"=>{"id" => subject.vehicle_journey_at_stops[1].id, "arrival_time" => (1.minutes.ago + 4.hour),"departure_time" => (1.minutes.ago + 4.hour)}           }}} -      it "should return false" do +      it "should return false", :skip => "Time gap validation is in pending status" do          expect(subject.update_attributes(params)).to be_falsey        end -      it "should make instance invalid" do +      it "should make instance invalid", :skip => "Time gap validation is in pending status" do          subject.update_attributes(params)          expect(subject).not_to be_valid        end -      it "should let first vjas without any errors" do +      it "should let first vjas without any errors", :skip => "Time gap validation is in pending status" do          subject.update_attributes(params)          expect(subject.vehicle_journey_at_stops[0].errors).to be_empty        end -      it "should add an error on second vjas" do +      it "should add an error on second vjas", :skip => "Time gap validation is in pending status" do          subject.update_attributes(params)          expect(subject.vehicle_journey_at_stops[1].errors[:departure_time]).not_to be_blank        end diff --git a/spec/models/time_table_combination_spec.rb b/spec/models/time_table_combination_spec.rb index ee934f50d..81f9dd7a6 100644 --- a/spec/models/time_table_combination_spec.rb +++ b/spec/models/time_table_combination_spec.rb @@ -44,60 +44,6 @@ describe TimeTableCombination, :type => :model do      end    end -  describe '#continuous_periods' do -    it 'should group continuous periods' do -      source.periods.clear - -      start_date = Date.today + 1.year -      end_date = start_date + 10 - -      # 6 more continuous dates, 2 isolated dates -      0.upto(4) do |i| -        source.periods.create(period_start: start_date, period_end: end_date) -        start_date = end_date + 1 -        end_date = start_date + 10 -      end - -      expect(source.reload.continuous_periods.flatten.count).to eq(5) -    end -  end - -  describe '#convert_continuous_periods_into_one' do -    it 'should convert continuous periods into one' do -      source.periods.clear - -      start_date = Date.today + 1.year -      end_date = start_date + 10 - -      # 6 more continuous dates, 2 isolated dates -      0.upto(4) do |i| -        source.periods.create(period_start: start_date, period_end: end_date) -        start_date = end_date + 1 -        end_date = start_date + 10 -      end - -      expect { -        source.reload.convert_continuous_periods_into_one -      }.to change {source.periods.count}.by(-4) -    end -  end - -  describe '#optimize_continuous_dates_and_periods' do -    it 'should update period if timetable has in_date just before or after ' do -      source.dates.clear -      source.periods.clear - -      source.periods.create(period_start: Date.today, period_end: Date.today + 10.day) -      source.dates.create(date: Date.today - 1.day, in_out: true) - -      expect { -        source.periods = source.optimize_continuous_dates_and_periods -      }.to change {source.dates.count}.by(-1) - -      expect(source.reload.periods.first.period_start).to eq(Date.today - 1.day) -    end -  end -    describe "#combine" do      context "when operation is union" do        before(:each) do diff --git a/spec/models/vehicle_journey_import_spec.rb b/spec/models/vehicle_journey_import_spec.rb index a743bdecb..b01523dd9 100644 --- a/spec/models/vehicle_journey_import_spec.rb +++ b/spec/models/vehicle_journey_import_spec.rb @@ -11,16 +11,16 @@ describe VehicleJourneyImport, :type => :model do          if counter == 0            row2 = []            row.each do |cell| -            cell = vehicle_journey1.id.to_s if cell == "import:VehicleJourney:1"  -            cell = vehicle_journey2.id.to_s if cell == "import:VehicleJourney:2"  -            cell = vehicle_journey3.id.to_s if cell == "import:VehicleJourney:3"  +            cell = vehicle_journey1.id.to_s if cell == "import:VehicleJourney:1" +            cell = vehicle_journey2.id.to_s if cell == "import:VehicleJourney:2" +            cell = vehicle_journey3.id.to_s if cell == "import:VehicleJourney:3"              row2 << cell            end            csv << row2          elsif  counter < 8            csv << row          else -          csv << ( row[0] = route.stop_points[counter - 8].id; row)           +          csv << ( row[0] = route.stop_points[counter - 8].id; row)          end          counter += 1        end @@ -29,7 +29,7 @@ describe VehicleJourneyImport, :type => :model do      File.open("/tmp/#{filename}")    end -   +    let!(:route) { create(:route) }    let!(:other_route) { create(:route) } @@ -39,14 +39,14 @@ describe VehicleJourneyImport, :type => :model do    let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:1", :route_id => route.id, :journey_pattern_id => journey_pattern.id) }    let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:2", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) }    let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:3", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } -   +    let!(:stop_point0) { route.stop_points[0] }    let!(:stop_point1) { route.stop_points[1] }    let!(:stop_point2) { route.stop_points[2] }    let!(:stop_point3) { route.stop_points[3] }    let!(:stop_point4) { route.stop_points[4] } -   +    # Must use uploaded file and not classical ruby File!    let(:valid_file) {      csv_file = update_csv_file_with_factory_data("vehicle_journey_imports_valid.csv") @@ -67,8 +67,8 @@ describe VehicleJourneyImport, :type => :model do      csv_file = update_csv_file_with_factory_data("vehicle_journey_imports_with_vjas_bad_order.csv")      double("CSV", :tempfile => csv_file, :original_filename => File.basename(csv_file), :path => File.path(csv_file) )    } -   -  subject { VehicleJourneyImport.new(:route => route, :file => valid_file) }  + +  subject { VehicleJourneyImport.new(:route => route, :file => valid_file) }    describe ".save" do @@ -86,33 +86,33 @@ describe VehicleJourneyImport, :type => :model do        expect(Chouette::VehicleJourneyAtStop.all.size).to eq(17)      end -    it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order" do       +    it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order", :skip => "Time gap validation is in pending status" do              expect(VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas_object).save).to be_falsey        expect(Chouette::VehicleJourney.all.size).to eq(3)        expect(Chouette::VehicleJourneyAtStop.all.size).to eq(0)      end -     +      # it "should not import vehicle_journeys and not create objects with invalid file" do      #   expect(VehicleJourneyImport.new(:file => invalid_file_on_vj, :route => route).save).to be_false      #   expect(Chouette::VehicleJourney.all.size).to eq(3)      #   expect(Chouette::VehicleJourneyAtStop.all.size).to eq(0)      # end -     +    end -  describe ".find_journey_pattern_schedule" do    +  describe ".find_journey_pattern_schedule" do -    it "should return journey pattern with same stop points" do           +    it "should return journey pattern with same stop points" do        expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => "9:10", stop_point3.id => "9:15", stop_point4.id => "9:20"} )).to eq(journey_pattern)        expect(subject.find_journey_pattern_schedule( 1, { stop_point1.id => "9:00", stop_point3.id => "9:10" } )).to eq(other_journey_pattern)      end -    it "should return new journey_pattern if no journey pattern with same stop points is founded" do       +    it "should return new journey_pattern if no journey pattern with same stop points is founded" do        expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => nil, stop_point3.id => "9:15", stop_point4.id => "9:20"} )).to be_truthy        expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => nil, stop_point3.id => "9:15", stop_point4.id => "9:20"} ).id).not_to eq(journey_pattern.id)        expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => nil, stop_point3.id => "9:15", stop_point4.id => "9:20"} ).id).not_to eq(other_journey_pattern.id)      end -     +    end    describe ".load_imported_vehicle_journeys" do @@ -122,30 +122,30 @@ describe VehicleJourneyImport, :type => :model do        expect { vehicle_journey_import.load_imported_vehicle_journeys }.to raise_error(RuntimeError)      end -    # it "should return errors when vehicle journeys in file are invalid" do             +    # it "should return errors when vehicle journeys in file are invalid" do      #   vehicle_journey_import = VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vj) -       +      #   expect { vehicle_journey_import.load_imported_vehicle_journeys }.to raise_error      # end -    it "should return errors when vehicle journey at stops in file are invalid" do            +    it "should return errors when vehicle journey at stops in file are invalid" do        vehicle_journey_import = VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas)        expect { vehicle_journey_import.load_imported_vehicle_journeys }.to raise_error(ArgumentError)      end -    it "should return errors when vehicle journey at stops are not in ascendant order" do     +    it "should return errors when vehicle journey at stops are not in ascendant order" do        vehicle_journey_import = VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas_object)        expect(vehicle_journey_import.load_imported_vehicle_journeys.size).to eq(3)        expect(vehicle_journey_import.errors.messages).to be_empty      end -     +      it "should load vehicle journeys" do        expect(subject.load_imported_vehicle_journeys.size).to eq(4)        expect(subject.errors.messages).to eq({})      end -     +    end -   -   + +  end | 
