Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

calendar-with-intervals.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Mixins
  2. import CalendarBase from './calendar-base';
  3. // Util
  4. import props from '../util/props';
  5. import { parseTime, copyTimestamp, updateMinutes, createDayList, createIntervalList, createNativeLocaleFormatter } from '../util/timestamp';
  6. /* @vue/component */
  7. export default CalendarBase.extend({
  8. name: 'calendar-with-intervals',
  9. props: props.intervals,
  10. computed: {
  11. parsedFirstInterval: function parsedFirstInterval() {
  12. return parseInt(this.firstInterval);
  13. },
  14. parsedIntervalMinutes: function parsedIntervalMinutes() {
  15. return parseInt(this.intervalMinutes);
  16. },
  17. parsedIntervalCount: function parsedIntervalCount() {
  18. return parseInt(this.intervalCount);
  19. },
  20. parsedIntervalHeight: function parsedIntervalHeight() {
  21. return parseFloat(this.intervalHeight);
  22. },
  23. firstMinute: function firstMinute() {
  24. return this.parsedFirstInterval * this.parsedIntervalMinutes;
  25. },
  26. bodyHeight: function bodyHeight() {
  27. return this.parsedIntervalCount * this.parsedIntervalHeight;
  28. },
  29. days: function days() {
  30. return createDayList(this.parsedStart, this.parsedEnd, this.times.today, this.weekdaySkips, this.maxDays);
  31. },
  32. intervals: function intervals() {
  33. var days = this.days;
  34. var first = this.parsedFirstInterval;
  35. var minutes = this.parsedIntervalMinutes;
  36. var count = this.parsedIntervalCount;
  37. var now = this.times.now;
  38. return days.map(function (d) {
  39. return createIntervalList(d, first, minutes, count, now);
  40. });
  41. },
  42. intervalFormatter: function intervalFormatter() {
  43. if (this.intervalFormat) {
  44. return this.intervalFormat;
  45. }
  46. var longOptions = { timeZone: 'UTC', hour12: true, hour: '2-digit', minute: '2-digit' };
  47. var shortOptions = { timeZone: 'UTC', hour12: true, hour: 'numeric', minute: '2-digit' };
  48. var shortHourOptions = { timeZone: 'UTC', hour12: true, hour: 'numeric' };
  49. return createNativeLocaleFormatter(this.locale, function (tms, short) {
  50. return short ? tms.minute === 0 ? shortHourOptions : shortOptions : longOptions;
  51. });
  52. }
  53. },
  54. methods: {
  55. showIntervalLabelDefault: function showIntervalLabelDefault(interval) {
  56. var first = this.intervals[0][0];
  57. var isFirst = first.hour === interval.hour && first.minute === interval.minute;
  58. return !isFirst && interval.minute === 0;
  59. },
  60. intervalStyleDefault: function intervalStyleDefault(_interval) {
  61. return undefined;
  62. },
  63. getTimestampAtEvent: function getTimestampAtEvent(e, day) {
  64. var timestamp = copyTimestamp(day);
  65. var bounds = e.currentTarget.getBoundingClientRect();
  66. var baseMinutes = this.firstMinute;
  67. var touchEvent = e;
  68. var mouseEvent = e;
  69. var touches = touchEvent.changedTouches || touchEvent.touches;
  70. var clientY = touches && touches[0] ? touches[0].clientY : mouseEvent.clientY;
  71. var addIntervals = (clientY - bounds.top) / this.parsedIntervalHeight;
  72. var addMinutes = Math.floor(addIntervals * this.parsedIntervalMinutes);
  73. var minutes = baseMinutes + addMinutes;
  74. return updateMinutes(timestamp, minutes, this.times.now);
  75. },
  76. getSlotScope: function getSlotScope(timestamp) {
  77. var scope = copyTimestamp(timestamp);
  78. scope.timeToY = this.timeToY;
  79. scope.minutesToPixels = this.minutesToPixels;
  80. return scope;
  81. },
  82. scrollToTime: function scrollToTime(time) {
  83. var y = this.timeToY(time);
  84. var pane = this.$refs.scrollArea;
  85. if (y === false || !pane) {
  86. return false;
  87. }
  88. pane.scrollTop = y;
  89. return true;
  90. },
  91. minutesToPixels: function minutesToPixels(minutes) {
  92. return minutes / this.parsedIntervalMinutes * this.parsedIntervalHeight;
  93. },
  94. timeToY: function timeToY(time) {
  95. var clamp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  96. var minutes = parseTime(time);
  97. if (minutes === false) {
  98. return false;
  99. }
  100. var min = this.firstMinute;
  101. var gap = this.parsedIntervalCount * this.parsedIntervalMinutes;
  102. var delta = (minutes - min) / gap;
  103. var y = delta * this.bodyHeight;
  104. if (clamp) {
  105. if (y < 0) {
  106. y = 0;
  107. }
  108. if (y > this.bodyHeight) {
  109. y = this.bodyHeight;
  110. }
  111. }
  112. return y;
  113. }
  114. }
  115. });
  116. //# sourceMappingURL=calendar-with-intervals.js.map