Skip to content

Commit

Permalink
Merge 5722f7e into 35ecae3
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehrke committed Feb 18, 2017
2 parents 35ecae3 + 5722f7e commit 23f8d0b
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 239 deletions.
5 changes: 5 additions & 0 deletions controller/viewcontroller.php
Expand Up @@ -23,6 +23,7 @@
*/
namespace OCA\Calendar\Controller;

use OC\AppFramework\Http\Request;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
Expand Down Expand Up @@ -111,6 +112,7 @@ public function index() {
}

$webCalWorkaround = $runningOnNextcloud10OrLater ? 'no' : 'yes';
$isIE = $this->request->isUserAgent([Request::USER_AGENT_IE]);

return new TemplateResponse('calendar', 'main', [
'appVersion' => $appVersion,
Expand All @@ -123,6 +125,7 @@ public function index() {
'defaultColor' => $defaultColor,
'webCalWorkaround' => $webCalWorkaround,
'isPublic' => false,
'isIE' => $isIE,
'needsAutosize' => $needsAutosize,
]);
}
Expand All @@ -148,6 +151,7 @@ public function publicIndex() {
}

$appVersion = $this->config->getAppValue($this->appName, 'installed_version');
$isIE = $this->request->isUserAgent([Request::USER_AGENT_IE]);

