Browse Source

Merge pull request #29318 from nextcloud/fix/dav-availability-settings-timezone-id

Read and write time zone ID when updating CalDAV availability
pull/29435/head
Christoph Wurst 4 years ago
committed by GitHub
parent
commit
9177afe8ab
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/dav/js/settings-admin-caldav.js
  2. 2
      apps/dav/js/settings-admin-caldav.js.map
  3. 30
      apps/dav/js/settings-personal-availability.js
  4. 2
      apps/dav/js/settings-personal-availability.js.map
  5. 29
      apps/dav/src/service/CalendarService.js
  6. 5
      apps/dav/src/views/Availability.vue
  7. 11
      package-lock.json
  8. 1
      package.json

4
apps/dav/js/settings-admin-caldav.js
File diff suppressed because it is too large
View File

2
apps/dav/js/settings-admin-caldav.js.map
File diff suppressed because it is too large
View File

30
apps/dav/js/settings-personal-availability.js
File diff suppressed because it is too large
View File

2
apps/dav/js/settings-personal-availability.js.map
File diff suppressed because it is too large
View File

29
apps/dav/src/service/CalendarService.js

@ -22,6 +22,7 @@ import { getClient } from '../dav/client'
import ICAL from 'ical.js'
import logger from './logger'
import { parseXML } from 'webdav/dist/node/tools/dav'
import { getZoneString } from 'icalzone'
import { v4 as uuidv4 } from 'uuid'
export function getEmptySlots() {
@ -64,8 +65,14 @@ export async function findScheduleInboxAvailability() {
const vcalendarComp = new ICAL.Component(parsedIcal)
const vavailabilityComp = vcalendarComp.getFirstSubcomponent('vavailability')
const availableComps = vavailabilityComp.getAllSubcomponents('available')
let timezoneId
const timezoneComp = vcalendarComp.getFirstSubcomponent('vtimezone')
if (timezoneComp) {
timezoneId = timezoneComp.getFirstProperty('tzid').getFirstValue()
}
const availableComps = vavailabilityComp.getAllSubcomponents('available')
// Combine all AVAILABLE blocks into a week of slots
const slots = getEmptySlots()
availableComps.forEach((availableComp) => {
@ -90,6 +97,7 @@ export async function findScheduleInboxAvailability() {
return {
slots,
timezoneId,
}
}
@ -99,6 +107,23 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
day: dayId,
})))]
const vcalendarComp = new ICAL.Component('vcalendar')
vcalendarComp.addPropertyWithValue('prodid', 'Nextcloud DAV app')
// Store time zone info
// If possible we use the info from a time zone database
const predefinedTimezoneIcal = getZoneString(timezoneId)
if (predefinedTimezoneIcal) {
const timezoneComp = new ICAL.Component(ICAL.parse(predefinedTimezoneIcal))
vcalendarComp.addSubcomponent(timezoneComp)
} else {
// Fall back to a simple markup
const timezoneComp = new ICAL.Component('vtimezone')
timezoneComp.addPropertyWithValue('tzid', timezoneId)
vcalendarComp.addSubcomponent(timezoneComp)
}
// Store availability info
const vavailabilityComp = new ICAL.Component('vavailability')
// Deduplicate by start and end time
@ -127,7 +152,6 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
const availableComp = new ICAL.Component('available')
// Define DTSTART and DTEND
// TODO: tz? moment.tz(dateTime, timezone).toDate()
const startTimeProp = availableComp.addPropertyWithValue('dtstart', ICAL.Time.fromJSDate(start, false))
startTimeProp.setParameter('tzid', timezoneId)
const endTimeProp = availableComp.addPropertyWithValue('dtend', ICAL.Time.fromJSDate(end, false))
@ -147,7 +171,6 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
return availableComp
}).map(vavailabilityComp.addSubcomponent.bind(vavailabilityComp))
const vcalendarComp = new ICAL.Component('vcalendar')
vcalendarComp.addSubcomponent(vavailabilityComp)
logger.debug('New availability ical created', {
asObject: vcalendarComp,

5
apps/dav/src/views/Availability.vue

@ -121,12 +121,15 @@ export default {
},
async mounted() {
try {
const { slots } = await findScheduleInboxAvailability()
const { slots, timezoneId } = await findScheduleInboxAvailability()
if (slots) {
this.daysOfTheWeek.forEach(day => {
day.slots.push(...slots[day.id])
})
}
if (timezoneId) {
this.timezone = timezoneId
}
console.info('availability loaded', this.daysOfTheWeek)
} catch (e) {
console.error('could not load existing availability', e)

11
package-lock.json

@ -40,6 +40,7 @@
"escape-html": "^1.0.3",
"handlebars": "^4.7.7",
"ical.js": "^1.4.0",
"icalzone": "^0.0.1",
"jquery": "~3.3",
"jquery-migrate": "~3.3",
"jquery-ui": "^1.13.0",
@ -13629,6 +13630,11 @@
"resolved": "https://registry.npmjs.org/ical.js/-/ical.js-1.4.0.tgz",
"integrity": "sha512-ltHZuOFNNjcyEYbzDgjemS7LWIFh2vydJeznxQHUh3dnarbxqOYsWONYteBVAq1MEOHnwXFGN2eskZReHclnrA=="
},
"node_modules/icalzone": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/icalzone/-/icalzone-0.0.1.tgz",
"integrity": "sha512-ln0AM3fMSLLuJijuWuRzwrN0Tg+BG8ADi7ha6slmC7ZqOijagif5I6b4Nl4/vPSXWexnxyrHiEof8VxDOllXVQ=="
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -34560,6 +34566,11 @@
"resolved": "https://registry.npmjs.org/ical.js/-/ical.js-1.4.0.tgz",
"integrity": "sha512-ltHZuOFNNjcyEYbzDgjemS7LWIFh2vydJeznxQHUh3dnarbxqOYsWONYteBVAq1MEOHnwXFGN2eskZReHclnrA=="
},
"icalzone": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/icalzone/-/icalzone-0.0.1.tgz",
"integrity": "sha512-ln0AM3fMSLLuJijuWuRzwrN0Tg+BG8ADi7ha6slmC7ZqOijagif5I6b4Nl4/vPSXWexnxyrHiEof8VxDOllXVQ=="
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",

1
package.json

@ -56,6 +56,7 @@
"escape-html": "^1.0.3",
"handlebars": "^4.7.7",
"ical.js": "^1.4.0",
"icalzone": "^0.0.1",
"jquery": "~3.3",
"jquery-migrate": "~3.3",
"jquery-ui": "^1.13.0",

Loading…
Cancel
Save