ui.scheduler.appointments.strategy.base.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. /**
  2. * DevExtreme (ui/scheduler/rendering_strategies/ui.scheduler.appointments.strategy.base.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. var _uiSchedulerAppointmentsPositioningStrategy = require("./ui.scheduler.appointmentsPositioning.strategy.base");
  11. var _uiSchedulerAppointmentsPositioningStrategy2 = _interopRequireDefault(_uiSchedulerAppointmentsPositioningStrategy);
  12. var _uiSchedulerAppointmentsPositioningStrategy3 = require("./ui.scheduler.appointmentsPositioning.strategy.adaptive");
  13. var _uiSchedulerAppointmentsPositioningStrategy4 = _interopRequireDefault(_uiSchedulerAppointmentsPositioningStrategy3);
  14. var _extend = require("../../../core/utils/extend");
  15. var _ui = require("../../widget/ui.errors");
  16. var _ui2 = _interopRequireDefault(_ui);
  17. var _date = require("../../../core/utils/date");
  18. var _date2 = _interopRequireDefault(_date);
  19. var _type = require("../../../core/utils/type");
  20. var _type2 = _interopRequireDefault(_type);
  21. var _themes = require("../../themes");
  22. var _themes2 = _interopRequireDefault(_themes);
  23. function _interopRequireDefault(obj) {
  24. return obj && obj.__esModule ? obj : {
  25. "default": obj
  26. }
  27. }
  28. function _classCallCheck(instance, Constructor) {
  29. if (!(instance instanceof Constructor)) {
  30. throw new TypeError("Cannot call a class as a function")
  31. }
  32. }
  33. function _defineProperties(target, props) {
  34. for (var i = 0; i < props.length; i++) {
  35. var descriptor = props[i];
  36. descriptor.enumerable = descriptor.enumerable || false;
  37. descriptor.configurable = true;
  38. if ("value" in descriptor) {
  39. descriptor.writable = true
  40. }
  41. Object.defineProperty(target, descriptor.key, descriptor)
  42. }
  43. }
  44. function _createClass(Constructor, protoProps, staticProps) {
  45. if (protoProps) {
  46. _defineProperties(Constructor.prototype, protoProps)
  47. }
  48. if (staticProps) {
  49. _defineProperties(Constructor, staticProps)
  50. }
  51. Object.defineProperty(Constructor, "prototype", {
  52. writable: false
  53. });
  54. return Constructor
  55. }
  56. var toMs = _date2.default.dateToMilliseconds;
  57. var APPOINTMENT_MIN_SIZE = 2;
  58. var COMPACT_APPOINTMENT_DEFAULT_WIDTH = 15;
  59. var APPOINTMENT_DEFAULT_HEIGHT = 20;
  60. var COMPACT_THEME_APPOINTMENT_DEFAULT_HEIGHT = 18;
  61. var DROP_DOWN_BUTTON_ADAPTIVE_SIZE = 28;
  62. var BaseRenderingStrategy = function() {
  63. function BaseRenderingStrategy(instance) {
  64. _classCallCheck(this, BaseRenderingStrategy);
  65. this.instance = instance;
  66. this._initPositioningStrategy()
  67. }
  68. _createClass(BaseRenderingStrategy, [{
  69. key: "_initPositioningStrategy",
  70. value: function() {
  71. this._positioningStrategy = this.instance.fire("isAdaptive") ? new _uiSchedulerAppointmentsPositioningStrategy4.default(this) : new _uiSchedulerAppointmentsPositioningStrategy2.default(this)
  72. }
  73. }, {
  74. key: "getPositioningStrategy",
  75. value: function() {
  76. return this._positioningStrategy
  77. }
  78. }, {
  79. key: "getAppointmentMinSize",
  80. value: function() {
  81. return APPOINTMENT_MIN_SIZE
  82. }
  83. }, {
  84. key: "keepAppointmentSettings",
  85. value: function() {
  86. return false
  87. }
  88. }, {
  89. key: "getDeltaTime",
  90. value: function() {}
  91. }, {
  92. key: "getAppointmentGeometry",
  93. value: function(coordinates) {
  94. return coordinates
  95. }
  96. }, {
  97. key: "needCorrectAppointmentDates",
  98. value: function() {
  99. return true
  100. }
  101. }, {
  102. key: "getDirection",
  103. value: function() {
  104. return "horizontal"
  105. }
  106. }, {
  107. key: "createTaskPositionMap",
  108. value: function(items) {
  109. delete this._maxAppointmentCountPerCell;
  110. var length = items && items.length;
  111. if (!length) {
  112. return
  113. }
  114. this._defaultWidth = this.instance._cellWidth;
  115. this._defaultHeight = this.instance._cellHeight;
  116. this._allDayHeight = this.instance._allDayCellHeight;
  117. var map = [];
  118. for (var i = 0; i < length; i++) {
  119. var coordinates = this._getItemPosition(items[i]);
  120. if (this._isRtl()) {
  121. coordinates = this._correctRtlCoordinates(coordinates)
  122. }
  123. map.push(coordinates)
  124. }
  125. var positionArray = this._getSortedPositions(map);
  126. var resultPositions = this._getResultPositions(positionArray);
  127. return this._getExtendedPositionMap(map, resultPositions)
  128. }
  129. }, {
  130. key: "_getDeltaWidth",
  131. value: function(args, initialSize) {
  132. var intervalWidth = this.instance.fire("getResizableStep") || this.getAppointmentMinSize();
  133. var initialWidth = initialSize.width;
  134. return Math.round((args.width - initialWidth) / intervalWidth)
  135. }
  136. }, {
  137. key: "_correctRtlCoordinates",
  138. value: function(coordinates) {
  139. var width = coordinates[0].width || this._getAppointmentMaxWidth();
  140. coordinates.forEach(function(coordinate) {
  141. if (!coordinate.appointmentReduced) {
  142. coordinate.left -= width
  143. }
  144. });
  145. return coordinates
  146. }
  147. }, {
  148. key: "_getAppointmentMaxWidth",
  149. value: function() {
  150. return this.getDefaultCellWidth()
  151. }
  152. }, {
  153. key: "_getItemPosition",
  154. value: function(item) {
  155. var position = this._getAppointmentCoordinates(item);
  156. var allDay = this.isAllDay(item);
  157. var result = [];
  158. var startDate = new Date(this.instance.fire("getField", "startDate", item));
  159. var isRecurring = !!this.instance.fire("getField", "recurrenceRule", item);
  160. for (var j = 0; j < position.length; j++) {
  161. var height = this.calculateAppointmentHeight(item, position[j], isRecurring);
  162. var width = this.calculateAppointmentWidth(item, position[j], isRecurring);
  163. var resultWidth = width;
  164. var appointmentReduced = null;
  165. var multiWeekAppointmentParts = [];
  166. var initialRowIndex = position[j].rowIndex;
  167. var initialCellIndex = position[j].cellIndex;
  168. if (this._needVerifyItemSize() || allDay) {
  169. var currentMaxAllowedPosition = position[j].hMax;
  170. if (this.isAppointmentGreaterThan(currentMaxAllowedPosition, {
  171. left: position[j].left,
  172. width: width
  173. })) {
  174. appointmentReduced = "head";
  175. initialRowIndex = position[j].rowIndex;
  176. initialCellIndex = position[j].cellIndex;
  177. resultWidth = this._reduceMultiWeekAppointment(width, {
  178. left: position[j].left,
  179. right: currentMaxAllowedPosition
  180. });
  181. multiWeekAppointmentParts = this._getAppointmentParts({
  182. sourceAppointmentWidth: width,
  183. reducedWidth: resultWidth,
  184. height: height
  185. }, position[j], startDate);
  186. if (this._isRtl()) {
  187. position[j].left = currentMaxAllowedPosition
  188. }
  189. }
  190. }(0, _extend.extend)(position[j], {
  191. height: height,
  192. width: resultWidth,
  193. allDay: allDay,
  194. rowIndex: initialRowIndex,
  195. cellIndex: initialCellIndex,
  196. appointmentReduced: appointmentReduced
  197. });
  198. result = this._getAppointmentPartsPosition(multiWeekAppointmentParts, position[j], result)
  199. }
  200. return result
  201. }
  202. }, {
  203. key: "_getAppointmentPartsPosition",
  204. value: function(appointmentParts, position, result) {
  205. if (appointmentParts.length) {
  206. appointmentParts.unshift(position);
  207. result = result.concat(appointmentParts)
  208. } else {
  209. result.push(position)
  210. }
  211. return result
  212. }
  213. }, {
  214. key: "_getAppointmentCoordinates",
  215. value: function(itemData) {
  216. var coordinates = [{
  217. top: 0,
  218. left: 0
  219. }];
  220. this.instance.fire("needCoordinates", {
  221. startDate: this.startDate(itemData),
  222. originalStartDate: this.startDate(itemData, true),
  223. appointmentData: itemData,
  224. callback: function(value) {
  225. coordinates = value
  226. }
  227. });
  228. return coordinates
  229. }
  230. }, {
  231. key: "_isRtl",
  232. value: function() {
  233. return this.instance.option("rtlEnabled")
  234. }
  235. }, {
  236. key: "_getAppointmentParts",
  237. value: function() {
  238. return []
  239. }
  240. }, {
  241. key: "_getCompactAppointmentParts",
  242. value: function(appointmentWidth) {
  243. var cellWidth = this.getDefaultCellWidth() || this.getAppointmentMinSize();
  244. return Math.round(appointmentWidth / cellWidth)
  245. }
  246. }, {
  247. key: "_reduceMultiWeekAppointment",
  248. value: function(sourceAppointmentWidth, bound) {
  249. if (this._isRtl()) {
  250. sourceAppointmentWidth = Math.floor(bound.left - bound.right)
  251. } else {
  252. sourceAppointmentWidth = bound.right - Math.floor(bound.left)
  253. }
  254. return sourceAppointmentWidth
  255. }
  256. }, {
  257. key: "calculateAppointmentHeight",
  258. value: function() {
  259. return 0
  260. }
  261. }, {
  262. key: "calculateAppointmentWidth",
  263. value: function() {
  264. return 0
  265. }
  266. }, {
  267. key: "isAppointmentGreaterThan",
  268. value: function(etalon, comparisonParameters) {
  269. var result = comparisonParameters.left + comparisonParameters.width - etalon;
  270. if (this._isRtl()) {
  271. result = etalon + comparisonParameters.width - comparisonParameters.left
  272. }
  273. return result > this.getDefaultCellWidth() / 2
  274. }
  275. }, {
  276. key: "isAllDay",
  277. value: function() {
  278. return false
  279. }
  280. }, {
  281. key: "cropAppointmentWidth",
  282. value: function(width, cellWidth) {
  283. if (this.instance.fire("isGroupedByDate")) {
  284. width = cellWidth
  285. }
  286. return width
  287. }
  288. }, {
  289. key: "_getSortedPositions",
  290. value: function(positionList) {
  291. var _this = this;
  292. var result = [];
  293. var round = function(value) {
  294. return Math.round(100 * value) / 100
  295. };
  296. var createItem = function(rowIndex, cellIndex, top, left, bottom, right, position, allDay) {
  297. return {
  298. i: rowIndex,
  299. j: cellIndex,
  300. top: round(top),
  301. left: round(left),
  302. bottom: round(bottom),
  303. right: round(right),
  304. cellPosition: position,
  305. allDay: allDay
  306. }
  307. };
  308. for (var rowIndex = 0, rowCount = positionList.length; rowIndex < rowCount; rowIndex++) {
  309. for (var cellIndex = 0, cellCount = positionList[rowIndex].length; cellIndex < cellCount; cellIndex++) {
  310. var _positionList$rowInde = positionList[rowIndex][cellIndex],
  311. top = _positionList$rowInde.top,
  312. left = _positionList$rowInde.left,
  313. height = _positionList$rowInde.height,
  314. width = _positionList$rowInde.width,
  315. cellPosition = _positionList$rowInde.cellPosition,
  316. allDay = _positionList$rowInde.allDay;
  317. result.push(createItem(rowIndex, cellIndex, top, left, top + height, left + width, cellPosition, allDay))
  318. }
  319. }
  320. return result.sort(function(a, b) {
  321. return _this._sortCondition(a, b)
  322. })
  323. }
  324. }, {
  325. key: "_sortCondition",
  326. value: function() {}
  327. }, {
  328. key: "_getConditions",
  329. value: function(a, b) {
  330. var isSomeEdge = this._isSomeEdge(a, b);
  331. return {
  332. columnCondition: isSomeEdge || this._normalizeCondition(a.left, b.left),
  333. rowCondition: isSomeEdge || this._normalizeCondition(a.top, b.top),
  334. cellPositionCondition: isSomeEdge || this._normalizeCondition(a.cellPosition, b.cellPosition)
  335. }
  336. }
  337. }, {
  338. key: "_rowCondition",
  339. value: function(a, b) {
  340. var conditions = this._getConditions(a, b);
  341. return conditions.columnCondition || conditions.rowCondition
  342. }
  343. }, {
  344. key: "_columnCondition",
  345. value: function(a, b) {
  346. var conditions = this._getConditions(a, b);
  347. return conditions.rowCondition || conditions.columnCondition
  348. }
  349. }, {
  350. key: "_isSomeEdge",
  351. value: function(a, b) {
  352. return a.i === b.i && a.j === b.j
  353. }
  354. }, {
  355. key: "_normalizeCondition",
  356. value: function(first, second) {
  357. var result = first - second;
  358. return Math.abs(result) > 1 ? result : 0
  359. }
  360. }, {
  361. key: "_isItemsCross",
  362. value: function(item, currentItem, orientation) {
  363. var side_1 = Math.floor(item[orientation[0]]);
  364. var side_2 = Math.floor(item[orientation[1]]);
  365. return item[orientation[2]] === currentItem[orientation[2]] && (side_1 <= currentItem[orientation[0]] && side_2 > currentItem[orientation[0]] || side_1 < currentItem[orientation[1]] && side_2 >= currentItem[orientation[1]] || side_1 === currentItem[orientation[0]] && side_2 === currentItem[orientation[1]])
  366. }
  367. }, {
  368. key: "_getOrientation",
  369. value: function() {
  370. return ["top", "bottom", "left"]
  371. }
  372. }, {
  373. key: "_getResultPositions",
  374. value: function(sortedArray) {
  375. var _this2 = this;
  376. var result = [];
  377. var i;
  378. var sortedIndex = 0;
  379. var currentItem;
  380. var indexes;
  381. var itemIndex;
  382. var maxIndexInStack = 0;
  383. var stack = {};
  384. var orientation = this._getOrientation();
  385. var findFreeIndex = function findFreeIndex(indexes, index) {
  386. var isFind = indexes.some(function(item) {
  387. return item === index
  388. });
  389. if (isFind) {
  390. return findFreeIndex(indexes, ++index)
  391. } else {
  392. return index
  393. }
  394. };
  395. var startNewStack = function(currentItem) {
  396. stack.items = [createItem(currentItem)];
  397. stack.left = currentItem.left;
  398. stack.right = currentItem.right;
  399. stack.top = currentItem.top;
  400. stack.bottom = currentItem.bottom
  401. };
  402. var createItem = function(currentItem, index) {
  403. var currentIndex = index || 0;
  404. return {
  405. index: currentIndex,
  406. i: currentItem.i,
  407. j: currentItem.j,
  408. left: currentItem.left,
  409. right: currentItem.right,
  410. top: currentItem.top,
  411. bottom: currentItem.bottom,
  412. sortedIndex: _this2._skipSortedIndex(currentIndex) ? null : sortedIndex++
  413. }
  414. };
  415. var pushItemsInResult = function(items) {
  416. items.forEach(function(item) {
  417. result.push({
  418. index: item.index,
  419. count: maxIndexInStack + 1,
  420. i: item.i,
  421. j: item.j,
  422. sortedIndex: item.sortedIndex
  423. })
  424. })
  425. };
  426. for (i = 0; i < sortedArray.length; i++) {
  427. currentItem = sortedArray[i];
  428. indexes = [];
  429. if (!stack.items) {
  430. startNewStack(currentItem)
  431. } else {
  432. if (this._isItemsCross(stack, currentItem, orientation)) {
  433. stack.items.forEach(function(item, index) {
  434. if (_this2._isItemsCross(item, currentItem, orientation)) {
  435. indexes.push(item.index)
  436. }
  437. });
  438. itemIndex = indexes.length ? findFreeIndex(indexes, 0) : 0;
  439. stack.items.push(createItem(currentItem, itemIndex));
  440. maxIndexInStack = Math.max(itemIndex, maxIndexInStack);
  441. stack.left = Math.min(stack.left, currentItem.left);
  442. stack.right = Math.max(stack.right, currentItem.right);
  443. stack.top = Math.min(stack.top, currentItem.top);
  444. stack.bottom = Math.max(stack.bottom, currentItem.bottom)
  445. } else {
  446. pushItemsInResult(stack.items);
  447. stack = {};
  448. startNewStack(currentItem);
  449. maxIndexInStack = 0
  450. }
  451. }
  452. }
  453. if (stack.items) {
  454. pushItemsInResult(stack.items)
  455. }
  456. return result.sort(function(a, b) {
  457. var columnCondition = a.j - b.j;
  458. var rowCondition = a.i - b.i;
  459. return rowCondition ? rowCondition : columnCondition
  460. })
  461. }
  462. }, {
  463. key: "_skipSortedIndex",
  464. value: function(index) {
  465. return this.instance.fire("getMaxAppointmentsPerCell") && index > this._getMaxAppointmentCountPerCell() - 1
  466. }
  467. }, {
  468. key: "_findIndexByKey",
  469. value: function(arr, iKey, jKey, iValue, jValue) {
  470. var result = 0;
  471. for (var i = 0, len = arr.length; i < len; i++) {
  472. if (arr[i][iKey] === iValue && arr[i][jKey] === jValue) {
  473. result = i;
  474. break
  475. }
  476. }
  477. return result
  478. }
  479. }, {
  480. key: "_getExtendedPositionMap",
  481. value: function(map, positions) {
  482. var positionCounter = 0;
  483. var result = [];
  484. for (var i = 0, mapLength = map.length; i < mapLength; i++) {
  485. var resultString = [];
  486. for (var j = 0, itemLength = map[i].length; j < itemLength; j++) {
  487. map[i][j].index = positions[positionCounter].index;
  488. map[i][j].sortedIndex = positions[positionCounter].sortedIndex;
  489. map[i][j].count = positions[positionCounter++].count;
  490. resultString.push(map[i][j]);
  491. this._checkLongCompactAppointment(map[i][j], resultString)
  492. }
  493. result.push(resultString)
  494. }
  495. return result
  496. }
  497. }, {
  498. key: "_checkLongCompactAppointment",
  499. value: function() {}
  500. }, {
  501. key: "_splitLongCompactAppointment",
  502. value: function(item, result) {
  503. var appointmentCountPerCell = this._getMaxAppointmentCountPerCellByType(item.allDay);
  504. var compactCount = 0;
  505. if (void 0 !== appointmentCountPerCell && item.index > appointmentCountPerCell - 1) {
  506. item.isCompact = true;
  507. compactCount = this._getCompactAppointmentParts(item.width);
  508. for (var k = 1; k < compactCount; k++) {
  509. var compactPart = (0, _extend.extend)(true, {}, item);
  510. compactPart.left = this._getCompactLeftCoordinate(item.left, k);
  511. compactPart.cellIndex = compactPart.cellIndex + k;
  512. compactPart.sortedIndex = null;
  513. result.push(compactPart)
  514. }
  515. }
  516. return result
  517. }
  518. }, {
  519. key: "startDate",
  520. value: function startDate(appointment, skipNormalize, position) {
  521. var startDate = position && position.startDate;
  522. var rangeStartDate = this.instance._getStartDate(appointment, skipNormalize);
  523. var text = this.instance.fire("getField", "text", appointment);
  524. if (startDate && rangeStartDate > startDate || !startDate) {
  525. startDate = rangeStartDate
  526. }
  527. if (isNaN(startDate.getTime())) {
  528. throw _ui2.default.Error("E1032", text)
  529. }
  530. return startDate
  531. }
  532. }, {
  533. key: "endDate",
  534. value: function endDate(appointment, position, isRecurring) {
  535. var ignoreViewDates = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : false;
  536. var endDate = this.instance._getEndDate(appointment, ignoreViewDates);
  537. var realStartDate = this.startDate(appointment, true);
  538. var viewStartDate = this.startDate(appointment, false, position);
  539. if (viewStartDate.getTime() > endDate.getTime() || isRecurring) {
  540. var recurrencePartStartDate = position ? position.initialStartDate || position.startDate : realStartDate;
  541. var recurrencePartCroppedByViewStartDate = position ? position.startDate : realStartDate;
  542. var fullDuration = this._adjustDurationByDaylightDiff(endDate.getTime() - realStartDate.getTime(), realStartDate, endDate);
  543. endDate = new Date(viewStartDate.getTime() >= recurrencePartStartDate.getTime() ? recurrencePartStartDate.getTime() : viewStartDate.getTime());
  544. if (isRecurring) {
  545. endDate = new Date(endDate.getTime() + fullDuration)
  546. }
  547. if (!_date2.default.sameDate(realStartDate, endDate) && recurrencePartCroppedByViewStartDate.getTime() < viewStartDate.getTime()) {
  548. var headDuration = _date2.default.trimTime(endDate).getTime() - recurrencePartCroppedByViewStartDate.getTime();
  549. var tailDuration = fullDuration - headDuration || fullDuration;
  550. endDate = new Date(_date2.default.trimTime(viewStartDate).getTime() + tailDuration)
  551. }
  552. }
  553. if (!this.isAllDay(appointment)) {
  554. var viewEndDate = _date2.default.roundToHour(this.instance.fire("getEndViewDate"));
  555. if (endDate > viewEndDate) {
  556. endDate = viewEndDate
  557. }
  558. var currentViewEndTime = new Date(new Date(endDate).setHours(this.instance.option("endDayHour"), 0, 0));
  559. if (endDate.getTime() > currentViewEndTime.getTime()) {
  560. endDate = currentViewEndTime
  561. }
  562. }
  563. return endDate
  564. }
  565. }, {
  566. key: "_adjustDurationByDaylightDiff",
  567. value: function(duration, startDate, endDate) {
  568. var daylightDiff = this.instance.fire("getDaylightOffset", startDate, endDate);
  569. return this._needAdjustDuration(daylightDiff) ? this._calculateDurationByDaylightDiff(duration, daylightDiff) : duration
  570. }
  571. }, {
  572. key: "_needAdjustDuration",
  573. value: function(diff) {
  574. return 0 !== diff
  575. }
  576. }, {
  577. key: "_calculateDurationByDaylightDiff",
  578. value: function(duration, diff) {
  579. return duration + diff * toMs("minute")
  580. }
  581. }, {
  582. key: "_getAppointmentDurationInMs",
  583. value: function(startDate, endDate, allDay) {
  584. var result;
  585. this.instance.fire("getAppointmentDurationInMs", {
  586. startDate: startDate,
  587. endDate: endDate,
  588. allDay: allDay,
  589. callback: function(duration) {
  590. result = duration
  591. }
  592. });
  593. return result
  594. }
  595. }, {
  596. key: "_getMaxNeighborAppointmentCount",
  597. value: function() {
  598. var overlappingMode = this.instance.fire("getMaxAppointmentsPerCell");
  599. if (!overlappingMode) {
  600. var outerAppointmentWidth = this.getCompactAppointmentDefaultWidth() + this.getCompactAppointmentLeftOffset();
  601. return Math.floor(this.getDropDownAppointmentWidth() / outerAppointmentWidth)
  602. } else {
  603. return 0
  604. }
  605. }
  606. }, {
  607. key: "_markAppointmentAsVirtual",
  608. value: function(coordinates, isAllDay) {
  609. var countFullWidthAppointmentInCell = this._getMaxAppointmentCountPerCellByType(isAllDay);
  610. if (coordinates.count - countFullWidthAppointmentInCell > this._getMaxNeighborAppointmentCount()) {
  611. coordinates.virtual = {
  612. top: coordinates.top,
  613. left: coordinates.left,
  614. index: "tail" === coordinates.appointmentReduced ? coordinates.groupIndex + "-" + coordinates.rowIndex + "-" + coordinates.cellIndex : coordinates.groupIndex + "-" + coordinates.rowIndex + "-" + coordinates.cellIndex + "-tail",
  615. isAllDay: isAllDay
  616. }
  617. }
  618. }
  619. }, {
  620. key: "_getMaxAppointmentCountPerCellByType",
  621. value: function(isAllDay) {
  622. var appointmentCountPerCell = this._getMaxAppointmentCountPerCell();
  623. if (_type2.default.isObject(appointmentCountPerCell)) {
  624. return isAllDay ? this._getMaxAppointmentCountPerCell().allDay : this._getMaxAppointmentCountPerCell().simple
  625. } else {
  626. return appointmentCountPerCell
  627. }
  628. }
  629. }, {
  630. key: "getDropDownAppointmentWidth",
  631. value: function(intervalCount, isAllDay) {
  632. return this.getPositioningStrategy().getDropDownAppointmentWidth(intervalCount, isAllDay)
  633. }
  634. }, {
  635. key: "getDropDownAppointmentHeight",
  636. value: function() {
  637. return this.getPositioningStrategy().getDropDownAppointmentHeight()
  638. }
  639. }, {
  640. key: "getDropDownButtonAdaptiveSize",
  641. value: function() {
  642. return DROP_DOWN_BUTTON_ADAPTIVE_SIZE
  643. }
  644. }, {
  645. key: "getDefaultCellWidth",
  646. value: function() {
  647. return this._defaultWidth
  648. }
  649. }, {
  650. key: "getDefaultCellHeight",
  651. value: function() {
  652. return this._defaultHeight
  653. }
  654. }, {
  655. key: "getDefaultAllDayCellHeight",
  656. value: function() {
  657. return this._allDayHeight
  658. }
  659. }, {
  660. key: "getCompactAppointmentDefaultWidth",
  661. value: function() {
  662. return COMPACT_APPOINTMENT_DEFAULT_WIDTH
  663. }
  664. }, {
  665. key: "getCompactAppointmentTopOffset",
  666. value: function(allDay) {
  667. return this.getPositioningStrategy().getCompactAppointmentTopOffset(allDay)
  668. }
  669. }, {
  670. key: "getCompactAppointmentLeftOffset",
  671. value: function() {
  672. return this.getPositioningStrategy().getCompactAppointmentLeftOffset()
  673. }
  674. }, {
  675. key: "getAppointmentDataCalculator",
  676. value: function() {}
  677. }, {
  678. key: "_customizeCoordinates",
  679. value: function(coordinates, height, appointmentCountPerCell, topOffset, isAllDay) {
  680. var index = coordinates.index;
  681. var appointmentHeight = height / appointmentCountPerCell;
  682. var appointmentTop = coordinates.top + index * appointmentHeight;
  683. var top = appointmentTop + topOffset;
  684. var width = coordinates.width;
  685. var left = coordinates.left;
  686. var compactAppointmentDefaultSize;
  687. var compactAppointmentLeftOffset;
  688. var compactAppointmentTopOffset = this.getCompactAppointmentTopOffset(isAllDay);
  689. if (coordinates.isCompact) {
  690. compactAppointmentDefaultSize = this.getCompactAppointmentDefaultWidth();
  691. compactAppointmentLeftOffset = this.getCompactAppointmentLeftOffset();
  692. top = coordinates.top + compactAppointmentTopOffset;
  693. left = coordinates.left + (index - appointmentCountPerCell) * (compactAppointmentDefaultSize + compactAppointmentLeftOffset) + compactAppointmentLeftOffset;
  694. if (this.instance.fire("isAdaptive")) {
  695. coordinates.top = top;
  696. coordinates.left = coordinates.left + compactAppointmentLeftOffset
  697. }
  698. appointmentHeight = compactAppointmentDefaultSize;
  699. width = compactAppointmentDefaultSize;
  700. this._markAppointmentAsVirtual(coordinates, isAllDay)
  701. }
  702. return {
  703. height: appointmentHeight,
  704. width: width,
  705. top: top,
  706. left: left,
  707. empty: this._isAppointmentEmpty(height, width)
  708. }
  709. }
  710. }, {
  711. key: "_isAppointmentEmpty",
  712. value: function(height, width) {
  713. return height < this._getAppointmentMinHeight() || width < this._getAppointmentMinWidth()
  714. }
  715. }, {
  716. key: "_calculateGeometryConfig",
  717. value: function(coordinates) {
  718. var overlappingMode = this.instance.fire("getMaxAppointmentsPerCell");
  719. var offsets = this._getOffsets();
  720. var appointmentDefaultOffset = this._getAppointmentDefaultOffset();
  721. var appointmentCountPerCell = this._getAppointmentCount(overlappingMode, coordinates);
  722. var ratio = this._getDefaultRatio(coordinates, appointmentCountPerCell);
  723. var maxHeight = this._getMaxHeight();
  724. if (!(0, _type.isNumeric)(appointmentCountPerCell)) {
  725. appointmentCountPerCell = coordinates.count;
  726. ratio = (maxHeight - offsets.unlimited) / maxHeight
  727. }
  728. var topOffset = (1 - ratio) * maxHeight;
  729. if ("auto" === overlappingMode || (0, _type.isNumeric)(overlappingMode)) {
  730. ratio = 1;
  731. maxHeight -= appointmentDefaultOffset;
  732. topOffset = appointmentDefaultOffset
  733. }
  734. return {
  735. height: ratio * maxHeight,
  736. appointmentCountPerCell: appointmentCountPerCell,
  737. offset: topOffset
  738. }
  739. }
  740. }, {
  741. key: "_getAppointmentCount",
  742. value: function() {}
  743. }, {
  744. key: "_getDefaultRatio",
  745. value: function() {}
  746. }, {
  747. key: "_getOffsets",
  748. value: function() {}
  749. }, {
  750. key: "_getMaxHeight",
  751. value: function() {}
  752. }, {
  753. key: "_needVerifyItemSize",
  754. value: function() {
  755. return false
  756. }
  757. }, {
  758. key: "needSeparateAppointment",
  759. value: function(allDay) {
  760. return this.instance.fire("isGroupedByDate") && allDay
  761. }
  762. }, {
  763. key: "_getMaxAppointmentCountPerCell",
  764. value: function() {
  765. if (!this._maxAppointmentCountPerCell) {
  766. var overlappingMode = this.instance.fire("getMaxAppointmentsPerCell");
  767. var appointmentCountPerCell;
  768. if (!overlappingMode) {
  769. appointmentCountPerCell = 2
  770. }
  771. if ((0, _type.isNumeric)(overlappingMode)) {
  772. appointmentCountPerCell = overlappingMode
  773. }
  774. if ("auto" === overlappingMode) {
  775. appointmentCountPerCell = this._getDynamicAppointmentCountPerCell()
  776. }
  777. if ("unlimited" === overlappingMode) {
  778. appointmentCountPerCell = void 0
  779. }
  780. this._maxAppointmentCountPerCell = appointmentCountPerCell
  781. }
  782. return this._maxAppointmentCountPerCell
  783. }
  784. }, {
  785. key: "_getDynamicAppointmentCountPerCell",
  786. value: function() {
  787. return this.getPositioningStrategy().getDynamicAppointmentCountPerCell()
  788. }
  789. }, {
  790. key: "hasAllDayAppointments",
  791. value: function() {
  792. return false
  793. }
  794. }, {
  795. key: "_isCompactTheme",
  796. value: function() {
  797. return "compact" === (_themes2.default.current() || "").split(".").pop()
  798. }
  799. }, {
  800. key: "_getAppointmentDefaultOffset",
  801. value: function() {
  802. return this.getPositioningStrategy().getAppointmentDefaultOffset()
  803. }
  804. }, {
  805. key: "_getAppointmentDefaultHeight",
  806. value: function() {
  807. return this._getAppointmentHeightByTheme()
  808. }
  809. }, {
  810. key: "_getAppointmentMinHeight",
  811. value: function() {
  812. return this._getAppointmentDefaultHeight()
  813. }
  814. }, {
  815. key: "_getAppointmentHeightByTheme",
  816. value: function() {
  817. return this._isCompactTheme() ? COMPACT_THEME_APPOINTMENT_DEFAULT_HEIGHT : APPOINTMENT_DEFAULT_HEIGHT
  818. }
  819. }, {
  820. key: "_getAppointmentDefaultWidth",
  821. value: function() {
  822. return this.getPositioningStrategy()._getAppointmentDefaultWidth()
  823. }
  824. }, {
  825. key: "_getAppointmentMinWidth",
  826. value: function() {
  827. return this._getAppointmentDefaultWidth()
  828. }
  829. }, {
  830. key: "_needVerticalGroupBounds",
  831. value: function() {
  832. return false
  833. }
  834. }, {
  835. key: "_needHorizontalGroupBounds",
  836. value: function() {
  837. return false
  838. }
  839. }]);
  840. return BaseRenderingStrategy
  841. }();
  842. module.exports = BaseRenderingStrategy;