-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6502 from nextcloud/feat/js-hook-avatar-action
feat: add availability action to the contacts menu
- Loading branch information
Showing
9 changed files
with
245 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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