Skip to content

Commit

Permalink
Import an .ics directly through Files app
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed Mar 23, 2017
1 parent 29603cd commit 39d7f4b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
11 changes: 11 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,16 @@
*/
namespace OCA\Calendar\AppInfo;

use OCP\Util;

$app = new Application();
$app->registerNavigation();
$server = $app->getContainer()->getServer();

// only load calendar action if the user is logged in
if ($server->getUserSession()->isLoggedIn()) {
$eventDispatcher = $server->getEventDispatcher();
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
Util::addScript('calendar', 'utility/registerUtility');
});
}
34 changes: 32 additions & 2 deletions js/app/controllers/calcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* Description: The fullcalendar controller.
*/

app.controller('CalController', ['$scope', 'Calendar', 'CalendarService', 'VEventService', 'SettingsService', 'TimezoneService', 'VEvent', 'is', 'fc', 'EventsEditorDialogService', 'PopoverPositioningUtility', '$window', 'isPublic',
function ($scope, Calendar, CalendarService, VEventService, SettingsService, TimezoneService, VEvent, is, fc, EventsEditorDialogService, PopoverPositioningUtility, $window, isPublic) {
app.controller('CalController', ['$scope', 'Calendar', 'CalendarService', 'VEventService', 'SettingsService', 'TimezoneService', 'VEvent', 'is', 'fc', 'EventsEditorDialogService', 'PopoverPositioningUtility', '$window', 'isPublic', '$http', '$rootScope', '$uibModal',
function ($scope, Calendar, CalendarService, VEventService, SettingsService, TimezoneService, VEvent, is, fc, EventsEditorDialogService, PopoverPositioningUtility, $window, isPublic, $http, $rootScope, $uibModal) {
'use strict';

is.loading = true;
Expand Down Expand Up @@ -146,6 +146,36 @@ app.controller('CalController', ['$scope', 'Calendar', 'CalendarService', 'VEven
});
}

$scope.importFileByPath = function(path) {
return $http.get(
OC.linkToRemoteBase('dav') + '/files/' + OC.getCurrentUser().displayName + '/' + decodeURI(path)
).then(function(response) {
const fileName = decodeURIComponent(path);
const fileBody = response.data;
let file = new File([fileBody], fileName, {type: 'text/calendar'});

$uibModal.open({
templateUrl: 'import.html',
controller: 'ImportController',
windowClass: 'import',
backdropClass: 'import-backdrop',
keyboard: false,
appendTo: angular.element('#importpopover-container'),
resolve: {
files: function () {
return [file];
}
},
scope: $scope
});
});
};

var hashParts = $window.location.hash.substr(1).split('/');
if (!hashParts[0] && hashParts[1] === 'import' && hashParts[2]) {
$scope.importFileByPath(hashParts[2]);
}


/**
* Calendar UI Configuration.
Expand Down
41 changes: 41 additions & 0 deletions js/utility/registerUtility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Calendar App
*
* @author Thomas Citharel
* @copyright 2016 Thomas Citharel <tcit@tcit.fr>
*
* 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/>.
*
*/

'use strict';

let register = (function () {

OCA.Files.fileActions.registerAction({
name: 'View',
mime: 'text/calendar',
displayName: t('calendar', 'Calendar'),
actionHandler: function(filename, context) {
let path = $('#fileList').find('[data-file="'+filename+'"]').data('path');
path = path.substring(1);
window.location = OC.generateUrl('apps/calendar/#/import/{filename}', {filename: encodeURI(path + '/' + filename)});
},
permissions: OC.PERMISSION_READ,
icon: function () {
return OC.imagePath('core', 'actions/view');
}
});
OCA.Files.fileActions.setDefault('text/calendar', 'View');
})();

0 comments on commit 39d7f4b

Please sign in to comment.