Skip to content

Commit

Permalink
Merge pull request #6169 from nextcloud/feat/3193/allow-calendarwide-…
Browse files Browse the repository at this point in the history
…freebusy-settings

feat: allow calendar-wide transparency settings
  • Loading branch information
miaulalala authored Jul 23, 2024
2 parents 7e436be + c1a408e commit 566f8ac
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
36 changes: 33 additions & 3 deletions src/components/AppNavigation/EditCalendarModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
:placeholder="$t('calendar', 'Calendar name …')"
@input="calendarNameChanged = true">
</div>

<template v-if="canBeShared">
<NcCheckboxRadioSwitch :checked.sync="isTransparent">
{{ $t('calendar', 'Never show me as busy (set this calendar to transparent)') }}
</NcCheckboxRadioSwitch>
</template>
<template v-if="canBeShared">
<h2 class="edit-calendar-modal__sharing-header">
{{ $t('calendar', 'Share calendar') }}
Expand Down Expand Up @@ -72,7 +76,7 @@
</template>

<script>
import { NcModal, NcColorPicker, NcButton, NcAppNavigationSpacer } from '@nextcloud/vue'
import { NcModal, NcColorPicker, NcButton, NcCheckboxRadioSwitch, NcAppNavigationSpacer } from '@nextcloud/vue'
import PublishCalendar from './EditCalendarModal/PublishCalendar.vue'
import SharingSearch from './EditCalendarModal/SharingSearch.vue'
import ShareItem from './EditCalendarModal/ShareItem.vue'
Expand Down Expand Up @@ -101,11 +105,13 @@ export default {
CheckIcon,
InternalLink,
NcAppNavigationSpacer,
NcCheckboxRadioSwitch,
},
data() {
return {
calendarColor: undefined,
calendarColorChanged: false,
isTransparent: false,
calendarName: undefined,
calendarNameChanged: false,
}
Expand Down Expand Up @@ -164,6 +170,7 @@ export default {
this.calendarColor = calendar.color
this.calendarNameChanged = false
this.calendarColorChanged = false
this.isTransparent = calendar.transparency === 'transparent'
},
},
methods: {
Expand Down Expand Up @@ -192,6 +199,24 @@ export default {
}
},
/**
* Save the calendar transparency.
*/
async saveTransparency() {
try {
await this.calendarsStore.changeCalendarTransparency({
calendar: this.calendar,
transparency: this.isTransparent ? 'transparent' : 'opaque',
})
} catch (error) {
logger.error('Failed to save calendar transparency', {
calendar: this.calendar,
transparency: this.isTransparent ? 'transparent' : 'opaque',
})
throw error
}
},
/**
* Save the calendar name.
*/
Expand Down Expand Up @@ -220,6 +245,7 @@ export default {
if (this.calendarColorChanged) {
await this.saveColor()
}
await this.saveTransparency()
if (this.calendarNameChanged) {
await this.saveName()
}
Expand All @@ -243,7 +269,7 @@ export default {
}
</script>
<style lang="scss" scoped>
<style lang="scss">
.edit-calendar-modal {
padding: 20px;
display: flex;
Expand Down Expand Up @@ -287,6 +313,10 @@ export default {
flex-direction: column;
gap: 5px;
}
.checkbox-content {
margin-left: 25px;
}
}
.app-navigation-spacer {
Expand Down
7 changes: 7 additions & 0 deletions src/models/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const getDefaultCalendarObject = (props = {}) => Object.assign({}, {
calendarObjects: [],
// Time-ranges that have already been fetched for this calendar
fetchedTimeRanges: [],
// Scheduling transparency
transparency: 'opaque',
}, props)

/**
Expand Down Expand Up @@ -86,6 +88,10 @@ const mapDavCollectionToCalendar = (calendar, currentUserPrincipal) => {
const url = calendar.url
const publishURL = calendar.publishURL || null
const timezone = calendar.timezone || null
// If this property is not present on a calendar collection,
// then the default value CALDAV:opaque MUST be assumed.
// https://datatracker.ietf.org/doc/html/rfc6638#section-9.1
const transparency = calendar.transparency || 'opaque'

let isSharedWithMe = false
if (!currentUserPrincipal) {
Expand Down Expand Up @@ -140,6 +146,7 @@ const mapDavCollectionToCalendar = (calendar, currentUserPrincipal) => {
canBePublished,
shares,
timezone,
transparency,
dav: calendar,
})
}
Expand Down
19 changes: 19 additions & 0 deletions src/store/calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,25 @@ export default defineStore('calendars', {
this.calendarsById[calendar.id].color = newColor
},

/**
* Change a calendars transparency
*
* @param {object} data destructuring object
* @param {object} data.calendar the calendar to modify
* @param {string} data.transparency the new transparency
* @return {Promise}
*/
async changeCalendarTransparency({ calendar, transparency }) {
if (calendar.dav.transparency === transparency) {
return
}

calendar.dav.transparency = transparency

await calendar.dav.update()
this.calendarsById[calendar.id].transparency = transparency
},

/**
* Share calendar with User or Group
*
Expand Down
21 changes: 18 additions & 3 deletions tests/javascript/unit/models/calendar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
canBePublished: false,
dav: false,
calendarObjects: [],
fetchedTimeRanges: []
fetchedTimeRanges: [],
transparency: 'opaque',
})
})

Expand Down Expand Up @@ -67,7 +68,8 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
canBePublished: false,
dav: false,
calendarObjects: [],
fetchedTimeRanges: []
fetchedTimeRanges: [],
transparency: 'opaque',
})
})

Expand All @@ -85,6 +87,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
publishURL: undefined,
enabled: true,
timezone: 'BEGIN:VCALENDAR...END:VCALENDAR',
transparency: 'opaque',
}

expect(mapDavCollectionToCalendar(cdavObject, {
Expand All @@ -107,6 +110,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: 'BEGIN:VCALENDAR...END:VCALENDAR',
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand All @@ -129,7 +133,8 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
order: undefined,
publishURL: undefined,
timezone: 'BEGIN:VCALENDAR...END:VCALENDAR',
enabled: false
transparency: 'transparent',
enabled: false,
}

expect(mapDavCollectionToCalendar(cdavObject, {
Expand All @@ -152,6 +157,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: 'BEGIN:VCALENDAR...END:VCALENDAR',
transparency: 'transparent',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -196,6 +202,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -240,6 +247,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: true,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -284,6 +292,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -328,6 +337,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -372,6 +382,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -416,6 +427,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -516,6 +528,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -632,6 +645,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: true,
timezone: null,
transparency: 'opaque',
url: '/foo/bar',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down Expand Up @@ -677,6 +691,7 @@ describe('Test suite: Calendar model (models/calendar.js)', () => {
supportsTasks: false,
isSharedWithMe: false,
timezone: 'BEGIN:VCALENDAR...END:VCALENDAR',
transparency: 'opaque',
url: '/remote.php/dav/calendars/admin/personal/',
calendarObjects: [],
fetchedTimeRanges: [],
Expand Down

0 comments on commit 566f8ac

Please sign in to comment.