UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

389 lines (387 loc) • 16.5 kB
/** * DevExtreme (cjs/__internal/scheduler/workspaces/m_timeline.js) * Version: 25.2.7 * Build date: Tue May 05 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _component_registrator = _interopRequireDefault(require("../../../core/component_registrator")); var _renderer = _interopRequireDefault(require("../../../core/renderer")); var _common = require("../../../core/utils/common"); var _date = _interopRequireDefault(require("../../../core/utils/date")); var _extend = require("../../../core/utils/extend"); var _position = require("../../../core/utils/position"); var _size = require("../../../core/utils/size"); var _window = require("../../../core/utils/window"); var _index = require("../../scheduler/r1/components/index"); var _index2 = require("../../scheduler/r1/utils/index"); var _m_classes = require("../m_classes"); var _m_table_creator = _interopRequireDefault(require("../m_table_creator")); var _m_utils_time_zone = _interopRequireDefault(require("../m_utils_time_zone")); var _current_time_shader_horizontal = _interopRequireDefault(require("../shaders/current_time_shader_horizontal")); var _m_work_space_indicator = _interopRequireDefault(require("./m_work_space_indicator")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const { tableCreator: tableCreator } = _m_table_creator.default; const TIMELINE_CLASS = "dx-scheduler-timeline"; const GROUP_TABLE_CLASS = "dx-scheduler-group-table"; const HORIZONTAL_GROUPED_WORKSPACE_CLASS = "dx-scheduler-work-space-horizontal-grouped"; const HEADER_PANEL_CELL_CLASS = "dx-scheduler-header-panel-cell"; const HEADER_PANEL_WEEK_CELL_CLASS = "dx-scheduler-header-panel-week-cell"; const HEADER_ROW_CLASS = "dx-scheduler-header-row"; const HORIZONTAL = "horizontal"; const toMs = _date.default.dateToMilliseconds; class SchedulerTimeline extends _m_work_space_indicator.default { constructor() { super(...arguments); this.viewDirection = "horizontal" } get verticalGroupTableClass() { return GROUP_TABLE_CLASS } get renovatedHeaderPanelComponent() { return _index.HeaderPanelTimelineComponent } getGroupTableWidth() { return this.$sidebarTable ? (0, _size.getOuterWidth)(this.$sidebarTable) : 0 } getTotalRowCount(groupCount) { if (this._isHorizontalGroupedWorkSpace()) { return this.getRowCount() } groupCount = groupCount || 1; return this.getRowCount() * groupCount } getFormat() { return "shorttime" } getWorkSpaceHeight() { if (this.option("crossScrollingEnabled") && (0, _window.hasWindow)()) { return (0, _position.getBoundingRect)(this._$dateTable.get(0)).height } return (0, _position.getBoundingRect)(this.$element().get(0)).height } dateTableScrollableConfig() { const config = super.dateTableScrollableConfig(); const timelineConfig = { direction: HORIZONTAL }; return this.option("crossScrollingEnabled") ? config : (0, _extend.extend)(config, timelineConfig) } needCreateCrossScrolling() { return true } headerScrollableConfig() { const config = super.headerScrollableConfig(); return (0, _extend.extend)(config, { scrollByContent: true }) } supportAllDayRow() { return false } getGroupHeaderContainer() { if (this._isHorizontalGroupedWorkSpace()) { return this._$thead } return this.$sidebarTable } insertAllDayRowsIntoDateTable() { return false } needRenderWeekHeader() { return false } incrementDate(date) { date.setDate(date.getDate() + 1) } getIndicationCellCount() { const timeDiff = this.getTimeDiff(); return this.calculateDurationInCells(timeDiff) } getTimeDiff() { let today = this.getToday(); const date = this.getIndicationFirstViewDate(); const startViewDate = this.getStartViewDate(); const dayLightOffset = _m_utils_time_zone.default.getDaylightOffsetInMs(startViewDate, today); if (dayLightOffset) { today = new Date(today.getTime() + dayLightOffset) } return today.getTime() - date.getTime() } calculateDurationInCells(timeDiff) { const today = this.getToday(); const differenceInDays = Math.floor(timeDiff / toMs("day")); let duration = (timeDiff - differenceInDays * toMs("day") - this.option("startDayHour") * toMs("hour")) / this.getCellDuration(); if (today.getHours() > this.option("endDayHour")) { duration = this.getCellCountInDay() } if (duration < 0) { duration = 0 } return differenceInDays * this.getCellCountInDay() + duration } getIndicationWidth() { if (this.isGroupedByDate()) { const cellCount = this.getIndicationCellCount(); const integerPart = Math.floor(cellCount); const fractionPart = cellCount - integerPart; return this.getCellWidth() * (integerPart * this._getGroupCount() + fractionPart) } return this.getIndicationCellCount() * this.getCellWidth() } isVerticalShader() { return false } isCurrentTimeHeaderCell() { return false } setTableSizes() { super.setTableSizes(); const minHeight = this.getWorkSpaceMinHeight(); (0, _size.setHeight)(this.$sidebarTable, minHeight); (0, _size.setHeight)(this._$dateTable, minHeight); this.virtualScrollingDispatcher.updateDimensions() } getWorkSpaceMinHeight() { let minHeight = this.getWorkSpaceHeight(); const workspaceContainerHeight = (0, _size.getOuterHeight)(this._$flexContainer, true); if (minHeight < workspaceContainerHeight) { minHeight = workspaceContainerHeight } return minHeight } getCellCoordinatesByIndex(index) { return { columnIndex: index % this._getCellCount(), rowIndex: 0 } } getCellElementByPosition(cellCoordinates, groupIndex) { const indexes = this._groupedStrategy.prepareCellIndexes(cellCoordinates, groupIndex); return this._$dateTable.find("tr").eq(indexes.rowIndex).find("td").eq(indexes.columnIndex) } getWorkSpaceWidth() { return (0, _size.getOuterWidth)(this._$dateTable, true) } getIndicationFirstViewDate() { return _date.default.trimTime(new Date(this.getStartViewDate())) } getIntervalBetween(currentDate, allDay) { const startDayHour = this.option("startDayHour"); const endDayHour = this.option("endDayHour"); const firstViewDate = this.getStartViewDate(); const firstViewDateTime = firstViewDate.getTime(); const hiddenInterval = (24 - endDayHour + startDayHour) * toMs("hour"); const timeZoneOffset = _date.default.getTimezonesDifference(firstViewDate, currentDate); const apptStart = currentDate.getTime(); const fullInterval = apptStart - firstViewDateTime - timeZoneOffset; const fullDays = Math.floor(fullInterval / toMs("day")); const tailDuration = fullInterval - fullDays * toMs("day"); let tailDelta = 0; const cellCount = this.getCellCountInDay() * (fullDays - this.getWeekendsCount(fullDays)); const gapBeforeAppt = apptStart - _date.default.trimTime(new Date(currentDate)).getTime(); let result = cellCount * this.option("hoursInterval") * toMs("hour"); if (!allDay) { const hour = currentDate.getHours(); switch (true) { case hour < startDayHour: tailDelta = tailDuration - hiddenInterval + gapBeforeAppt; break; case hour >= startDayHour && hour < endDayHour: tailDelta = tailDuration; break; case hour >= endDayHour: tailDelta = tailDuration - (gapBeforeAppt - endDayHour * toMs("hour")); break; case !fullDays: result = fullInterval } result += tailDelta } return result } getWeekendsCount(argument) { return 0 } getAllDayContainer() { return null } getTimePanelWidth() { return 0 } getIntervalDuration(allDay) { return this.getCellDuration() } getCellMinWidth() { return 0 } getWorkSpaceLeftOffset() { return 0 } renderRAllDayPanel() {} renderRTimeTable() {} renderGroupAllDayPanel() {} generateRenderOptions(argument) { const options = super.generateRenderOptions(true); return Object.assign({}, options, { isGenerateWeekDaysHeaderData: this.needRenderWeekHeader(), getDateForHeaderText: _index2.timelineWeekUtils.getDateForHeaderText }) } _init() { super._init(); this.$element().addClass(TIMELINE_CLASS); this.$sidebarTable = (0, _renderer.default)("<div>").addClass(GROUP_TABLE_CLASS) } getDefaultGroupStrategy() { return "vertical" } toggleGroupingDirectionClass() { this.$element().toggleClass(HORIZONTAL_GROUPED_WORKSPACE_CLASS, this._isHorizontalGroupedWorkSpace()) } _getDefaultOptions() { return (0, _extend.extend)(super._getDefaultOptions(), { groupOrientation: "vertical" }) } createWorkSpaceElements() { this.createWorkSpaceScrollableElements() } updateAllDayVisibility() { return (0, _common.noop)() } getDateHeaderTemplate() { return this.option("timeCellTemplate") } renderView() { let groupCellTemplates; if (!this.isRenovatedRender()) { groupCellTemplates = this.renderGroupHeader() } this.renderWorkSpace(); if (this.isRenovatedRender()) { this.virtualScrollingDispatcher.updateDimensions() } this._shader = new _current_time_shader_horizontal.default(this); this.$sidebarTable.appendTo(this._sidebarScrollable.$content()); if (this.isRenovatedRender() && this.isVerticalGroupedWorkSpace()) { this.renderRGroupPanel() } this.updateHeaderEmptyCellWidth(); this.applyCellTemplates(groupCellTemplates) } setHorizontalGroupHeaderCellsHeight() { return (0, _common.noop)() } getTimePanelCells() { return this.$element().find(`.${HEADER_PANEL_CELL_CLASS}:not(.${HEADER_PANEL_WEEK_CELL_CLASS})`) } getCurrentTimePanelCellIndices() { const columnCountPerGroup = this._getCellCount(); const today = this.getToday(); const index = this.getCellIndexByDate(today); const { columnIndex: currentTimeColumnIndex } = this.getCellCoordinatesByIndex(index); if (void 0 === currentTimeColumnIndex) { return [] } const horizontalGroupCount = this._isHorizontalGroupedWorkSpace() && !this.isGroupedByDate() ? this._getGroupCount() : 1; return [...new Array(horizontalGroupCount)].map((_, groupIndex) => columnCountPerGroup * groupIndex + currentTimeColumnIndex) } renderTimePanel() { return (0, _common.noop)() } renderAllDayPanel() { return (0, _common.noop)() } createAllDayPanelElements() { return (0, _common.noop)() } renderDateHeader() { const $headerRow = super.renderDateHeader(); if (this.needRenderWeekHeader()) { const firstViewDate = new Date(this.getStartViewDate()); let currentDate = new Date(firstViewDate); const $cells = []; const groupCount = this._getGroupCount(); const cellCountInDay = this.getCellCountInDay(); const colSpan = this.isGroupedByDate() ? cellCountInDay * groupCount : cellCountInDay; const cellTemplate = this.option("dateCellTemplate"); const horizontalGroupCount = this._isHorizontalGroupedWorkSpace() && !this.isGroupedByDate() ? groupCount : 1; const cellsInGroup = this.viewDataProvider.viewDataGenerator.daysInInterval * this.option("intervalCount"); const cellsCount = cellsInGroup * horizontalGroupCount; for (let templateIndex = 0; templateIndex < cellsCount; templateIndex++) { const $th = (0, _renderer.default)("<th>"); const text = (0, _index2.formatWeekdayAndDay)(currentDate); if (cellTemplate) { const templateOptions = { model: Object.assign({ text: text, date: new Date(currentDate) }, this.getGroupsForDateHeaderTemplate(templateIndex, colSpan)), container: $th, index: templateIndex }; cellTemplate.render(templateOptions) } else { $th.text(text) } $th.addClass(HEADER_PANEL_CELL_CLASS).addClass(HEADER_PANEL_WEEK_CELL_CLASS).attr("colSpan", colSpan); $cells.push($th); if (templateIndex % cellsInGroup === cellsInGroup - 1) { currentDate = new Date(firstViewDate) } else { this.incrementDate(currentDate) } } const $row = (0, _renderer.default)("<tr>").addClass(HEADER_ROW_CLASS).append($cells); $headerRow.before($row) } } renderIndicator(height, rtlOffset, $container, groupCount) { let $indicator; const width = this.getIndicationWidth(); if ("vertical" === this.option("groupOrientation")) { $indicator = this.createIndicator($container); (0, _size.setHeight)($indicator, (0, _position.getBoundingRect)($container.get(0)).height); $indicator.css("left", rtlOffset ? rtlOffset - width : width) } else { for (let i = 0; i < groupCount; i++) { const offset = this.isGroupedByDate() ? i * this.getCellWidth() : this._getCellCount() * this.getCellWidth() * i; $indicator = this.createIndicator($container); (0, _size.setHeight)($indicator, (0, _position.getBoundingRect)($container.get(0)).height); $indicator.css("left", rtlOffset ? rtlOffset - width - offset : width + offset) } } } makeGroupRows(groups, groupByDate) { const tableCreatorStrategy = "vertical" === this.option("groupOrientation") ? tableCreator.VERTICAL : tableCreator.HORIZONTAL; return tableCreator.makeGroupedTable(tableCreatorStrategy, groups, { groupRowClass: _m_classes.GROUP_ROW_CLASS, groupHeaderRowClass: _m_classes.GROUP_ROW_CLASS, groupHeaderClass: this.getGroupHeaderClass.bind(this), groupHeaderContentClass: _m_classes.GROUP_HEADER_CONTENT_CLASS }, this._getCellCount() || 1, this.option("resourceCellTemplate"), this.getTotalRowCount(this._getGroupCount()), groupByDate) } setCurrentTimeCells() { const timePanelCells = this.getTimePanelCells(); const currentTimeCellIndices = this.getCurrentTimePanelCellIndices(); currentTimeCellIndices.forEach(timePanelCellIndex => { timePanelCells.eq(timePanelCellIndex).addClass(_m_classes.HEADER_CURRENT_TIME_CELL_CLASS) }) } }(0, _component_registrator.default)("dxSchedulerTimeline", SchedulerTimeline); var _default = exports.default = SchedulerTimeline;