ngx-bootstrap
Version:
Native Angular Bootstrap Components
179 lines • 8.05 kB
JavaScript
import { Injectable } from '@angular/core';
import { getFullYear, getMonth } from '../../chronos/utils/date-getters';
import { BsDatepickerActions } from './bs-datepicker.actions';
import { BsLocaleService } from '../bs-locale.service';
import { filter, map } from 'rxjs/operators';
var BsDatepickerEffects = /** @class */ (function () {
function BsDatepickerEffects(_actions, _localeService) {
this._actions = _actions;
this._localeService = _localeService;
this._subs = [];
}
BsDatepickerEffects.prototype.init = function (_bsDatepickerStore) {
this._store = _bsDatepickerStore;
return this;
};
/** setters */
/** setters */
BsDatepickerEffects.prototype.setValue = /** setters */
function (value) {
this._store.dispatch(this._actions.select(value));
};
BsDatepickerEffects.prototype.setRangeValue = function (value) {
this._store.dispatch(this._actions.selectRange(value));
};
BsDatepickerEffects.prototype.setMinDate = function (value) {
this._store.dispatch(this._actions.minDate(value));
return this;
};
BsDatepickerEffects.prototype.setMaxDate = function (value) {
this._store.dispatch(this._actions.maxDate(value));
return this;
};
BsDatepickerEffects.prototype.setDisabled = function (value) {
this._store.dispatch(this._actions.isDisabled(value));
return this;
};
/* Set rendering options */
/* Set rendering options */
BsDatepickerEffects.prototype.setOptions = /* Set rendering options */
function (_config) {
var _options = Object.assign({ locale: this._localeService.currentLocale }, _config);
this._store.dispatch(this._actions.setOptions(_options));
return this;
};
/** view to mode bindings */
/** view to mode bindings */
BsDatepickerEffects.prototype.setBindings = /** view to mode bindings */
function (container) {
container.daysCalendar = this._store
.select(function (state) { return state.flaggedMonths; })
.pipe(filter(function (months) { return !!months; }));
// month calendar
container.monthsCalendar = this._store
.select(function (state) { return state.flaggedMonthsCalendar; })
.pipe(filter(function (months) { return !!months; }));
// year calendar
container.yearsCalendar = this._store
.select(function (state) { return state.yearsCalendarFlagged; })
.pipe(filter(function (years) { return !!years; }));
container.viewMode = this._store.select(function (state) { return state.view.mode; });
container.options = this._store
.select(function (state) { return state.showWeekNumbers; })
.pipe(map(function (showWeekNumbers) { return ({ showWeekNumbers: showWeekNumbers }); }));
return this;
};
/** event handlers */
/** event handlers */
BsDatepickerEffects.prototype.setEventHandlers = /** event handlers */
function (container) {
var _this = this;
container.setViewMode = function (event) {
_this._store.dispatch(_this._actions.changeViewMode(event));
};
container.navigateTo = function (event) {
_this._store.dispatch(_this._actions.navigateStep(event.step));
};
container.dayHoverHandler = function (event) {
var _cell = event.cell;
if (_cell.isOtherMonth || _cell.isDisabled) {
return;
}
_this._store.dispatch(_this._actions.hoverDay(event));
_cell.isHovered = event.isHovered;
};
container.monthHoverHandler = function (event) {
event.cell.isHovered = event.isHovered;
};
container.yearHoverHandler = function (event) {
event.cell.isHovered = event.isHovered;
};
/** select handlers */
// container.daySelectHandler = (day: DayViewModel): void => {
// if (day.isOtherMonth || day.isDisabled) {
// return;
// }
// this._store.dispatch(this._actions.select(day.date));
// };
container.monthSelectHandler = function (event) {
if (event.isDisabled) {
return;
}
_this._store.dispatch(_this._actions.navigateTo({
unit: { month: getMonth(event.date) },
viewMode: 'day'
}));
};
container.yearSelectHandler = function (event) {
if (event.isDisabled) {
return;
}
_this._store.dispatch(_this._actions.navigateTo({
unit: { year: getFullYear(event.date) },
viewMode: 'month'
}));
};
return this;
};
BsDatepickerEffects.prototype.registerDatepickerSideEffects = function () {
var _this = this;
this._subs.push(this._store.select(function (state) { return state.view; }).subscribe(function (view) {
_this._store.dispatch(_this._actions.calculate());
}));
// format calendar values on month model change
this._subs.push(this._store
.select(function (state) { return state.monthsModel; })
.pipe(filter(function (monthModel) { return !!monthModel; }))
.subscribe(function (month) { return _this._store.dispatch(_this._actions.format()); }));
// flag day values
this._subs.push(this._store
.select(function (state) { return state.formattedMonths; })
.pipe(filter(function (month) { return !!month; }))
.subscribe(function (month) { return _this._store.dispatch(_this._actions.flag()); }));
// flag day values
this._subs.push(this._store
.select(function (state) { return state.selectedDate; })
.pipe(filter(function (selectedDate) { return !!selectedDate; }))
.subscribe(function (selectedDate) { return _this._store.dispatch(_this._actions.flag()); }));
// flag for date range picker
this._subs.push(this._store
.select(function (state) { return state.selectedRange; })
.pipe(filter(function (selectedRange) { return !!selectedRange; }))
.subscribe(function (selectedRange) { return _this._store.dispatch(_this._actions.flag()); }));
// monthsCalendar
this._subs.push(this._store
.select(function (state) { return state.monthsCalendar; })
.subscribe(function () { return _this._store.dispatch(_this._actions.flag()); }));
// years calendar
this._subs.push(this._store
.select(function (state) { return state.yearsCalendarModel; })
.pipe(filter(function (state) { return !!state; }))
.subscribe(function () { return _this._store.dispatch(_this._actions.flag()); }));
// on hover
this._subs.push(this._store
.select(function (state) { return state.hoveredDate; })
.pipe(filter(function (hoveredDate) { return !!hoveredDate; }))
.subscribe(function (hoveredDate) { return _this._store.dispatch(_this._actions.flag()); }));
// on locale change
this._subs.push(this._localeService.localeChange
.subscribe(function (locale) { return _this._store.dispatch(_this._actions.setLocale(locale)); }));
return this;
};
BsDatepickerEffects.prototype.destroy = function () {
for (var _i = 0, _a = this._subs; _i < _a.length; _i++) {
var sub = _a[_i];
sub.unsubscribe();
}
};
BsDatepickerEffects.decorators = [
{ type: Injectable },
];
/** @nocollapse */
BsDatepickerEffects.ctorParameters = function () { return [
{ type: BsDatepickerActions, },
{ type: BsLocaleService, },
]; };
return BsDatepickerEffects;
}());
export { BsDatepickerEffects };
//# sourceMappingURL=bs-datepicker.effects.js.map