Skip to content

Commit

Permalink
fixup! feat: add availability action to the contacts menu
Browse files Browse the repository at this point in the history
  • Loading branch information
st3iny committed Nov 27, 2024
1 parent 4e99f03 commit d35511b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/Editor/FreeBusy/FreeBusy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<template>
<NcDialog size="large"
:name="dialogName"
:name="dialogName || $t('calendar', 'Availability of attendees, resources and rooms')"
@closing="$emit('close')">
<div class="modal__content modal--scheduler">
<div v-if="loadingIndicator" class="loading-indicator">
Expand Down Expand Up @@ -210,7 +210,7 @@ export default {
},
dialogName: {

Check warning on line 211 in src/components/Editor/FreeBusy/FreeBusy.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Prop 'dialogName' requires default value to be set
type: String,
default: () => $t('calendar', 'Availability of attendees, resources and rooms'),
required: false,
},
showDoneButton: {
type: Boolean,
Expand Down
42 changes: 33 additions & 9 deletions src/views/ContactsMenuAvailability.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@
:end-date="endDate"
:organizer="organizer"
:attendees="attendees"
@close="close"
/>
@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'

Expand All @@ -45,12 +49,16 @@ export default {
},
},
data() {
const initialAttendee = AttendeeProperty.fromNameAndEMail(this.userId, this.userEmail)
const attendees = [mapAttendeePropertyToAttendeeObject(initialAttendee)]

Check warning on line 53 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L47-L53

Added lines #L47 - L53 were not covered by tests

return {

Check warning on line 55 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L55

Added line #L55 was not covered by tests
initialized: false,
attendees,

Check warning on line 57 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L57

Added line #L57 was not covered by tests
}
},

Check warning on line 59 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L59

Added line #L59 was not covered by tests
computed: {
...mapStores(usePrincipalsStore),
...mapStores(usePrincipalsStore, useSettingsStore),
dialogName() {
return t('calendar', 'Availability of {displayName}', {
displayName: this.userDisplayName,
Expand All @@ -77,20 +85,36 @@ export default {
true,

Check warning on line 85 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L85

Added line #L85 was not covered by tests
)
},
attendees() {
const attendee = AttendeeProperty.fromNameAndEMail(this.userId, this.userEmail, false)
return [mapAttendeePropertyToAttendeeObject(attendee)]
},
},
async created() {
// Initialize CalDAV service and fetch current user principal
this.initSettings()
await initializeClientForUserView()

Check warning on line 91 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L91

Added line #L91 was not covered by tests
await this.principalsStore.fetchCurrentUserPrincipal()
getTimezoneManager()
await this.loadMomentLocale()
this.initialized = true

Check warning on line 95 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L95

Added line #L95 was not covered by tests
},
methods: {
initSettings() {
this.settingsStore.loadSettingsFromServer({
timezone: 'automatic',

Check warning on line 100 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L100

Added line #L100 was not covered by tests
})
this.settingsStore.initializeCalendarJsConfig()
},

Check warning on line 103 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L102-L103

Added lines #L102 - L103 were not covered by tests
async loadMomentLocale() {
const locale = await loadMomentLocalization()
this.settingsStore.setMomentLocale({ locale })
},
addAttendee({ commonName, email }) {
this.attendees.push(mapAttendeePropertyToAttendeeObject(
AttendeeProperty.fromNameAndEMail(commonName, email)

Check warning on line 110 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L108-L110

Added lines #L108 - L110 were not covered by tests
))
},

Check warning on line 112 in src/views/ContactsMenuAvailability.vue

View check run for this annotation

Codecov / codecov/patch

src/views/ContactsMenuAvailability.vue#L112

Added line #L112 was not covered by tests
removeAttendee({ email }) {
this.attendees = this.attendees.filter((att) => att.uri !== email)
},
close() {
this.$destroy();
this.$destroy()
},
},
}
Expand Down

0 comments on commit d35511b

Please sign in to comment.