-
Notifications
You must be signed in to change notification settings - Fork 290
feat: add availability action to the contacts menu #6502
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import 'core-js/stable/index.js' | ||
|
|
||
| import '../css/calendar.scss' | ||
|
|
||
| import { getRequestToken } from '@nextcloud/auth' | ||
| import { linkTo } from '@nextcloud/router' | ||
| import { translate as t } from '@nextcloud/l10n' | ||
| import { registerContactsMenuAction } from '@nextcloud/vue' | ||
| import CalendarBlankSvg from '@mdi/svg/svg/calendar-blank.svg' | ||
|
|
||
| // CSP config for webpack dynamic chunk loading | ||
| // eslint-disable-next-line | ||
| __webpack_nonce__ = btoa(getRequestToken()) | ||
|
|
||
| // Correct the root of the app for chunk loading | ||
| // OC.linkTo matches the apps folders | ||
| // OC.generateUrl ensure the index.php (or not) | ||
| // We do not want the index.php since we're loading files | ||
| // eslint-disable-next-line | ||
| __webpack_public_path__ = linkTo('calendar', 'js/') | ||
|
|
||
| // Decode calendar icon (inline data url -> raw svg) | ||
| const CalendarBlankSvgRaw = atob(CalendarBlankSvg.split(',')[1]) | ||
|
|
||
| registerContactsMenuAction({ | ||
| id: 'calendar-availability', | ||
| displayName: () => t('calendar', 'Show availability'), | ||
| iconSvg: () => CalendarBlankSvgRaw, | ||
| enabled: (entry) => entry.isUser, | ||
| callback: async (args) => { | ||
| const { default: Vue } = await import('vue') | ||
| const { default: ContactsMenuAvailability } = await import('./views/ContactsMenuAvailability.vue') | ||
| const { default: ClickOutside } = await import('vue-click-outside') | ||
| const { default: VTooltip } = await import('v-tooltip') | ||
| const { default: VueShortKey } = await import('vue-shortkey') | ||
| const { createPinia, PiniaVuePlugin } = await import('pinia') | ||
| const { translatePlural } = await import('@nextcloud/l10n') | ||
|
|
||
| Vue.use(PiniaVuePlugin) | ||
| const pinia = createPinia() | ||
|
|
||
| // Register global components | ||
| Vue.directive('ClickOutside', ClickOutside) | ||
| Vue.use(VTooltip) | ||
| Vue.use(VueShortKey, { prevent: ['input', 'textarea'] }) | ||
|
|
||
| Vue.prototype.$t = t | ||
| Vue.prototype.$n = translatePlural | ||
|
|
||
| // The nextcloud-vue package does currently rely on t and n | ||
| Vue.prototype.t = t | ||
| Vue.prototype.n = translatePlural | ||
|
|
||
| // Append container element to the body to mount the vm at | ||
| const el = document.createElement('div') | ||
| document.body.appendChild(el) | ||
|
|
||
| const View = Vue.extend(ContactsMenuAvailability) | ||
| const vm = new View({ | ||
| propsData: { | ||
| userId: args.uid, | ||
| userDisplayName: args.fullName, | ||
| userEmail: args.emailAddresses[0], | ||
| }, | ||
| pinia, | ||
| }) | ||
| vm.$mount(el) | ||
| }, | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <template> | ||
| <FreeBusy v-if="initialized" | ||
| :dialog-name="dialogName" | ||
| :start-date="startDate" | ||
| :end-date="endDate" | ||
| :organizer="organizer" | ||
| :attendees="attendees" | ||
| :disable-find-time="true" | ||
| @add-attendee="addAttendee" | ||
| @remove-attendee="removeAttendee" | ||
| @close="close" /> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { mapStores } from 'pinia' | ||
| import usePrincipalsStore from '../store/principals.js' | ||
| import useSettingsStore from '../store/settings.js' | ||
| import { | ||
| mapAttendeePropertyToAttendeeObject, | ||
| mapPrincipalObjectToAttendeeObject, | ||
| } from '../models/attendee.js' | ||
| import loadMomentLocalization from '../utils/moment.js' | ||
| import { initializeClientForUserView } from '../services/caldavService.js' | ||
| import getTimezoneManager from '../services/timezoneDataProviderService.js' | ||
| import FreeBusy from '../components/Editor/FreeBusy/FreeBusy.vue' | ||
| import { AttendeeProperty } from '@nextcloud/calendar-js' | ||
|
|
||
| export default { | ||
| name: 'ContactsMenuAvailability', | ||
| components: { | ||
| FreeBusy, | ||
| }, | ||
| props: { | ||
| userId: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| userDisplayName: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| userEmail: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| }, | ||
| data() { | ||
| const initialAttendee = AttendeeProperty.fromNameAndEMail(this.userId, this.userEmail) | ||
| const attendees = [mapAttendeePropertyToAttendeeObject(initialAttendee)] | ||
|
|
||
| return { | ||
| initialized: false, | ||
| attendees, | ||
| } | ||
| }, | ||
| computed: { | ||
| ...mapStores(usePrincipalsStore, useSettingsStore), | ||
| dialogName() { | ||
| return t('calendar', 'Availability of {displayName}', { | ||
| displayName: this.userDisplayName, | ||
| }) | ||
| }, | ||
| startDate() { | ||
| return new Date() | ||
| }, | ||
| endDate() { | ||
| // Let's assign a slot of one hour as a default for now | ||
| const date = new Date(this.startDate) | ||
| date.setHours(date.getHours() + 1) | ||
| return date | ||
| }, | ||
| organizer() { | ||
| if (!this.principalsStore.getCurrentUserPrincipal) { | ||
| throw new Error('No principal available for current user') | ||
| } | ||
|
|
||
| return mapPrincipalObjectToAttendeeObject( | ||
| this.principalsStore.getCurrentUserPrincipal, | ||
| true, | ||
| ) | ||
| }, | ||
| }, | ||
| async created() { | ||
| this.initSettings() | ||
| await initializeClientForUserView() | ||
| await this.principalsStore.fetchCurrentUserPrincipal() | ||
| getTimezoneManager() | ||
| await this.loadMomentLocale() | ||
| this.initialized = true | ||
| }, | ||
| methods: { | ||
| initSettings() { | ||
| this.settingsStore.loadSettingsFromServer({ | ||
| timezone: 'automatic', | ||
| }) | ||
| this.settingsStore.initializeCalendarJsConfig() | ||
| }, | ||
| async loadMomentLocale() { | ||
| const locale = await loadMomentLocalization() | ||
| this.settingsStore.setMomentLocale({ locale }) | ||
| }, | ||
| addAttendee({ commonName, email }) { | ||
| this.attendees.push(mapAttendeePropertyToAttendeeObject( | ||
| AttendeeProperty.fromNameAndEMail(commonName, email) | ||
| )) | ||
| }, | ||
| removeAttendee({ email }) { | ||
| this.attendees = this.attendees.filter((att) => att.uri !== email) | ||
| }, | ||
| close() { | ||
| this.$destroy() | ||
| }, | ||
| }, | ||
| } | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped> | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.