Skip to content

Commit

Permalink
Merge 2d0a89e into 016b2c0
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehrke committed Oct 11, 2016
2 parents 016b2c0 + 2d0a89e commit b5f64b1
Show file tree
Hide file tree
Showing 16 changed files with 4,889 additions and 1,110 deletions.
2 changes: 1 addition & 1 deletion js/app/controllers/calcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ app.controller('CalController', ['$scope', 'Calendar', 'CalendarService', 'VEven
});
}).then(function(result) {
createAndRenderEvent(result.calendar, result.vevent.data, view.start, view.end, $scope.defaulttimezone);
}).catch(function() {
}).catch(function(reason) {
//fcEvent is removed by unlock callback
//no need to anything
return null;
Expand Down
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;
};
});
3 changes: 3 additions & 0 deletions js/app/models/calendarmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ app.factory('Calendar', function($window, Hook, VEventService, TimezoneService,
context.fcEventSource.isRendering = true;
iface.emit(Calendar.hookFinishedRendering);

start = moment(start.stripZone().format());
end = moment(end.stripZone().format());

const TimezoneServicePromise = TimezoneService.get(timezone);
const VEventServicePromise = VEventService.getAll(iface, start, end);
Promise.all([TimezoneServicePromise, VEventServicePromise]).then(function(results) {
Expand Down
159 changes: 159 additions & 0 deletions js/app/models/fcEventModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* 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);

let id = context.vevent.uri;
if (event.hasProperty('recurrence-id')) {
id += context.event.getFirstPropertyValue('recurrence-id').toICALString();
}

const allDay = (start.icaltype === 'date' && end.icaltype === 'date');

const iface = {
_isAFcEventObject: true,
id: id,
allDay: allDay,
start: start.toJSDate(),
end: end.toJSDate(),
repeating: context.iCalEvent.isRecurring(),
className: ['fcCalendar-id-' + vevent.calendar.tmpId],
editable: vevent.calendar.isWritable(),
backgroundColor: vevent.calendar.color,
borderColor: vevent.calendar.color,
textColor: vevent.calendar.textColor,
title: event.getFirstPropertyValue('summary')
};

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
}
});

/**
* 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());

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.getFirstProperty('dtstart');
const dtend = dtstart.getFirstValue().clone();
dtend.addDuration(delta);

const prop = context.event.addPropertyWithValue('dtend', dtend);

const tzid = dtstart.getParameter('tzid');
if (tzid) {
prop.setParameter('tzid', tzid);
}
}

context.vevent.touch();
};

/**
* lock fc event for editing
*/
iface.lock = function() {
context.lock = true;
};

/**
* unlock fc event
*/
iface.unlock = function() {
context.lock = false;
};

return iface;
}

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

return FcEvent;
});
170 changes: 0 additions & 170 deletions js/app/models/fceventmodel.js

This file was deleted.

Loading

0 comments on commit b5f64b1

Please sign in to comment.