aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorGuillaume2017-09-25 12:38:10 +0200
committerGuillaume2017-09-25 12:38:10 +0200
commit903cc58aa530385f6fc3ceba3bbbacf46f4cd316 (patch)
tree40c20ac148ba804724652976f3639715871b41a1 /app/assets/javascripts
parent8e543f38ac615a8e5ee7a949ed5c374dfd7a5e32 (diff)
parent76b3b813fb3cafc6880e50a57e823634a79d9a32 (diff)
downloadchouette-core-903cc58aa530385f6fc3ceba3bbbacf46f4cd316.tar.bz2
Merge branch 'master' of https://github.com/af83/stif-boiv
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/es6_browserified/itineraries/form_helper.js62
-rw-r--r--app/assets/javascripts/es6_browserified/itineraries/index.js19
-rw-r--r--app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js2
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/actions/index.js79
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js30
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js2
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js10
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js12
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js6
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js6
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js79
11 files changed, 195 insertions, 112 deletions
diff --git a/app/assets/javascripts/es6_browserified/itineraries/form_helper.js b/app/assets/javascripts/es6_browserified/itineraries/form_helper.js
index 0baba27ef..f682e39c0 100644
--- a/app/assets/javascripts/es6_browserified/itineraries/form_helper.js
+++ b/app/assets/javascripts/es6_browserified/itineraries/form_helper.js
@@ -1,11 +1,55 @@
-const addInput = (name, value, index) => {
- let form = document.querySelector('form')
- let input = document.createElement('input')
- let formatedName = 'route[stop_points_attributes]['+ index.toString()+']['+name+']'
- input.setAttribute('type', 'hidden')
- input.setAttribute('name', formatedName)
- input.setAttribute('value', value)
- form.appendChild(input)
+const formHelper = {
+ addInput: (name, value, index) => {
+ let form = document.querySelector('form')
+ let input = document.createElement('input')
+ let formatedName = `route[stop_points_attributes][${index.toString()}][${name}]`
+ input.setAttribute('type', 'hidden')
+ input.setAttribute('name', formatedName)
+ input.setAttribute('value', value)
+ form.appendChild(input)
+ },
+ addError: (ids) => {
+ ids.forEach((id) => {
+ if (!$(id).parents('.form-group').hasClass('has-error')) {
+ $(id).parents('.form-group').addClass('has-error')
+ $(id).parent().append(`<span class='help-block small'>${'doit être rempli(e)'}</span>`)
+ }
+ })
+ },
+ cleanInputs: (ids) => {
+ ids.forEach((id) =>{
+ $(id).parents('.form-group').removeClass('has-error')
+ $(id).siblings('span').remove()
+ })
+ },
+ handleForm: (...ids) => {
+ let filledInputs = []
+ let blankInputs = []
+ ids.forEach(id => {
+ $(id).val() == "" ? blankInputs.push(id) : filledInputs.push(id)
+ })
+
+ if (filledInputs.length > 0) formHelper.cleanInputs(filledInputs)
+ if (blankInputs.length > 0) formHelper.addError(blankInputs)
+ },
+ handleStopPoints: (event, state) => {
+ if (state.stopPoints.length >= 2) {
+ state.stopPoints.map((stopPoint, i) => {
+ formHelper.addInput('id', stopPoint.stoppoint_id ? stopPoint.stoppoint_id : '', i)
+ formHelper.addInput('stop_area_id', stopPoint.stoparea_id, i)
+ formHelper.addInput('position', i, i)
+ formHelper.addInput('for_boarding', stopPoint.for_boarding, i)
+ formHelper.addInput('for_alighting', stopPoint.for_alighting, i)
+ })
+ if ($('.alert.alert-danger').length > 0) $('.alert.alert-danger').remove()
+ } else {
+ event.preventDefault()
+ let msg = "L'itinéraire doit comporter au moins deux arrêts"
+ if ($('.alert.alert-danger').length == 0) {
+ $('#stop_points').find('.subform').after(`<div class='alert alert-danger'><span class='fa fa-lg fa-exclamation-circle'></span><span>" ${msg} "</span></div>`)
+ }
+ }
+ }
}
-module.exports = addInput
+module.exports = formHelper \ No newline at end of file
diff --git a/app/assets/javascripts/es6_browserified/itineraries/index.js b/app/assets/javascripts/es6_browserified/itineraries/index.js
index ad32b9519..bb06126f7 100644
--- a/app/assets/javascripts/es6_browserified/itineraries/index.js
+++ b/app/assets/javascripts/es6_browserified/itineraries/index.js
@@ -4,7 +4,7 @@ var Provider = require('react-redux').Provider
var createStore = require('redux').createStore
var reducers = require('./reducers')
var App = require('./components/App')
-var addInput = require('./form_helper')
+var { handleForm, handleStopPoints } = require('./form_helper')
let datas = JSON.parse(decodeURIComponent(window.itinerary_stop))
// logger, DO NOT REMOVE
@@ -67,17 +67,12 @@ render(
document.querySelector('input[name=commit]').addEventListener('click', (event)=>{
let state = store.getState()
- if(state.stopPoints.length >= 2) {
- state.stopPoints.map((stopPoint, i) => {
- addInput('id', stopPoint.stoppoint_id ? stopPoint.stoppoint_id : '', i)
- addInput('stop_area_id',stopPoint.stoparea_id, i)
- addInput('position',i, i)
- addInput('for_boarding',stopPoint.for_boarding, i)
- addInput('for_alighting',stopPoint.for_alighting, i)
- })
- } else {
+ let name = $("#route_name").val()
+ let publicName = $("#route_published_name").val()
+ if (name == "" || publicName == "") {
event.preventDefault()
- let msg = "L'itinéraire doit comporter au moins deux arrêts"
- $('#stop_points').find('.subform').after("<div class='alert alert-danger'><span class='fa fa-lg fa-exclamation-circle'></span><span>" + msg + "</span></div>")
+ handleForm("#route_name", "#route_published_name")
}
+
+ handleStopPoints(event, state)
})
diff --git a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
index a3b8accb3..f3a26b8d7 100644
--- a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
+++ b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
@@ -1,5 +1,5 @@
var _ = require('lodash')
-var addInput = require('../form_helper')
+var { addInput } = require('../form_helper')
const stopPoint = (state = {}, action, length) => {
switch (action.type) {
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 02ece1654..ba5d91568 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
@@ -113,14 +113,26 @@ const actions = {
timetableInDates,
error
}),
- 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
@@ -157,43 +169,31 @@ const actions = {
let date = new Date(strDate)
return date.toLocaleDateString()
},
+ updateSynthesis: ({current_month, time_table_dates: dates, time_table_periods: periods}) => {
+ let newPeriods = _.reject(periods, 'deleted')
+ let improvedCM = current_month.map((d, i) => {
+ let isInPeriod = actions.isInPeriod(newPeriods, d.date)
+ let isIncluded = _.some(dates, {'date': d.date, 'in_out': true})
- updateSynthesis: (state, daytypes) => {
- let periods = state.time_table_periods
-
- let isInPeriod = function(d){
- let currentMonth = state.current_periode_range.split('-')
- let twodigitsDay = d.mday < 10 ? ('0' + d.mday) : d.mday
- let currentDate = new Date(currentMonth[0] + '-' + currentMonth[1] + '-' + twodigitsDay)
-
- // We compare periods & currentDate, to determine if it is included or not
- let testDate = false
- periods.map((p, i) => {
- if (p.deleted) return false
-
- let begin = new Date(p.period_start)
- let end = new Date(p.period_end)
-
- if(testDate === false){
- if(currentDate >= begin && currentDate <= end) {
- testDate = true
- // p.include_date = false
- }
- }
- })
- return testDate
- }
-
- let improvedCM = state.current_month.map((d, i) => {
- 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,
- excluded_date: !bool ? false : state.current_month[i].excluded_date
+ return _.assign({}, current_month[i], {
+ in_periods: isInPeriod,
+ include_date: isIncluded,
+ excluded_date: !isInPeriod ? false : current_month[i].excluded_date
})
})
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
+ },
checkConfirmModal: (event, callback, stateChanged, dispatch, metas, timetable) => {
if(stateChanged){
const error = actions.errorModalKey(timetable.time_table_periods, metas.day_types)
@@ -318,13 +318,6 @@ const actions = {
}
},
- checkIfTTHasDate: (dates, date) => {
- if (_.some(dates, date)) {
- return _.reject(dates, ['date', date.date])
- } else {
- return dates.concat(date)
- }
- }
}
module.exports = actions
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()
}}
>
<span className='fa fa-times'></span>
</button>
</div>
)
- } else if(this.props.value.current_month[this.props.index].in_periods == false) {
+ } else {
return (
<div className='td'>
<button
@@ -36,20 +45,21 @@ class ExceptionsInDay extends Component {
data-actiontype='add'
onClick={(e) => {
$(e.currentTarget).toggleClass('active')
- this.props.onIncludeDateInPeriod(this.props.index, this.props.metas.day_types, this.props.currentDate)
+ this.handleClick()
}}
>
<span className='fa fa-plus'></span>
</button>
</div>
)
- } else if(this.props.value.current_month[this.props.index].in_periods == true && this.props.blueDaytype == false){
- return (
- <div className='td'></div>
- )
- } else{
- return false
- }
+ // } else if(this.props.value.current_month[this.props.index].in_periods == true && this.props.blueDaytype == false){
+ // return (
+ // <div className='td'></div>
+ // )
+ // } else{
+ // return false
+ // }
+ }
}
}
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js
index ca44d3a07..f56509b99 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js
@@ -35,7 +35,7 @@ class PeriodsInDay extends Component {
render() {
return (
<div
- className={this.isIn(this.props.currentDate)}
+ className={this.isIn(this.props.currentDate) + (this.props.metas.day_types[this.props.day.wday] || !this.props.day.in_periods ? '' : ' out_from_daytypes')}
>
{this.props.value.map((p, i) => {
if(!p.deleted){
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
index 3af1a11a4..a613549c3 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
@@ -60,13 +60,14 @@ class Timetable extends Component{
{this.props.timetable.current_month.map((d, i) =>
<div
key={i}
- className={'td-group' + (this.props.metas.day_types[d.wday] || !d.in_periods ? '' : ' out_from_daytypes') + (d.wday == 0 ? ' last_wday' : '')}
+ className={'td-group'+ (d.wday == 0 ? ' last_wday' : '')}
>
{/* day_types */}
- <div className="td"></div>
+ <div className={"td" + (this.props.metas.day_types[d.wday] || !d.in_periods ? '' : ' out_from_daytypes') }></div>
{/* periods */}
<PeriodsInDay
+ day={d}
index={i}
value={this.props.timetable.time_table_periods}
currentDate={this.currentDate(this.props.timetable.current_periode_range, d.mday)}
@@ -77,11 +78,16 @@ class Timetable extends Component{
{/* exceptions */}
<ExceptionsInDay
+ day={d}
index={i}
value={this.props.timetable}
currentDate={d.date}
metas={this.props.metas}
blueDaytype={this.props.metas.day_types[d.wday]}
+ onAddIncludedDate={this.props.onAddIncludedDate}
+ onRemoveIncludedDate={this.props.onRemoveIncludedDate}
+ onAddExcludedDate={this.props.onAddExcludedDate}
+ onRemoveExcludedDate={this.props.onRemoveExcludedDate}
onExcludeDateFromPeriod={this.props.onExcludeDateFromPeriod}
onIncludeDateInPeriod={this.props.onIncludeDateInPeriod}
/>
diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js b/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js
index 639a1e2ab..a37e99982 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js
@@ -15,6 +15,18 @@ const mapDispatchToProps = (dispatch) => {
onDeletePeriod: (index, dayTypes) =>{
dispatch(actions.deletePeriod(index, dayTypes))
},
+ onAddIncludedDate: (index, dayTypes, date) => {
+ dispatch(actions.addIncludedDate(index, dayTypes, date))
+ },
+ onRemoveIncludedDate: (index, dayTypes, date) => {
+ dispatch(actions.removeIncludedDate(index, dayTypes, date))
+ },
+ onAddExcludedDate: (index, dayTypes, date) => {
+ dispatch(actions.addExcludedDate(index, dayTypes, date))
+ },
+ onRemoveExcludedDate: (index, dayTypes, date) => {
+ dispatch(actions.removeExcludedDate(index, dayTypes, date))
+ },
onExcludeDateFromPeriod: (index, dayTypes, date) => {
dispatch(actions.excludeDateFromPeriod(index, dayTypes, date))
},
diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js
index 2ce084efd..ab5ed3d91 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js
@@ -15,8 +15,10 @@ const metas = (state = {}, action) => {
case 'RECEIVE_MONTH':
let dt = (typeof state.day_types === 'string') ? actions.strToArrayDayTypes(state.day_types) : state.day_types
return _.assign({}, state, {day_types: dt})
- case 'INCLUDE_DATE_IN_PERIOD':
- case 'EXCLUDE_DATE_FROM_PERIOD':
+ case 'ADD_INCLUDED_DATE':
+ case 'REMOVE_INCLUDED_DATE':
+ case 'ADD_EXCLUDED_DATE':
+ case 'REMOVE_EXCLUDED_DATE':
case 'DELETE_PERIOD':
case 'VALIDATE_PERIOD_FORM':
return _.assign({}, state, {calendar: null})
diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
index 45fec6b5f..f38b124d9 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
@@ -20,8 +20,10 @@ const pagination = (state = {}, action) => {
case 'CHANGE_PAGE':
toggleOnConfirmModal()
return _.assign({}, state, {currentPage : action.page, stateChanged: false})
- case 'INCLUDE_DATE_IN_PERIOD':
- case 'EXCLUDE_DATE_FROM_PERIOD':
+ case 'ADD_INCLUDED_DATE':
+ case 'REMOVE_INCLUDED_DATE':
+ case 'ADD_EXCLUDED_DATE':
+ case 'REMOVE_EXCLUDED_DATE':
case 'DELETE_PERIOD':
case 'VALIDATE_PERIOD_FORM':
case 'UPDATE_COMMENT':
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 390bdffb0..edb965065 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js
@@ -1,7 +1,6 @@
const _ = require('lodash')
var actions = require('../actions')
-let newState = {}
-let newDates = []
+let newState, newPeriods, newDates, newCM
const timetable = (state = {}, action) => {
switch (action.type) {
@@ -11,14 +10,14 @@ const timetable = (state = {}, action) => {
current_periode_range: action.json.current_periode_range,
periode_range: action.json.periode_range,
time_table_periods: action.json.time_table_periods,
- time_table_dates: action.json.time_table_dates
+ time_table_dates: _.sortBy(action.json.time_table_dates, ['date'])
})
- return _.assign({}, fetchedState, {current_month: actions.updateSynthesis(fetchedState, actions.strToArrayDayTypes(action.json.day_types))})
+ return _.assign({}, fetchedState, {current_month: actions.updateSynthesis(fetchedState)})
case 'RECEIVE_MONTH':
newState = _.assign({}, state, {
current_month: action.json.days
})
- return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, actions.strToArrayDayTypes(action.json.day_types))})
+ return _.assign({}, newState, {current_month: actions.updateSynthesis(newState)})
case 'GO_TO_PREVIOUS_PAGE':
case 'GO_TO_NEXT_PAGE':
let nextPage = action.nextPage ? 1 : -1
@@ -31,34 +30,44 @@ const timetable = (state = {}, action) => {
actions.fetchTimeTables(action.dispatch, action.page)
return _.assign({}, state, {current_periode_range: action.page})
case 'DELETE_PERIOD':
- let ttperiods = state.time_table_periods.map((period, i) =>{
+ newPeriods = state.time_table_periods.map((period, i) =>{
if(i == action.index){
period.deleted = true
}
return period
})
- newState = _.assign({}, state, {time_table_periods : ttperiods})
- return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)})
- case 'INCLUDE_DATE_IN_PERIOD':
- newDates = actions.checkIfTTHasDate(state.time_table_dates, {date: action.date, in_out: true})
- let newCMi = state.current_month.map((d, i) => {
- if(i == action.index){
- d.include_date = !d.include_date
- }
+ let deletedPeriod = Array.of(state.time_table_periods[action.index])
+ newDates = _.reject(state.time_table_dates, d => actions.isInPeriod(deletedPeriod, d.date) && !d.in_out)
+ newState = _.assign({}, state, {time_table_periods : newPeriods, time_table_dates: newDates})
+ return _.assign({}, newState, { current_month: actions.updateSynthesis(newState)})
+ 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
return d
})
- newState = _.assign({}, state, {current_month: newCMi, time_table_dates: newDates})
- return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)})
- case 'EXCLUDE_DATE_FROM_PERIOD':
- newDates = actions.checkIfTTHasDate(state.time_table_dates, {date: action.date, in_out: false})
- let newCMe = state.current_month.map((d, i) => {
- if(i == action.index){
- d.excluded_date = !d.excluded_date
- }
+ 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
+ return d
+ })
+ 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
+ return d
+ })
+ 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
return d
})
- newState = _.assign({}, state, {current_month: newCMe, 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) => {
@@ -67,11 +76,17 @@ 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()
+
+ if (d.in_out) {
+ return actions.isInPeriod(state.time_table_periods, d.date) && weekDays.includes(weekDay)
+ } else {
+ return !weekDays.includes(weekDay)
+ }
})
return _.assign({}, state, {time_table_dates: newDates})
case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES':
- return _.assign({}, state, {current_month: actions.updateSynthesis(state, action.dayTypes)})
+ return _.assign({}, state, {current_month: actions.updateSynthesis(state)})
case 'VALIDATE_PERIOD_FORM':
if (action.error != '') return state
@@ -81,8 +96,10 @@ const timetable = (state = {}, action) => {
let newPeriods = JSON.parse(JSON.stringify(action.timeTablePeriods))
if (action.modalProps.index !== false){
- newPeriods[action.modalProps.index].period_start = period_start
- newPeriods[action.modalProps.index].period_end = period_end
+ updatePeriod = newPeriods[action.modalProps.index]
+ updatePeriod.period_start = period_start
+ updatePeriod.period_end = period_end
+ newDates = _.reject(state.time_table_dates, d => actions.isInPeriod(newPeriods, d.date) && !d.in_out)
}else{
let newPeriod = {
period_start: period_start,
@@ -90,8 +107,10 @@ const timetable = (state = {}, action) => {
}
newPeriods.push(newPeriod)
}
- newState =_.assign({}, state, {time_table_periods: newPeriods})
- return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.metas.day_types)})
+
+ newDates = newDates || state.time_table_dates
+ newState =_.assign({}, state, {time_table_periods: newPeriods, time_table_dates: newDates})
+ return _.assign({}, newState, {current_month: actions.updateSynthesis(newState)})
default:
return state
}