Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement WebCal support #694

Merged
merged 18 commits into from Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -137,6 +137,7 @@ appstore:
$(copy_command) --parents -r \
"appinfo" \
"controller" \
"http" \
"img" \
"l10n" \
"templates" \
Expand Down
6 changes: 6 additions & 0 deletions appinfo/application.php
Expand Up @@ -55,6 +55,12 @@ public function __construct($params=[]) {

return new Controller\ViewController($c->getAppName(), $request, $userSession, $config);
});
$container->registerService('ProxyController', function(IAppContainer $c) {
$request = $c->query('Request');
$client = $c->getServer()->getHTTPClientService();

return new Controller\ProxyController($c->getAppName(), $request, $client);
});
}

/**
Expand Down
2 changes: 2 additions & 0 deletions appinfo/routes.php
Expand Up @@ -35,5 +35,7 @@
//Autocompletion
['name' => 'contact#searchAttendee', 'url' => '/v1/autocompletion/attendee', 'verb' => 'GET'],
['name' => 'contact#searchLocation', 'url' => '/v1/autocompletion/location', 'verb' => 'GET'],

['name' => 'proxy#proxy', 'url' => '/v1/proxy', 'verb' => 'GET'],
]
];
73 changes: 73 additions & 0 deletions controller/proxycontroller.php
@@ -0,0 +1,73 @@
<?php
/**
* ownCloud - Calendar App
*
* @author Georg Ehrke
* @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/>.
*
*/
namespace OCA\Calendar\Controller;

use GuzzleHttp\Exception\ClientException;
use OCA\Calendar\Http\StreamResponse;
use OCP\AppFramework\Http\JSONResponse;

use OCP\AppFramework\Controller;
use OCP\Http\Client\IClientService;
use OCP\IRequest;

class ProxyController extends Controller {

/**
* @var IClientService
*/
protected $client;

/**
* @param string $appName
* @param IRequest $request an instance of the request
* @param IClientService $client
*/
public function __construct($appName, IRequest $request,
IClientService $client) {
parent::__construct($appName, $request);
$this->client = $client;
}

/**
* @NoAdminRequired
*
* @param $url
* @return StreamResponse|JSONResponse
*/
public function proxy($url) {
$client = $this->client->newClient();
try {
$clientResponse = $client->get($url, [
'stream' => true,
]);
$response = new StreamResponse($clientResponse->getBody());
$response->setHeaders([
'Content-Type' => 'text/calendar',
]);
} catch (ClientException $e) {
$error_code = $e->getResponse()->getStatusCode();
$response = new JSONResponse();
$response->setStatus($error_code);
}
return $response;
}
}
2 changes: 1 addition & 1 deletion controller/viewcontroller.php
Expand Up @@ -47,8 +47,8 @@ class ViewController extends Controller {
/**
* @param string $appName
* @param IRequest $request an instance of the request
* @param IConfig $config
* @param IUserSession $userSession
* @param IConfig $config
*/
public function __construct($appName, IRequest $request,
IUserSession $userSession, IConfig $config) {
Expand Down
4 changes: 4 additions & 0 deletions css/app/calendarlist.css
Expand Up @@ -387,3 +387,7 @@ ul.dropdown-menu li > a:hover {
line-height: initial;
padding-left: 3px;
}

.app-navigation-entry-menu .icon-link {
background-size: 16px;
}
51 changes: 51 additions & 0 deletions http/streamresponse.php
@@ -0,0 +1,51 @@
<?php
/**
* ownCloud - Calendar App
*
* @author Georg Ehrke
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Calendar\Http;

use OCP\AppFramework\Http\ICallbackResponse;
use OCP\AppFramework\Http\IOutput;
use OCP\AppFramework\Http\Response;

class StreamResponse extends Response implements ICallbackResponse {

/**
* @var resource
*/
protected $stream;

/**
* @param resource $stream
*/
public function __construct ($stream) {
$this->stream = $stream;
}


/**
* @param IOutput $output a small wrapper that handles output
*/
public function callback (IOutput $output) {
rewind($this->stream);
fpassthru($this->stream);
}

}
44 changes: 29 additions & 15 deletions js/app/controllers/calendarlistcontroller.js
Expand Up @@ -26,16 +26,17 @@
* Description: Takes care of CalendarList in App Navigation.
*/

app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'CalendarService', 'is', 'CalendarListItem', 'Calendar',
function ($scope, $rootScope, $window, CalendarService, is, CalendarListItem, Calendar) {
app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'CalendarService', 'WebCalService', 'is', 'CalendarListItem', 'Calendar', 'ColorUtility',
function ($scope, $rootScope, $window, CalendarService, WebCalService, is, CalendarListItem, Calendar, ColorUtility) {
'use strict';

$scope.calendarListItems = [];
$scope.is = is;
$scope.newCalendarInputVal = '';
$scope.newCalendarColorVal = '';

window.scope = $scope;
$scope.newSubscriptionUrl = '';
$scope.newSubscriptionLocked = false;

$scope.$watchCollection('calendars', function(newCalendars, oldCalendars) {
newCalendars = newCalendars || [];
Expand All @@ -62,10 +63,6 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ca
return itemToCheck.calendar !== calendar;
});
});

if (!$scope.$$phase) {
$scope.$apply();
}
});

$scope.create = function (name, color) {
Expand All @@ -80,15 +77,32 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ca
angular.element('#new-calendar-button').click();
};

