diff options
Diffstat (limited to 'app/javascript/time_tables')
| -rw-r--r-- | app/javascript/time_tables/actions/index.js | 24 | ||||
| -rw-r--r-- | app/javascript/time_tables/components/Navigate.js | 4 | ||||
| -rw-r--r-- | app/javascript/time_tables/components/PeriodForm.js | 4 | ||||
| -rw-r--r-- | app/javascript/time_tables/components/SaveTimetable.js | 1 | ||||
| -rw-r--r-- | app/javascript/time_tables/components/TagsSelect2.js | 13 | ||||
| -rw-r--r-- | app/javascript/time_tables/containers/PeriodForm.js | 4 | ||||
| -rw-r--r-- | app/javascript/time_tables/reducers/metas.js | 19 | ||||
| -rw-r--r-- | app/javascript/time_tables/reducers/modal.js | 26 | ||||
| -rw-r--r-- | app/javascript/time_tables/reducers/pagination.js | 12 | ||||
| -rw-r--r-- | app/javascript/time_tables/reducers/status.js | 8 | ||||
| -rw-r--r-- | app/javascript/time_tables/reducers/timetable.js | 51 |
11 files changed, 88 insertions, 78 deletions
diff --git a/app/javascript/time_tables/actions/index.js b/app/javascript/time_tables/actions/index.js index 5a02e8523..13cb96b64 100644 --- a/app/javascript/time_tables/actions/index.js +++ b/app/javascript/time_tables/actions/index.js @@ -1,10 +1,14 @@ -import _ from 'lodash' +import range from 'lodash/range' +import assign from 'lodash/assign' +import reject from 'lodash/reject' +import some from 'lodash/some' +import every from 'lodash/every' import clone from '../../helpers/clone' const I18n = clone(window, "I18n") const actions = { weekDays: (index) => { - return _.range(1, 8).map(n => I18n.time_tables.edit.metas.days[n]) + return range(1, 8).map(n => I18n.time_tables.edit.metas.days[n]) }, strToArrayDayTypes: (str) =>{ return actions.weekDays().map(day => str.indexOf(day) !== -1) @@ -151,7 +155,7 @@ const actions = { type : 'CLOSE_MODAL' }), monthName(strDate) { - let monthList = _.range(1,13).map(n => I18n.calendars.months[n]) + let monthList = range(1,13).map(n => I18n.calendars.months[n]) let date = new Date(strDate) return monthList[date.getMonth()] }, @@ -172,12 +176,12 @@ const actions = { return date.toLocaleDateString() }, updateSynthesis: ({current_month, time_table_dates: dates, time_table_periods: periods}) => { - let newPeriods = _.reject(periods, 'deleted') + 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 isIncluded = some(dates, {'date': d.date, 'in_out': true}) - return _.assign({}, current_month[i], { + return assign({}, current_month[i], { in_periods: isInPeriod, include_date: isIncluded, excluded_date: !isInPeriod ? false : current_month[i].excluded_date @@ -271,8 +275,8 @@ const actions = { submitTimetable: (dispatch, timetable, metas, next) => { dispatch(actions.fetchingApi()) let strDayTypes = actions.arrayToStrDayTypes(metas.day_types) - metas.day_types= strDayTypes - let sentState = _.assign({}, timetable, metas) + metas.day_types = strDayTypes + let sentState = assign({}, timetable, metas) let urlJSON = window.location.pathname.split('/', 5).join('/') let hasError = false fetch(urlJSON + '.json', { @@ -302,8 +306,8 @@ const actions = { }) }, errorModalKey: (periods, dayTypes) => { - const withoutPeriodsWithDaysTypes = _.reject(periods, 'deleted').length == 0 && _.some(dayTypes) && "withoutPeriodsWithDaysTypes" - const withPeriodsWithoutDayTypes = _.reject(periods, 'deleted').length > 0 && _.every(dayTypes, dt => dt == false) && "withPeriodsWithoutDayTypes" + const withoutPeriodsWithDaysTypes = reject(periods, 'deleted').length == 0 && some(dayTypes) && "withoutPeriodsWithDaysTypes" + const withPeriodsWithoutDayTypes = reject(periods, 'deleted').length > 0 && every(dayTypes, dt => dt == false) && "withPeriodsWithoutDayTypes" return (withoutPeriodsWithDaysTypes || withPeriodsWithoutDayTypes) && (withoutPeriodsWithDaysTypes ? "withoutPeriodsWithDaysTypes" : "withPeriodsWithoutDayTypes") diff --git a/app/javascript/time_tables/components/Navigate.js b/app/javascript/time_tables/components/Navigate.js index 6ae80bce0..7307d819b 100644 --- a/app/javascript/time_tables/components/Navigate.js +++ b/app/javascript/time_tables/components/Navigate.js @@ -1,5 +1,5 @@ import React, { PropTypes, Component } from 'react' -import _ from 'lodash' +import map from 'lodash/map' import actions from '../actions' export default function Navigate({ dispatch, metas, timetable, pagination, status, filters}) { @@ -30,7 +30,7 @@ export default function Navigate({ dispatch, metas, timetable, pagination, statu className='dropdown-menu' aria-labelledby='date_selector' > - {_.map(pagination.periode_range, (month, i) => ( + {map(pagination.periode_range, (month, i) => ( <li key={i}> <button type='button' diff --git a/app/javascript/time_tables/components/PeriodForm.js b/app/javascript/time_tables/components/PeriodForm.js index 893a1fa6a..d9f1d3437 100644 --- a/app/javascript/time_tables/components/PeriodForm.js +++ b/app/javascript/time_tables/components/PeriodForm.js @@ -1,5 +1,5 @@ import React, { PropTypes } from 'react' -import _ from 'lodash' +import filter from 'lodash/filter' let monthsArray = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'] const formatNumber = (val) => { @@ -108,7 +108,7 @@ export default function PeriodForm({modal, timetable, metas, onOpenAddPeriodForm <button type='button' className='btn btn-outline-primary mr-sm' - onClick={() => onValidatePeriodForm(modal.modalProps, timetable.time_table_periods, metas, _.filter(timetable.time_table_dates, ['in_out', true]))} + onClick={() => onValidatePeriodForm(modal.modalProps, timetable.time_table_periods, metas, filter(timetable.time_table_dates, ['in_out', true]))} > {I18n.actions.submit} </button> diff --git a/app/javascript/time_tables/components/SaveTimetable.js b/app/javascript/time_tables/components/SaveTimetable.js index 0dffc7936..d5a57bd1c 100644 --- a/app/javascript/time_tables/components/SaveTimetable.js +++ b/app/javascript/time_tables/components/SaveTimetable.js @@ -1,5 +1,4 @@ import React, { PropTypes, Component } from 'react' -import _ from 'lodash' import actions from '../actions' export default class SaveTimetable extends Component{ diff --git a/app/javascript/time_tables/components/TagsSelect2.js b/app/javascript/time_tables/components/TagsSelect2.js index 22dc7aa9c..70a748a04 100644 --- a/app/javascript/time_tables/components/TagsSelect2.js +++ b/app/javascript/time_tables/components/TagsSelect2.js @@ -1,5 +1,8 @@ import React, { PropTypes, Component } from 'react' -import _ from 'lodash' +import mapKeys from 'lodash/mapKeys' +import map from 'lodash/map' +import filter from 'lodash/filter' +import assign from 'lodash/assign' import Select2 from 'react-select2' // get JSON full path @@ -13,7 +16,7 @@ export default class TagsSelect2 extends Component { mapKeys(array){ return array.map((item) => - _.mapKeys(item, (v, k) => + mapKeys(item, (v, k) => ((k == 'name') ? 'text' : k) ) ) @@ -22,7 +25,7 @@ export default class TagsSelect2 extends Component { render() { return ( <Select2 - value={(this.props.tags.length) ? _.map(this.props.tags, 'id') : undefined} + value={(this.props.tags.length) ? map(this.props.tags, 'id') : undefined} data={(this.props.initialTags.length) ? this.mapKeys(this.props.initialTags) : undefined} onSelect={(e) => this.props.onSelect2Tags(e)} onUnselect={(e) => setTimeout( () => this.props.onUnselect2Tags(e, 150))} @@ -47,10 +50,10 @@ export default class TagsSelect2 extends Component { }; }, processResults: function(data, params) { - let items = _.filter(data, ({name}) => name.includes(params.term) ) + let items = filter(data, ({name}) => name.includes(params.term) ) return { results: items.map( - item => _.assign( + item => assign( {}, item, {text: item.name} diff --git a/app/javascript/time_tables/containers/PeriodForm.js b/app/javascript/time_tables/containers/PeriodForm.js index 49e79f348..1bde039e2 100644 --- a/app/javascript/time_tables/containers/PeriodForm.js +++ b/app/javascript/time_tables/containers/PeriodForm.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux' -import _ from 'lodash' +import assign from 'lodash/assign' import actions from '../actions' import PeriodFormComponent from '../components/PeriodForm' @@ -23,7 +23,7 @@ const mapDispatchToProps = (dispatch) => { }, onUpdatePeriodForm: (e, group, selectType, modalProps) => { dispatch(actions.updatePeriodForm(e.currentTarget.value, group, selectType)) - let mProps = _.assign({}, modalProps) + let mProps = assign({}, modalProps) mProps[group][selectType] = e.currentTarget.value let val = window.correctDay([parseInt(mProps[group]['day']), parseInt(mProps[group]['month']), parseInt(mProps[group]['year'])]) val = (val < 10) ? '0' + String(val) : String(val) diff --git a/app/javascript/time_tables/reducers/metas.js b/app/javascript/time_tables/reducers/metas.js index 548798012..51e1ec149 100644 --- a/app/javascript/time_tables/reducers/metas.js +++ b/app/javascript/time_tables/reducers/metas.js @@ -1,10 +1,11 @@ -import _ from 'lodash' +import assign from 'lodash/assign' +import filter from 'lodash/filter' import actions from '../actions' export default function metas(state = {}, action) { switch (action.type) { case 'RECEIVE_TIME_TABLES': - return _.assign({}, state, { + return assign({}, state, { comment: action.json.comment, day_types: actions.strToArrayDayTypes(action.json.day_types), tags: action.json.tags, @@ -14,26 +15,26 @@ export default function 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}) + return assign({}, state, {day_types: dt}) 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}) + return assign({}, state, {calendar: null}) case 'UPDATE_DAY_TYPES': - return _.assign({}, state, {day_types: action.dayTypes, calendar : null}) + return assign({}, state, {day_types: action.dayTypes, calendar : null}) case 'UPDATE_COMMENT': - return _.assign({}, state, {comment: action.comment}) + return assign({}, state, {comment: action.comment}) case 'UPDATE_COLOR': - return _.assign({}, state, {color: action.color}) + return assign({}, state, {color: action.color}) case 'UPDATE_SELECT_TAG': let tags = [...state.tags] tags.push(action.selectedItem) - return _.assign({}, state, {tags: tags}) + return assign({}, state, {tags: tags}) case 'UPDATE_UNSELECT_TAG': - return _.assign({}, state, {tags: _.filter(state.tags, (t) => (t.id != action.selectedItem.id))}) + return assign({}, state, {tags: filter(state.tags, (t) => (t.id != action.selectedItem.id))}) default: return state } diff --git a/app/javascript/time_tables/reducers/modal.js b/app/javascript/time_tables/reducers/modal.js index a530b2717..5e870a6ef 100644 --- a/app/javascript/time_tables/reducers/modal.js +++ b/app/javascript/time_tables/reducers/modal.js @@ -1,4 +1,4 @@ -import _ from 'lodash' +import assign from 'lodash/assign' import actions from '../actions' let newModalProps = {} @@ -13,7 +13,7 @@ export default function modal(state = {}, action) { switch (action.type) { case 'OPEN_CONFIRM_MODAL': $('#ConfirmModal').modal('show') - return _.assign({}, state, { + return assign({}, state, { type: 'confirm', confirmModal: { callback: action.callback, @@ -21,14 +21,14 @@ export default function modal(state = {}, action) { }) case 'OPEN_ERROR_MODAL': $('#ErrorModal').modal('show') - newModalProps = _.assign({}, state.modalProps, {error: action.error}) - return _.assign({}, state, {type: 'error'}, {modalProps: newModalProps}) + newModalProps = assign({}, state.modalProps, {error: action.error}) + return assign({}, state, {type: 'error'}, {modalProps: newModalProps}) case 'RESET_MODAL_ERRORS': - newModalProps = _.assign({}, state.modalProps, {error: ''}) - return _.assign({}, state, {type: ''}, {modalProps: newModalProps}) + newModalProps = assign({}, state.modalProps, {error: ''}) + return assign({}, state, {type: ''}, {modalProps: newModalProps}) case 'CLOSE_PERIOD_FORM': - newModalProps = _.assign({}, state.modalProps, {active: false, error: ""}) - return _.assign({}, state, {modalProps: newModalProps}) + newModalProps = assign({}, state.modalProps, {active: false, error: ""}) + return assign({}, state, {modalProps: newModalProps}) case 'OPEN_EDIT_PERIOD_FORM': period_start = action.period.period_start.split('-') period_end = action.period.period_end.split('-') @@ -45,19 +45,19 @@ export default function modal(state = {}, action) { newModalProps.active = true newModalProps.index = action.index newModalProps.error = '' - return _.assign({}, state, {modalProps: newModalProps}) + return assign({}, state, {modalProps: newModalProps}) case 'OPEN_ADD_PERIOD_FORM': - newModalProps = _.assign({}, state.modalProps, {active: true, begin: emptyDate, end: emptyDate, index: false, error: ''}) - return _.assign({}, state, {modalProps: newModalProps}) + newModalProps = assign({}, state.modalProps, {active: true, begin: emptyDate, end: emptyDate, index: false, error: ''}) + return assign({}, state, {modalProps: newModalProps}) case 'UPDATE_PERIOD_FORM': newModalProps = JSON.parse(JSON.stringify(state.modalProps)) newModalProps[action.group][action.selectType] = action.val - return _.assign({}, state, {modalProps: newModalProps}) + return assign({}, state, {modalProps: newModalProps}) case 'VALIDATE_PERIOD_FORM': newModalProps = JSON.parse(JSON.stringify(state.modalProps)) newModalProps.error = action.error newModalProps.active = (newModalProps.error == '') ? false : true - return _.assign({}, state, {modalProps: newModalProps}) + return assign({}, state, {modalProps: newModalProps}) default: return state } diff --git a/app/javascript/time_tables/reducers/pagination.js b/app/javascript/time_tables/reducers/pagination.js index e9ca9e1ec..53a753356 100644 --- a/app/javascript/time_tables/reducers/pagination.js +++ b/app/javascript/time_tables/reducers/pagination.js @@ -1,25 +1,25 @@ -import _ from 'lodash' +import assign from 'lodash/assign' export default function pagination(state = {}, action) { switch (action.type) { case 'RECEIVE_TIME_TABLES': - return _.assign({}, state, { + return assign({}, state, { currentPage: action.json.current_periode_range, periode_range: action.json.periode_range, stateChanged: false }) case 'RECEIVE_MONTH': case 'RECEIVE_ERRORS': - return _.assign({}, state, {stateChanged: false}) + return assign({}, state, {stateChanged: false}) case 'GO_TO_PREVIOUS_PAGE': case 'GO_TO_NEXT_PAGE': let nextPage = action.nextPage ? 1 : -1 let newPage = action.pagination.periode_range[action.pagination.periode_range.indexOf(action.pagination.currentPage) + nextPage] toggleOnConfirmModal() - return _.assign({}, state, {currentPage : newPage, stateChanged: false}) + return assign({}, state, {currentPage : newPage, stateChanged: false}) case 'CHANGE_PAGE': toggleOnConfirmModal() - return _.assign({}, state, {currentPage : action.page, stateChanged: false}) + return assign({}, state, {currentPage : action.page, stateChanged: false}) case 'ADD_INCLUDED_DATE': case 'REMOVE_INCLUDED_DATE': case 'ADD_EXCLUDED_DATE': @@ -31,7 +31,7 @@ export default function pagination(state = {}, action) { case 'UPDATE_DAY_TYPES': case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES': toggleOnConfirmModal('modal') - return _.assign({}, state, {stateChanged: true}) + return assign({}, state, {stateChanged: true}) default: return state } diff --git a/app/javascript/time_tables/reducers/status.js b/app/javascript/time_tables/reducers/status.js index 8d93bc2e2..256059191 100644 --- a/app/javascript/time_tables/reducers/status.js +++ b/app/javascript/time_tables/reducers/status.js @@ -1,14 +1,14 @@ -import _ from 'lodash' +import assign from 'lodash/assign' export default function status(state = {}, action) { switch (action.type) { case 'UNAVAILABLE_SERVER': - return _.assign({}, state, {fetchSuccess: false}) + return assign({}, state, {fetchSuccess: false}) case 'FETCH_API': - return _.assign({}, state, {isFetching: true}) + return assign({}, state, {isFetching: true}) case 'RECEIVE_TIME_TABLES': case 'RECEIVE_MONTH': - return _.assign({}, state, {fetchSuccess: true, isFetching: false}) + return assign({}, state, {fetchSuccess: true, isFetching: false}) default: return state } diff --git a/app/javascript/time_tables/reducers/timetable.js b/app/javascript/time_tables/reducers/timetable.js index 274153a69..21ca1efed 100644 --- a/app/javascript/time_tables/reducers/timetable.js +++ b/app/javascript/time_tables/reducers/timetable.js @@ -1,34 +1,37 @@ -import _ from 'lodash' +import assign from 'lodash/assign' +import reject from 'lodash/reject' +import sortBy from 'lodash/sortBy' +import reduce from 'lodash/reduce' import actions from '../actions' let newState, newPeriods, newDates, newCM export default function timetable(state = {}, action) { switch (action.type) { case 'RECEIVE_TIME_TABLES': - let fetchedState = _.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, - time_table_dates: _.sortBy(action.json.time_table_dates, ['date']) + time_table_dates: sortBy(action.json.time_table_dates, ['date']) }) - return _.assign({}, fetchedState, {current_month: actions.updateSynthesis(fetchedState)}) + return assign({}, fetchedState, {current_month: actions.updateSynthesis(fetchedState)}) case 'RECEIVE_MONTH': - newState = _.assign({}, state, { + newState = assign({}, state, { current_month: action.json.days }) - return _.assign({}, newState, {current_month: actions.updateSynthesis(newState)}) + return assign({}, newState, {current_month: actions.updateSynthesis(newState)}) case 'GO_TO_PREVIOUS_PAGE': case 'GO_TO_NEXT_PAGE': let nextPage = action.nextPage ? 1 : -1 let newPage = action.pagination.periode_range[action.pagination.periode_range.indexOf(action.pagination.currentPage) + nextPage] $('#ConfirmModal').modal('hide') actions.fetchTimeTables(action.dispatch, newPage) - return _.assign({}, state, {current_periode_range: newPage}) + return assign({}, state, {current_periode_range: newPage}) case 'CHANGE_PAGE': $('#ConfirmModal').modal('hide') actions.fetchTimeTables(action.dispatch, action.page) - return _.assign({}, state, {current_periode_range: action.page}) + return assign({}, state, {current_periode_range: action.page}) case 'DELETE_PERIOD': newPeriods = state.time_table_periods.map((period, i) =>{ if(i == action.index){ @@ -37,45 +40,45 @@ export default function timetable(state = {}, action) { return period }) 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)}) + 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 }) - return _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) + return assign({}, state, {current_month: newCM, time_table_dates: newDates}) case 'REMOVE_INCLUDED_DATE': - newDates = _.reject(state.time_table_dates, ['date', action.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}) + 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}) + return assign({}, state, {current_month: newCM, time_table_dates: newDates}) case 'REMOVE_EXCLUDED_DATE': - newDates = _.reject(state.time_table_dates, ['date', action.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 }) - return _.assign({}, state, {current_month: newCM, time_table_dates: newDates}) + 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) => { + let weekDays = reduce(action.dayTypes, (array, dt, i) => { if (dt) array.push(i) return array }, []) - newDates = _.reject(state.time_table_dates, (d) => { + newDates = reject(state.time_table_dates, (d) => { let weekDay = new Date(d.date).getDay() if (d.in_out) { @@ -84,9 +87,9 @@ export default function timetable(state = {}, action) { return !weekDays.includes(weekDay) } }) - return _.assign({}, state, {time_table_dates: newDates}) + return assign({}, state, {time_table_dates: newDates}) case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES': - return _.assign({}, state, {current_month: actions.updateSynthesis(state)}) + return assign({}, state, {current_month: actions.updateSynthesis(state)}) case 'VALIDATE_PERIOD_FORM': if (action.error != '') return state @@ -99,7 +102,7 @@ export default function timetable(state = {}, action) { let updatedPeriod = newPeriods[action.modalProps.index] updatedPeriod.period_start = period_start updatedPeriod.period_end = period_end - newDates = _.reject(state.time_table_dates, d => actions.isInPeriod(newPeriods, d.date) && !d.in_out) + newDates = reject(state.time_table_dates, d => actions.isInPeriod(newPeriods, d.date) && !d.in_out) }else{ let newPeriod = { period_start: period_start, @@ -109,8 +112,8 @@ export default function 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)}) + newState =assign({}, state, {time_table_periods: newPeriods, time_table_dates: newDates}) + return assign({}, newState, {current_month: actions.updateSynthesis(newState)}) default: return state } |
