diff options
| author | Robert | 2017-06-28 14:57:46 +0200 |
|---|---|---|
| committer | Robert | 2017-06-28 14:57:46 +0200 |
| commit | f64246b8272a35731b3edba243b8d8e1898df1de (patch) | |
| tree | f0cee935671238a16781711ac1e7bffdf6afd384 | |
| parent | 74f5fb8bfb960df1bf670324566dc315b91c5291 (diff) | |
| parent | fc7ef3fe160703ba5c7d5a265d68d990b024b235 (diff) | |
| download | chouette-core-f64246b8272a35731b3edba243b8d8e1898df1de.tar.bz2 | |
Merge branch 'master' of github.com:af83/stif-boiv
10 files changed, 95 insertions, 115 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js index 1a6c67b6b..a8a92c522 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js @@ -61,30 +61,30 @@ const PeriodForm = ({modal, timetable, metas, onOpenAddPeriodForm, onClosePeriod <div className="nested-fields"> <div className="wrapper"> <div> - <div className={'form-group date' + (modal.modalProps.error ? ' has-error' : '')}> + <div className={'form-group date smart_date' + (modal.modalProps.error ? ' has-error' : '')}> <div className="form-inline"> - <select value={formatNumber(modal.modalProps.begin.day)} onChange={(e) => onUpdatePeriodForm(e.currentTarget.value, 'begin', 'day')} id="q_validity_period_begin_gteq_3i" className="date required form-control"> + <select value={formatNumber(modal.modalProps.begin.day)} onChange={(e) => onUpdatePeriodForm(e, 'begin', 'day')} id="q_validity_period_begin_gteq_3i" className="date required form-control"> {makeDaysOptions(modal.modalProps.begin.day)} </select> - <select value={formatNumber(modal.modalProps.begin.month)} onChange={(e) => onUpdatePeriodForm(e.currentTarget.value, 'begin', 'month')} id="q_validity_period_begin_gteq_2i" className="date required form-control"> + <select value={formatNumber(modal.modalProps.begin.month)} onChange={(e) => onUpdatePeriodForm(e, 'begin', 'month')} id="q_validity_period_begin_gteq_2i" className="date required form-control"> {makeMonthsOptions(modal.modalProps.begin.month)} </select> - <select value={modal.modalProps.begin.year} onChange={(e) => onUpdatePeriodForm(e.currentTarget.value, 'begin', 'year')} id="q_validity_period_begin_gteq_1i" className="date required form-control"> + <select value={modal.modalProps.begin.year} onChange={(e) => onUpdatePeriodForm(e, 'begin', 'year')} id="q_validity_period_begin_gteq_1i" className="date required form-control"> {makeYearsOptions(modal.modalProps.begin.year)} </select> </div> </div> </div> <div> - <div className={'form-group date' + (modal.modalProps.error ? ' has-error' : '')}> + <div className={'form-group date smart_date' + (modal.modalProps.error ? ' has-error' : '')}> <div className="form-inline"> - <select value={formatNumber(modal.modalProps.end.day)} onChange={(e) => onUpdatePeriodForm(e.currentTarget.value, 'end', 'day')} id="q_validity_period_end_gteq_3i" className="date required form-control"> + <select value={formatNumber(modal.modalProps.end.day)} onChange={(e) => onUpdatePeriodForm(e, 'end', 'day')} id="q_validity_period_end_gteq_3i" className="date required form-control"> {makeDaysOptions(modal.modalProps.end.day)} </select> - <select value={formatNumber(modal.modalProps.end.month)} onChange={(e) => onUpdatePeriodForm(e.currentTarget.value, 'end', 'month')} id="q_validity_period_end_gteq_2i" className="date required form-control"> + <select value={formatNumber(modal.modalProps.end.month)} onChange={(e) => onUpdatePeriodForm(e, 'end', 'month')} id="q_validity_period_end_gteq_2i" className="date required form-control"> {makeMonthsOptions(modal.modalProps.end.month)} </select> - <select value={modal.modalProps.end.year} onChange={(e) => onUpdatePeriodForm(e.currentTarget.value, 'end', 'year')} id="q_validity_period_end_gteq_1i" className="date required form-control"> + <select value={modal.modalProps.end.year} onChange={(e) => onUpdatePeriodForm(e, 'end', 'year')} id="q_validity_period_end_gteq_1i" className="date required form-control"> {makeYearsOptions(modal.modalProps.end.year)} </select> </div> diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js b/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js index b6004c7f1..a7edbc328 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js +++ b/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js @@ -18,8 +18,10 @@ const mapDispatchToProps = (dispatch) => { onClosePeriodForm: () => { dispatch(actions.closePeriodForm()) }, - onUpdatePeriodForm: (val, group, selectType) => { - dispatch(actions.updatePeriodForm(val, group, selectType)) + onUpdatePeriodForm: (e, group, selectType) => { + dispatch(actions.updatePeriodForm(e.currentTarget.value, group, selectType)) + let selector = '#q_validity_period_' + group + '_gteq_3i' + dispatch(actions.updatePeriodForm($(selector).val(), group, 'day')) }, onValidatePeriodForm: (modalProps, timeTablePeriods, metas) => { dispatch(actions.validatePeriodForm(modalProps, timeTablePeriods, metas)) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/ShiftVehicleJourney.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/ShiftVehicleJourney.js index ee7d01cf5..2164344c2 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/ShiftVehicleJourney.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/ShiftVehicleJourney.js @@ -40,7 +40,7 @@ class ShiftVehicleJourney extends Component { <div className='modal-header'> <h4 className='modal-title'>Mettre à jour une course</h4> {(this.props.modal.type == 'shift') && ( - <em>Mettre à jour les horaires de la course {actions.getSelected(this.props.vehicleJourneys)[0].objectid}</em> + <em>Mettre à jour les horaires de la course {actions.humanOID(actions.getSelected(this.props.vehicleJourneys)[0].objectid)}</em> )} </div> @@ -57,6 +57,7 @@ class ShiftVehicleJourney extends Component { min='-59' max='59' className='form-control' + defaultValue='0' onKeyDown={(e) => actions.resetValidation(e.currentTarget)} required /> diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js index 09588f824..b4a70ec08 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js @@ -15,7 +15,7 @@ const filters = (state = {}, action) => { minute: '59' } } - newQuery = _.assign({}, state.query, {interval: interval, journeyPattern: {}, vehicleJourney: {}, timetable: {}, withoutSchedule: true, withoutTimeTable: false }) + newQuery = _.assign({}, state.query, {interval: interval, journeyPattern: {}, vehicleJourney: {}, timetable: {}, withoutSchedule: true, withoutTimeTable: true }) return _.assign({}, state, {query: newQuery, queryString: ''}) case 'TOGGLE_WITHOUT_SCHEDULE': newQuery = _.assign({}, state.query, {withoutSchedule: !state.query.withoutSchedule}) diff --git a/app/assets/javascripts/smart_date.coffee b/app/assets/javascripts/smart_date.coffee index 7ea634a19..8e416de82 100644 --- a/app/assets/javascripts/smart_date.coffee +++ b/app/assets/javascripts/smart_date.coffee @@ -1,15 +1,15 @@ -legalDaysPerMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] +window.legalDaysPerMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] -isLeapYear = (year) -> +window.isLeapYear = (year) -> (year % 4 == 0) && ((year % 400 == 0) || (year % 100 != 0)) -correctDay = (dateValues) -> +window.correctDay = (dateValues) -> [day, month, year] = dateValues return day if legalDaysPerMonth[month-1] >= day return 29 if day == 29 && isLeapYear(year) legalDaysPerMonth[month-1] -smartCorrectDate = -> +window.smartCorrectDate = -> allSelectors = $(@).parent().children('select') # N'a pas un sibbling('select', include_self = true) ? allVals = allSelectors.map (index, sel) -> parseInt($(sel).val()) diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass index e3a33e131..20679a3ba 100644 --- a/app/assets/stylesheets/components/_tables.sass +++ b/app/assets/stylesheets/components/_tables.sass @@ -296,6 +296,9 @@ border-right: 1px solid rgba($grey, 0.5) .th + > div + min-height: 19px + > *:first-child padding-right: 30px diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 4186af6d2..c566452f4 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -477,63 +477,22 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord # merge effective days from another timetable def merge!(another_tt) transaction do - # merge dates - self.dates ||= [] - another_tt.included_days.each do |d| - add_included_day d - end + self.periods = another_tt.clone_periods + self.periods + self.periods = self.optimize_periods - # if one tt has no period, just merge lists - if self.periods.empty? || another_tt.periods.empty? - if !another_tt.periods.empty? - # copy periods - self.periods = another_tt.clone_periods - end - else - # check if periods can be kept - common_day_types = self.int_day_types & another_tt.int_day_types & 508 - # if common day types : merge periods - if common_day_types != 0 - periods = self.optimize_periods - another_periods = another_tt.optimize_periods - # add not common days of both periods as peculiar days - self.effective_days_of_periods(self.class.valid_days(self.int_day_types ^ common_day_types)).each do |d| - self.dates |= [Chouette::TimeTableDate.new(:date => d, :in_out => true)] - end - another_tt.effective_days_of_periods(self.class.valid_days(another_tt.int_day_types ^ common_day_types)).each do |d| - add_included_day d - end - # merge periods - self.periods = periods | another_periods - self.int_day_types = common_day_types - self.periods = self.optimize_periods - else - # convert all period in days - self.effective_days_of_periods.each do |d| - self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) unless self.include_in_dates?(d) - end - another_tt.effective_days_of_periods.each do |d| - add_included_day d + # For included dates + another_tt.included_days.map{ |d| add_included_day(d) } + + # For excluded dates + existing_out_date = self.dates.where(in_out: false).map(&:date) + another_tt.dates.where(in_out: false).each do |d| + unless existing_out_date.include?(d.date) + self.dates << Chouette::TimeTableDate.new(:date => d.date, :in_out => false) end end - end - # if remained excluded dates are valid in other tt , remove it from result - self.dates.each do |date| - date.in_out = true if date.in_out == false && another_tt.include_day?(date.date) + self.save! end - # if peculiar dates are valid in new periods, remove them - if !self.periods.empty? - days_in_period = self.effective_days_of_periods - dates = [] - self.dates.each do |date| - dates << date unless date.in_out && days_in_period.include?(date.date) - end - self.dates = dates - end - self.dates.to_a.sort! { |a,b| a.date <=> b.date} - self.save! - end self.convert_continuous_dates_to_periods end diff --git a/app/views/routing_constraint_zones/_filters.html.slim b/app/views/routing_constraint_zones/_filters.html.slim index 18ef40d61..07d351b1f 100644 --- a/app/views/routing_constraint_zones/_filters.html.slim +++ b/app/views/routing_constraint_zones/_filters.html.slim @@ -9,7 +9,7 @@ .ffg-row .form-group = f.label 'Itinéraire associé', required: false, class: 'control-label' - = f.input :route_id, as: :select, collection: @line.routing_constraint_zones.pluck(:route_id), label: false, label_method: lambda {|r| @line.routing_constraint_zones.find_by(route_id: r).route_name}, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Indiquez un itinéraire...' }, wrapper_html: { class: 'select2ed'} + = f.input :route_id_eq, as: :select, collection: @line.routing_constraint_zones.pluck(:route_id).uniq, label: false, label_method: lambda { |r| @line.routing_constraint_zones.find_by(route_id: r).route_name }, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Indiquez un itinéraire...' }, wrapper_html: { class: 'select2ed'} .actions = link_to 'Effacer', referential_line_routing_constraint_zones_path(@referential, @line), class: 'btn btn-link' diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index 2ab88386a..0a6729c8b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -31,7 +31,7 @@ describe('filters reducer', () => { vehicleJourney: {}, timetable: {}, withoutSchedule: true, - withoutTimeTable: false + withoutTimeTable: true }, queryString: '' } @@ -153,7 +153,7 @@ describe('filters reducer', () => { "&q%5Bvehicle_journey_at_stops_departure_time_gteq%5D=11%3A11", "&q%5Bvehicle_journey_at_stops_departure_time_lteq%5D=22%3A22", "&q%5Bvehicle_journey_without_departure_time%5D=true", - "&q%5Bvehicle_journey_without_time_table%5D=false" + "&q%5Bvehicle_journey_without_time_table%5D=true" ].join('') expect( diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 7a8863cb3..76c5def5c 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -2,18 +2,74 @@ require 'spec_helper' describe Chouette::TimeTable, :type => :model do subject { create(:time_table) } + let(:subject_periods_to_range) { subject.periods.map{|p| p.period_start..p.period_end } } it { is_expected.to validate_presence_of :comment } it { is_expected.to validate_uniqueness_of :objectid } - context "merge with calendar" do - let(:calendar) { create(:calendar) } + describe "#merge! with time_table" do + let(:another_tt) { create(:time_table) } + let(:another_tt_periods_to_range) { another_tt.periods.map{|p| p.period_start..p.period_end } } + + # Make sur we don't have overlapping periods or dates + before do + another_tt.periods.each do |p| + p.period_start = p.period_start + 1.year + p.period_end = p.period_end + 1.year + end + another_tt.dates.each{| d| d.date = d.date + 1.year } + end + + it 'should merge dates' do + subject.dates.clear + subject.merge!(another_tt) + expect(subject.dates.map(&:date)).to include(*another_tt.dates.map(&:date)) + end + + it 'should merge periods' do + subject.periods.clear + subject.merge!(another_tt) + + expect(subject_periods_to_range).to include(*another_tt_periods_to_range) + end + + it 'should not modify int_day_types' do + int_day_types = subject.int_day_types + subject.merge!(another_tt) + expect(subject.int_day_types).to eq int_day_types + end + + it 'should 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) + end + end + + context "#merge! with calendar" do + let(:calendar) { create(:calendar, date_ranges: [Date.today + 1.year..Date.tomorrow + 1.year]) } - it 'should add calendar dates to time_table' do + it 'should merge calendar dates' do subject.dates.clear subject.merge!(calendar.convert_to_time_table) expect(subject.dates.map(&:date)).to include(*calendar.dates) end + + it 'should merge calendar periods with no periods in source' do + subject.periods.clear + another_tt = calendar.convert_to_time_table + subject.merge!(another_tt) + expect(subject_periods_to_range).to include(*calendar.date_ranges) + end + + it 'should add calendar periods with existing periods in source' do + another_tt = calendar.convert_to_time_table + subject.merge!(another_tt) + + expect(subject_periods_to_range).to include(*calendar.date_ranges) + end end describe "actualize" do @@ -981,47 +1037,6 @@ end end end - - describe "#merge!" do - context "timetables have periods with common day_types " do - before do - subject.periods.clear - subject.dates.clear - subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,5)) - subject.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,6,30), :period_end => Date.new(2014,7,6)) - subject.dates << Chouette::TimeTableDate.new( :date => Date.new(2014,7,16), :in_out => true) - subject.int_day_types = 4|16|32|128 - another_tt = create(:time_table , :int_day_types => (4|16|64|128) ) - another_tt.periods.clear - another_tt.dates.clear - another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,5), :period_end => Date.new(2014,8,12)) - another_tt.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,7,15), :period_end => Date.new(2014,7,25)) - subject.merge! another_tt - subject.reload - end - it "should have merged periods" do - expect(subject.periods.size).to eq(3) - expect(subject.periods[0].period_start).to eq(Date.new(2014, 6, 30)) - expect(subject.periods[0].period_end).to eq(Date.new(2014, 7, 6)) - expect(subject.periods[1].period_start).to eq(Date.new(2014, 7, 15)) - expect(subject.periods[1].period_end).to eq(Date.new(2014, 7, 25)) - expect(subject.periods[2].period_start).to eq(Date.new(2014, 8, 1)) - expect(subject.periods[2].period_end).to eq(Date.new(2014, 8, 12)) - end - it "should not modify day_types" do - expect(subject.int_day_types).to eq(4|16|128) - end - it "should have dates for thursdays and fridays" do - expect(subject.dates.size).to eq(4) - expect(subject.dates[0].date).to eq(Date.new(2014,7,3)) - expect(subject.dates[1].date).to eq(Date.new(2014,7,18)) - expect(subject.dates[2].date).to eq(Date.new(2014,7,25)) - expect(subject.dates[3].date).to eq(Date.new(2014,8,8)) - end - end - - end - describe "#intersect!" do context "timetables have periods with common day_types " do before do |
