ui.scheduler.appointments.strategy.horizontal.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /**
  2. * DevExtreme (ui/scheduler/rendering_strategies/ui.scheduler.appointments.strategy.horizontal.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 _date = require("../../../core/utils/date");
  21. var _date2 = _interopRequireDefault(_date);
  22. function _interopRequireDefault(obj) {
  23. return obj && obj.__esModule ? obj : {
  24. "default": obj
  25. }
  26. }
  27. function _classCallCheck(instance, Constructor) {
  28. if (!(instance instanceof Constructor)) {
  29. throw new TypeError("Cannot call a class as a function")
  30. }
  31. }
  32. function _defineProperties(target, props) {
  33. for (var i = 0; i < props.length; i++) {
  34. var descriptor = props[i];
  35. descriptor.enumerable = descriptor.enumerable || false;
  36. descriptor.configurable = true;
  37. if ("value" in descriptor) {
  38. descriptor.writable = true
  39. }
  40. Object.defineProperty(target, descriptor.key, descriptor)
  41. }
  42. }
  43. function _createClass(Constructor, protoProps, staticProps) {
  44. if (protoProps) {
  45. _defineProperties(Constructor.prototype, protoProps)
  46. }
  47. if (staticProps) {
  48. _defineProperties(Constructor, staticProps)
  49. }
  50. Object.defineProperty(Constructor, "prototype", {
  51. writable: false
  52. });
  53. return Constructor
  54. }
  55. function _get() {
  56. if ("undefined" !== typeof Reflect && Reflect.get) {
  57. _get = Reflect.get.bind()
  58. } else {
  59. _get = function(target, property, receiver) {
  60. var base = _superPropBase(target, property);
  61. if (!base) {
  62. return
  63. }
  64. var desc = Object.getOwnPropertyDescriptor(base, property);
  65. if (desc.get) {
  66. return desc.get.call(arguments.length < 3 ? target : receiver)
  67. }
  68. return desc.value
  69. }
  70. }
  71. return _get.apply(this, arguments)
  72. }
  73. function _superPropBase(object, property) {
  74. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  75. object = _getPrototypeOf(object);
  76. if (null === object) {
  77. break
  78. }
  79. }
  80. return object
  81. }
  82. function _inherits(subClass, superClass) {
  83. if ("function" !== typeof superClass && null !== superClass) {
  84. throw new TypeError("Super expression must either be null or a function")
  85. }
  86. subClass.prototype = Object.create(superClass && superClass.prototype, {
  87. constructor: {
  88. value: subClass,
  89. writable: true,
  90. configurable: true
  91. }
  92. });
  93. Object.defineProperty(subClass, "prototype", {
  94. writable: false
  95. });
  96. if (superClass) {
  97. _setPrototypeOf(subClass, superClass)
  98. }
  99. }
  100. function _setPrototypeOf(o, p) {
  101. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  102. o.__proto__ = p;
  103. return o
  104. };
  105. return _setPrototypeOf(o, p)
  106. }
  107. function _createSuper(Derived) {
  108. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  109. return function() {
  110. var result, Super = _getPrototypeOf(Derived);
  111. if (hasNativeReflectConstruct) {
  112. var NewTarget = _getPrototypeOf(this).constructor;
  113. result = Reflect.construct(Super, arguments, NewTarget)
  114. } else {
  115. result = Super.apply(this, arguments)
  116. }
  117. return _possibleConstructorReturn(this, result)
  118. }
  119. }
  120. function _possibleConstructorReturn(self, call) {
  121. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  122. return call
  123. } else {
  124. if (void 0 !== call) {
  125. throw new TypeError("Derived constructors may only return object or undefined")
  126. }
  127. }
  128. return _assertThisInitialized(self)
  129. }
  130. function _assertThisInitialized(self) {
  131. if (void 0 === self) {
  132. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  133. }
  134. return self
  135. }
  136. function _isNativeReflectConstruct() {
  137. if ("undefined" === typeof Reflect || !Reflect.construct) {
  138. return false
  139. }
  140. if (Reflect.construct.sham) {
  141. return false
  142. }
  143. if ("function" === typeof Proxy) {
  144. return true
  145. }
  146. try {
  147. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  148. return true
  149. } catch (e) {
  150. return false
  151. }
  152. }
  153. function _getPrototypeOf(o) {
  154. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  155. return o.__proto__ || Object.getPrototypeOf(o)
  156. };
  157. return _getPrototypeOf(o)
  158. }
  159. var MAX_APPOINTMENT_HEIGHT = 100;
  160. var DEFAULT_APPOINTMENT_HEIGHT = 60;
  161. var MIN_APPOINTMENT_HEIGHT = 35;
  162. var DROP_DOWN_BUTTON_OFFSET = 2;
  163. var BOTTOM_CELL_GAP = 20;
  164. var toMs = _date2.default.dateToMilliseconds;
  165. var HorizontalRenderingStrategy = function(_BaseAppointmentsStra) {
  166. _inherits(HorizontalRenderingStrategy, _BaseAppointmentsStra);
  167. var _super = _createSuper(HorizontalRenderingStrategy);
  168. function HorizontalRenderingStrategy() {
  169. _classCallCheck(this, HorizontalRenderingStrategy);
  170. return _super.apply(this, arguments)
  171. }
  172. _createClass(HorizontalRenderingStrategy, [{
  173. key: "_needVerifyItemSize",
  174. value: function() {
  175. return true
  176. }
  177. }, {
  178. key: "calculateAppointmentWidth",
  179. value: function(appointment, position, isRecurring) {
  180. var cellWidth = this.getDefaultCellWidth() || this.getAppointmentMinSize();
  181. var allDay = this.instance.fire("getField", "allDay", appointment);
  182. var startDate = this.startDate(appointment, false, position);
  183. var endDate = this.endDate(appointment, position, isRecurring, false);
  184. var appointmentDuration = this._getAppointmentDurationInMs(startDate, endDate, allDay);
  185. appointmentDuration = this._adjustDurationByDaylightDiff(appointmentDuration, startDate, endDate);
  186. var cellDuration = this.instance.getAppointmentDurationInMinutes() * toMs("minute");
  187. var durationInCells = appointmentDuration / cellDuration;
  188. var width = this.cropAppointmentWidth(durationInCells * cellWidth, cellWidth);
  189. return width
  190. }
  191. }, {
  192. key: "_needAdjustDuration",
  193. value: function(diff) {
  194. return diff < 0
  195. }
  196. }, {
  197. key: "getAppointmentGeometry",
  198. value: function(coordinates) {
  199. var result = this._customizeAppointmentGeometry(coordinates);
  200. return _get(_getPrototypeOf(HorizontalRenderingStrategy.prototype), "getAppointmentGeometry", this).call(this, result)
  201. }
  202. }, {
  203. key: "_customizeAppointmentGeometry",
  204. value: function(coordinates) {
  205. var overlappingMode = this.instance.fire("getMaxAppointmentsPerCell");
  206. if (overlappingMode) {
  207. var config = this._calculateGeometryConfig(coordinates);
  208. return this._customizeCoordinates(coordinates, config.height, config.appointmentCountPerCell, config.offset)
  209. } else {
  210. var cellHeight = (this.getDefaultCellHeight() || this.getAppointmentMinSize()) - BOTTOM_CELL_GAP;
  211. var height = cellHeight / coordinates.count;
  212. if (height > MAX_APPOINTMENT_HEIGHT) {
  213. height = MAX_APPOINTMENT_HEIGHT
  214. }
  215. var top = coordinates.top + coordinates.index * height;
  216. return {
  217. height: height,
  218. width: coordinates.width,
  219. top: top,
  220. left: coordinates.left
  221. }
  222. }
  223. }
  224. }, {
  225. key: "_getOffsets",
  226. value: function() {
  227. return {
  228. unlimited: 0,
  229. auto: 0
  230. }
  231. }
  232. }, {
  233. key: "_checkLongCompactAppointment",
  234. value: function(item, result) {
  235. var overlappingMode = this.instance.fire("getMaxAppointmentsPerCell");
  236. if (overlappingMode) {
  237. this._splitLongCompactAppointment(item, result);
  238. return result
  239. }
  240. }
  241. }, {
  242. key: "_getCompactLeftCoordinate",
  243. value: function(itemLeft, index) {
  244. var cellWidth = this.getDefaultCellWidth() || this.getAppointmentMinSize();
  245. return itemLeft + cellWidth * index
  246. }
  247. }, {
  248. key: "_getMaxHeight",
  249. value: function() {
  250. return this.getDefaultCellHeight() || this.getAppointmentMinSize()
  251. }
  252. }, {
  253. key: "_getAppointmentCount",
  254. value: function(overlappingMode, coordinates) {
  255. return this._getMaxAppointmentCountPerCellByType(false)
  256. }
  257. }, {
  258. key: "_getAppointmentDefaultHeight",
  259. value: function() {
  260. return DEFAULT_APPOINTMENT_HEIGHT
  261. }
  262. }, {
  263. key: "_getAppointmentMinHeight",
  264. value: function() {
  265. return MIN_APPOINTMENT_HEIGHT
  266. }
  267. }, {
  268. key: "_sortCondition",
  269. value: function(a, b) {
  270. return this._columnCondition(a, b)
  271. }
  272. }, {
  273. key: "_getOrientation",
  274. value: function() {
  275. return ["left", "right", "top"]
  276. }
  277. }, {
  278. key: "_getMaxAppointmentWidth",
  279. value: function(startDate) {
  280. var result;
  281. this.instance.fire("getMaxAppointmentWidth", {
  282. date: startDate,
  283. callback: function(width) {
  284. result = width
  285. }
  286. });
  287. return result
  288. }
  289. }, {
  290. key: "getDropDownAppointmentWidth",
  291. value: function() {
  292. return this.getDefaultCellWidth() - 2 * DROP_DOWN_BUTTON_OFFSET
  293. }
  294. }, {
  295. key: "getDeltaTime",
  296. value: function(args, initialSize) {
  297. var deltaTime = 0;
  298. var deltaWidth = args.width - initialSize.width;
  299. deltaTime = toMs("minute") * Math.round(deltaWidth / this.getDefaultCellWidth() * this.instance.getAppointmentDurationInMinutes());
  300. return deltaTime
  301. }
  302. }, {
  303. key: "isAllDay",
  304. value: function(appointmentData) {
  305. return this.instance.fire("getField", "allDay", appointmentData)
  306. }
  307. }, {
  308. key: "needSeparateAppointment",
  309. value: function() {
  310. return this.instance.fire("isGroupedByDate")
  311. }
  312. }]);
  313. return HorizontalRenderingStrategy
  314. }(_uiSchedulerAppointmentsStrategy2.default);
  315. module.exports = HorizontalRenderingStrategy;