schedules.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. Template Name: Skote - Admin & Dashboard Template
  3. Author: Themesbrand
  4. Website: https://themesbrand.com/
  5. Contact: themesbrand@gmail.com
  6. File: schedules (calendar) Js File
  7. */
  8. 'use strict';
  9. /*eslint-disable*/
  10. var ScheduleList = [];
  11. var SCHEDULE_CATEGORY = [
  12. 'milestone',
  13. 'task'
  14. ];
  15. function ScheduleInfo() {
  16. this.id = null;
  17. this.calendarId = null;
  18. this.title = null;
  19. this.body = null;
  20. this.isAllday = false;
  21. this.start = null;
  22. this.end = null;
  23. this.category = '';
  24. this.dueDateClass = '';
  25. this.color = null;
  26. this.bgColor = null;
  27. this.dragBgColor = null;
  28. this.borderColor = null;
  29. this.customStyle = '';
  30. this.isFocused = false;
  31. this.isPending = false;
  32. this.isVisible = true;
  33. this.isReadOnly = false;
  34. this.goingDuration = 0;
  35. this.comingDuration = 0;
  36. this.recurrenceRule = '';
  37. this.state = '';
  38. this.raw = {
  39. memo: '',
  40. hasToOrCc: false,
  41. hasRecurrenceRule: false,
  42. location: null,
  43. class: 'public', // or 'private'
  44. creator: {
  45. name: '',
  46. avatar: '',
  47. company: '',
  48. email: '',
  49. phone: ''
  50. }
  51. };
  52. }
  53. function generateTime(schedule, renderStart, renderEnd) {
  54. var startDate = moment(renderStart.getTime())
  55. var endDate = moment(renderEnd.getTime());
  56. var diffDate = endDate.diff(startDate, 'days');
  57. schedule.isAllday = chance.bool({likelihood: 30});
  58. if (schedule.isAllday) {
  59. schedule.category = 'allday';
  60. } else if (chance.bool({likelihood: 30})) {
  61. schedule.category = SCHEDULE_CATEGORY[chance.integer({min: 0, max: 1})];
  62. if (schedule.category === SCHEDULE_CATEGORY[1]) {
  63. schedule.dueDateClass = 'morning';
  64. }
  65. } else {
  66. schedule.category = 'time';
  67. }
  68. startDate.add(chance.integer({min: 0, max: diffDate}), 'days');
  69. startDate.hours(chance.integer({min: 0, max: 23}))
  70. startDate.minutes(chance.bool() ? 0 : 30);
  71. schedule.start = startDate.toDate();
  72. endDate = moment(startDate);
  73. if (schedule.isAllday) {
  74. endDate.add(chance.integer({min: 0, max: 3}), 'days');
  75. }
  76. schedule.end = endDate
  77. .add(chance.integer({min: 1, max: 4}), 'hour')
  78. .toDate();
  79. if (!schedule.isAllday && chance.bool({likelihood: 20})) {
  80. schedule.goingDuration = chance.integer({min: 30, max: 120});
  81. schedule.comingDuration = chance.integer({min: 30, max: 120});;
  82. if (chance.bool({likelihood: 50})) {
  83. schedule.end = schedule.start;
  84. }
  85. }
  86. }
  87. function generateNames() {
  88. var names = [];
  89. var i = 0;
  90. var length = chance.integer({min: 1, max: 10});
  91. for (; i < length; i += 1) {
  92. names.push(chance.name());
  93. }
  94. return names;
  95. }
  96. function generateRandomSchedule(calendar, renderStart, renderEnd) {
  97. var schedule = new ScheduleInfo();
  98. schedule.id = chance.guid();
  99. schedule.calendarId = calendar.id;
  100. schedule.title = chance.sentence({words: 3});
  101. schedule.body = chance.bool({likelihood: 20}) ? chance.sentence({words: 10}) : '';
  102. schedule.isReadOnly = chance.bool({likelihood: 20});
  103. generateTime(schedule, renderStart, renderEnd);
  104. schedule.isPrivate = chance.bool({likelihood: 10});
  105. schedule.location = chance.address();
  106. schedule.attendees = chance.bool({likelihood: 70}) ? generateNames() : [];
  107. schedule.recurrenceRule = chance.bool({likelihood: 20}) ? 'repeated events' : '';
  108. schedule.state = chance.bool({likelihood: 20}) ? 'Free' : 'Busy';
  109. schedule.color = calendar.color;
  110. schedule.bgColor = calendar.bgColor;
  111. schedule.dragBgColor = calendar.dragBgColor;
  112. schedule.borderColor = calendar.borderColor;
  113. if (schedule.category === 'milestone') {
  114. schedule.color = schedule.bgColor;
  115. schedule.bgColor = 'transparent';
  116. schedule.dragBgColor = 'transparent';
  117. schedule.borderColor = 'transparent';
  118. }
  119. schedule.raw.memo = chance.sentence();
  120. schedule.raw.creator.name = chance.name();
  121. schedule.raw.creator.avatar = chance.avatar();
  122. schedule.raw.creator.company = chance.company();
  123. schedule.raw.creator.email = chance.email();
  124. schedule.raw.creator.phone = chance.phone();
  125. if (chance.bool({ likelihood: 20 })) {
  126. var travelTime = chance.minute();
  127. schedule.goingDuration = travelTime;
  128. schedule.comingDuration = travelTime;
  129. }
  130. ScheduleList.push(schedule);
  131. }
  132. function generateSchedule(viewName, renderStart, renderEnd) {
  133. ScheduleList = [];
  134. CalendarList.forEach(function(calendar) {
  135. var i = 0, length = 10;
  136. if (viewName === 'month') {
  137. length = 3;
  138. } else if (viewName === 'day') {
  139. length = 4;
  140. }
  141. for (; i < length; i += 1) {
  142. generateRandomSchedule(calendar, renderStart, renderEnd);
  143. }
  144. });
  145. }