ui.scheduler.appointments.strategy.vertical.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /**
  2. * DevExtreme (ui/scheduler/rendering_strategies/ui.scheduler.appointments.strategy.vertical.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. function _typeof(obj) {
  11. "@babel/helpers - typeof";
  12. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
  13. return typeof obj
  14. } : function(obj) {
  15. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
  16. }, _typeof(obj)
  17. }
  18. var _uiSchedulerAppointmentsStrategy = require("./ui.scheduler.appointments.strategy.base");
  19. var _uiSchedulerAppointmentsStrategy2 = _interopRequireDefault(_uiSchedulerAppointmentsStrategy);
  20. var _extend = require("../../../core/utils/extend");
  21. var _type = require("../../../core/utils/type");
  22. var _devices = require("../../../core/devices");
  23. var _devices2 = _interopRequireDefault(_devices);
  24. var _date = require("../../../core/utils/date");
  25. var _date2 = _interopRequireDefault(_date);
  26. function _interopRequireDefault(obj) {
  27. return obj && obj.__esModule ? obj : {
  28. "default": obj
  29. }
  30. }
  31. function _classCallCheck(instance, Constructor) {
  32. if (!(instance instanceof Constructor)) {
  33. throw new TypeError("Cannot call a class as a function")
  34. }
  35. }
  36. function _defineProperties(target, props) {
  37. for (var i = 0; i < props.length; i++) {
  38. var descriptor = props[i];
  39. descriptor.enumerable = descriptor.enumerable || false;
  40. descriptor.configurable = true;
  41. if ("value" in descriptor) {
  42. descriptor.writable = true
  43. }
  44. Object.defineProperty(target, descriptor.key, descriptor)
  45. }
  46. }
  47. function _createClass(Constructor, protoProps, staticProps) {
  48. if (protoProps) {
  49. _defineProperties(Constructor.prototype, protoProps)
  50. }
  51. if (staticProps) {
  52. _defineProperties(Constructor, staticProps)
  53. }
  54. Object.defineProperty(Constructor, "prototype", {
  55. writable: false
  56. });
  57. return Constructor
  58. }
  59. function _get() {
  60. if ("undefined" !== typeof Reflect && Reflect.get) {
  61. _get = Reflect.get.bind()
  62. } else {
  63. _get = function(target, property, receiver) {
  64. var base = _superPropBase(target, property);
  65. if (!base) {
  66. return
  67. }
  68. var desc = Object.getOwnPropertyDescriptor(base, property);
  69. if (desc.get) {
  70. return desc.get.call(arguments.length < 3 ? target : receiver)
  71. }
  72. return desc.value
  73. }
  74. }
  75. return _get.apply(this, arguments)
  76. }
  77. function _superPropBase(object, property) {
  78. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  79. object = _getPrototypeOf(object);
  80. if (null === object) {
  81. break
  82. }
  83. }
  84. return object
  85. }
  86. function _inherits(subClass, superClass) {
  87. if ("function" !== typeof superClass && null !== superClass) {
  88. throw new TypeError("Super expression must either be null or a function")
  89. }
  90. subClass.prototype = Object.create(superClass && superClass.prototype, {
  91. constructor: {
  92. value: subClass,
  93. writable: true,
  94. configurable: true
  95. }
  96. });
  97. Object.defineProperty(subClass, "prototype", {
  98. writable: false
  99. });
  100. if (superClass) {
  101. _setPrototypeOf(subClass, superClass)
  102. }
  103. }
  104. function _setPrototypeOf(o, p) {
  105. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  106. o.__proto__ = p;
  107. return o
  108. };
  109. return _setPrototypeOf(o, p)
  110. }
  111. function _createSuper(Derived) {
  112. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  113. return function() {
  114. var result, Super = _getPrototypeOf(Derived);
  115. if (hasNativeReflectConstruct) {
  116. var NewTarget = _getPrototypeOf(this).constructor;
  117. result = Reflect.construct(Super, arguments, NewTarget)
  118. } else {
  119. result = Super.apply(this, arguments)
  120. }
  121. return _possibleConstructorReturn(this, result)
  122. }
  123. }
  124. function _possibleConstructorReturn(self, call) {
  125. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  126. return call
  127. } else {
  128. if (void 0 !== call) {
  129. throw new TypeError("Derived constructors may only return object or undefined")
  130. }
  131. }
  132. return _assertThisInitialized(self)
  133. }
  134. function _assertThisInitialized(self) {
  135. if (void 0 === self) {
  136. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  137. }
  138. return self
  139. }
  140. function _isNativeReflectConstruct() {
  141. if ("undefined" === typeof Reflect || !Reflect.construct) {
  142. return false
  143. }
  144. if (Reflect.construct.sham) {
  145. return false
  146. }
  147. if ("function" === typeof Proxy) {
  148. return true
  149. }
  150. try {
  151. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  152. return true
  153. } catch (e) {
  154. return false
  155. }
  156. }
  157. function _getPrototypeOf(o) {
  158. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  159. return o.__proto__ || Object.getPrototypeOf(o)
  160. };
  161. return _getPrototypeOf(o)
  162. }
  163. var WEEK_APPOINTMENT_DEFAULT_OFFSET = 25;
  164. var WEEK_APPOINTMENT_MOBILE_OFFSET = 50;
  165. var APPOINTMENT_MIN_WIDTH = 5;
  166. var ALLDAY_APPOINTMENT_MIN_VERTICAL_OFFSET = 5;
  167. var ALLDAY_APPOINTMENT_MAX_VERTICAL_OFFSET = 20;
  168. var toMs = _date2.default.dateToMilliseconds;
  169. var VerticalRenderingStrategy = function(_BaseAppointmentsStra) {
  170. _inherits(VerticalRenderingStrategy, _BaseAppointmentsStra);
  171. var _super = _createSuper(VerticalRenderingStrategy);
  172. function VerticalRenderingStrategy() {
  173. _classCallCheck(this, VerticalRenderingStrategy);
  174. return _super.apply(this, arguments)
  175. }
  176. _createClass(VerticalRenderingStrategy, [{
  177. key: "getDeltaTime",
  178. value: function(args, initialSize, appointment) {
  179. var deltaTime = 0;
  180. if (this.isAllDay(appointment)) {
  181. deltaTime = this._getDeltaWidth(args, initialSize) * toMs("day")
  182. } else {
  183. var deltaHeight = args.height - initialSize.height;
  184. deltaTime = toMs("minute") * Math.round(deltaHeight / this.getDefaultCellHeight() * this.instance.getAppointmentDurationInMinutes())
  185. }
  186. return deltaTime
  187. }
  188. }, {
  189. key: "getAppointmentGeometry",
  190. value: function(coordinates) {
  191. var result;
  192. var allDay = coordinates.allDay;
  193. if (allDay) {
  194. result = this._getAllDayAppointmentGeometry(coordinates)
  195. } else {
  196. result = this._getVerticalAppointmentGeometry(coordinates)
  197. }
  198. return _get(_getPrototypeOf(VerticalRenderingStrategy.prototype), "getAppointmentGeometry", this).call(this, result)
  199. }
  200. }, {
  201. key: "_getItemPosition",
  202. value: function(item) {
  203. var allDay = this.isAllDay(item);
  204. var isRecurring = !!this.instance.fire("getField", "recurrenceRule", item);
  205. if (allDay) {
  206. return _get(_getPrototypeOf(VerticalRenderingStrategy.prototype), "_getItemPosition", this).call(this, item)
  207. }
  208. var position = this._getAppointmentCoordinates(item);
  209. var result = [];
  210. for (var j = 0; j < position.length; j++) {
  211. var height = this.calculateAppointmentHeight(item, position[j], isRecurring);
  212. var width = this.calculateAppointmentWidth(item, position[j], isRecurring);
  213. var resultHeight = height;
  214. var appointmentReduced = null;
  215. var multiDaysAppointmentParts = [];
  216. var currentMaxAllowedPosition = position[j].vMax;
  217. if (this._isMultiDayAppointment(position[j], height)) {
  218. appointmentReduced = "head";
  219. resultHeight = this._reduceMultiDayAppointment(height, {
  220. top: position[j].top,
  221. bottom: currentMaxAllowedPosition
  222. });
  223. multiDaysAppointmentParts = this._getAppointmentParts({
  224. sourceAppointmentHeight: height,
  225. reducedHeight: resultHeight,
  226. width: width
  227. }, position[j])
  228. }(0, _extend.extend)(position[j], {
  229. height: resultHeight,
  230. width: width,
  231. allDay: allDay,
  232. appointmentReduced: appointmentReduced
  233. });
  234. result = this._getAppointmentPartsPosition(multiDaysAppointmentParts, position[j], result)
  235. }
  236. return result
  237. }
  238. }, {
  239. key: "_isMultiDayAppointment",
  240. value: function(position, height) {
  241. var maxTop = position.vMax;
  242. var result = height > maxTop - position.top;
  243. return result
  244. }
  245. }, {
  246. key: "_reduceMultiDayAppointment",
  247. value: function(sourceAppointmentHeight, bound) {
  248. sourceAppointmentHeight = bound.bottom - Math.floor(bound.top);
  249. return sourceAppointmentHeight
  250. }
  251. }, {
  252. key: "_getAppointmentParts",
  253. value: function(appointmentGeometry, appointmentSettings) {
  254. var tailHeight = appointmentGeometry.sourceAppointmentHeight - appointmentGeometry.reducedHeight;
  255. var width = appointmentGeometry.width;
  256. var result = [];
  257. var currentPartTop = this.instance.fire("getGroupTop", appointmentSettings.groupIndex);
  258. var offset = this.instance.fire("isGroupedByDate") ? this.getDefaultCellWidth() * this.instance.fire("getGroupCount") : this.getDefaultCellWidth();
  259. var left = appointmentSettings.left + offset;
  260. if (tailHeight) {
  261. var minHeight = this.getAppointmentMinSize();
  262. if (tailHeight < minHeight) {
  263. tailHeight = minHeight
  264. }
  265. currentPartTop += this.instance.fire("getOffsetByAllDayPanel", appointmentSettings.groupIndex);
  266. result.push((0, _extend.extend)(true, {}, appointmentSettings, {
  267. top: currentPartTop,
  268. left: left,
  269. height: tailHeight,
  270. width: width,
  271. appointmentReduced: "tail",
  272. rowIndex: ++appointmentSettings.rowIndex
  273. }))
  274. }
  275. return result
  276. }
  277. }, {
  278. key: "_getMinuteHeight",
  279. value: function() {
  280. return this.getDefaultCellHeight() / this.instance.getAppointmentDurationInMinutes()
  281. }
  282. }, {
  283. key: "_getCompactLeftCoordinate",
  284. value: function(itemLeft, index) {
  285. var cellBorderSize = 1;
  286. var cellWidth = this.getDefaultCellWidth() || this.getAppointmentMinSize();
  287. return itemLeft + (cellBorderSize + cellWidth) * index
  288. }
  289. }, {
  290. key: "_checkLongCompactAppointment",
  291. value: function(item, result) {
  292. this._splitLongCompactAppointment(item, result);
  293. return result
  294. }
  295. }, {
  296. key: "_getVerticalAppointmentGeometry",
  297. value: function(coordinates) {
  298. var overlappingMode = this.instance.fire("getMaxAppointmentsPerCell");
  299. if (overlappingMode) {
  300. var config = this._calculateVerticalGeometryConfig(coordinates);
  301. return this._customizeVerticalCoordinates(coordinates, config.width, config.appointmentCountPerCell, config.offset)
  302. } else {
  303. var width = this._getAppointmentMaxWidth() / coordinates.count;
  304. var height = coordinates.height;
  305. var top = coordinates.top;
  306. var left = coordinates.left + coordinates.index * width;
  307. if (width < APPOINTMENT_MIN_WIDTH) {
  308. width = APPOINTMENT_MIN_WIDTH
  309. }
  310. return {
  311. height: height,
  312. width: width,
  313. top: top,
  314. left: left,
  315. empty: this._isAppointmentEmpty(height, width)
  316. }
  317. }
  318. }
  319. }, {
  320. key: "_customizeVerticalCoordinates",
  321. value: function(coordinates, width, appointmentCountPerCell, topOffset, isAllDay) {
  322. var index = coordinates.index;
  323. var appointmentWidth = Math.max(width / appointmentCountPerCell, width / coordinates.count);
  324. var height = coordinates.height;
  325. var appointmentLeft = coordinates.left + coordinates.index * appointmentWidth;
  326. var top = coordinates.top;
  327. var compactAppointmentDefaultSize;
  328. var compactAppointmentDefaultOffset;
  329. if (coordinates.isCompact) {
  330. compactAppointmentDefaultSize = this.getCompactAppointmentDefaultWidth();
  331. compactAppointmentDefaultOffset = this.getCompactAppointmentLeftOffset();
  332. top = coordinates.top + compactAppointmentDefaultOffset;
  333. appointmentLeft = coordinates.left + (index - appointmentCountPerCell) * (compactAppointmentDefaultSize + compactAppointmentDefaultOffset) + compactAppointmentDefaultOffset;
  334. appointmentWidth = compactAppointmentDefaultSize;
  335. width = compactAppointmentDefaultSize;
  336. this._markAppointmentAsVirtual(coordinates, isAllDay)
  337. }
  338. return {
  339. height: height,
  340. width: appointmentWidth,
  341. top: top,
  342. left: appointmentLeft,
  343. empty: this._isAppointmentEmpty(height, width)
  344. }
  345. }
  346. }, {
  347. key: "_calculateVerticalGeometryConfig",
  348. value: function(coordinates) {
  349. var overlappingMode = this.instance.fire("getMaxAppointmentsPerCell");
  350. var offsets = this._getOffsets();
  351. var appointmentDefaultOffset = this._getAppointmentDefaultOffset();
  352. var appointmentCountPerCell = this._getAppointmentCount(overlappingMode, coordinates);
  353. var ratio = this._getDefaultRatio(coordinates, appointmentCountPerCell);
  354. var maxWidth = this._getMaxWidth();
  355. if (!appointmentCountPerCell) {
  356. appointmentCountPerCell = coordinates.count;
  357. ratio = (maxWidth - offsets.unlimited) / maxWidth
  358. }
  359. var topOffset = (1 - ratio) * maxWidth;
  360. if ("auto" === overlappingMode || (0, _type.isNumeric)(overlappingMode)) {
  361. ratio = 1;
  362. maxWidth -= appointmentDefaultOffset;
  363. topOffset = 0
  364. }
  365. return {
  366. width: ratio * maxWidth,
  367. appointmentCountPerCell: appointmentCountPerCell,
  368. offset: topOffset
  369. }
  370. }
  371. }, {
  372. key: "_getMaxWidth",
  373. value: function() {
  374. return this.getDefaultCellWidth() || this.invoke("getCellWidth")
  375. }
  376. }, {
  377. key: "isAllDay",
  378. value: function(appointmentData) {
  379. var allDay = this.instance.fire("getField", "allDay", appointmentData);
  380. if (allDay) {
  381. return true
  382. }
  383. return this.instance.appointmentTakesAllDay(appointmentData)
  384. }
  385. }, {
  386. key: "_getAppointmentMaxWidth",
  387. value: function() {
  388. var offset = "desktop" === _devices2.default.current().deviceType && !this.instance.fire("isAdaptive") ? WEEK_APPOINTMENT_DEFAULT_OFFSET : WEEK_APPOINTMENT_MOBILE_OFFSET;
  389. var width = this.getDefaultCellWidth() - offset;
  390. return width > 0 ? width : this.getAppointmentMinSize()
  391. }
  392. }, {
  393. key: "calculateAppointmentWidth",
  394. value: function(appointment, position, isRecurring) {
  395. if (!this.isAllDay(appointment)) {
  396. return 0
  397. }
  398. var startDate = new Date(this.startDate(appointment, false, position));
  399. var endDate = this.endDate(appointment, position, isRecurring);
  400. var cellWidth = this.getDefaultCellWidth() || this.getAppointmentMinSize();
  401. startDate = _date2.default.trimTime(startDate);
  402. var durationInHours = (endDate.getTime() - startDate.getTime()) / toMs("hour");
  403. var width = Math.ceil(durationInHours / 24) * cellWidth;
  404. width = this.cropAppointmentWidth(width, cellWidth);
  405. return width
  406. }
  407. }, {
  408. key: "calculateAppointmentHeight",
  409. value: function(appointment, position, isRecurring) {
  410. var endDate = this.endDate(appointment, position, isRecurring);
  411. var startDate = this.startDate(appointment, false, position);
  412. var allDay = this.instance.fire("getField", "allDay", appointment);
  413. if (this.isAllDay(appointment)) {
  414. return 0
  415. }
  416. var fullDuration = this._getAppointmentDurationInMs(startDate, endDate, allDay);
  417. var durationInMinutes = this._adjustDurationByDaylightDiff(fullDuration, startDate, endDate) / toMs("minute");
  418. var height = durationInMinutes * this._getMinuteHeight();
  419. return height
  420. }
  421. }, {
  422. key: "getDirection",
  423. value: function() {
  424. return "vertical"
  425. }
  426. }, {
  427. key: "_sortCondition",
  428. value: function(a, b) {
  429. var allDayCondition = a.allDay - b.allDay;
  430. var isAllDay = a.allDay && b.allDay;
  431. var condition = "vertical" === this.instance._groupOrientation && isAllDay ? this._columnCondition(a, b) : this._rowCondition(a, b);
  432. return allDayCondition ? allDayCondition : condition
  433. }
  434. }, {
  435. key: "hasAllDayAppointments",
  436. value: function() {
  437. return true
  438. }
  439. }, {
  440. key: "_getAllDayAppointmentGeometry",
  441. value: function(coordinates) {
  442. var config = this._calculateGeometryConfig(coordinates);
  443. return this._customizeCoordinates(coordinates, config.height, config.appointmentCountPerCell, config.offset, true)
  444. }
  445. }, {
  446. key: "_calculateGeometryConfig",
  447. value: function(coordinates) {
  448. if (!this.instance._allowResizing() || !this.instance._allowAllDayResizing()) {
  449. coordinates.skipResizing = true
  450. }
  451. var config = _get(_getPrototypeOf(VerticalRenderingStrategy.prototype), "_calculateGeometryConfig", this).call(this, coordinates);
  452. if (coordinates.count <= this._getDynamicAppointmentCountPerCell().allDay) {
  453. config.offset = 0
  454. }
  455. return config
  456. }
  457. }, {
  458. key: "_getAppointmentCount",
  459. value: function(overlappingMode, coordinates) {
  460. return "auto" !== overlappingMode && 1 === coordinates.count && !(0, _type.isNumeric)(overlappingMode) ? coordinates.count : this._getMaxAppointmentCountPerCellByType(coordinates.allDay)
  461. }
  462. }, {
  463. key: "_getDefaultRatio",
  464. value: function(coordinates, appointmentCountPerCell) {
  465. return coordinates.count > this.instance.option("_appointmentCountPerCell") ? .65 : 1
  466. }
  467. }, {
  468. key: "_getOffsets",
  469. value: function() {
  470. return {
  471. unlimited: ALLDAY_APPOINTMENT_MIN_VERTICAL_OFFSET,
  472. auto: ALLDAY_APPOINTMENT_MAX_VERTICAL_OFFSET
  473. }
  474. }
  475. }, {
  476. key: "_getMaxHeight",
  477. value: function() {
  478. return this.getDefaultAllDayCellHeight() || this.getAppointmentMinSize()
  479. }
  480. }, {
  481. key: "_needVerticalGroupBounds",
  482. value: function(allDay) {
  483. return !allDay
  484. }
  485. }, {
  486. key: "_needHorizontalGroupBounds",
  487. value: function() {
  488. return false
  489. }
  490. }]);
  491. return VerticalRenderingStrategy
  492. }(_uiSchedulerAppointmentsStrategy2.default);
  493. module.exports = VerticalRenderingStrategy;