ui.scheduler.appointments.layout_manager.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /**
  2. * DevExtreme (ui/scheduler/ui.scheduler.appointments.layout_manager.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 _common = require("../../core/utils/common");
  11. var _common2 = _interopRequireDefault(_common);
  12. var _uiSchedulerAppointmentsStrategy = require("./rendering_strategies/ui.scheduler.appointments.strategy.vertical");
  13. var _uiSchedulerAppointmentsStrategy2 = _interopRequireDefault(_uiSchedulerAppointmentsStrategy);
  14. var _uiSchedulerAppointmentsStrategy3 = require("./rendering_strategies/ui.scheduler.appointments.strategy.horizontal");
  15. var _uiSchedulerAppointmentsStrategy4 = _interopRequireDefault(_uiSchedulerAppointmentsStrategy3);
  16. var _uiSchedulerAppointmentsStrategy5 = require("./rendering_strategies/ui.scheduler.appointments.strategy.horizontal_month_line");
  17. var _uiSchedulerAppointmentsStrategy6 = _interopRequireDefault(_uiSchedulerAppointmentsStrategy5);
  18. var _uiSchedulerAppointmentsStrategy7 = require("./rendering_strategies/ui.scheduler.appointments.strategy.horizontal_month");
  19. var _uiSchedulerAppointmentsStrategy8 = _interopRequireDefault(_uiSchedulerAppointmentsStrategy7);
  20. var _uiSchedulerAppointmentsStrategy9 = require("./rendering_strategies/ui.scheduler.appointments.strategy.agenda");
  21. var _uiSchedulerAppointmentsStrategy10 = _interopRequireDefault(_uiSchedulerAppointmentsStrategy9);
  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. var RENDERING_STRATEGIES = {
  56. horizontal: _uiSchedulerAppointmentsStrategy4.default,
  57. horizontalMonth: _uiSchedulerAppointmentsStrategy8.default,
  58. horizontalMonthLine: _uiSchedulerAppointmentsStrategy6.default,
  59. vertical: _uiSchedulerAppointmentsStrategy2.default,
  60. agenda: _uiSchedulerAppointmentsStrategy10.default
  61. };
  62. var AppointmentLayoutManager = function() {
  63. function AppointmentLayoutManager(instance, renderingStrategy) {
  64. _classCallCheck(this, AppointmentLayoutManager);
  65. this.instance = instance;
  66. renderingStrategy && this.initRenderingStrategy(renderingStrategy)
  67. }
  68. _createClass(AppointmentLayoutManager, [{
  69. key: "getCellDimensions",
  70. value: function(options) {
  71. if (this.instance._workSpace) {
  72. options.callback(this.instance._workSpace.getCellWidth(), this.instance._workSpace.getCellHeight(), this.instance._workSpace.getAllDayHeight())
  73. }
  74. }
  75. }, {
  76. key: "getGroupOrientation",
  77. value: function(options) {
  78. if (this.instance._workSpace) {
  79. options.callback(this.instance._workSpace._getRealGroupOrientation())
  80. }
  81. }
  82. }, {
  83. key: "initRenderingStrategy",
  84. value: function(renderingStrategy) {
  85. var Strategy = RENDERING_STRATEGIES[renderingStrategy];
  86. this._renderingStrategyInstance = new Strategy(this.instance);
  87. this.renderingStrategy = renderingStrategy
  88. }
  89. }, {
  90. key: "createAppointmentsMap",
  91. value: function(items) {
  92. var _this = this;
  93. this.getCellDimensions({
  94. callback: function(width, height, allDayHeight) {
  95. _this.instance._cellWidth = width;
  96. _this.instance._cellHeight = height;
  97. _this.instance._allDayCellHeight = allDayHeight
  98. }
  99. });
  100. this.getGroupOrientation({
  101. callback: function(groupOrientation) {
  102. return _this.instance._groupOrientation = groupOrientation
  103. }
  104. });
  105. this._positionMap = this._renderingStrategyInstance.createTaskPositionMap(items);
  106. return this._createAppointmentsMapCore(items || [], this._positionMap)
  107. }
  108. }, {
  109. key: "_createAppointmentsMapCore",
  110. value: function(list, positionMap) {
  111. var _this2 = this;
  112. return list.map(function(data, index) {
  113. if (!_this2._renderingStrategyInstance.keepAppointmentSettings()) {
  114. delete data.settings
  115. }
  116. var appointmentSettings = positionMap[index];
  117. appointmentSettings.forEach(function(settings) {
  118. settings.direction = "vertical" === _this2.renderingStrategy && !settings.allDay ? "vertical" : "horizontal"
  119. });
  120. return {
  121. itemData: data,
  122. settings: appointmentSettings,
  123. needRepaint: true,
  124. needRemove: false
  125. }
  126. })
  127. }
  128. }, {
  129. key: "_hasChangesInData",
  130. value: function(data) {
  131. var updatedData = this.instance.getUpdatedAppointment();
  132. return updatedData === data || this.instance.getUpdatedAppointmentKeys().some(function(item) {
  133. return data[item.key] === item.value
  134. })
  135. }
  136. }, {
  137. key: "_hasChangesInSettings",
  138. value: function(settingList, oldSettingList) {
  139. if (settingList.length !== oldSettingList.length) {
  140. return true
  141. }
  142. for (var i = 0; i < settingList.length; i++) {
  143. var newSettings = settingList[i];
  144. var oldSettings = oldSettingList[i];
  145. if (oldSettings) {
  146. oldSettings.sortedIndex = newSettings.sortedIndex
  147. }
  148. if (!_common2.default.equalByValue(newSettings, oldSettings)) {
  149. return true
  150. }
  151. }
  152. return false
  153. }
  154. }, {
  155. key: "_getEqualAppointmentFromList",
  156. value: function(appointment, list) {
  157. for (var i = 0; i < list.length; i++) {
  158. var item = list[i];
  159. if (item.itemData === appointment.itemData) {
  160. return item
  161. }
  162. }
  163. return null
  164. }
  165. }, {
  166. key: "_getDeletedAppointments",
  167. value: function(appointmentList, oldAppointmentList) {
  168. var result = [];
  169. for (var i = 0; i < oldAppointmentList.length; i++) {
  170. var oldAppointment = oldAppointmentList[i];
  171. var appointment = this._getEqualAppointmentFromList(oldAppointment, appointmentList);
  172. if (!appointment) {
  173. oldAppointment.needRemove = true;
  174. result.push(oldAppointment)
  175. }
  176. }
  177. return result
  178. }
  179. }, {
  180. key: "getRepaintedAppointments",
  181. value: function(appointmentList, oldAppointmentList) {
  182. if (0 === oldAppointmentList.length || "agenda" === this.renderingStrategy) {
  183. return appointmentList
  184. }
  185. for (var i = 0; i < appointmentList.length; i++) {
  186. var appointment = appointmentList[i];
  187. var oldAppointment = this._getEqualAppointmentFromList(appointment, oldAppointmentList);
  188. if (oldAppointment) {
  189. appointment.needRepaint = this._hasChangesInData(appointment.itemData) || this._hasChangesInSettings(appointment.settings, oldAppointment.settings)
  190. }
  191. }
  192. return appointmentList.concat(this._getDeletedAppointments(appointmentList, oldAppointmentList))
  193. }
  194. }, {
  195. key: "getRenderingStrategyInstance",
  196. value: function() {
  197. return this._renderingStrategyInstance
  198. }
  199. }]);
  200. return AppointmentLayoutManager
  201. }();
  202. module.exports = AppointmentLayoutManager;