$scope.download = function (item) {
var url = item.calendar.url;
// cut off last slash to have a fancy name for the ics
if (url.slice(url.length - 1) === '/') {
url = url.slice(0, url.length - 1);
}
url += '?export';
$scope.createSubscription = function(url) {
$scope.newSubscriptionLocked = true;
WebCalService.get(url, true).then(function(splittedICal) {
const color = splittedICal.color || ColorUtility.randomColor();
const name = splittedICal.name || url;
CalendarService.createWebCal(name, color, url)
.then(function(calendar) {
$scope.newSubscriptionUrl = '';
angular.element('#new-subscription-button').click();
$scope.calendars.push(calendar);
$scope.$digest();
$scope.$parent.$digest();
$scope.newSubscriptionLocked = false;
})
.catch(function() {
OC.Notification.showTemporary(t('calendar', 'Error saving WebCal-calendar'));
$scope.newSubscriptionLocked = false;
});
}).catch(function(error) {
OC.Notification.showTemporary(error);
$scope.newSubscriptionLocked = false;
});
};

$window.open(url);
$scope.download = function (item) {
$window.open(item.calendar.downloadUrl);
};

$scope.toggleSharesEditor = function (calendar) {
Expand Down
1 change: 1 addition & 0 deletions js/app/controllers/editorcontroller.js
Expand Up @@ -35,6 +35,7 @@ app.controller('EditorController', ['$scope', 'TimezoneService', 'AutoCompletion
$scope.calendar = calendar;
$scope.oldCalendar = isNew ? calendar : vevent.calendar;
$scope.readOnly = isNew ? false : !vevent.calendar.isWritable();
$scope.accessibleViaCalDAV = vevent.calendar.eventsAccessibleViaCalDAV();
$scope.selected = 1;
$scope.timezones = [];
$scope.emailAddress = emailAddress;
Expand Down
21 changes: 19 additions & 2 deletions js/app/models/calendarListItemModel.js
Expand Up @@ -21,15 +21,16 @@
*
*/

app.factory('CalendarListItem', function(Calendar) {
app.factory('CalendarListItem', function(Calendar, WebCal) {
'use strict';

function CalendarListItem(calendar) {
const context = {
calendar: calendar,
isEditingShares: false,
isEditingProperties: false,
isDisplayingCalDAVUrl: false
isDisplayingCalDAVUrl: false,
isDisplayingWebCalUrl: false
};
const iface = {
_isACalendarListItemObject: true
Expand All @@ -55,10 +56,22 @@ app.factory('CalendarListItem', function(Calendar) {
context.isDisplayingCalDAVUrl = true;
};

iface.displayWebCalUrl = function() {
return context.isDisplayingWebCalUrl;
};

iface.hideCalDAVUrl = function() {
context.isDisplayingCalDAVUrl = false;
};

iface.showWebCalUrl = function() {
context.isDisplayingWebCalUrl = true;
};

iface.hideWebCalUrl = function() {
context.isDisplayingWebCalUrl = false;
};

iface.isEditingShares = function() {
return context.isEditingShares;
};
Expand Down Expand Up @@ -107,6 +120,10 @@ app.factory('CalendarListItem', function(Calendar) {
context.isEditingProperties = false;
};

iface.isWebCal = function() {
return WebCal.isWebCal(context.calendar);
};

//Properties for ng-model of calendar editor
iface.color = '';
iface.displayname = '';
Expand Down
62 changes: 41 additions & 21 deletions js/app/models/calendarmodel.js
Expand Up @@ -30,32 +30,35 @@ app.factory('Calendar', function($window, Hook, VEventService, TimezoneService,

context.fcEventSource.events = function (start, end, timezone, callback) {
const fcAPI = this;
context.fcEventSource.isRendering = true;
iface.emit(Calendar.hookFinishedRendering);

TimezoneService.get(timezone).then(function (tz) {
context.fcEventSource.isRendering = true;
iface.emit(Calendar.hookFinishedRendering);
const TimezoneServicePromise = TimezoneService.get(timezone);
const VEventServicePromise = VEventService.getAll(iface, start, end);
Promise.all([TimezoneServicePromise, VEventServicePromise]).then(function(results) {
const [tz, events] = results;
let vevents = [];

VEventService.getAll(iface, start, end).then(function (events) {
var vevents = [];
for (var i = 0; i < events.length; i++) {
var vevent;
try {
vevent = events[i].getFcEvent(start, end, tz);
} catch (err) {
iface.addWarning(err.toString());
console.log(err);
console.log(events[i]);
continue;
}
vevents = vevents.concat(vevent);
for (var i = 0; i < events.length; i++) {
var vevent;
try {
vevent = events[i].getFcEvent(start, end, tz);
} catch (err) {
iface.addWarning(err.toString());
console.log(err);
console.log(events[i]);
continue;
}
vevents = vevents.concat(vevent);
}

callback(vevents);
fcAPI.reportEvents(fcAPI.clientEvents());
context.fcEventSource.isRendering = false;
callback(vevents);
fcAPI.reportEvents(fcAPI.clientEvents());
context.fcEventSource.isRendering = false;

iface.emit(Calendar.hookFinishedRendering);
});
iface.emit(Calendar.hookFinishedRendering);
}).catch(function(reason) {
console.log(reason);
});
};
context.fcEventSource.editable = context.writable;
Expand Down Expand Up @@ -142,6 +145,19 @@ app.factory('Calendar', function($window, Hook, VEventService, TimezoneService,
return context.url;
}
},
downloadUrl: {
get: function() {
let url = context.url;
// cut off last slash to have a fancy name for the ics
if (url.slice(url.length - 1) === '/') {
url = url.slice(0, url.length - 1);
}
url += '?export';

return url;
},
configurable: true
},
caldav: {
get: function() {
return $window.location.origin + context.url;
Expand Down Expand Up @@ -233,6 +249,10 @@ app.factory('Calendar', function($window, Hook, VEventService, TimezoneService,
return context.writableProperties;
};

iface.eventsAccessibleViaCalDAV = function() {
return true;
};

Object.assign(
iface,
Hook(context)
Expand Down