big-scheduler
Version:
Big scheduler is a powerful and intuitive scheduler and resource planning solution built with React. Seamlessly integrate this modern browser-compatible component into your applications to effectively manage time, appointments, and resources. With drag-a
1,171 lines (1,159 loc) • 53.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _dayjs = _interopRequireDefault(require("dayjs"));
var _quarterOfYear = _interopRequireDefault(require("dayjs/plugin/quarterOfYear"));
var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
var _weekday = _interopRequireDefault(require("dayjs/plugin/weekday"));
var _rrule = require("rrule");
var _scheduler = _interopRequireDefault(require("../config/scheduler"));
var _behaviors = _interopRequireDefault(require("../helper/behaviors"));
var _default = require("../config/default");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var SchedulerData = exports["default"] = /*#__PURE__*/function () {
function SchedulerData() {
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _dayjs["default"])();
var viewType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _default.ViewType.Week;
var showAgenda = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var isEventPerspective = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var newConfig = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
var newBehaviors = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : undefined;
_classCallCheck(this, SchedulerData);
this.resources = [];
this.events = [];
this.eventGroups = [];
this.eventGroupsAutoGenerated = true;
this.viewType = viewType;
this.cellUnit = viewType === _default.ViewType.Day ? _default.CellUnit.Hour : _default.CellUnit.Day;
this.showAgenda = showAgenda;
this.isEventPerspective = isEventPerspective;
this.resizing = false;
this.scrollToSpecialDayjs = false;
this.documentWidth = 0;
this._shouldReloadViewType = false;
this.calendarPopoverLocale = undefined;
_dayjs["default"].extend(_quarterOfYear["default"]);
_dayjs["default"].extend(_weekday["default"]);
_dayjs["default"].extend(_utc["default"]);
this.localeDayjs = _dayjs["default"];
this.config = newConfig === undefined ? _scheduler["default"] : _objectSpread(_objectSpread({}, _scheduler["default"]), newConfig);
this._validateMinuteStep(this.config.minuteStep);
this.behaviors = newBehaviors === undefined ? _behaviors["default"] : _objectSpread(_objectSpread({}, _behaviors["default"]), newBehaviors);
this._resolveDate(0, date);
this._createHeaders();
this._createRenderData();
}
return _createClass(SchedulerData, [{
key: "setSchedulerLocale",
value: function setSchedulerLocale(preset) {
if (!preset) return;
this.localeDayjs.locale(preset);
this._shouldReloadViewType = true;
this.setViewType(this.viewType, this.showAgenda, this.isEventPerspective);
}
}, {
key: "setCalendarPopoverLocale",
value: function setCalendarPopoverLocale(lang) {
if (lang) {
this.calendarPopoverLocale = lang;
}
}
}, {
key: "setResources",
value: function setResources(resources) {
this._validateResource(resources);
this.resources = Array.from(new Set(resources));
this._createRenderData();
this.setScrollToSpecialDayjs(true);
}
}, {
key: "setEventGroupsAutoGenerated",
value: function setEventGroupsAutoGenerated(autoGenerated) {
this.eventGroupsAutoGenerated = autoGenerated;
}
// optional
}, {
key: "setEventGroups",
value: function setEventGroups(eventGroups) {
this._validateEventGroups(eventGroups);
this.eventGroups = Array.from(new Set(eventGroups));
this.eventGroupsAutoGenerated = false;
this._createRenderData();
this.setScrollToSpecialDayjs(true);
}
}, {
key: "setMinuteStep",
value: function setMinuteStep(minuteStep) {
if (this.config.minuteStep !== minuteStep) {
this._validateMinuteStep(minuteStep);
this.config.minuteStep = minuteStep;
this._createHeaders();
this._createRenderData();
}
}
}, {
key: "setBesidesWidth",
value: function setBesidesWidth(besidesWidth) {
if (besidesWidth >= 0) {
this.config.besidesWidth = besidesWidth;
}
}
}, {
key: "getMinuteStepsInHour",
value: function getMinuteStepsInHour() {
return 60 / this.config.minuteStep;
}
}, {
key: "addResource",
value: function addResource(resource) {
var existedResources = this.resources.filter(function (x) {
return x.id === resource.id;
});
if (existedResources.length === 0) {
this.resources.push(resource);
this._createRenderData();
}
}
}, {
key: "addEventGroup",
value: function addEventGroup(eventGroup) {
var existedEventGroups = this.eventGroups.filter(function (x) {
return x.id === eventGroup.id;
});
if (existedEventGroups.length === 0) {
this.eventGroups.push(eventGroup);
this._createRenderData();
}
}
}, {
key: "removeEventGroupById",
value: function removeEventGroupById(eventGroupId) {
var index = -1;
this.eventGroups.forEach(function (item, idx) {
if (item.id === eventGroupId) index = idx;
});
if (index !== -1) this.eventGroups.splice(index, 1);
}
}, {
key: "containsEventGroupId",
value: function containsEventGroupId(eventGroupId) {
var index = -1;
this.eventGroups.forEach(function (item, idx) {
if (item.id === eventGroupId) index = idx;
});
return index !== -1;
}
}, {
key: "setEvents",
value: function setEvents(events) {
this._validateEvents(events);
this.events = Array.from(events);
if (this.eventGroupsAutoGenerated) this._generateEventGroups();
if (this.config.recurringEventsEnabled) this._handleRecurringEvents();
this._createRenderData();
}
}, {
key: "setScrollToSpecialDayjs",
value: function setScrollToSpecialDayjs(scrollToSpecialDayjs) {
if (this.config.scrollToSpecialDayjsEnabled) this.scrollToSpecialDayjs = scrollToSpecialDayjs;
}
}, {
key: "prev",
value: function prev() {
this._resolveDate(-1);
this.events = [];
this._createHeaders();
this._createRenderData();
}
}, {
key: "next",
value: function next() {
this._resolveDate(1);
this.events = [];
this._createHeaders();
this._createRenderData();
}
}, {
key: "setDate",
value: function setDate() {
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _dayjs["default"])(new Date());
this._resolveDate(0, date);
this.events = [];
this._createHeaders();
this._createRenderData();
}
}, {
key: "setViewType",
value: function setViewType() {
var viewType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _default.ViewType.Week;
var showAgenda = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var isEventPerspective = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
this.showAgenda = showAgenda;
this.isEventPerspective = isEventPerspective;
this.cellUnit = _default.CellUnit.Day;
if (this.viewType !== viewType || this._shouldReloadViewType) {
var date = this.startDate;
if (viewType === _default.ViewType.Custom || viewType === _default.ViewType.Custom1 || viewType === _default.ViewType.Custom2) {
this.viewType = viewType;
this._resolveDate(0, date);
} else {
if (this.viewType < viewType) {
if (viewType === _default.ViewType.Week) {
this.startDate = this.localeDayjs(new Date(date)).startOf("week");
this.endDate = this.localeDayjs(new Date(this.startDate)).endOf("week");
} else if (viewType === _default.ViewType.Month) {
this.startDate = this.localeDayjs(new Date(date)).startOf("month");
this.endDate = this.localeDayjs(new Date(this.startDate)).endOf("month");
} else if (viewType === _default.ViewType.Quarter) {
this.startDate = this.localeDayjs(new Date(date)).startOf("quarter");
this.endDate = this.localeDayjs(new Date(this.startDate)).endOf("quarter");
} else if (viewType === _default.ViewType.Year) {
this.startDate = this.localeDayjs(new Date(date)).startOf("year");
this.endDate = this.localeDayjs(new Date(this.startDate)).endOf("year");
}
} else {
var start = this.localeDayjs(new Date(this.startDate));
var end = this.localeDayjs(new Date(this.endDate)).add(1, "days");
if (this.selectDate !== undefined) {
var selectDate = this.localeDayjs(new Date(this.selectDate));
if (selectDate >= start && selectDate < end) {
date = this.selectDate;
}
}
var now = this.localeDayjs();
if (now >= start && now < end) {
date = now.startOf("day");
}
if (viewType === _default.ViewType.Day) {
this.startDate = date;
this.endDate = this.startDate;
this.cellUnit = _default.CellUnit.Hour;
} else if (viewType === _default.ViewType.Week) {
this.startDate = this.localeDayjs(new Date(date)).startOf("week");
this.endDate = this.localeDayjs(new Date(this.startDate)).endOf("week");
} else if (viewType === _default.ViewType.Month) {
this.startDate = this.localeDayjs(new Date(date)).startOf("month");
this.endDate = this.localeDayjs(new Date(this.startDate)).endOf("month");
} else if (viewType === _default.ViewType.Quarter) {
this.startDate = this.localeDayjs(new Date(date)).startOf("quarter");
this.endDate = this.localeDayjs(new Date(this.startDate)).endOf("quarter");
}
}
this.viewType = viewType;
}
this._shouldReloadViewType = false;
this.events = [];
this._createHeaders();
this._createRenderData();
this.setScrollToSpecialDayjs(true);
}
}
}, {
key: "setSchedulerMaxHeight",
value: function setSchedulerMaxHeight(newSchedulerMaxHeight) {
this.config.schedulerMaxHeight = newSchedulerMaxHeight;
}
}, {
key: "isSchedulerResponsive",
value: function isSchedulerResponsive() {
return !!this.config.schedulerWidth.endsWith && this.config.schedulerWidth.endsWith("%");
}
}, {
key: "toggleExpandStatus",
value: function toggleExpandStatus(slotId) {
var slotEntered = false;
var slotIndent = -1;
var isExpanded = false;
var expandedMap = new Map();
this.renderData.forEach(function (item) {
if (slotEntered === false) {
if (item.slotId === slotId && item.hasChildren) {
slotEntered = true;
isExpanded = !item.expanded;
item.expanded = isExpanded;
slotIndent = item.indent;
expandedMap.set(item.indent, {
expanded: item.expanded,
render: item.render
});
}
} else if (item.indent > slotIndent) {
var expandStatus = expandedMap.get(item.indent - 1);
item.render = expandStatus.expanded && expandStatus.render;
if (item.hasChildren) {
expandedMap.set(item.indent, {
expanded: item.expanded,
render: item.render
});
}
} else {
slotEntered = false;
}
});
}
}, {
key: "isResourceViewResponsive",
value: function isResourceViewResponsive() {
var resourceTableWidth = this.getResourceTableConfigWidth();
return !!resourceTableWidth.endsWith && resourceTableWidth.endsWith("%");
}
}, {
key: "isContentViewResponsive",
value: function isContentViewResponsive() {
var contentCellWidth = this.getContentCellConfigWidth();
return !!contentCellWidth.endsWith && contentCellWidth.endsWith("%");
}
}, {
key: "getSchedulerWidth",
value: function getSchedulerWidth() {
var baseWidth = this.documentWidth - this.config.besidesWidth > 0 ? this.documentWidth - this.config.besidesWidth : 0;
return this.isSchedulerResponsive() ? parseInt(baseWidth * Number(this.config.schedulerWidth.slice(0, -1)) / 100, 10) : this.config.schedulerWidth;
}
}, {
key: "getResourceTableWidth",
value: function getResourceTableWidth() {
var resourceTableConfigWidth = this.getResourceTableConfigWidth();
var schedulerWidth = this.getSchedulerWidth();
var resourceTableWidth = this.isResourceViewResponsive() ? parseInt(schedulerWidth * Number(resourceTableConfigWidth.slice(0, -1)) / 100, 10) : resourceTableConfigWidth;
if (this.isSchedulerResponsive() && this.getContentTableWidth() + resourceTableWidth < schedulerWidth) resourceTableWidth = schedulerWidth - this.getContentTableWidth();
return resourceTableWidth;
}
}, {
key: "getContentCellWidth",
value: function getContentCellWidth() {
var contentCellConfigWidth = this.getContentCellConfigWidth();
var schedulerWidth = this.getSchedulerWidth();
return this.isContentViewResponsive() ? parseInt(schedulerWidth * Number(contentCellConfigWidth.slice(0, -1)) / 100, 10) : contentCellConfigWidth;
}
}, {
key: "getContentTableWidth",
value: function getContentTableWidth() {
return this.headers.length * this.getContentCellWidth();
}
}, {
key: "getScrollToSpecialDayjs",
value: function getScrollToSpecialDayjs() {
if (this.config.scrollToSpecialDayjsEnabled) return this.scrollToSpecialDayjs;
return false;
}
}, {
key: "getSlots",
value: function getSlots() {
return this.isEventPerspective ? this.eventGroups : this.resources;
}
}, {
key: "getSlotById",
value: function getSlotById(slotId) {
var slots = this.getSlots();
var slot;
slots.forEach(function (item) {
if (item.id === slotId) slot = item;
});
return slot;
}
}, {
key: "getResourceById",
value: function getResourceById(resourceId) {
var resource;
this.resources.forEach(function (item) {
if (item.id === resourceId) resource = item;
});
return resource;
}
}, {
key: "getTableHeaderHeight",
value: function getTableHeaderHeight() {
return this.config.tableHeaderHeight;
}
}, {
key: "getSchedulerContentDesiredHeight",
value: function getSchedulerContentDesiredHeight() {
var height = 0;
this.renderData.forEach(function (item) {
if (item.render) height += item.rowHeight;
});
return height;
}
}, {
key: "getCellMaxEvents",
value: function getCellMaxEvents() {
var viewConfigMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _default.ViewType.Week, "weekMaxEvents"), _default.ViewType.Day, "dayMaxEvents"), _default.ViewType.Month, "monthMaxEvents"), _default.ViewType.Year, "yearMaxEvents"), _default.ViewType.Quarter, "quarterMaxEvents");
var configProperty = viewConfigMap[this.viewType] || "customMaxEvents";
return this.config[configProperty];
}
}, {
key: "getCalendarPopoverLocale",
value: function getCalendarPopoverLocale() {
return this.calendarPopoverLocale;
}
}, {
key: "getSelectedDate",
value: function getSelectedDate() {
return this.selectDate.format(_default.DATE_FORMAT);
}
}, {
key: "getViewStartDate",
value: function getViewStartDate() {
return this.startDate;
}
}, {
key: "getViewEndDate",
value: function getViewEndDate() {
return this.endDate;
}
}, {
key: "getViewDates",
value: function getViewDates() {
return {
startDate: this.startDate,
endDate: this.endDate
};
}
}, {
key: "getDateLabel",
value: function getDateLabel() {
var start = this.localeDayjs(new Date(this.startDate));
var end = this.localeDayjs(new Date(this.endDate));
var dateLabel = start.format("LL");
if (start !== end) dateLabel = "".concat(start.format("LL"), "-").concat(end.format("LL"));
if (this.behaviors.getDateLabelFunc) dateLabel = this.behaviors.getDateLabelFunc(this, this.viewType, this.startDate, this.endDate);
return dateLabel;
}
}, {
key: "addEvent",
value: function addEvent(newEvent) {
this._attachEvent(newEvent);
if (this.eventGroupsAutoGenerated) this._generateEventGroups();
this._createRenderData();
}
}, {
key: "updateEventStart",
value: function updateEventStart(event, newStart) {
this._detachEvent(event);
event.start = newStart;
this._attachEvent(event);
this._createRenderData();
}
}, {
key: "updateEventEnd",
value: function updateEventEnd(event, newEnd) {
event.end = newEnd;
this._createRenderData();
}
}, {
key: "swapEvent",
value: function swapEvent(eventSource, eventDest) {
// Swap group or resource IDs
if (this.isEventPerspective) {
var _ref = [eventDest.groupId, eventSource.groupId];
eventSource.groupId = _ref[0];
eventDest.groupId = _ref[1];
var _ref2 = [eventDest.groupName, eventSource.groupName];
eventSource.groupName = _ref2[0];
eventDest.groupName = _ref2[1];
} else {
var _ref3 = [eventDest.resourceId, eventSource.resourceId];
eventSource.resourceId = _ref3[0];
eventDest.resourceId = _ref3[1];
}
// Swap start and end times
var _ref4 = [eventDest.start, eventSource.start];
eventSource.start = _ref4[0];
eventDest.start = _ref4[1];
// Update the events
var _ref5 = [eventDest.end, eventSource.end];
eventSource.end = _ref5[0];
eventDest.end = _ref5[1];
this._detachEvent(eventSource);
this._detachEvent(eventDest);
this._attachEvent(eventSource);
this._attachEvent(eventDest);
this._createRenderData();
}
}, {
key: "swapEvent2",
value: function swapEvent2(eventSource, eventDest) {
var tempEventSource = _objectSpread({}, eventSource);
var tempEventDest = _objectSpread({}, eventDest);
this._detachEvent(eventSource);
this._detachEvent(eventDest);
if (this.isEventPerspective) {
tempEventSource.groupId = eventDest.groupId;
tempEventSource.groupName = eventDest.groupName;
tempEventDest.groupId = eventSource.groupId;
tempEventDest.groupName = eventSource.groupName;
} else {
tempEventSource.resourceId = eventDest.resourceId;
tempEventDest.resourceId = eventSource.resourceId;
}
tempEventSource.end = eventDest.end;
tempEventSource.start = eventDest.start;
tempEventDest.end = eventSource.end;
tempEventDest.start = eventSource.start;
this._attachEvent(tempEventSource);
this._attachEvent(tempEventDest);
this._createRenderData();
}
}, {
key: "moveEvent",
value: function moveEvent(event, newSlotId, newSlotName, newStart, newEnd) {
this._detachEvent(event);
if (this.isEventPerspective) {
event.groupId = newSlotId;
event.groupName = newSlotName;
} else event.resourceId = newSlotId;
event.end = newEnd;
event.start = newStart;
this._attachEvent(event);
this._createRenderData();
}
}, {
key: "isEventInTimeWindow",
value: function isEventInTimeWindow(eventStart, eventEnd, windowStart, windowEnd) {
return eventStart < windowEnd && eventEnd > windowStart;
}
}, {
key: "removeEvent",
value: function removeEvent(event) {
var index = this.events.indexOf(event);
if (index !== -1) {
this.events.splice(index, 1);
this._createRenderData();
}
}
}, {
key: "removeEventById",
value: function removeEventById(eventId) {
var index = -1;
this.events.forEach(function (item, idx) {
if (item.id === eventId) index = idx;
});
if (index !== -1) {
this.events.splice(index, 1);
this._createRenderData();
}
}
}, {
key: "getResourceTableConfigWidth",
value: function getResourceTableConfigWidth() {
if (this.showAgenda) {
return this.config.agendaResourceTableWidth;
}
var viewConfigMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _default.ViewType.Week, "weekResourceTableWidth"), _default.ViewType.Day, "dayResourceTableWidth"), _default.ViewType.Month, "monthResourceTableWidth"), _default.ViewType.Year, "yearResourceTableWidth"), _default.ViewType.Quarter, "quarterResourceTableWidth");
var configProperty = viewConfigMap[this.viewType] || "customResourceTableWidth";
return this.config[configProperty];
}
}, {
key: "getContentCellConfigWidth",
value: function getContentCellConfigWidth() {
var viewConfigMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _default.ViewType.Week, "weekCellWidth"), _default.ViewType.Day, "dayCellWidth"), _default.ViewType.Month, "monthCellWidth"), _default.ViewType.Year, "yearCellWidth"), _default.ViewType.Quarter, "quarterCellWidth");
var configProperty = viewConfigMap[this.viewType] || "customCellWidth";
return this.config[configProperty];
}
}, {
key: "_setDocumentWidth",
value: function _setDocumentWidth(documentWidth) {
if (documentWidth >= 0) {
this.documentWidth = documentWidth;
}
}
}, {
key: "_detachEvent",
value: function _detachEvent(event) {
var index = this.events.indexOf(event);
if (index !== -1) this.events.splice(index, 1);
}
}, {
key: "_attachEvent",
value: function _attachEvent(event) {
var _this = this;
var pos = 0;
var eventStart = this.localeDayjs(new Date(event.start));
this.events.forEach(function (item, index) {
var start = _this.localeDayjs(new Date(item.start));
if (eventStart >= start) pos = index + 1;
});
this.events.splice(pos, 0, event);
}
}, {
key: "_handleRecurringEvents",
value: function _handleRecurringEvents() {
var _this2 = this;
var recurringEvents = this.events.filter(function (x) {
return !!x.rrule;
});
recurringEvents.forEach(function (item) {
_this2._detachEvent(item);
});
recurringEvents.forEach(function (item) {
var windowStart = _this2.startDate;
var windowEnd = _this2.endDate.add(1, "days");
var oldStart = _this2.localeDayjs(new Date(item.start));
var oldEnd = _this2.localeDayjs(new Date(item.end));
var rule = (0, _rrule.rrulestr)(item.rrule);
var oldDtstart;
var oldUntil = rule.origOptions.until || windowEnd.toDate();
if (rule.origOptions.dtstart) {
oldDtstart = _this2.localeDayjs(new Date(rule.origOptions.dtstart));
}
// rule.origOptions.dtstart = oldStart.toDate();
if (windowEnd < oldUntil) {
rule.origOptions.until = windowEnd.toDate();
}
// reload
rule = (0, _rrule.rrulestr)(rule.toString());
if (item.exdates || item.exrule) {
var rruleSet = new _rrule.RRuleSet();
rruleSet.rrule(rule);
if (item.exrule) {
rruleSet.exrule((0, _rrule.rrulestr)(item.exrule));
}
if (item.exdates) {
item.exdates.forEach(function (exdate) {
rruleSet.exdate(_this2.localeDayjs(exdate).toDate());
});
}
rule = rruleSet;
}
var all = rule.between(new Date(windowStart), new Date(windowEnd));
all.forEach(function (time, index) {
var newEvent = _objectSpread(_objectSpread({}, item), {}, {
recurringEventId: item.id,
recurringEventStart: item.start,
recurringEventEnd: item.end,
id: "".concat(item.id, "-").concat(index),
start: rule.origOptions.tzid ? _this2.localeDayjs.utc(time).utcOffset(_this2.localeDayjs(new Date().utcOffset)(), true).format(_default.DATETIME_FORMAT) : _this2.localeDayjs(new Date(time)).format(_default.DATETIME_FORMAT),
end: rule.origOptions.tzid ? _this2.localeDayjs.utc(time).utcOffset(_this2.localeDayjs(new Date().utcOffset)(), true).add(oldEnd.diff(oldStart), "ms").add(_this2.localeDayjs(new Date(oldUntil)).utcOffset() - _this2.localeDayjs(new Date(item.start)).utcOffset(), "m").format(_default.DATETIME_FORMAT) : _this2.localeDayjs(new Date(time)).add(oldEnd.diff(oldStart), "ms").format(_default.DATETIME_FORMAT)
});
var eventStart = _this2.localeDayjs(newEvent.start);
var eventEnd = _this2.localeDayjs(newEvent.end);
if (_this2.isEventInTimeWindow(eventStart, eventEnd, windowStart, windowEnd) && (!oldDtstart || eventStart >= oldDtstart)) {
_this2._attachEvent(newEvent);
}
});
});
}
}, {
key: "_resolveDate",
value: function _resolveDate(num) {
var _this3 = this;
var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
if (date !== undefined) {
this.selectDate = this.localeDayjs(date);
}
var setStartAndEndDates = function setStartAndEndDates(unit) {
_this3.startDate = date !== undefined ? _this3.selectDate.startOf(unit) : _this3.startDate.add(num, "".concat(unit, "s"));
_this3.endDate = _this3.startDate.endOf(unit);
};
switch (this.viewType) {
case _default.ViewType.Week:
setStartAndEndDates("week");
break;
case _default.ViewType.Day:
this.startDate = date !== undefined ? this.selectDate : this.startDate.add(num, "days");
this.endDate = this.startDate;
break;
case _default.ViewType.Month:
setStartAndEndDates("month");
break;
case _default.ViewType.Quarter:
setStartAndEndDates("quarter");
break;
case _default.ViewType.Year:
setStartAndEndDates("year");
break;
case _default.ViewType.Custom:
case _default.ViewType.Custom1:
case _default.ViewType.Custom2:
if (this.behaviors.getCustomDateFunc !== undefined) {
var customDate = this.behaviors.getCustomDateFunc(this, num, date);
var customStartDate = this.localeDayjs(customDate.startDate);
var customEndDate = this.localeDayjs(customDate.endDate);
if (num === -1 && !customStartDate.isAfter(this.selectDate)) {
customEndDate = this.startDate.add(_default.DATE_CONFIG.customViewPrevOffset, _default.DATE_CONFIG.customViewUnit);
customStartDate = customEndDate.subtract(_default.DATE_CONFIG.customViewRange, _default.DATE_CONFIG.customViewUnit).startOf(_default.DATE_CONFIG.startOfUnit);
} else if (num === 1) {
customStartDate = this.endDate.subtract(_default.DATE_CONFIG.customViewNextOffset, _default.DATE_CONFIG.customViewUnit);
customEndDate = customStartDate.add(_default.DATE_CONFIG.customViewRange, _default.DATE_CONFIG.customViewUnit).endOf(_default.DATE_CONFIG.endOfUnit);
}
this.startDate = customStartDate;
this.endDate = customEndDate;
if (customDate.cellUnit) {
this.cellUnit = customDate.cellUnit;
}
} else {
throw new Error("This is a custom view type, set behaviors.getCustomDateFunc func to resolve the time window (startDate and endDate) yourself");
}
break;
default:
break;
}
}
// Previous Code
}, {
key: "_createHeaders",
value: function _createHeaders() {
var headers = [];
var start = this.localeDayjs(new Date(this.startDate));
var end = this.localeDayjs(new Date(this.endDate));
var header = start;
if (this.showAgenda) {
headers.push({
time: header.format(_default.DATETIME_FORMAT),
nonWorkingTime: false
});
} else if (this.cellUnit === _default.CellUnit.Hour) {
if (start.hour() === 0) {
start = start.add(this.config.dayStartFrom, "hours");
}
if (end.hour() === 0) {
end = end.add(this.config.dayStopTo, "hours");
}
header = start;
var prevHour = -1;
while (header >= start && header <= end) {
// prevent doubled hours on time change
if (header.hour() === prevHour) {
header = header.add(1, "hours");
// eslint-disable-next-line no-continue
continue;
}
prevHour = header.hour();
var minuteSteps = this.getMinuteStepsInHour();
for (var i = 0; i < minuteSteps; i += 1) {
var hour = header.hour();
if (hour >= this.config.dayStartFrom && hour <= this.config.dayStopTo) {
var time = header.format(_default.DATETIME_FORMAT);
var nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
headers.push({
time: time,
nonWorkingTime: nonWorkingTime
});
}
header = header.add(this.config.minuteStep, "minutes");
}
}
} else if (this.cellUnit === _default.CellUnit.Day) {
while (header >= start && header <= end) {
var _time = header.format(_default.DATETIME_FORMAT);
var dayOfWeek = header.weekday();
if (this.config.displayWeekend || dayOfWeek !== 0 && dayOfWeek !== 6) {
var _nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, _time);
headers.push({
time: _time,
nonWorkingTime: _nonWorkingTime
});
}
header = header.add(1, "days");
}
} else if (this.cellUnit === _default.CellUnit.Week) {
while (header >= start && header <= end) {
var _time2 = header.format(_default.DATE_FORMAT);
headers.push({
time: _time2
});
header = header.add(1, "weeks").startOf("week");
}
} else if (this.cellUnit === _default.CellUnit.Month) {
while (header >= start && header <= end) {
var _time3 = header.format(_default.DATE_FORMAT);
headers.push({
time: _time3
});
header = header.add(1, "months").startOf("month");
}
} else if (this.cellUnit === _default.CellUnit.Year) {
while (header >= start && header <= end) {
var _time4 = header.format(_default.DATE_FORMAT);
headers.push({
time: _time4
});
header = header.add(1, "years").startOf("year");
}
}
this.headers = headers;
}
// Fix Optimited code
// _createHeaders() {
// const headers = [];
// const start = this.localeDayjs(new Date(this.startDate));
// const end = this.localeDayjs(new Date(this.endDate));
// const processHeader = (header, format, unit, incrementFn) => {
// let head = header;
// while (head >= start && head <= end) {
// const time = head.format(format);
// if (unit === CellUnit.Day) {
// const dayOfWeek = head.weekday();
// if (this.config.displayWeekend || (dayOfWeek !== 0 && dayOfWeek !== 6)) {
// const nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
// headers.push({ time, nonWorkingTime });
// }
// } else {
// headers.push({ time });
// }
// head = head.add(1, incrementFn);
// }
// };
// if (this.showAgenda) {
// headers.push({ time: start.format(DATETIME_FORMAT), nonWorkingTime: false });
// } else if (this.cellUnit === CellUnit.Hour) {
// const hourIncrement = this.config.minuteStep < 60 ? 'minutes' : 'hours';
// const minuteSteps = this.getMinuteStepsInHour();
// let header = start.hour() === 0 ? start.add(this.config.dayStartFrom, 'hours') : start;
// while (header <= end) {
// const hour = header.hour();
// if (hour >= this.config.dayStartFrom && hour <= this.config.dayStopTo) {
// const time = header.format(DATETIME_FORMAT);
// const nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
// headers.push({ time, nonWorkingTime });
// }
// header = header.add(minuteSteps, hourIncrement);
// }
// } else {
// const header = start;
// const format = this.cellUnit === CellUnit.Day ? DATETIME_FORMAT : DATE_FORMAT;
// const incrementFn = this.cellUnit === CellUnit.Day ? 'days' : `${this.cellUnit}s`;
// processHeader(header, format, this.cellUnit, incrementFn);
// }
// this.headers = headers;
// }
}, {
key: "_createInitHeaderEvents",
value: function _createInitHeaderEvents(header) {
var start = this.localeDayjs(new Date(header.time));
var startValue = start.format(_default.DATETIME_FORMAT);
var endValue;
if (this.showAgenda) {
var incrementUnit = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _default.ViewType.Day, "days"), _default.ViewType.Week, "weeks"), _default.ViewType.Month, "months"), _default.ViewType.Year, "years"), _default.ViewType.Quarter, "quarters")[this.viewType] || "days";
if (incrementUnit === "days") {
endValue = this.localeDayjs(new Date(this.endDate)).add(1, "days").format(_default.DATETIME_FORMAT);
} else {
endValue = start.add(1, incrementUnit).format(_default.DATETIME_FORMAT);
}
} else {
var _incrementUnit = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _default.CellUnit.Hour, "minutes"), _default.CellUnit.Week, "weeks"), _default.CellUnit.Month, "months"), _default.CellUnit.Year, "years")[this.cellUnit] || "days";
endValue = start.add(_incrementUnit === "minutes" ? this.config.minuteStep : 1, _incrementUnit).format(this.cellUnit === _default.CellUnit.Year || this.cellUnit === _default.CellUnit.Month || this.cellUnit === _default.CellUnit.Week ? _default.DATE_FORMAT : _default.DATETIME_FORMAT);
}
return {
time: header.time,
nonWorkingTime: header.nonWorkingTime,
start: startValue,
end: endValue,
count: 0,
addMore: 0,
addMoreIndex: 0,
events: Array(3)
};
}
}, {
key: "_createHeaderEvent",
value: function _createHeaderEvent(render, span, eventItem) {
return {
render: render,
span: span,
eventItem: eventItem
};
}
}, {
key: "_getEventSlotId",
value: function _getEventSlotId(event) {
return this.isEventPerspective ? this._getEventGroupId(event) : event.resourceId;
}
}, {
key: "_getEventGroupId",
value: function _getEventGroupId(event) {
return event.groupId ? event.groupId.toString() : event.id.toString();
}
}, {
key: "_getEventGroupName",
value: function _getEventGroupName(event) {
return event.groupName ? event.groupName : event.title;
}
}, {
key: "_generateEventGroups",
value: function _generateEventGroups() {
var _this4 = this;
var eventGroups = [];
var set = new Set();
this.events.forEach(function (item) {
var groupId = _this4._getEventGroupId(item);
var groupName = _this4._getEventGroupName(item);
if (!set.has(groupId)) {
eventGroups.push({
id: groupId,
name: groupName,
state: item
});
set.add(groupId);
}
});
this.eventGroups = eventGroups;
}
}, {
key: "_createInitRenderData",
value: function _createInitRenderData(isEventPerspective, eventGroups, resources, headers) {
var _this5 = this;
var slots = isEventPerspective ? eventGroups : resources;
var slotTree = [];
var slotMap = new Map();
slots.forEach(function (slot) {
var headerEvents = headers.map(function (header) {
return _this5._createInitHeaderEvents(header);
});
var slotRenderData = {
slotId: slot.id,
slotName: slot.name,
slotTitle: slot.title,
parentId: slot.parentId,
groupOnly: slot.groupOnly,
"static": slot["static"],
hasSummary: false,
rowMaxCount: 0,
rowHeight: _this5.config.nonAgendaSlotMinHeight !== 0 ? _this5.config.nonAgendaSlotMinHeight : _this5.config.eventItemLineHeight + 2,
headerItems: headerEvents,
indent: 0,
hasChildren: false,
expanded: true,
render: true
};
var id = slot.id;
var value;
if (slotMap.has(id)) {
value = slotMap.get(id);
value.data = slotRenderData;
} else {
value = {
data: slotRenderData,
children: []
};
slotMap.set(id, value);
}
var parentId = slot.parentId;
if (!parentId || parentId === id) {
slotTree.push(value);
} else {
var parentValue;
if (slotMap.has(parentId)) {
parentValue = slotMap.get(parentId);
} else {
parentValue = {
data: undefined,
children: []
};
slotMap.set(parentId, parentValue);
}
parentValue.children.push(value);
}
});
var slotStack = [];
var i;
for (i = slotTree.length - 1; i >= 0; i -= 1) {
slotStack.push(slotTree[i]);
}
var initRenderData = [];
var currentNode;
while (slotStack.length > 0) {
currentNode = slotStack.pop();
if (currentNode.data.indent > 0) {
currentNode.data.render = this.config.defaultExpanded;
}
if (currentNode.children.length > 0) {
currentNode.data.hasChildren = true;
currentNode.data.expanded = this.config.defaultExpanded;
}
initRenderData.push(currentNode.data);
for (i = currentNode.children.length - 1; i >= 0; i -= 1) {
currentNode.children[i].data.indent = currentNode.data.indent + 1;
slotStack.push(currentNode.children[i]);
}
}
return initRenderData;
}
}, {
key: "_getSpan",
value: function _getSpan(startTime, endTime, headers) {
if (this.showAgenda) return 1;
// function startOfWeek(date) {
// const day = date.getDay();
// const diff = date.getDate() - day;
// return new Date(date.getFullYear(), date.getMonth(), diff);
// }
var timeBetween = function timeBetween(date1, date2, timeIn) {
if (timeIn === "days" || timeIn === "day") {
if (date1.getDate() === date2.getDate() && date1.getMonth() === date2.getMonth()) {
return 1;
}
}
var one;
switch (timeIn) {
case "days":
case "day":
one = 1000 * 60 * 60 * 24;
break;
case "minutes":
case "minute":
one = 1000 * 60;
break;
default:
return 0;
}
var date1Ms = date1.getTime();
var date2Ms = date2.getTime();
var diff = (date2Ms - date1Ms) / one;
return diff < 0 ? 0 : diff;
};
var eventStart = new Date(startTime);
var eventEnd = new Date(endTime);
var span = 0;
var windowStart = new Date(this.startDate);
var windowEnd = new Date(this.endDate);
windowStart.setHours(0, 0, 0, 0);
windowEnd.setHours(23, 59, 59);
if (this.viewType === _default.ViewType.Day) {
if (headers.length > 0) {
var day = new Date(headers[0].time);
if (day.getDate() > eventStart.getDate() && day.getDate() < eventEnd.getDate()) {
span = 1440 / this.config.minuteStep;
} else if (day.getDate() > eventStart.getDate() && day.getDate() === eventEnd.getDate()) {
span = Math.ceil(timeBetween(day, eventEnd, "minutes") / this.config.minuteStep);
} else if (day.getDate() === eventStart.getDate() && day.getDate() < eventEnd.getDate()) {
day.setHours(23, 59, 59);
span = Math.ceil(timeBetween(eventStart, day, "minutes") / this.config.minuteStep);
} else if (day.getDate() === eventStart.getDate() && day.getDate() === eventEnd.getDate() || eventEnd.getDate() === eventStart.getDate()) {
span = Math.ceil(timeBetween(eventStart, eventEnd, "minutes") / this.config.minuteStep);
}
}
} else if (this.viewType === _default.ViewType.Week || this.viewType === _default.ViewType.Month || this.viewType === _default.ViewType.Quarter || this.viewType === _default.ViewType.Year) {
var startDate = windowStart < eventStart ? eventStart : windowStart;
var endDate = windowEnd > eventEnd ? eventEnd : windowEnd;
span = Math.ceil(timeBetween(startDate, endDate, "days"));
} else {
if (this.cellUnit === _default.CellUnit.Day) {
eventEnd.setHours(23, 59, 59);
eventStart.setHours(0, 0, 0, 0);
}
var timeIn = this.cellUnit === _default.CellUnit.Day ? "days" : "minutes";
var dividedBy = this.cellUnit === _default.CellUnit.Day ? 1 : this.config.minuteStep;
if (windowStart >= eventStart && eventEnd <= windowEnd) {
span = Math.ceil(timeBetween(windowStart, eventEnd, timeIn) / dividedBy);
} else if (windowStart > eventStart && eventEnd > windowEnd) {
span = Math.ceil(timeBetween(windowStart, windowEnd, timeIn) / dividedBy);
} else if (windowStart <= eventStart && eventEnd >= windowEnd) {
span = Math.ceil(timeBetween(eventStart, windowEnd, timeIn) / dividedBy);
} else {
span = Math.ceil(timeBetween(eventStart, eventEnd, timeIn) / dividedBy);
}
}
return span;
}
}, {
key: "_validateResource",
value: function _validateResource(resources) {
if (Object.prototype.toString.call(resources) !== "[object Array]") {
throw new Error("Resources should be Array object");
}
resources.forEach(function (item, index) {
if (item === undefined) {
console.error("Resource undefined: ".concat(index));
throw new Error("Resource undefined: ".concat(index));
}
if (item.id === undefined || item.name === undefined) {
console.error("Resource property missed", index, item);
throw new Error("Resource property undefined: ".concat(index));
}
});
}
}, {
key: "_validateEventGroups",
value: function _validateEventGroups(eventGroups) {
if (Object.prototype.toString.call(eventGroups) !== "[object Array]") {
throw new Error("Event groups should be Array object");
}
eventGroups.forEach(function (item, index) {
if (item === undefined) {
console.error("Event group undefined: ".concat(index));
throw new Error("Event group undefined: ".concat(index));
}
if (item.id === undefined || item.name === undefined) {
console.error("Event group property missed", index, item);
throw new Error("Event group property undefined: ".concat(index));
}
});
}
}, {
key: "_validateEvents",
value: function _validateEvents(events) {
if (Object.prototype.toString.call(events) !== "[object Array]") {
throw new Error("Events should be Array object");
}
events.forEach(function (e, index) {
if (e === undefined) {
console.error("Event undefined: ".concat(index));
throw new Error("Event undefined: ".concat(index));
}
if (e.id === undefined || e.resourceId === undefined || e.title === undefined || e.start === undefined || e.end === undefined) {
console.error("Event property missed", index, e);
throw new Error("Event property undefined: ".concat(index));
}
});
}
}, {
key: "_validateMinuteStep",
value: function _validateMinuteStep(minuteStep) {
if (60 % minuteStep !== 0) {
console.error("Minute step is not set properly - 60 minutes must be divisible without remainder by this number");
throw new Error("Minute step is not set properly - 60 minutes must be divisible without remainder by this number");
}
}
}, {
key: "_compare",
value: function _compare(event1, event2) {
var start1 = this.localeDayjs(event1.start);
var start2 = this.localeDayjs(event2.start);
if (start1 !== start2) return start1 < start2 ? -1 : 1;
var end1 = this.localeDayjs(event1.end);
var end2 = this.localeDayjs(event2.end);
if (end1 !== end2) return end1 < end2 ? -1 : 1;
return event1.id < event2.id ? -1 : 1;
}
}, {
key: "_createRenderData",
value: function _createRenderData() {
var _this6 = this;
var initRenderData = this._createInitRenderData(this.isEventPerspective, this.eventGroups, this.resources, this.headers);
// this.events.sort(this._compare);
var cellMaxEventsCount = this.getCellMaxEvents();
var cellMaxEventsCountValue = 30;
this.events.forEach(function (item) {
var resourceEventsList = initRenderData.filter(function (x) {
return x.slotId === _this6._getEventSlotId(item);
});
if (resourceEventsList.length > 0) {
var resourceEvents = resourceEventsList[0];
var span = _this6._getSpan(item.start, item.end, _this6.headers);
var eventStart = new Date(item.start);
var eventEnd = new Date(item.end);
var pos = -1;
resourceEvents.headerItems.forEach(function (header, index) {
var headerStart = new Date(header.start);
var headerEnd = new Date(header.end);
if (headerEnd > eventStart && headerStart < eventEnd) {
header.count += 1;
if (header.count > resourceEvents.rowMaxCount) {
resourceEvents.rowMaxCount = header.count;
var rowsCount = cellMaxEventsCount <= cellMaxEventsCountValue && resourceEvents.rowMaxCount > cellMaxEventsCount ? cellMaxEventsCount : resourceEvents.rowMaxCount;
// get new row height increase/decrease the value
var newRowHeight = rowsCount * _this6.config.eventItemLineHeight + (_this6.config.creatable && _this6.config.checkConflict === false ? 2 : 0);
if (newRowHeight > resourceEvents.rowHeight) resourceEvents.rowHeight = newRowHeight;
}