Skip to content

Commit

Permalink
Merge 351c6d7 into 9e62f7a
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehrke committed Aug 11, 2016
2 parents 9e62f7a + 351c6d7 commit bcc89e0
Show file tree
Hide file tree
Showing 17 changed files with 457 additions and 113 deletions.
8 changes: 8 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 All @@ -64,6 +70,8 @@ public function registerNavigation() {
$appName = $this->getContainer()->getAppName();
$server = $this->getContainer()->getServer();

$this->getContainer()->getServer()->getHTTPClientService();

$server->getNavigationManager()->add(array(
'id' => $appName,
'order' => 5,
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'],
]
];
67 changes: 67 additions & 0 deletions controller/proxycontroller.php
@@ -0,0 +1,67 @@
<?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 OCA\Calendar\Http\StreamResponse;

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
*/
public function proxy($url) {
$client = $this->client->newClient();
$clientResponse = $client->get($url, [
'stream' => true,
]);

$response = new StreamResponse($clientResponse->getBody());
$response->setHeaders([
'Content-Type' => 'text/calendar',
]);

return $response;
}
}
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -146,4 +146,4 @@ private function getTimezoneList() {
return (substr($file, -4) === '.ics');
}));
}
}
}
10 changes: 0 additions & 10 deletions css/app/calendarlist.css
Expand Up @@ -86,16 +86,6 @@
background: #1a1a1a;
}

.add-new-subscription .calendarlist-fieldset input {
width: 130px;
margin-right: 2px;

}

.add-new-subscription .calendarlist-fieldset select {
width: 80px;
}

#app-navigation .app-navigation-list-item .calendarCheckbox {
position: absolute;
margin-left: 17px;
Expand Down
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);
}

}
19 changes: 17 additions & 2 deletions js/app/controllers/calendarlistcontroller.js
Expand Up @@ -26,8 +26,8 @@
* 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 = [];
Expand Down Expand Up @@ -80,6 +80,21 @@ app.controller('CalendarListController', ['$scope', '$rootScope', '$window', 'Ca
angular.element('#new-calendar-button').click();
};

$scope.createSubscription = function(url) {
WebCalService.get(url).then(function(splittedICal) {
const color = splittedICal.color || ColorUtility.randomColor();
const name = splittedICal.name || url;
CalendarService.createWebCal(name, color, url).then(function(calendar) {
$scope.calendars.push(calendar);
}).catch(function() {

});
}).catch(function() {
console.log('catch');
console.log(this);
});
};

$scope.download = function (item) {
var url = item.calendar.url;
// cut off last slash to have a fancy name for the ics
Expand Down
81 changes: 81 additions & 0 deletions js/app/models/webcalModel.js
@@ -0,0 +1,81 @@
/**
* 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/>.
*
*/

app.factory('WebCal', function($http, Calendar, VEvent, TimezoneService, WebCalService) {
'use strict';

function WebCal(url, props) {
const context = {};

if (props.href.startsWith('webcal://')) {
context.url = 'http://' + props.href.substr(9);
} else if (props.href.startsWith('webcals://')) {
context.url = 'https://' + props.href.substr(10);
} else {
context.url = props.href;
}

const iface = Calendar(url, props);
iface._isAWebCalObject = true;

iface.fcEventSource.events = function (start, end, timezone, callback) {
var fcAPI = this;

TimezoneService.get(timezone).then(function(tz) {
iface.fcEventSource.isRendering = true;
iface.emit(Calendar.hookFinishedRendering);

WebCalService.get(context.url).then(function(response) {
let vevents = [];

response.vevents.forEach(function(ical) {
try {
const vevent = new VEvent(iface, ical, '', '');
const events = vevent.getFcEvent(start, end, tz);
vevents = vevents.concat(events);
} catch (err) {
iface.addWarning(err.toString());
console.log(err);
console.log(event);
return;
}
});

callback(vevents);
fcAPI.reportEvents(fcAPI.clientEvents());

iface.fcEventSource.isRendering = false;
iface.emit(Calendar.hookFinishedRendering);
}, function(error) {
console.log(error);
});
});
};

return iface;
}

WebCal.isWebCal = function(obj) {
return (typeof obj === 'object' && obj !== null && obj._isAWebCalObject === false);
};

return WebCal;
});

0 comments on commit bcc89e0

Please sign in to comment.