schedules.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. 'use strict'
  2. /*eslint-disable*/
  3. var ScheduleList = [];
  4. var SCHEDULE_CATEGORY = [
  5. 'milestone',
  6. 'task'
  7. ];
  8. function ScheduleInfo() {
  9. this.id = null;
  10. this.calendarId = null;
  11. this.title = null;
  12. this.body = null;
  13. this.isAllday = false;
  14. this.start = null;
  15. this.end = null;
  16. this.category = '';
  17. this.dueDateClass = '';
  18. this.color = null;
  19. this.bgColor = null;
  20. this.dragBgColor = null;
  21. this.borderColor = null;
  22. this.customStyle = '';
  23. this.isFocused = false;
  24. this.isPending = false;
  25. this.isVisible = true;
  26. this.isReadOnly = false;
  27. this.goingDuration = 0;
  28. this.comingDuration = 0;
  29. this.recurrenceRule = '';
  30. this.state = '';
  31. this.raw = {
  32. memo: '',
  33. hasToOrCc: false,
  34. hasRecurrenceRule: false,
  35. location: null,
  36. class: 'public', // or 'private'
  37. creator: {
  38. name: '',
  39. avatar: '',
  40. company: '',
  41. email: '',
  42. phone: ''
  43. }
  44. };
  45. }
  46. function generateTime(schedule, renderStart, renderEnd) {
  47. var startDate = moment(renderStart.getTime())
  48. var endDate = moment(renderEnd.getTime());
  49. var diffDate = endDate.diff(startDate, 'days');
  50. schedule.isAllday = chance.bool({likelihood: 30});
  51. if (schedule.isAllday) {
  52. schedule.category = 'allday';
  53. } else if (chance.bool({likelihood: 30})) {
  54. schedule.category = SCHEDULE_CATEGORY[chance.integer({min: 0, max: 1})];
  55. if (schedule.category === SCHEDULE_CATEGORY[1]) {
  56. schedule.dueDateClass = 'morning';
  57. }
  58. } else {
  59. schedule.category = 'time';
  60. }
  61. startDate.add(chance.integer({min: 0, max: diffDate}), 'days');
  62. startDate.hours(chance.integer({min: 0, max: 23}))
  63. startDate.minutes(chance.bool() ? 0 : 30);
  64. schedule.start = startDate.toDate();
  65. endDate = moment(startDate);
  66. if (schedule.isAllday) {
  67. endDate.add(chance.integer({min: 0, max: 0}), 'days');
  68. }
  69. schedule.end = endDate
  70. .add(chance.integer({min: 0, max: 0}), 'hour')
  71. .toDate();
  72. if (!schedule.isAllday && chance.bool({likelihood: 20})) {
  73. schedule.goingDuration = chance.integer({min: 30, max: 120});
  74. schedule.comingDuration = chance.integer({min: 30, max: 120});;
  75. if (chance.bool({likelihood: 50})) {
  76. schedule.end = schedule.start;
  77. }
  78. }
  79. }
  80. function generateNames() {
  81. var names = [];
  82. var i = 0;
  83. var length = chance.integer({min: 1, max: 10});
  84. for (; i < length; i += 1) {
  85. names.push(chance.name());
  86. }
  87. return names;
  88. }
  89. function generateRandomSchedule(calendar, renderStart, renderEnd) {
  90. var schedule = new ScheduleInfo();
  91. schedule.id = chance.guid();
  92. schedule.calendarId = calendar.id;
  93. schedule.title = chance.sentence({words: 3});
  94. schedule.body = chance.bool({likelihood: 20}) ? chance.sentence({words: 10}) : '';
  95. schedule.isReadOnly = chance.bool({likelihood: 20});
  96. generateTime(schedule, renderStart, renderEnd);
  97. schedule.isPrivate = chance.bool({likelihood: 10});
  98. schedule.location = chance.address();
  99. schedule.attendees = chance.bool({likelihood: 70}) ? generateNames() : [];
  100. schedule.recurrenceRule = chance.bool({likelihood: 20}) ? 'repeated events' : '';
  101. schedule.state = chance.bool({likelihood: 20}) ? 'Free' : 'Busy';
  102. schedule.color = calendar.color;
  103. schedule.bgColor = calendar.bgColor;
  104. schedule.dragBgColor = calendar.dragBgColor;
  105. schedule.borderColor = calendar.borderColor;
  106. if (schedule.category === 'milestone') {
  107. schedule.color = schedule.bgColor;
  108. schedule.bgColor = 'transparent';
  109. schedule.dragBgColor = 'transparent';
  110. schedule.borderColor = 'transparent';
  111. }
  112. schedule.raw.memo = chance.sentence();
  113. schedule.raw.creator.name = chance.name();
  114. schedule.raw.creator.avatar = chance.avatar();
  115. schedule.raw.creator.company = chance.name();
  116. schedule.raw.creator.email = chance.email();
  117. schedule.raw.creator.phone = chance.phone();
  118. if (chance.bool({ likelihood: 20 })) {
  119. var travelTime = chance.minute();
  120. schedule.goingDuration = travelTime;
  121. schedule.comingDuration = travelTime;
  122. }
  123. console.log(schedule);
  124. ScheduleList.push(schedule);
  125. }
  126. function generateSchedule(viewName, renderStart, renderEnd) {
  127. ScheduleList = [];
  128. generateScheduleFromLocal()
  129. /*CalendarList.forEach(function(calendar) {
  130. var i = 0, length = 10;
  131. if (viewName === 'month') {
  132. length = 3;
  133. } else if (viewName === 'day') {
  134. length = 4;
  135. }
  136. for (; i < length; i += 1) {
  137. generateRandomSchedule(calendar, renderStart, renderEnd);
  138. }
  139. });*/
  140. }
  141. function getDate(strDate) {
  142. var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
  143. function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
  144. return date;
  145. }
  146. function generateScheduleFromLocal() {
  147. var sList = JSON.parse(localStorage.getItem('scheduleList'))
  148. for (var i = 0; i < sList.length; i++) {
  149. var schedule = new ScheduleInfo();
  150. schedule.id = sList[i].id;
  151. schedule.calendarId = sList[i].calendarId;
  152. schedule.title = sList[i].title;
  153. schedule.body = sList[i].body;
  154. schedule.isReadOnly = sList[i].isReadOnly;
  155. schedule.isAllday = sList[i].isAllday;
  156. schedule.dueDateClass = sList[i].dueDateClass;
  157. schedule.category = sList[i].category;
  158. schedule.isPrivate = sList[i].isPrivate;
  159. schedule.location = sList[i].location;
  160. schedule.attendees = sList[i].attendees;
  161. schedule.recurrenceRule = sList[i].recurrenceRule;
  162. schedule.state = sList[i].state;
  163. schedule.color = sList[i].color;
  164. schedule.bgColor = sList[i].bgColor;
  165. schedule.dragBgColor = sList[i].dragBgColor;
  166. schedule.borderColor = sList[i].borderColor;
  167. schedule.start = sList[i].start;
  168. schedule.end = sList[i].start;
  169. schedule.raw.memo = sList[i].raw.memo;
  170. schedule.raw.creator.name = sList[i].raw.creator.name;
  171. schedule.raw.creator.avatar = sList[i].raw.creator.avatar;
  172. schedule.raw.creator.company = sList[i].raw.creator.company;
  173. schedule.raw.creator.email = sList[i].raw.creator.email;
  174. schedule.raw.creator.phone = sList[i].raw.creator.phone;
  175. console.log(sList[i].start);
  176. console.log(schedule.start);
  177. ScheduleList.push(schedule);
  178. }
  179. }