Skip to content

Commit

Permalink
Merge 2f759b6 into c95f0eb
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehrke committed Oct 1, 2016
2 parents c95f0eb + 2f759b6 commit cf74a32
Show file tree
Hide file tree
Showing 13 changed files with 1,356 additions and 707 deletions.
28 changes: 28 additions & 0 deletions js/app/factory/icalFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
app.service('ICalFactory', function() {
'use strict';

const self = this;

/**
* create a new ICAL calendar object
* @returns {ICAL.Component}
*/
this.new = function() {
const root = new ICAL.Component(['vcalendar', [], []]);

Expand All @@ -35,4 +41,26 @@ app.service('ICalFactory', function() {

return root;
};

/**
* create a new ICAL calendar object that contains a calendar
* @param uid
* @returns ICAL.Component
*/
this.newEvent = function(uid) {
const comp = self.new();

const event = new ICAL.Component('vevent');
comp.addSubcomponent(event);

event.updatePropertyWithValue('created', ICAL.Time.now());
event.updatePropertyWithValue('dtstamp', ICAL.Time.now());
event.updatePropertyWithValue('last-modified', ICAL.Time.now());
event.updatePropertyWithValue('uid', uid);

//add a dummy dtstart, so it's a valid ics
event.updatePropertyWithValue('dtstart', ICAL.Time.now());

return comp;
};
});
194 changes: 194 additions & 0 deletions js/app/models/fcEventModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/**
* Calendar App
*
* @author Raghu Nayyar
* @author Georg Ehrke
* @copyright 2016 Raghu Nayyar <hey@raghunayyar.com>
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

app.factory('FcEvent', function(SimpleEvent) {
'use strict';

/**
* @param {VEvent} vevent
* @param {ICAL.Component} event
* @param {ICAL.Time} start
* @param {ICAL.Time} end
*/
function FcEvent(vevent, event, start, end) {
const context = {vevent, event, start, end};
context.iCalEvent = new ICAL.Event(event);

const iface = {
_isAFcEventObject: true
};

Object.defineProperties(iface, {
vevent: {
get: function() {
return context.vevent;
},
enumerable: true
},
event: {
get: function() {
return context.event;
},
enumerable: true
},
calendar: {
get: () => context.vevent.calendar,
enumerable: true
},
id: {
get: function() {
let id = context.vevent.uri;
if (event.hasProperty('recurrence-id')) {
id += context.event.getFirstPropertyValue('recurrence-id').toICALString();
}

return id;
},
enumerable: true
},
allDay: {
get: function() {
return (context.start.icaltype === 'date' &&
context.end.icaltype === 'date');
},
enumerable: true
},
start: {
get: function() {
return context.start.toJSDate();
},
enumerable: true
},
end: {
get: function() {
return context.end.toJSDate();
},
enumerable: true
},
repeating: {
get: function() {
return context.iCalEvent.isRecurring();
},
enumerable: true
},
backgroundColor: {
get: function() {
return context.vevent.calendar.color;
},
enumerable: true
},
borderColor: {
get: function() {
return context.vevent.calendar.color;
},
enumerable: true
},
className: {
get: function() {
return ['fcCalendar-id-' + context.vevent.calendar.tmpId];
},
enumerable: true
},
editable: {
get: function() {
return context.vevent.calendar.isWritable();
},
enumerable: true
},
textColor: {
get: function() {
return context.vevent.calendar.textColor;
},
enumerable: true
},
title: {
get: function() {
return context.event.getFirstPropertyValue('summary');
},
enumerable: true
}
});

/**
* get SimpleEvent for current fcEvent
* @returns {SimpleEvent}
*/
iface.getSimpleEvent = function () {
return SimpleEvent(context.event);
};

/**
* moves the event to a different position
* @param {Duration} delta
*/
iface.drop = function (delta) {
delta = new ICAL.Duration().fromSeconds(delta.asSeconds());

if (context.event.hasProperty('dtstart')) {
const dtstart = context.event.getFirstPropertyValue('dtstart');
dtstart.addDuration(delta);
context.event.updatePropertyWithValue('dtstart', dtstart);
}

if (context.event.hasProperty('dtend')) {
const dtend = context.event.getFirstPropertyValue('dtend');
dtend.addDuration(delta);
context.event.updatePropertyWithValue('dtend', dtend);
}

context.vevent.touch();
};

/**
* resizes the event
* @param {moment.duration} delta
*/
iface.resize = function (delta) {
delta = new ICAL.Duration().fromSeconds(delta.asSeconds());

if (context.event.hasProperty('duration')) {
const duration = context.event.getFirstPropertyValue('duration');
duration.fromSeconds((delta.toSeconds() + duration.toSeconds()));
context.event.updatePropertyWithValue('duration', duration);
} else if (context.event.hasProperty('dtend')) {
const dtend = context.event.getFirstPropertyValue('dtend');
dtend.addDuration(delta);
context.event.updatePropertyWithValue('dtend', dtend);
} else if (context.event.hasProperty('dtstart')) {
const dtstart = event.getFirstPropertyValue('dtstart').clone();
dtstart.addDuration(delta);
context.event.addPropertyWithValue('dtend', dtstart);
}

context.vevent.touch();
};

return iface;
}

FcEvent.isFcEvent = function(obj) {
return (typeof obj === 'object' && obj !== null && obj._isAFcEventObject === true);
};

return FcEvent;
});
Loading

0 comments on commit cf74a32

Please sign in to comment.