devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
288 lines (281 loc) • 13.6 kB
JavaScript
/**
* DevExtreme (cjs/__internal/scheduler/m_appointments_layout_manager.js)
* Version: 23.2.6
* Build date: Wed May 01 2024
*
* Copyright (c) 2012 - 2024 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 _common = require("../../core/utils/common");
var _date = _interopRequireDefault(require("../../core/utils/date"));
var _index = require("../scheduler/r1/utils/index");
var _m_view_model_generator = require("./appointments/m_view_model_generator");
var _m_position_helper = require("./workspaces/helpers/m_position_helper");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
}
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key]
}
}
}
return target
};
return _extends.apply(this, arguments)
}
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(arg) {
var key = _toPrimitive(arg, "string");
return "symbol" === typeof key ? key : String(key)
}
function _toPrimitive(input, hint) {
if ("object" !== typeof input || null === input) {
return input
}
var prim = input[Symbol.toPrimitive];
if (void 0 !== prim) {
var res = prim.call(input, hint || "default");
if ("object" !== typeof res) {
return res
}
throw new TypeError("@@toPrimitive must return a primitive value.")
}
return ("string" === hint ? String : Number)(input)
}
const toMs = _date.default.dateToMilliseconds;
let AppointmentLayoutManager = function() {
function AppointmentLayoutManager(instance) {
this.instance = instance;
this.appointmentViewModel = new _m_view_model_generator.AppointmentViewModelGenerator
}
var _proto = AppointmentLayoutManager.prototype;
_proto.getCellDimensions = function(options) {
if (this.instance._workSpace) {
return {
width: this.instance._workSpace.getCellWidth(),
height: this.instance._workSpace.getCellHeight(),
allDayHeight: this.instance._workSpace.getAllDayHeight()
}
}
return
};
_proto._getRenderingStrategyOptions = function() {
const workspace = this.instance.getWorkSpace();
const {
virtualScrollingDispatcher: virtualScrollingDispatcher
} = this.instance.getWorkSpace();
const {
cellCountInsideLeftVirtualCell: cellCountInsideLeftVirtualCell,
cellCountInsideTopVirtualRow: cellCountInsideTopVirtualRow
} = virtualScrollingDispatcher;
const groupCount = (0, _index.getGroupCount)(this.instance.option("loadedResources"));
const DOMMetaData = workspace.getDOMElementsMetaData();
const allDayHeight = (0, _m_position_helper.getAllDayHeight)(workspace.option("showAllDayPanel"), workspace._isVerticalGroupedWorkSpace(), DOMMetaData);
const rowCount = workspace._getRowCount();
const {
positionHelper: positionHelper,
viewDataProvider: viewDataProvider
} = workspace;
const visibleDayDuration = viewDataProvider.getVisibleDayDuration(workspace.option("startDayHour"), workspace.option("endDayHour"), workspace.option("hoursInterval"));
const cellDuration = (0, _index.getCellDuration)(workspace.type, workspace.option("startDayHour"), workspace.option("endDayHour"), workspace.option("hoursInterval"));
return {
resources: this.instance.option("resources"),
loadedResources: this.instance.option("loadedResources"),
getAppointmentColor: this.instance.createGetAppointmentColor(),
dataAccessors: this.instance._dataAccessors,
appointmentRenderingStrategyName: this.appointmentRenderingStrategyName,
adaptivityEnabled: this.instance.option("adaptivityEnabled"),
rtlEnabled: this.instance.option("rtlEnabled"),
startDayHour: this.instance._getCurrentViewOption("startDayHour"),
endDayHour: this.instance._getCurrentViewOption("endDayHour"),
viewOffset: this.instance._getCurrentViewOption("offset") * toMs("minute"),
maxAppointmentsPerCell: this.instance._getCurrentViewOption("maxAppointmentsPerCell"),
currentDate: this.instance.option("currentDate"),
isVirtualScrolling: this.instance.isVirtualScrolling(),
leftVirtualCellCount: cellCountInsideLeftVirtualCell,
topVirtualCellCount: cellCountInsideTopVirtualRow,
intervalCount: workspace.option("intervalCount"),
hoursInterval: workspace.option("hoursInterval"),
showAllDayPanel: workspace.option("showAllDayPanel"),
isGroupedAllDayPanel: workspace.isGroupedAllDayPanel(),
groups: this.instance._getCurrentViewOption("groups"),
groupCount: groupCount,
rowCount: rowCount,
appointmentCountPerCell: this.instance.option("_appointmentCountPerCell"),
appointmentOffset: this.instance.option("_appointmentOffset"),
allowResizing: this.instance._allowResizing(),
allowAllDayResizing: this.instance._allowAllDayResizing(),
startViewDate: workspace.getStartViewDate(),
groupOrientation: workspace._getRealGroupOrientation(),
cellWidth: (0, _m_position_helper.getCellWidth)(DOMMetaData),
cellHeight: (0, _m_position_helper.getCellHeight)(DOMMetaData),
allDayHeight: allDayHeight,
resizableStep: positionHelper.getResizableStep(),
visibleDayDuration: visibleDayDuration,
allDayPanelMode: this.instance._getCurrentViewOption("allDayPanelMode"),
timeZoneCalculator: this.instance.timeZoneCalculator,
timeZone: this.instance.option("timeZone"),
firstDayOfWeek: this.instance.getFirstDayOfWeek(),
viewStartDayHour: this.instance._getCurrentViewOption("startDayHour"),
viewEndDayHour: this.instance._getCurrentViewOption("endDayHour"),
viewType: workspace.type,
endViewDate: workspace.getEndViewDate(),
positionHelper: positionHelper,
isGroupedByDate: workspace.isGroupedByDate(),
cellDuration: cellDuration,
cellDurationInMinutes: workspace.option("cellDuration"),
viewDataProvider: workspace.viewDataProvider,
supportAllDayRow: workspace.supportAllDayRow(),
dateRange: workspace.getDateRange(),
intervalDuration: workspace.getIntervalDuration(),
allDayIntervalDuration: workspace.getIntervalDuration(true),
isVerticalGroupOrientation: workspace.isVerticalOrientation(),
DOMMetaData: DOMMetaData,
instance: this.instance,
agendaDuration: workspace.option("agendaDuration")
}
};
_proto.createAppointmentsMap = function(items) {
const renderingStrategyOptions = this._getRenderingStrategyOptions();
const {
viewModel: viewModel,
positionMap: positionMap
} = this.appointmentViewModel.generate(items, renderingStrategyOptions);
this._positionMap = positionMap;
return viewModel
};
_proto._isDataChanged = function(data) {
const {
appointmentDataProvider: appointmentDataProvider
} = this.instance;
const updatedData = appointmentDataProvider.getUpdatedAppointment();
return updatedData === data || appointmentDataProvider.getUpdatedAppointmentKeys().some(item => data[item.key] === item.value)
};
_proto._isAppointmentShouldAppear = function(currentAppointment, sourceAppointment) {
return currentAppointment.needRepaint && sourceAppointment.needRemove
};
_proto._isSettingChanged = function(settings, sourceSetting) {
if (settings.length !== sourceSetting.length) {
return true
}
const createSettingsToCompare = (settings, index) => {
const currentSetting = settings[index];
const leftVirtualCellCount = currentSetting.leftVirtualCellCount || 0;
const topVirtualCellCount = currentSetting.topVirtualCellCount || 0;
const columnIndex = currentSetting.columnIndex + leftVirtualCellCount;
const rowIndex = currentSetting.rowIndex + topVirtualCellCount;
const hMax = currentSetting.reduced ? currentSetting.hMax : void 0;
const vMax = currentSetting.reduced ? currentSetting.vMax : void 0;
return _extends(_extends({}, currentSetting), {
columnIndex: columnIndex,
rowIndex: rowIndex,
positionByMap: void 0,
topVirtualCellCount: void 0,
leftVirtualCellCount: void 0,
leftVirtualWidth: void 0,
topVirtualHeight: void 0,
hMax: hMax,
vMax: vMax,
info: {}
})
};
for (let i = 0; i < settings.length; i++) {
const newSettings = createSettingsToCompare(settings, i);
const oldSettings = createSettingsToCompare(sourceSetting, i);
if (oldSettings) {
oldSettings.sortedIndex = newSettings.sortedIndex
}
if (!(0, _common.equalByValue)(newSettings, oldSettings)) {
return true
}
}
return false
};
_proto._getAssociatedSourceAppointment = function(currentAppointment, sourceAppointments) {
for (let i = 0; i < sourceAppointments.length; i++) {
const item = sourceAppointments[i];
if (item.itemData === currentAppointment.itemData) {
return item
}
}
return null
};
_proto._getDeletedAppointments = function(currentAppointments, sourceAppointments) {
const result = [];
for (let i = 0; i < sourceAppointments.length; i++) {
const sourceAppointment = sourceAppointments[i];
const currentAppointment = this._getAssociatedSourceAppointment(sourceAppointment, currentAppointments);
if (!currentAppointment) {
sourceAppointment.needRemove = true;
result.push(sourceAppointment)
}
}
return result
};
_proto.getRepaintedAppointments = function(currentAppointments, sourceAppointments) {
if (0 === sourceAppointments.length || "agenda" === this.appointmentRenderingStrategyName) {
return currentAppointments
}
currentAppointments.forEach(appointment => {
const sourceAppointment = this._getAssociatedSourceAppointment(appointment, sourceAppointments);
if (sourceAppointment) {
const isDataChanged = this._isDataChanged(appointment.itemData);
const isSettingChanged = this._isSettingChanged(appointment.settings, sourceAppointment.settings);
const isAppointmentShouldAppear = this._isAppointmentShouldAppear(appointment, sourceAppointment);
appointment.needRepaint = isDataChanged || isSettingChanged || isAppointmentShouldAppear
}
});
return currentAppointments.concat(this._getDeletedAppointments(currentAppointments, sourceAppointments))
};
_proto.getRenderingStrategyInstance = function() {
const renderingStrategy = this.appointmentViewModel.getRenderingStrategy();
if (!renderingStrategy) {
const options = this._getRenderingStrategyOptions();
this.appointmentViewModel.initRenderingStrategy(options)
}
return this.appointmentViewModel.getRenderingStrategy()
};
_createClass(AppointmentLayoutManager, [{
key: "appointmentRenderingStrategyName",
get: function() {
return (0, _index.getAppointmentRenderingStrategyName)(this.instance.currentViewType)
}
}]);
return AppointmentLayoutManager
}();
var _default = AppointmentLayoutManager;
exports.default = _default;