$response = new TemplateResponse('calendar', 'main', [
'appVersion' => $appVersion,
Expand All @@ -157,6 +161,7 @@ public function publicIndex() {
'weekNumbers' => 'no',
'supportsClass' => $supportsClass,
'firstRun' => 'no',
'isIE' => $isIE,
'webCalWorkaround' => 'no',
'isPublic' => true,
'shareURL' => $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . $this->request->getRequestUri(),
Expand Down
82 changes: 46 additions & 36 deletions js/app/service/calendarService.js
Expand Up @@ -64,10 +64,10 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
];

const UPDATABLE_PROPERTIES_MAP = {
color: 'a:calendar-color',
displayname: 'd:displayname',
enabled: 'o:calendar-enabled',
order: 'a:calendar-order'
color: [DavClient.NS_APPLE, 'a:calendar-color'],
displayname: [DavClient.NS_DAV, 'd:displayname'],
enabled: [DavClient.NS_OWNCLOUD, 'o:calendar-enabled'],
order: [DavClient.NS_APPLE, 'a:calendar-order']
};

const SHARE_USER = constants.SHARE_TYPE_USER;
Expand Down Expand Up @@ -287,35 +287,37 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
*/
this.create = function(name, color, components=['vevent', 'vtodo']) {
return context.bootPromise.then(function() {
const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton('d:mkcol', 'd:set', 'd:prop');
const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton(
[DavClient.NS_DAV, 'd:mkcol'], [DavClient.NS_DAV, 'd:set'],
[DavClient.NS_DAV, 'd:prop']);
dPropChildren.push({
name: 'd:resourcetype',
name: [DavClient.NS_DAV, 'd:resourcetype'],
children: [{
name: 'd:collection'
name: [DavClient.NS_DAV, 'd:collection']
}, {
name: 'c:calendar'
name: [DavClient.NS_IETF, 'c:calendar']
}]
});
dPropChildren.push({
name: 'd:displayname',
name: [DavClient.NS_DAV, 'd:displayname'],
value: name
});
dPropChildren.push({
name: 'a:calendar-color',
name: [DavClient.NS_APPLE, 'a:calendar-color'],
value: color
});
dPropChildren.push({
name: 'o:calendar-enabled',
name: [DavClient.NS_OWNCLOUD, 'o:calendar-enabled'],
value: '1'
});
dPropChildren.push({
name: 'c:supported-calendar-component-set',
name: [DavClient.NS_IETF, 'c:supported-calendar-component-set'],
children: components.map(function(component) {
return {
name: 'c:comp',
attributes: {
name: component.toUpperCase()
}
name: [DavClient.NS_IETF, 'c:comp'],
attributes: [
['name', component.toUpperCase()]
]
};
})
});
Expand Down Expand Up @@ -357,31 +359,33 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
*/
this.createWebCal = function(name, color, source) {
return context.bootPromise.then(function() {
const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton('d:mkcol', 'd:set', 'd:prop');
const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton(
[DavClient.NS_DAV, 'd:mkcol'], [DavClient.NS_DAV, 'd:set'],
[DavClient.NS_DAV, 'd:prop']);
dPropChildren.push({
name: 'd:resourcetype',
name: [DavClient.NS_DAV, 'd:resourcetype'],
children: [{
name: 'd:collection'
name: [DavClient.NS_DAV, 'd:collection']
}, {
name: 'cs:subscribed'
name: [DavClient.NS_CALENDARSERVER, 'cs:subscribed']
}]
});
dPropChildren.push({
name: 'd:displayname',
name: [DavClient.NS_DAV, 'd:displayname'],
value: name
});
dPropChildren.push({
name: 'a:calendar-color',
name: [DavClient.NS_APPLE, 'a:calendar-color'],
value: color
});
dPropChildren.push({
name: 'o:calendar-enabled',
name: [DavClient.NS_OWNCLOUD, 'o:calendar-enabled'],
value: '1'
});
dPropChildren.push({
name: 'cs:source',
name: [DavClient.NS_CALENDARSERVER, 'cs:source'],
children: [{
name: 'd:href',
name: [DavClient.NS_DAV, 'd:href'],
value: source
}]
});
Expand Down Expand Up @@ -439,7 +443,9 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
return Promise.resolve(calendar);
}

const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton('d:propertyupdate', 'd:set', 'd:prop');
const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton(
[DavClient.NS_DAV, 'd:propertyupdate'], [DavClient.NS_DAV, 'd:set'],
[DavClient.NS_DAV, 'd:prop']);
updatedProperties.forEach(function(name) {
if (UPDATABLE_PROPERTIES.indexOf(name) === -1) {
return;
Expand All @@ -452,9 +458,9 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca

if (name === 'storedUrl') {
dPropChildren.push({
name: 'cs:source',
name: [DavClient.NS_CALENDARSERVER, 'cs:source'],
children: [{
name: 'd:href',
name: [DavClient.NS_DAV, 'd:href'],
value: value
}]
});
Expand Down Expand Up @@ -517,23 +523,24 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
* @returns {Promise}
*/
privateAPI.share = function(calendar, shareType, shareWith, writable, existingShare) {
const [skeleton, oSetChildren] = XMLUtility.getRootSkeleton('o:share', 'o:set');
const [skeleton, oSetChildren] = XMLUtility.getRootSkeleton(
[DavClient.NS_OWNCLOUD, 'o:share'], [DavClient.NS_OWNCLOUD, 'o:set']);

const hrefValue = context.getShareValue(shareType, shareWith);
oSetChildren.push({
name: 'd:href',
name: [DavClient.NS_DAV, 'd:href'],
value: hrefValue
});
oSetChildren.push({
name: 'o:summary',
name: [DavClient.NS_OWNCLOUD, 'o:summary'],
value: t('calendar', '{calendar} shared by {owner}', {
calendar: calendar.displayname,
owner: calendar.owner
})
});
if (writable) {
oSetChildren.push({
name: 'o:read-write'
name: [DavClient.NS_OWNCLOUD, 'o:read-write']
});
}

Expand Down Expand Up @@ -579,11 +586,12 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
* @returns {Promise}
*/
privateAPI.unshare = function(calendar, shareType, shareWith) {
const [skeleton, oRemoveChildren] = XMLUtility.getRootSkeleton('o:share', 'o:remove');
const [skeleton, oRemoveChildren] = XMLUtility.getRootSkeleton(
[DavClient.NS_OWNCLOUD, 'o:share'], [DavClient.NS_OWNCLOUD, 'o:remove']);

const hrefValue = context.getShareValue(shareType, shareWith);
oRemoveChildren.push({
name: 'd:href',
name: [DavClient.NS_DAV, 'd:href'],
value: hrefValue
});

Expand Down Expand Up @@ -620,7 +628,8 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
* @returns {Promise}
*/
privateAPI.publish = function(calendar) {
const [skeleton] = XMLUtility.getRootSkeleton('cs:publish-calendar');
const [skeleton] = XMLUtility.getRootSkeleton(
[DavClient.NS_CALENDARSERVER, 'cs:publish-calendar']);

const method = 'POST';
const url = calendar.url;
Expand All @@ -647,7 +656,8 @@ app.service('CalendarService', function(DavClient, StringUtility, XMLUtility, Ca
* @returns {Promise}
*/
privateAPI.unpublish = function(calendar) {
const [skeleton] = XMLUtility.getRootSkeleton('cs:unpublish-calendar');
const [skeleton] = XMLUtility.getRootSkeleton(
[DavClient.NS_CALENDARSERVER, 'cs:unpublish-calendar']);

const method = 'POST';
const url = calendar.url;
Expand Down
36 changes: 18 additions & 18 deletions js/app/service/veventService.js
Expand Up @@ -57,33 +57,33 @@ app.service('VEventService', function(DavClient, StringUtility, XMLUtility, VEve
* @returns {Promise}
*/
this.getAll = function (calendar, start, end) {
const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton('c:calendar-query');
const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton([DavClient.NS_IETF, 'c:calendar-query']);
dPropChildren.push({
name: 'd:prop',
name: [DavClient.NS_DAV, 'd:prop'],
children: [{
name: 'd:getetag'
name: [DavClient.NS_DAV, 'd:getetag']
}, {
name: 'c:calendar-data'
name: [DavClient.NS_IETF, 'c:calendar-data']
}]
});
dPropChildren.push({
name: 'c:filter',
name: [DavClient.NS_IETF, 'c:filter'],
children: [{
name: 'c:comp-filter',
attributes: {
name: 'VCALENDAR'
},
name: [DavClient.NS_IETF, 'c:comp-filter'],
attributes: [
['name', 'VCALENDAR']
],
children: [{
name: 'c:comp-filter',
attributes: {
name: 'VEVENT'
},
name: [DavClient.NS_IETF, 'c:comp-filter'],
attributes: [
['name', 'VEVENT']
],
children: [{
name: 'c:time-range',
attributes: {
start: context.getTimeRangeString(start),
end: context.getTimeRangeString(end)
}
name: [DavClient.NS_IETF, 'c:time-range'],
attributes: [
['start', context.getTimeRangeString(start)],
['end', context.getTimeRangeString(end)]
]
}]
}]
}]
Expand Down
23 changes: 9 additions & 14 deletions js/app/utility/xmlUtility.js
Expand Up @@ -24,13 +24,16 @@ app.service('XMLUtility', function() {

const context = {};
context.XMLify = function(xmlDoc, parent, json) {
const element = xmlDoc.createElement(json.name);
const element = xmlDoc.createElementNS(json.name[0], json.name[1]);

for (let key in json.attributes) {
if (json.attributes.hasOwnProperty(key)) {
element.setAttribute(key, json.attributes[key]);
json.attributes = json.attributes || [];
json.attributes.forEach((a) => {
if (a.length === 2) {
element.setAttribute(a[0], a[1]);
} else {
element.setAttributeNS(a[0], a[1], a[2]);
}
}
});

if (json.value) {
element.textContent = json.value;
Expand All @@ -54,14 +57,6 @@ app.service('XMLUtility', function() {

const skeleton = {
name: arguments[0],
attributes: {
'xmlns:c': 'urn:ietf:params:xml:ns:caldav',
'xmlns:d': 'DAV:',
'xmlns:a': 'http://apple.com/ns/ical/',
'xmlns:o': 'http://owncloud.org/ns',
'xmlns:n': 'http://nextcloud.com/ns',
'xmlns:cs': 'http://calendarserver.org/ns/'
},
children: []
};

Expand Down Expand Up @@ -89,6 +84,6 @@ app.service('XMLUtility', function() {
const root = document.implementation.createDocument('', '', null);
context.XMLify(root, root, json);

return serializer.serializeToString(root.firstChild);
return serializer.serializeToString(root);
};
});
14 changes: 14 additions & 0 deletions js/gulpfile.js
Expand Up @@ -37,6 +37,8 @@ const cssBuildTarget = 'app.css';
const cssBuildTargetMin = 'app.min.css';
const vendorTarget = 'vendor.js';
const vendorTargetMin = 'vendor.min.js';
const vendorIETarget = 'vendor.ie.js';
const vendorIETargetMin = 'vendor.ie.min.js';
const vendorCssTarget = 'vendor.css';
const vendorCssTargetMin = 'vendor.min.css';
const karmaConfig = __dirname + '/../tests/js/config/karma.js';
Expand Down Expand Up @@ -123,6 +125,10 @@ gulp.task('buildVendor', () => {
.pipe(concat(vendorCssTarget))
.pipe(gulp.dest(cssDestinationFolder));

gulp.src(['node_modules/babel-polyfill/dist/polyfill.js'].concat(vendorSources))
.pipe(concat(vendorIETarget))
.pipe(gulp.dest(destinationFolder));

return gulp.src(vendorSources)
.pipe(concat(vendorTarget))
.pipe(gulp.dest(destinationFolder));
Expand All @@ -139,6 +145,14 @@ gulp.task('minifyVendor', () => {
.pipe(sourcemaps.write('./', {includeContent: false}))
.pipe(gulp.dest(cssDestinationFolder));

gulp.src([destinationFolder + vendorIETarget])
.pipe(concat(vendorIETargetMin))
.pipe(sourcemaps.init({identityMap: true, largeFile: true}))
.pipe(strip())
.pipe(uglify())
.pipe(sourcemaps.write('./', {includeContent: false}))
.pipe(gulp.dest(destinationFolder));

return gulp.src([destinationFolder + vendorTarget])
.pipe(concat(vendorTargetMin))
.pipe(sourcemaps.init({identityMap: true, largeFile: true}))
Expand Down
1 change: 1 addition & 0 deletions js/package.json
Expand Up @@ -16,6 +16,7 @@
"url": "https://github.com/nextcloud/calendar/issues"
},
"devDependencies": {
"babel-polyfill": "^6.22.0",
"babel-preset-es2015": "^6.14.0",
"bower": "^1.7.9",
"coveralls": "^2.11.12",
Expand Down

0 comments on commit 23f8d0b

Please sign in to comment.