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 /app/assets/javascripts | |
| 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
Diffstat (limited to 'app/assets/javascripts')
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/actions/index.js | 12 | ||||
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js | 36 |
2 files changed, 25 insertions, 23 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': |
