ionic2-calendar-scheduler
Version:
Ionic5 calendar scheduler component
102 lines (101 loc) • 4.9 kB
JavaScript
import * as tslib_1 from "tslib";
import { Injectable } from '@angular/core';
import { Subject } from "rxjs";
var CalendarService = /** @class */ (function () {
function CalendarService() {
this.currentDateChangedFromParent = new Subject();
this.currentDateChangedFromChildren = new Subject();
this.eventSourceChanged = new Subject();
this.currentDateChangedFromParent$ = this.currentDateChangedFromParent.asObservable();
this.currentDateChangedFromChildren$ = this.currentDateChangedFromChildren.asObservable();
this.eventSourceChanged$ = this.eventSourceChanged.asObservable();
}
CalendarService.prototype.setCurrentDate = function (val, fromParent) {
if (fromParent === void 0) { fromParent = false; }
this._currentDate = val;
if (fromParent) {
this.currentDateChangedFromParent.next(val);
}
else {
this.currentDateChangedFromChildren.next(val);
}
};
Object.defineProperty(CalendarService.prototype, "currentDate", {
get: function () {
return this._currentDate;
},
enumerable: true,
configurable: true
});
CalendarService.prototype.rangeChanged = function (component) {
if (this.queryMode === 'local') {
if (component.bookingsSource && component.onDataLoaded) {
component.onDataLoaded();
}
}
else if (this.queryMode === 'remote') {
component.onRangeChanged.emit(component.range);
}
};
CalendarService.prototype.getStep = function () {
return {
years: 0,
months: 0,
days: 7
};
};
CalendarService.prototype.getAdjacentCalendarDate = function (mode, direction) {
var step = this.getStep();
var calculateCalendarDate = new Date(this.currentDate.getTime()), year = calculateCalendarDate.getFullYear() + direction * step.years, month = calculateCalendarDate.getMonth() + direction * step.months, date = calculateCalendarDate.getDate() + direction * step.days;
calculateCalendarDate.setFullYear(year, month, date);
return calculateCalendarDate;
};
CalendarService.prototype.getAdjacentViewStartTime = function (component, direction) {
var adjacentCalendarDate = this.getAdjacentCalendarDate(component.mode, direction);
return component.getRange(adjacentCalendarDate).startTime;
};
CalendarService.prototype.populateAdjacentViews = function (component) {
var currentViewStartDate, currentViewData, toUpdateViewIndex, currentViewIndex = component.currentViewIndex;
if (component.direction === 1) {
currentViewStartDate = this.getAdjacentViewStartTime(component, 1);
toUpdateViewIndex = (currentViewIndex + 1) % 3;
component.views[toUpdateViewIndex] = component.getViewData(currentViewStartDate);
}
else if (component.direction === -1) {
currentViewStartDate = this.getAdjacentViewStartTime(component, -1);
toUpdateViewIndex = (currentViewIndex + 2) % 3;
component.views[toUpdateViewIndex] = component.getViewData(currentViewStartDate);
}
else {
if (!component.views) {
currentViewData = [];
currentViewStartDate = component.range.startTime;
currentViewData.push(component.getViewData(currentViewStartDate));
currentViewStartDate = this.getAdjacentViewStartTime(component, 1);
currentViewData.push(component.getViewData(currentViewStartDate));
currentViewStartDate = this.getAdjacentViewStartTime(component, -1);
currentViewData.push(component.getViewData(currentViewStartDate));
component.views = currentViewData;
}
else {
currentViewStartDate = component.range.startTime;
component.views[currentViewIndex] = component.getViewData(currentViewStartDate);
currentViewStartDate = this.getAdjacentViewStartTime(component, -1);
toUpdateViewIndex = (currentViewIndex + 2) % 3;
component.views[toUpdateViewIndex] = component.getViewData(currentViewStartDate);
currentViewStartDate = this.getAdjacentViewStartTime(component, 1);
toUpdateViewIndex = (currentViewIndex + 1) % 3;
component.views[toUpdateViewIndex] = component.getViewData(currentViewStartDate);
}
}
};
CalendarService.prototype.loadEvents = function () {
this.eventSourceChanged.next();
};
CalendarService = tslib_1.__decorate([
Injectable(),
tslib_1.__metadata("design:paramtypes", [])
], CalendarService);
return CalendarService;
}());
export { CalendarService };