Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/components/AppNavigation/EditCalendarModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
:placeholder="$t('calendar', 'Calendar name …')">
</div>

<h2>{{ $t('calendar', 'Timezone') }}</h2>
<div class="edit-calendar-modal__timezone">
<NcTimezonePicker v-model="calendarTimezone"
@input="saveTimezone" />
</div>

<template v-if="canBeShared">
<h2 class="edit-calendar-modal__sharing-header">
{{ $t('calendar', 'Share calendar') }}
Expand Down Expand Up @@ -88,9 +94,13 @@
</template>

<script>
import ICAL from 'ical.js'

Check warning on line 97 in src/components/AppNavigation/EditCalendarModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L97

Added line #L97 was not covered by tests
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import NcColorPicker from '@nextcloud/vue/dist/Components/NcColorPicker.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcTimezonePicker from '@nextcloud/vue/dist/Components/NcTimezonePicker.js'
import { TimezoneComponent } from '@nextcloud/calendar-js'
import PublishCalendar from './EditCalendarModal/PublishCalendar.vue'
import SharingSearch from './EditCalendarModal/SharingSearch.vue'
import ShareItem from './EditCalendarModal/ShareItem.vue'
Expand All @@ -110,6 +120,7 @@
NcModal,
NcColorPicker,
NcButton,
NcTimezonePicker,
PublishCalendar,
SharingSearch,
ShareItem,
Expand All @@ -127,6 +138,7 @@
calendarColorChanged: false,
calendarName: undefined,
calendarNameChanged: false,
calendarTimezone: undefined,
}
},
computed: {
Expand Down Expand Up @@ -172,6 +184,23 @@
this.calendarName = this.calendar.displayName
this.calendarColor = this.calendar.color
if (this.calendar.timezone) {
try {
const jCal = ICAL.parse(this.calendar.timezone)
const iCalComp = new ICAL.Component(jCal)

Check warning on line 190 in src/components/AppNavigation/EditCalendarModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L187-L190

Added lines #L187 - L190 were not covered by tests
const tzComp = TimezoneComponent.fromICALJs(iCalComp)
this.calendarTimezone = tzComp.getFirstComponent('VTIMEZONE').getFirstProperty('TZID').value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (non-blocking): Do we need to validate the value? Maybe use calendar-js' TimezoneManager.hasTimezoneForId() before assigning it?

} catch (error) {
logger.error('Could not load calendar timezone', {
error,
calendar: this.calendar,
timezone: this.calendar.timezone,
})
this.calendarTimezone = 'floating'
}

Check warning on line 200 in src/components/AppNavigation/EditCalendarModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L194-L200

Added lines #L194 - L200 were not covered by tests
} else {
this.calendarTimezone = 'floating'
}
},
},
created() {
Expand Down Expand Up @@ -229,6 +258,25 @@
}
},
async saveTimezone() {
this.loading = true
try {
await this.$store.dispatch('setCalendarTimezone', {
calendar: this.calendar,
timezone: this.calendarTimezone,
})
} catch (error) {

Check warning on line 269 in src/components/AppNavigation/EditCalendarModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L261-L269

Added lines #L261 - L269 were not covered by tests
logger.error('Failed to save calendar timezone', {
calendar: this.calendar,
timezone: this.calendarTimezone,
error,
})
} finally {
this.loading = false
}
},

Check warning on line 279 in src/components/AppNavigation/EditCalendarModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L273-L279

Added lines #L273 - L279 were not covered by tests
/**
* Save unsaved changes and close the modal.
*
Expand Down
34 changes: 34 additions & 0 deletions src/store/calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@
state.calendarsById[calendar.id].displayName = newName
},

/**
* Set a calendar's timezone
*
* @param {object} state the store mutations
* @param {object} data destructuring object
* @param {object} data.calendar the calendar to modify
* @param {string} data.timezone the new timezone of the calendar
*/
setCalendarTimezone(state, { calendar, timezone }) {
state.calendarsById[calendar.id].timezone = timezone

Check warning on line 186 in src/store/calendars.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendars.js#L185-L186

Added lines #L185 - L186 were not covered by tests
},

/**
* Changes calendar's color
*
Expand Down Expand Up @@ -868,6 +880,28 @@
context.commit('renameCalendar', { calendar, newName })
},

/**
* Set a calendar's timezone
*
* @param {object} context the store mutations Current context
* @param {object} data destructuring object
* @param {object} data.calendar the calendar to modify
* @param {string} data.timezone the new timezone of the calendar
* @return {Promise}
*/
async setCalendarTimezone(context, { calendar, timezone }) {
let timezoneIcs = null
const timezoneObject = getTimezoneManager().getTimezoneForId(timezone)
if (timezoneObject !== Timezone.utc && timezoneObject !== Timezone.floating) {
const calendar = CalendarComponent.fromEmpty()
calendar.addComponent(TimezoneComponent.fromICALJs(timezoneObject.toICALJs()))
timezoneIcs = calendar.toICS(false)

Check warning on line 898 in src/store/calendars.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendars.js#L892-L898

Added lines #L892 - L898 were not covered by tests
}
calendar.dav.timezone = timezoneIcs
await calendar.dav.update()
context.commit('setCalendarTimezone', { calendar, timezone: timezoneIcs })

Check warning on line 902 in src/store/calendars.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendars.js#L900-L902

Added lines #L900 - L902 were not covered by tests
},

/**
* Change a calendar's color
*
Expand Down