diff options
| author | cedricnjanga | 2017-09-20 12:00:45 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-09-20 12:00:45 +0200 |
| commit | ce579b6fe5edb8f462de45a84ab7f4affe1b525a (patch) | |
| tree | f7f6827020695a61902077e06ce87d22f666ee12 | |
| parent | d0703700f5b5e663739e9897c04c2136c953fa7e (diff) | |
| download | chouette-core-ce579b6fe5edb8f462de45a84ab7f4affe1b525a.tar.bz2 | |
Merge master to branch and resolve all the conflicts
We also needed to take remove the right time table dates when we update day types :
- excluded dates that are out of day types
- included dates that are in day types and in periods
3 files changed, 48 insertions, 31 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js index a6add8418..761c29ba3 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -169,7 +169,6 @@ const actions = { let date = new Date(strDate) return date.toLocaleDateString() }, - updateSynthesis: (state, daytypes) => { let periods = state.time_table_periods @@ -206,6 +205,17 @@ const actions = { }) return improvedCM }, + isInPeriod: (periods, date) => { + date = new Date(date) + + for (let period of periods) { + let begin = new Date(period.period_start) + let end = new Date(period.period_end) + if (date >= begin && date <= end) return true + } + + return false + }, updateExcludedDates: (period_start, period_end, dates) => { // We remove excluded dates which was in the updated/deleted period let begin = new Date(period_start) diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js index d61c813ec..dcdee6f9b 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js +++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js @@ -42,47 +42,35 @@ const timetable = (state = {}, action) => { let deletedPeriod = state.time_table_periods[action.index] newDates = actions.updateExcludedDates(deletedPeriod.period_start, deletedPeriod.period_end, state.time_table_dates) newState = _.assign({}, state, {time_table_periods : newPeriods, time_table_dates: newDates}) - return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)}) + return _.assign({}, newState, { current_month: actions.updateSynthesis(newState, action.dayTypes)}) case 'ADD_INCLUDED_DATE': newDates = state.time_table_dates.concat({date: action.date, in_out: true}) newCM = state.current_month.map((d, i) => { - if (i == action.index){ - d.include_date = true - } + if (i == action.index) d.include_date = true return d }) - newState = _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) - return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)}) + return _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) case 'REMOVE_INCLUDED_DATE': newDates = _.reject(state.time_table_dates, ['date', action.date]) newCM = state.current_month.map((d, i) => { - if (i == action.index){ - d.include_date = false - } + if (i == action.index) d.include_date = false return d }) - newState = _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) - return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)}) + return _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) case 'ADD_EXCLUDED_DATE': newDates = state.time_table_dates.concat({date: action.date, in_out: false}) newCM = state.current_month.map((d, i) => { - if (i == action.index){ - d.excluded_date = true - } + if (i == action.index) d.excluded_date = true return d }) - newState = _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) - return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)}) + return _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) case 'REMOVE_EXCLUDED_DATE': newDates = _.reject(state.time_table_dates, ['date', action.date]) newCM = state.current_month.map((d, i) => { - if (i == action.index){ - d.excluded_date = false - } + if (i == action.index) d.excluded_date = false return d }) - newState = _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) - return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)}) + return _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) case 'UPDATE_DAY_TYPES': // We get the week days of the activated day types to reject the out_dates that that are out of newDayTypes let weekDays = _.reduce(action.dayTypes, (array, dt, i) => { @@ -91,7 +79,11 @@ const timetable = (state = {}, action) => { }, []) newDates = _.reject(state.time_table_dates, (d) => { - return d.in_out == false && !weekDays.includes(new Date(d.date).getDay()) + let weekDay = new Date(d.date).getDay() + let excludedDatesToRemove = d.in_out == false && !weekDays.includes(weekDay) + let includedDatesToRemove = d.in_out == true && actions.isInPeriod(state.time_table_periods, d.date) && weekDays.includes(weekDay) + + return excludedDatesToRemove || includedDatesToRemove }) return _.assign({}, state, {time_table_dates: newDates}) case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES': diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js index 99dfa9c0d..21f6d236d 100644 --- a/spec/javascripts/time_table/reducers/timetable_spec.js +++ b/spec/javascripts/time_table/reducers/timetable_spec.js @@ -6,6 +6,7 @@ const dispatch = function(){} let arrDayTypes = [true, true, true, true, true, true, true] let strDayTypes = 'LuMaMeJeVeSaDi' let time_table_periods = [{"id":261,"period_start":"2017-02-23","period_end":"2017-03-05"},{"id":262,"period_start":"2017-03-15","period_end":"2017-03-25"},{"id":263,"period_start":"2017-04-04","period_end":"2017-04-14"},{"id":264,"period_start":"2017-04-24","period_end":"2017-05-04"},{"id":265,"period_start":"2017-05-14","period_end":"2017-05-24"}] +let time_table_dates = [] let current_periode_range = "2017-05-01" let periode_range = ["2014-05-01","2014-06-01","2014-07-01","2014-08-01","2014-09-01","2014-10-01","2014-11-01","2014-12-01","2015-01-01","2015-02-01","2015-03-01","2015-04-01","2015-05-01","2015-06-01","2015-07-01","2015-08-01","2015-09-01","2015-10-01","2015-11-01","2015-12-01","2016-01-01","2016-02-01","2016-03-01","2016-04-01","2016-05-01","2016-06-01","2016-07-01","2016-08-01","2016-09-01","2016-10-01","2016-11-01","2016-12-01","2017-01-01","2017-02-01","2017-03-01","2017-04-01","2017-05-01","2017-06-01","2017-07-01","2017-08-01","2017-09-01","2017-10-01","2017-11-01","2017-12-01","2018-01-01","2018-02-01","2018-03-01","2018-04-01","2018-05-01","2018-06-01","2018-07-01","2018-08-01","2018-09-01","2018-10-01","2018-11-01","2018-12-01","2019-01-01","2019-02-01","2019-03-01","2019-04-01","2019-05-01","2019-06-01","2019-07-01","2019-08-01","2019-09-01","2019-10-01","2019-11-01","2019-12-01","2020-01-01","2020-02-01","2020-03-01","2020-04-01","2020-05-01"] let current_month = [{"day":"lundi","date":"2017-05-01","wday":1,"wnumber":"18","mday":1,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-02","wday":2,"wnumber":"18","mday":2,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-03","wday":3,"wnumber":"18","mday":3,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-04","wday":4,"wnumber":"18","mday":4,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-05","wday":5,"wnumber":"18","mday":5,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-06","wday":6,"wnumber":"18","mday":6,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-07","wday":0,"wnumber":"18","mday":7,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-08","wday":1,"wnumber":"19","mday":8,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-09","wday":2,"wnumber":"19","mday":9,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-10","wday":3,"wnumber":"19","mday":10,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-11","wday":4,"wnumber":"19","mday":11,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-12","wday":5,"wnumber":"19","mday":12,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-13","wday":6,"wnumber":"19","mday":13,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-14","wday":0,"wnumber":"19","mday":14,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-15","wday":1,"wnumber":"20","mday":15,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-16","wday":2,"wnumber":"20","mday":16,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-17","wday":3,"wnumber":"20","mday":17,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-18","wday":4,"wnumber":"20","mday":18,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-19","wday":5,"wnumber":"20","mday":19,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-20","wday":6,"wnumber":"20","mday":20,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-21","wday":0,"wnumber":"20","mday":21,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-22","wday":1,"wnumber":"21","mday":22,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-23","wday":2,"wnumber":"21","mday":23,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-24","wday":3,"wnumber":"21","mday":24,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-25","wday":4,"wnumber":"21","mday":25,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-26","wday":5,"wnumber":"21","mday":26,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-27","wday":6,"wnumber":"21","mday":27,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-28","wday":0,"wnumber":"21","mday":28,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-29","wday":1,"wnumber":"22","mday":29,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-30","wday":2,"wnumber":"22","mday":30,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-31","wday":3,"wnumber":"22","mday":31,"include_date":false,"excluded_date":false}] @@ -195,12 +196,15 @@ describe('timetable reducer with filled state', () => { let newDates = state.time_table_dates.concat({date: "2017-05-01", in_out: false}) let newCM = newCurrentMonth.map((d,i) => { - if (i == 0) d.include_date = false + if (i == 0){ + d.include_date = false + d.excluded_date = true + } return d }) let newState = Object.assign({}, state, {time_table_dates: newDates, current_month: newCM}) - state.current_month[0].excluded_date = true + expect( timetableReducer(state, { type: 'ADD_EXCLUDED_DATE', @@ -213,11 +217,11 @@ describe('timetable reducer with filled state', () => { it('should handle REMOVE_EXCLUDED_DATE', () => { state.time_table_dates = [{date: "2017-05-01", in_out: false}] - state.current_month[0].excluded_date = true + state.current_month[0].excluded_date = false let newState = Object.assign({}, state, {time_table_dates: []}) expect( timetableReducer(state, { - type: 'EXCLUDE_DATE_FROM_PERIOD', + type: 'REMOVE_EXCLUDED_DATE', index: 0, dayTypes: arrDayTypes, date: "2017-05-01" @@ -227,9 +231,10 @@ describe('timetable reducer with filled state', () => { it('should handle UPDATE_DAY_TYPES and remove out_day that are out of day types', () => { state.time_table_dates = [{date: "2017-05-01", in_out: false}] - let newArrDayTypes = arrDayTypes.slice(0) - newArrDayTypes[1] = false - let newState = Object.assign({}, state, {time_table_dates: []}) + let newArrDayTypes = Array.from(arrDayTypes, (dt, i) => { + if (i == 1) dt = false + return dt + }) expect( timetableReducer(state, { type: 'UPDATE_DAY_TYPES', @@ -238,9 +243,19 @@ describe('timetable reducer with filled state', () => { ).toEqual([]) }) + it('should handle UPDATE_DAY_TYPES and remove in_day that are in day types and in period', () => { + state.time_table_dates = [{ date: "2017-05-16", in_out: true }] + expect( + timetableReducer(state, { + type: 'UPDATE_DAY_TYPES', + dayTypes: arrDayTypes + }).time_table_dates + ).toEqual([]) + }) + it('should handle VALIDATE_PERIOD_FORM and add period if modalProps index = false', () => { let newPeriods = state.time_table_periods.concat({"period_start": "2018-05-15", "period_end": "2018-05-24"}) - let newState = Object.assign({}, state, {time_table_periods: newPeriods}) + let newState = Object.assign({}, state, {time_table_periods: newPeriods, time_table_dates: []}) let modalProps = { active: false, begin: { |
