From efa8b6072e35f09d580f227b0b3175260c145fea Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Mon, 21 Aug 2017 11:58:13 +0200 Subject: Add the possibility to add included days in a period --- .../es6_browserified/time_tables/actions/index.js | 36 ++++++++--- .../time_tables/components/ExceptionsInDay.js | 30 ++++++--- .../time_tables/components/PeriodsInDay.js | 2 +- .../time_tables/components/Timetable.js | 10 ++- .../time_tables/containers/Timetable.js | 12 ++++ .../es6_browserified/time_tables/index.js | 12 ++-- .../es6_browserified/time_tables/reducers/metas.js | 6 +- .../es6_browserified/time_tables/reducers/modal.js | 2 +- .../time_tables/reducers/pagination.js | 6 +- .../time_tables/reducers/timetable.js | 71 +++++++++++++++------- 10 files changed, 134 insertions(+), 53 deletions(-) (limited to 'app/assets/javascripts') 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 61667f5ab..7a1ba10ff 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -112,14 +112,26 @@ const actions = { metas, timetableInDates }), - includeDateInPeriod: (index, dayTypes, date) => ({ - type: 'INCLUDE_DATE_IN_PERIOD', + addIncludedDate: (index, dayTypes, date) => ({ + type: 'ADD_INCLUDED_DATE', index, dayTypes, date }), - excludeDateFromPeriod: (index, dayTypes, date) => ({ - type: 'EXCLUDE_DATE_FROM_PERIOD', + removeIncludedDate: (index, dayTypes, date) => ({ + type: 'REMOVE_INCLUDED_DATE', + index, + dayTypes, + date + }), + addExcludedDate: (index, dayTypes, date) => ({ + type: 'ADD_EXCLUDED_DATE', + index, + dayTypes, + date + }), + removeExcludedDate: (index, dayTypes, date) => ({ + type: 'REMOVE_EXCLUDED_DATE', index, dayTypes, date @@ -187,12 +199,20 @@ const actions = { let bool = isInPeriod(state.current_month[i]) return _.assign({}, state.current_month[i], { in_periods: bool, - include_date: bool ? false : state.current_month[i].include_date, + // include_date: bool ? false : state.current_month[i].include_date, excluded_date: !bool ? false : state.current_month[i].excluded_date }) }) return improvedCM }, + updateExcludedDates: (period_start, period_end, dates) => { + // We remove excluded dates which was in the updated/deleted period + let begin = new Date(period_start) + let end = new Date(period_end) + + return _.reject(dates, d => new Date(d.date) >= begin && new Date(d.date) <= end && d.in_out == false) + + }, checkConfirmModal: (event, callback, stateChanged, dispatch, metas, timetable) => { if(stateChanged){ const error = actions.errorModalKey(timetable.time_table_periods, metas.day_types) @@ -209,7 +229,7 @@ const actions = { formatDate: (props) => { return props.year + '-' + props.month + '-' + props.day }, - checkErrorsInPeriods: (start, end, index, periods, days) => { + checkErrorsInPeriods: (start, end, index, periods) => { let error = '' start = new Date(start) end = new Date(end) @@ -221,13 +241,13 @@ const actions = { }) return error }, - checkErrorsInDates: (start, end, in_days) => { + checkErrorsInDates: (start, end, in_days, dayTypes) => { let error = '' start = new Date(start) end = new Date(end) _.each(in_days, ({date}) => { - if (start <= new Date(date) && end >= new Date(date)) { + if (start <= new Date(date) && end >= new Date(date) && dayTypes[new Date(date).getDay()]) { error = 'Une période ne peut chevaucher une date dans un calendrier' } }) diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js index 4879e537f..80c2e4b7a 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js @@ -8,6 +8,15 @@ class ExceptionsInDay extends Component { super(props) } + handleClick() { + const {index, day, metas: {day_types} } = this.props + if (day.in_periods && day_types[day.wday]) { + day.excluded_date ? this.props.onRemoveExcludedDate(index, day_types, day.date) : this.props.onAddExcludedDate(index, day_types, day.date) + } else { + day.include_date ? this.props.onRemoveIncludedDate(index, day_types, day.date) : this.props.onAddIncludedDate(index, day_types, day.date) + } + } + render() { {/* display add or remove link, only if true in daytypes */} {/* display add or remove link, according to context (presence in period, or not) */} @@ -20,14 +29,14 @@ class ExceptionsInDay extends Component { data-actiontype='remove' onClick={(e) => { $(e.currentTarget).toggleClass('active') - this.props.onExcludeDateFromPeriod(this.props.index, this.props.metas.day_types, this.props.currentDate) + this.handleClick() }} > ) - } else if(this.props.value.current_month[this.props.index].in_periods == false) { + } else { return (