From eb42e4f75c4d2a706ffb723196e673c10be1fbae Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 18 Apr 2017 15:27:22 +0200 Subject: Refs #2982: adding synthesis display for tt#edit --- .../es6_browserified/time_tables/actions/index.js | 40 +++++++++++++++++++++- .../time_tables/components/TimeTableDay.js | 2 +- .../time_tables/reducers/timetable.js | 4 ++- 3 files changed, 43 insertions(+), 3 deletions(-) (limited to 'app/assets/javascripts/es6_browserified') 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 185a9eac9..1b800e547 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -1,3 +1,5 @@ +const _ = require('lodash') + const actions = { strToArrayDayTypes: (str) =>{ let weekDays = ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'] @@ -5,7 +7,7 @@ const actions = { }, fetchingApi: () =>({ - type: 'FETCH_API' + type: 'FETCH_API' }), unavailableServer: () => ({ type: 'UNAVAILABLE_SERVER' @@ -40,6 +42,42 @@ const actions = { name: selectedTag.name } }), + + updateSynthesis: (state) => { + let periods = state.time_table_periods + + let isInPeriod = function(data){ + let currentMonth = state.current_periode_range.split('-') + let currentDate = new Date(currentMonth[0] + '-' + currentMonth[1] + '-' + data.mday) + + // Exception wins anyway + if(data.excluded_date) { + return false + } else if(data.include_date) { + return true + } else { + // We compare periods & currentdate, to determine if it is included or not + let testDate = false + periods.map((p, i) => { + let begin = new Date(p.period_start) + let end = new Date(p.period_end) + + if(currentDate >= begin && currentDate <= end) { + testDate = true + } + }) + return testDate + } + } + + let improvedCM = state.current_month.map((d, i) => { + return _.assign({}, state.current_month[i], { + in_periods: isInPeriod(state.current_month[i]) + }) + }) + return improvedCM + }, + fetchTimeTables: (dispatch, currentPage, nextPage) => { let urlJSON = window.location.pathname.split('/', 5).join('/') + '.json' let hasError = false diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/TimeTableDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/TimeTableDay.js index dff64ba80..cc47c2052 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/TimeTableDay.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/TimeTableDay.js @@ -17,7 +17,7 @@ class TimeTableDay extends Component { {((this.props.value.day).charAt(0) == 'm') ? (this.props.value.day).substr(0, 2) : (this.props.value.day).charAt(0)} {this.props.value.mday} 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 538e72d2c..0e7f84590 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js +++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js @@ -1,14 +1,16 @@ const _ = require('lodash') +var actions = require('../actions') const timetable = (state = {}, action) => { switch (action.type) { case 'RECEIVE_TIME_TABLES': - return _.assign({}, state, { + let fetchedState = _.assign({}, state, { current_month: action.json.current_month, current_periode_range: action.json.current_periode_range, periode_range: action.json.periode_range, time_table_periods: action.json.time_table_periods }) + return _.assign({}, fetchedState, {current_month: actions.updateSynthesis(fetchedState)}) default: return state } -- cgit v1.2.3