UNPKG

react-big-scheduler-stch

Version:

A scheduler and resource planning component built for React and made for modern browsers (A react-big-scheduler fork with additional features and fixes).

120 lines (99 loc) 5.01 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.isNonWorkingTime = exports.getScrollSpecialDayjs = exports.getEventText = exports.getDateLabel = exports.getNonAgendaViewBodyCellBgColor = exports.getCustomDate = exports.getSummary = undefined; var _index = require('./index'); //getSummary func example var getSummary = exports.getSummary = function getSummary(schedulerData, headerEvents, slotId, slotName, headerStart, headerEnd) { return { text: 'Summary', color: 'red', fontSize: '1.2rem' }; }; //getCustomDate example var getCustomDate = exports.getCustomDate = function getCustomDate(schedulerData, num) { var date = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; var viewType = schedulerData.viewType; var selectDate = schedulerData.startDate; if (date != undefined) selectDate = date; var startDate = num === 0 ? selectDate : schedulerData.localeDayjs(new Date(selectDate)).add(2 * num, 'days'), endDate = schedulerData.localeDayjs(new Date(startDate)).add(1, 'days'), cellUnit = _index.CellUnit.Hour; if (viewType === _index.ViewType.Custom1) { var monday = schedulerData.localeDayjs(new Date(selectDate)).startOf('week'); startDate = num === 0 ? monday : schedulerData.localeDayjs(new Date(monday)).add(2 * num, 'weeks'); endDate = schedulerData.localeDayjs(new Date(startDate)).add(1, 'weeks').endOf('week'); cellUnit = _index.CellUnit.Day; } else if (viewType === _index.ViewType.Custom2) { var firstDayOfMonth = schedulerData.localeDayjs(new Date(selectDate)).startOf('month'); startDate = num === 0 ? firstDayOfMonth : schedulerData.localeDayjs(new Date(firstDayOfMonth)).add(2 * num, 'months'); endDate = schedulerData.localeDayjs(new Date(startDate)).add(1, 'months').endOf('month'); cellUnit = _index.CellUnit.Day; } return { startDate: startDate, endDate: endDate, cellUnit: cellUnit }; }; //getNonAgendaViewBodyCellBgColor example var getNonAgendaViewBodyCellBgColor = exports.getNonAgendaViewBodyCellBgColor = function getNonAgendaViewBodyCellBgColor(schedulerData, slotId, header) { if (!header.nonWorkingTime) { return '#87e8de'; } return undefined; }; //getDateLabel func example var getDateLabel = exports.getDateLabel = function getDateLabel(schedulerData, viewType, startDate, endDate) { var start = schedulerData.localeDayjs(new Date(startDate)); var end = schedulerData.localeDayjs(endDate); var dateLabel = start.format('MMM D, YYYY'); if (viewType === _index.ViewType.Week || start != end && (viewType === _index.ViewType.Custom || viewType === _index.ViewType.Custom1 || viewType === _index.ViewType.Custom2)) { dateLabel = start.format('MMM D') + '-' + end.format('D, YYYY'); if (start.month() !== end.month()) dateLabel = start.format('MMM D') + '-' + end.format('MMM D, YYYY'); if (start.year() !== end.year()) dateLabel = start.format('MMM D, YYYY') + '-' + end.format('MMM D, YYYY'); } else if (viewType === _index.ViewType.Month) { dateLabel = start.format('MMMM YYYY'); } else if (viewType === _index.ViewType.Quarter) { dateLabel = start.format('MMM D') + '-' + end.format('MMM D, YYYY'); } else if (viewType === _index.ViewType.Year) { dateLabel = start.format('YYYY'); } return dateLabel; }; var getEventText = exports.getEventText = function getEventText(schedulerData, event) { if (!schedulerData.isEventPerspective) return event.title; var eventText = event.title; schedulerData.resources.forEach(function (item) { if (item.id === event.resourceId) { eventText = item.name; } }); return eventText; }; var getScrollSpecialDayjs = exports.getScrollSpecialDayjs = function getScrollSpecialDayjs(schedulerData, startDayjs, endDayjs) { // return endDayjs; var localeDayjs = schedulerData.localeDayjs; return localeDayjs(new Date()); }; var isNonWorkingTime = exports.isNonWorkingTime = function isNonWorkingTime(schedulerData, time) { var localeDayjs = schedulerData.localeDayjs; if (schedulerData.cellUnit === _index.CellUnit.Hour) { var hour = localeDayjs(new Date(time)).hour(); if (hour < 9 || hour > 18) return true; } else { var dayOfWeek = localeDayjs(new Date(time)).weekday(); if (dayOfWeek === 0 || dayOfWeek === 6) return true; } return false; }; exports.default = { //getSummaryFunc: getSummary, getSummaryFunc: undefined, //getCustomDateFunc: getCustomDate, getCustomDateFunc: undefined, // getNonAgendaViewBodyCellBgColorFunc: getNonAgendaViewBodyCellBgColor, getNonAgendaViewBodyCellBgColorFunc: undefined, getScrollSpecialDayjsFunc: getScrollSpecialDayjs, getDateLabelFunc: getDateLabel, getEventTextFunc: getEventText, isNonWorkingTimeFunc: isNonWorkingTime };