123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- 'use strict'
- /*eslint-disable*/
- var ScheduleList = [];
- var SCHEDULE_CATEGORY = [
- 'milestone',
- 'task'
- ];
- function ScheduleInfo() {
- this.id = null;
- this.calendarId = null;
- this.title = null;
- this.body = null;
- this.isAllday = false;
- this.start = null;
- this.end = null;
- this.category = '';
- this.dueDateClass = '';
- this.color = null;
- this.bgColor = null;
- this.dragBgColor = null;
- this.borderColor = null;
- this.customStyle = '';
- this.isFocused = false;
- this.isPending = false;
- this.isVisible = true;
- this.isReadOnly = false;
- this.goingDuration = 0;
- this.comingDuration = 0;
- this.recurrenceRule = '';
- this.state = '';
- this.raw = {
- memo: '',
- hasToOrCc: false,
- hasRecurrenceRule: false,
- location: null,
- class: 'public', // or 'private'
- creator: {
- name: '',
- avatar: '',
- company: '',
- email: '',
- phone: ''
- }
- };
- }
- function generateTime(schedule, renderStart, renderEnd) {
- var startDate = moment(renderStart.getTime())
- var endDate = moment(renderEnd.getTime());
- var diffDate = endDate.diff(startDate, 'days');
- schedule.isAllday = chance.bool({likelihood: 30});
- if (schedule.isAllday) {
- schedule.category = 'allday';
- } else if (chance.bool({likelihood: 30})) {
- schedule.category = SCHEDULE_CATEGORY[chance.integer({min: 0, max: 1})];
- if (schedule.category === SCHEDULE_CATEGORY[1]) {
- schedule.dueDateClass = 'morning';
- }
- } else {
- schedule.category = 'time';
- }
- startDate.add(chance.integer({min: 0, max: diffDate}), 'days');
- startDate.hours(chance.integer({min: 0, max: 23}))
- startDate.minutes(chance.bool() ? 0 : 30);
- schedule.start = startDate.toDate();
- endDate = moment(startDate);
- if (schedule.isAllday) {
- endDate.add(chance.integer({min: 0, max: 0}), 'days');
- }
- schedule.end = endDate
- .add(chance.integer({min: 0, max: 0}), 'hour')
- .toDate();
- if (!schedule.isAllday && chance.bool({likelihood: 20})) {
- schedule.goingDuration = chance.integer({min: 30, max: 120});
- schedule.comingDuration = chance.integer({min: 30, max: 120});;
- if (chance.bool({likelihood: 50})) {
- schedule.end = schedule.start;
- }
- }
- }
- function generateNames() {
- var names = [];
- var i = 0;
- var length = chance.integer({min: 1, max: 10});
- for (; i < length; i += 1) {
- names.push(chance.name());
- }
- return names;
- }
- function generateRandomSchedule(calendar, renderStart, renderEnd) {
- var schedule = new ScheduleInfo();
- schedule.id = chance.guid();
- schedule.calendarId = calendar.id;
- schedule.title = chance.sentence({words: 3});
- schedule.body = chance.bool({likelihood: 20}) ? chance.sentence({words: 10}) : '';
- schedule.isReadOnly = chance.bool({likelihood: 20});
- generateTime(schedule, renderStart, renderEnd);
- schedule.isPrivate = chance.bool({likelihood: 10});
- schedule.location = chance.address();
- schedule.attendees = chance.bool({likelihood: 70}) ? generateNames() : [];
- schedule.recurrenceRule = chance.bool({likelihood: 20}) ? 'repeated events' : '';
- schedule.state = chance.bool({likelihood: 20}) ? 'Free' : 'Busy';
- schedule.color = calendar.color;
- schedule.bgColor = calendar.bgColor;
- schedule.dragBgColor = calendar.dragBgColor;
- schedule.borderColor = calendar.borderColor;
- if (schedule.category === 'milestone') {
- schedule.color = schedule.bgColor;
- schedule.bgColor = 'transparent';
- schedule.dragBgColor = 'transparent';
- schedule.borderColor = 'transparent';
- }
- schedule.raw.memo = chance.sentence();
- schedule.raw.creator.name = chance.name();
- schedule.raw.creator.avatar = chance.avatar();
- schedule.raw.creator.company = chance.name();
- schedule.raw.creator.email = chance.email();
- schedule.raw.creator.phone = chance.phone();
- if (chance.bool({ likelihood: 20 })) {
- var travelTime = chance.minute();
- schedule.goingDuration = travelTime;
- schedule.comingDuration = travelTime;
- }
- console.log(schedule);
- ScheduleList.push(schedule);
- }
- function generateSchedule(viewName, renderStart, renderEnd) {
- ScheduleList = [];
- generateScheduleFromLocal()
- /*CalendarList.forEach(function(calendar) {
- var i = 0, length = 10;
- if (viewName === 'month') {
- length = 3;
- } else if (viewName === 'day') {
- length = 4;
- }
- for (; i < length; i += 1) {
- generateRandomSchedule(calendar, renderStart, renderEnd);
- }
- });*/
- }
- function getDate(strDate) {
- var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
- function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
- return date;
- }
- function generateScheduleFromLocal() {
- var sList = JSON.parse(localStorage.getItem('scheduleList'))
- for (var i = 0; i < sList.length; i++) {
- var schedule = new ScheduleInfo();
- schedule.id = sList[i].id;
- schedule.calendarId = sList[i].calendarId;
- schedule.title = sList[i].title;
- schedule.body = sList[i].body;
- schedule.isReadOnly = sList[i].isReadOnly;
- schedule.isAllday = sList[i].isAllday;
- schedule.dueDateClass = sList[i].dueDateClass;
- schedule.category = sList[i].category;
- schedule.isPrivate = sList[i].isPrivate;
- schedule.location = sList[i].location;
- schedule.attendees = sList[i].attendees;
- schedule.recurrenceRule = sList[i].recurrenceRule;
- schedule.state = sList[i].state;
- schedule.color = sList[i].color;
- schedule.bgColor = sList[i].bgColor;
- schedule.dragBgColor = sList[i].dragBgColor;
- schedule.borderColor = sList[i].borderColor;
- schedule.start = sList[i].start;
- schedule.end = sList[i].start;
- schedule.raw.memo = sList[i].raw.memo;
- schedule.raw.creator.name = sList[i].raw.creator.name;
- schedule.raw.creator.avatar = sList[i].raw.creator.avatar;
- schedule.raw.creator.company = sList[i].raw.creator.company;
- schedule.raw.creator.email = sList[i].raw.creator.email;
- schedule.raw.creator.phone = sList[i].raw.creator.phone;
- console.log(sList[i].start);
- console.log(schedule.start);
- ScheduleList.push(schedule);
- }
- }
|