Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow calendar-wide transparency settings #6169

Merged
merged 1 commit into from
Jul 23, 2024
Merged
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
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>

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

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L31

Added line #L31 was not covered by tests
<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 @@
CheckIcon,
InternalLink,
NcAppNavigationSpacer,
NcCheckboxRadioSwitch,

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

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L108

Added line #L108 was not covered by tests
},
data() {
return {
calendarColor: undefined,
calendarColorChanged: false,
isTransparent: false,

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

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L114

Added line #L114 was not covered by tests
calendarName: undefined,
calendarNameChanged: false,
}
Expand Down Expand Up @@ -164,6 +170,7 @@
this.calendarColor = calendar.color
this.calendarNameChanged = false
this.calendarColorChanged = false
this.isTransparent = calendar.transparency === 'transparent'
GVodyanov marked this conversation as resolved.
Show resolved Hide resolved
},
},
methods: {
Expand Down Expand Up @@ -192,6 +199,24 @@
}
},

/**
* 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

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

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/EditCalendarModal.vue#L215-L216

Added lines #L215 - L216 were not covered by tests
}
},

/**
* Save the calendar name.
*/
Expand Down Expand Up @@ -220,6 +245,7 @@
if (this.calendarColorChanged) {
await this.saveColor()
}
await this.saveTransparency()
GVodyanov marked this conversation as resolved.
Show resolved Hide resolved
if (this.calendarNameChanged) {
await this.saveName()
}
Expand All @@ -243,7 +269,7 @@
}
</script>

<style lang="scss" scoped>
<style lang="scss">
.edit-calendar-modal {
padding: 20px;
display: flex;
Expand Down Expand Up @@ -287,6 +313,10 @@
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 @@
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 }) {

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

View check run for this annotation

Codecov / codecov/patch

src/store/calendars.js#L548

Added line #L548 was not covered by tests
if (calendar.dav.transparency === transparency) {
return

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

View check run for this annotation

Codecov / codecov/patch

src/store/calendars.js#L550

Added line #L550 was not covered by tests
}

calendar.dav.transparency = transparency

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

View check run for this annotation

Codecov / codecov/patch

src/store/calendars.js#L553

Added line #L553 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

src/store/calendars.js#L555-L556

Added lines #L555 - L556 were not covered by tests
},

/**
* 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
Loading