ngx-bootstrap
Version:
Native Angular Bootstrap Components
65 lines • 3.32 kB
JavaScript
import { initialDatepickerState } from './bs-datepicker.state';
import { BsDatepickerActions } from './bs-datepicker.actions';
import { calculateMonthModel } from '../engine/calc-month-view';
import { formatMonthView } from '../engine/format-month-view';
import { changeDate } from '../utils/date-utils';
import { flagMonthView } from '../engine/flag-month-view';
export function bsDatepickerReducer(state, action) {
if (state === void 0) { state = initialDatepickerState; }
switch (action.type) {
/*
case (BsDatepickerActions.INIT): {
const locale = getLocale(state.formatOptions.locale);
const monthViewOptions = Object.assign({}, state.monthViewOptions, {firstDayOfWeek: locale.firstDayOfWeek()});
const monthModel = calculateMonthModel(state.viewDate, monthViewOptions);
return Object.assign({}, state, {locale, monthViewOptions, monthModel});
}
*/
case (BsDatepickerActions.CALCULATE): {
var displayMonths = state.renderOptions.displayMonths;
var monthsModel = new Array(displayMonths);
var viewDate = state.viewDate;
for (var monthIndex = 0; monthIndex < displayMonths; monthIndex++) {
// todo: for unlinked calendars it will be harder
monthsModel[monthIndex] = calculateMonthModel(viewDate, state.monthViewOptions);
viewDate = changeDate(viewDate, { month: 1 });
}
return Object.assign({}, state, { monthsModel: monthsModel });
}
case (BsDatepickerActions.FORMAT): {
var formattedMonths = state.monthsModel
.map(function (month, monthIndex) { return formatMonthView(month, state.formatOptions, monthIndex); });
return Object.assign({}, state, { formattedMonths: formattedMonths });
}
case (BsDatepickerActions.FLAG): {
var flaggedMonths = state.formattedMonths
.map(function (formattedMonth, monthIndex) { return flagMonthView(formattedMonth, {
hoveredDate: state.hoveredDate,
selectedDate: state.selectedDate,
selectedRange: state.selectedRange,
displayMonths: state.renderOptions.displayMonths,
monthIndex: monthIndex
}); });
return Object.assign({}, state, { flaggedMonths: flaggedMonths });
}
case (BsDatepickerActions.STEP_NAVIGATION): {
var viewDate = changeDate(state.viewDate, action.payload);
return Object.assign({}, state, { viewDate: viewDate });
}
case (BsDatepickerActions.HOVER): {
return Object.assign({}, state, { hoveredDate: action.payload });
}
case (BsDatepickerActions.SELECT): {
return Object.assign({}, state, { selectedDate: action.payload });
}
case (BsDatepickerActions.RENDER_OPTIONS): {
return Object.assign({}, state, { renderOptions: action.payload });
}
// date range picker
case (BsDatepickerActions.SELECT_RANGE): {
return Object.assign({}, state, { selectedRange: action.payload });
}
default: return state;
}
}
//# sourceMappingURL=bs-datepicker.reducer.js.map