aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets
diff options
context:
space:
mode:
authorcedricnjanga2017-09-21 15:11:26 +0200
committercedricnjanga2017-09-21 15:11:26 +0200
commit68192809695a5c2dc44198882b7cc7bc14b5500e (patch)
tree5c8790d27b418a4c370931e0fcb6e6d25282245f /app/assets
parent2b9fffca90da37f2f681befc5bceca53a8350161 (diff)
downloadchouette-core-68192809695a5c2dc44198882b7cc7bc14b5500e.tar.bz2
Merge pull request 55 into master
=> Debug to add the possibility to add included dates in a period (outside of day types) => Refacto in the timetable reducer to share more code between some actions
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/actions/index.js55
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/index.js12
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js23
3 files changed, 25 insertions, 65 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 928a63d2b..ba5d91568 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
@@ -169,38 +169,16 @@ const actions = {
let date = new Date(strDate)
return date.toLocaleDateString()
},
- updateSynthesis: (state, daytypes) => {
- let periods = state.time_table_periods
+ 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})
- 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
@@ -216,14 +194,6 @@ const actions = {
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)
- 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)
@@ -348,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/index.js b/app/assets/javascripts/es6_browserified/time_tables/index.js
index a91747991..9873f5532 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/index.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/index.js
@@ -6,10 +6,10 @@ var timeTablesApp = require('./reducers')
var App = require('./containers/App')
// logger, DO NOT REMOVE
-// var applyMiddleware = require('redux').applyMiddleware
-// var createLogger = require('redux-logger')
-// var thunkMiddleware = require('redux-thunk').default
-// var promise = require('redux-promise')
+var applyMiddleware = require('redux').applyMiddleware
+var createLogger = require('redux-logger')
+var thunkMiddleware = require('redux-thunk').default
+var promise = require('redux-promise')
var initialState = {
status: {
@@ -58,12 +58,12 @@ var initialState = {
confirmModal: {}
}
}
-// const loggerMiddleware = createLogger()
+const loggerMiddleware = createLogger()
let store = createStore(
timeTablesApp,
initialState,
- // applyMiddleware(thunkMiddleware, promise, loggerMiddleware)
+ applyMiddleware(thunkMiddleware, promise, loggerMiddleware)
)
render(
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 8bd830415..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,9 +1,6 @@
const _ = require('lodash')
var actions = require('../actions')
-let newState = {}
-let newPeriods = []
-let newDates = []
-let newCM = []
+let newState, newPeriods, newDates, newCM
const timetable = (state = {}, action) => {
switch (action.type) {
@@ -15,12 +12,12 @@ const timetable = (state = {}, action) => {
time_table_periods: action.json.time_table_periods,
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
@@ -39,10 +36,10 @@ const timetable = (state = {}, action) => {
}
return period
})
- let deletedPeriod = state.time_table_periods[action.index]
- newDates = actions.updateExcludedDates(deletedPeriod.period_start, deletedPeriod.period_end, state.time_table_dates)
+ 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, action.dayTypes)})
+ 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) => {
@@ -89,7 +86,7 @@ const timetable = (state = {}, action) => {
})
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
@@ -99,10 +96,10 @@ const timetable = (state = {}, action) => {
let newPeriods = JSON.parse(JSON.stringify(action.timeTablePeriods))
if (action.modalProps.index !== false){
- updatePeriod = state.time_table_periods[action.modalProps.index]
+ updatePeriod = newPeriods[action.modalProps.index]
updatePeriod.period_start = period_start
updatePeriod.period_end = period_end
- newDates = actions.updateExcludedDates(updatePeriod.period_start, updatePeriod.period_end, state.time_table_dates)
+ newDates = _.reject(state.time_table_dates, d => actions.isInPeriod(newPeriods, d.date) && !d.in_out)
}else{
let newPeriod = {
period_start: period_start,
@@ -113,7 +110,7 @@ const timetable = (state = {}, action) => {
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, action.metas.day_types)})
+ return _.assign({}, newState, {current_month: actions.updateSynthesis(newState)})
default:
return state
}