ui.scheduler.appointments.strategy.agenda.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /**
  2. * DevExtreme (ui/scheduler/rendering_strategies/ui.scheduler.appointments.strategy.agenda.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 _date = require("../../../core/utils/date");
  19. var _date2 = _interopRequireDefault(_date);
  20. var _iterator = require("../../../core/utils/iterator");
  21. var _array = require("../../../core/utils/array");
  22. var _array2 = _interopRequireDefault(_array);
  23. var _uiSchedulerAppointmentsStrategy = require("./ui.scheduler.appointments.strategy.base");
  24. var _uiSchedulerAppointmentsStrategy2 = _interopRequireDefault(_uiSchedulerAppointmentsStrategy);
  25. function _interopRequireDefault(obj) {
  26. return obj && obj.__esModule ? obj : {
  27. "default": obj
  28. }
  29. }
  30. function _classCallCheck(instance, Constructor) {
  31. if (!(instance instanceof Constructor)) {
  32. throw new TypeError("Cannot call a class as a function")
  33. }
  34. }
  35. function _defineProperties(target, props) {
  36. for (var i = 0; i < props.length; i++) {
  37. var descriptor = props[i];
  38. descriptor.enumerable = descriptor.enumerable || false;
  39. descriptor.configurable = true;
  40. if ("value" in descriptor) {
  41. descriptor.writable = true
  42. }
  43. Object.defineProperty(target, descriptor.key, descriptor)
  44. }
  45. }
  46. function _createClass(Constructor, protoProps, staticProps) {
  47. if (protoProps) {
  48. _defineProperties(Constructor.prototype, protoProps)
  49. }
  50. if (staticProps) {
  51. _defineProperties(Constructor, staticProps)
  52. }
  53. Object.defineProperty(Constructor, "prototype", {
  54. writable: false
  55. });
  56. return Constructor
  57. }
  58. function _inherits(subClass, superClass) {
  59. if ("function" !== typeof superClass && null !== superClass) {
  60. throw new TypeError("Super expression must either be null or a function")
  61. }
  62. subClass.prototype = Object.create(superClass && superClass.prototype, {
  63. constructor: {
  64. value: subClass,
  65. writable: true,
  66. configurable: true
  67. }
  68. });
  69. Object.defineProperty(subClass, "prototype", {
  70. writable: false
  71. });
  72. if (superClass) {
  73. _setPrototypeOf(subClass, superClass)
  74. }
  75. }
  76. function _setPrototypeOf(o, p) {
  77. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  78. o.__proto__ = p;
  79. return o
  80. };
  81. return _setPrototypeOf(o, p)
  82. }
  83. function _createSuper(Derived) {
  84. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  85. return function() {
  86. var result, Super = _getPrototypeOf(Derived);
  87. if (hasNativeReflectConstruct) {
  88. var NewTarget = _getPrototypeOf(this).constructor;
  89. result = Reflect.construct(Super, arguments, NewTarget)
  90. } else {
  91. result = Super.apply(this, arguments)
  92. }
  93. return _possibleConstructorReturn(this, result)
  94. }
  95. }
  96. function _possibleConstructorReturn(self, call) {
  97. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  98. return call
  99. } else {
  100. if (void 0 !== call) {
  101. throw new TypeError("Derived constructors may only return object or undefined")
  102. }
  103. }
  104. return _assertThisInitialized(self)
  105. }
  106. function _assertThisInitialized(self) {
  107. if (void 0 === self) {
  108. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  109. }
  110. return self
  111. }
  112. function _isNativeReflectConstruct() {
  113. if ("undefined" === typeof Reflect || !Reflect.construct) {
  114. return false
  115. }
  116. if (Reflect.construct.sham) {
  117. return false
  118. }
  119. if ("function" === typeof Proxy) {
  120. return true
  121. }
  122. try {
  123. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  124. return true
  125. } catch (e) {
  126. return false
  127. }
  128. }
  129. function _getPrototypeOf(o) {
  130. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  131. return o.__proto__ || Object.getPrototypeOf(o)
  132. };
  133. return _getPrototypeOf(o)
  134. }
  135. var AgendaRenderingStrategy = function(_BaseAppointmentsStra) {
  136. _inherits(AgendaRenderingStrategy, _BaseAppointmentsStra);
  137. var _super = _createSuper(AgendaRenderingStrategy);
  138. function AgendaRenderingStrategy() {
  139. _classCallCheck(this, AgendaRenderingStrategy);
  140. return _super.apply(this, arguments)
  141. }
  142. _createClass(AgendaRenderingStrategy, [{
  143. key: "getAppointmentMinSize",
  144. value: function() {}
  145. }, {
  146. key: "getDeltaTime",
  147. value: function() {}
  148. }, {
  149. key: "keepAppointmentSettings",
  150. value: function() {
  151. return true
  152. }
  153. }, {
  154. key: "getAppointmentGeometry",
  155. value: function(geometry) {
  156. return geometry
  157. }
  158. }, {
  159. key: "createTaskPositionMap",
  160. value: function(appointments) {
  161. if (appointments.length) {
  162. var height = this.instance.fire("getAgendaVerticalStepHeight");
  163. var appointmentsByResources = this.instance.fire("groupAppointmentsByResources", appointments);
  164. var groupedAppts = [];
  165. (0, _iterator.each)(appointmentsByResources, function(i, appts) {
  166. var additionalAppointments = [];
  167. var recurrentIndexes = [];
  168. (0, _iterator.each)(appts, function(index, appointment) {
  169. var recurrenceBatch = this.instance.getAppointmentsInstance()._processRecurrenceAppointment(appointment, index);
  170. var appointmentBatch = null;
  171. if (!recurrenceBatch.indexes.length) {
  172. appointmentBatch = {
  173. parts: []
  174. };
  175. appointmentBatch = this.instance.getAppointmentsInstance()._processLongAppointment(appointment);
  176. additionalAppointments = additionalAppointments.concat(appointmentBatch.parts)
  177. }
  178. additionalAppointments = additionalAppointments.concat(recurrenceBatch.parts);
  179. recurrentIndexes = recurrentIndexes.concat(recurrenceBatch.indexes)
  180. }.bind(this));
  181. this.instance.getAppointmentsInstance()._reduceRecurrenceAppointments(recurrentIndexes, appts);
  182. this.instance.getAppointmentsInstance()._combineAppointments(appts, additionalAppointments);
  183. groupedAppts = groupedAppts.concat(appts)
  184. }.bind(this));
  185. Array.prototype.splice.apply(appointments, [0, appointments.length].concat(groupedAppts))
  186. }
  187. var result = [];
  188. var sortedIndex = 0;
  189. appointments.forEach(function(appt, index) {
  190. result.push([{
  191. height: height,
  192. width: "100%",
  193. sortedIndex: sortedIndex++,
  194. groupIndex: this._calculateGroupIndex(index, appointmentsByResources)
  195. }])
  196. }.bind(this));
  197. return result
  198. }
  199. }, {
  200. key: "_calculateGroupIndex",
  201. value: function(apptIndex, appointmentsByResources) {
  202. var resultInd;
  203. var counter = 0;
  204. for (var i in appointmentsByResources) {
  205. var countApptInGroup = appointmentsByResources[i].length;
  206. if (apptIndex >= counter && apptIndex < counter + countApptInGroup) {
  207. resultInd = Number(i);
  208. break
  209. }
  210. counter += countApptInGroup
  211. }
  212. return resultInd
  213. }
  214. }, {
  215. key: "_getDeltaWidth",
  216. value: function() {}
  217. }, {
  218. key: "_getAppointmentMaxWidth",
  219. value: function() {
  220. return this.getDefaultCellWidth()
  221. }
  222. }, {
  223. key: "_needVerifyItemSize",
  224. value: function() {
  225. return false
  226. }
  227. }, {
  228. key: "_isRtl",
  229. value: function() {
  230. return this.instance.option("rtlEnabled")
  231. }
  232. }, {
  233. key: "_getAppointmentParts",
  234. value: function() {}
  235. }, {
  236. key: "_reduceMultiWeekAppointment",
  237. value: function() {}
  238. }, {
  239. key: "calculateAppointmentHeight",
  240. value: function() {
  241. return 0
  242. }
  243. }, {
  244. key: "calculateAppointmentWidth",
  245. value: function() {
  246. return 0
  247. }
  248. }, {
  249. key: "isAppointmentGreaterThan",
  250. value: function() {}
  251. }, {
  252. key: "isAllDay",
  253. value: function() {
  254. return false
  255. }
  256. }, {
  257. key: "_sortCondition",
  258. value: function() {}
  259. }, {
  260. key: "_rowCondition",
  261. value: function() {}
  262. }, {
  263. key: "_columnCondition",
  264. value: function() {}
  265. }, {
  266. key: "_findIndexByKey",
  267. value: function() {}
  268. }, {
  269. key: "_getMaxNeighborAppointmentCount",
  270. value: function() {}
  271. }, {
  272. key: "_markAppointmentAsVirtual",
  273. value: function() {}
  274. }, {
  275. key: "getDropDownAppointmentWidth",
  276. value: function() {}
  277. }, {
  278. key: "getDefaultCellWidth",
  279. value: function() {
  280. return this._defaultWidth
  281. }
  282. }, {
  283. key: "getCompactAppointmentDefaultWidth",
  284. value: function() {}
  285. }, {
  286. key: "getCompactAppointmentLeftOffset",
  287. value: function() {}
  288. }, {
  289. key: "getCompactAppointmentTopOffset",
  290. value: function() {}
  291. }, {
  292. key: "calculateRows",
  293. value: function(appointments, agendaDuration, currentDate, needClearSettings) {
  294. this._rows = [];
  295. var appts = {
  296. indexes: [],
  297. parts: []
  298. };
  299. var groupedAppointments = this.instance.fire("groupAppointmentsByResources", appointments);
  300. currentDate = _date2.default.trimTime(new Date(currentDate));
  301. (0, _iterator.each)(groupedAppointments, function(groupIndex, currentAppointments) {
  302. var groupResult = [];
  303. if (!currentAppointments.length) {
  304. this._rows.push([]);
  305. return true
  306. }(0, _iterator.each)(currentAppointments, function(index, appointment) {
  307. var startDate = this.instance.fire("getField", "startDate", appointment);
  308. var endDate = this.instance.fire("getField", "endDate", appointment);
  309. this.instance.fire("fixWrongEndDate", appointment, startDate, endDate);
  310. needClearSettings && delete appointment.settings;
  311. var result = this.instance.getAppointmentsInstance()._processRecurrenceAppointment(appointment, index, false);
  312. appts.parts = appts.parts.concat(result.parts);
  313. appts.indexes = appts.indexes.concat(result.indexes)
  314. }.bind(this));
  315. this.instance.getAppointmentsInstance()._reduceRecurrenceAppointments(appts.indexes, currentAppointments);
  316. _array2.default.merge(currentAppointments, appts.parts);
  317. var appointmentCount = currentAppointments.length;
  318. for (var i = 0; i < agendaDuration; i++) {
  319. var day = new Date(currentDate);
  320. day.setMilliseconds(day.getMilliseconds() + 864e5 * i);
  321. if (void 0 === groupResult[i]) {
  322. groupResult[i] = 0
  323. }
  324. for (var j = 0; j < appointmentCount; j++) {
  325. var appointmentData = currentAppointments[j].settings || currentAppointments[j];
  326. var appointmentIsLong = this.instance.fire("appointmentTakesSeveralDays", currentAppointments[j]);
  327. var appointmentIsRecurrence = this.instance.fire("getField", "recurrenceRule", currentAppointments[j]);
  328. if (this.instance.fire("dayHasAppointment", day, appointmentData, true) || !appointmentIsRecurrence && appointmentIsLong && this.instance.fire("dayHasAppointment", day, currentAppointments[j], true)) {
  329. groupResult[i] += 1
  330. }
  331. }
  332. }
  333. this._rows.push(groupResult)
  334. }.bind(this));
  335. return this._rows
  336. }
  337. }, {
  338. key: "_iterateRow",
  339. value: function(row, obj, index) {
  340. for (var i = 0; i < row.length; i++) {
  341. obj.counter = obj.counter + row[i];
  342. if (obj.counter >= index) {
  343. obj.indexInRow = i;
  344. break
  345. }
  346. }
  347. }
  348. }, {
  349. key: "getDateByIndex",
  350. value: function(index, rows, startViewDate) {
  351. var obj = {
  352. counter: 0,
  353. indexInRow: 0
  354. };
  355. index++;
  356. for (var i = 0; i < rows.length; i++) {
  357. this._iterateRow(rows[i], obj, index);
  358. if (obj.indexInRow) {
  359. break
  360. }
  361. }
  362. return new Date(new Date(startViewDate).setDate(startViewDate.getDate() + obj.indexInRow))
  363. }
  364. }, {
  365. key: "getAppointmentDataCalculator",
  366. value: function() {
  367. return function($appointment, originalStartDate) {
  368. var apptIndex = $appointment.index();
  369. var startViewDate = this.instance.getStartViewDate();
  370. var calculatedStartDate = this.getDateByIndex(apptIndex, this._rows, startViewDate);
  371. var wrappedOriginalStartDate = new Date(originalStartDate);
  372. return {
  373. startDate: new Date(calculatedStartDate.setHours(wrappedOriginalStartDate.getHours(), wrappedOriginalStartDate.getMinutes(), wrappedOriginalStartDate.getSeconds(), wrappedOriginalStartDate.getMilliseconds()))
  374. }
  375. }.bind(this)
  376. }
  377. }]);
  378. return AgendaRenderingStrategy
  379. }(_uiSchedulerAppointmentsStrategy2.default);
  380. module.exports = AgendaRenderingStrategy;