Skip to content

Commit

Permalink
feat: add organizer selection
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
SebastianKrupinski authored and st3iny committed Aug 28, 2024
1 parent 7b55dd5 commit cbfbda2
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 4 deletions.
82 changes: 79 additions & 3 deletions src/components/Editor/Invitees/InviteesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
@add-attendee="addAttendee" />
<OrganizerListItem v-if="hasOrganizer"
:is-read-only="isReadOnly"
:organizer="calendarObjectInstance.organizer" />
:is-shared-with-me="isSharedWithMe"
:organizer="calendarObjectInstance.organizer"
:organizer-selection="organizerSelection"
@change-organizer="changeOrganizer" />
<InviteesListItem v-for="invitee in limitedInviteesWithoutOrganizer"
:key="invitee.email"
:attendee="invitee"
Expand Down Expand Up @@ -81,6 +84,7 @@ import {
import { organizerDisplayName, removeMailtoPrefix } from '../../../utils/attendee.js'
import AccountMultipleIcon from 'vue-material-design-icons/AccountMultiple.vue'
import usePrincipalsStore from '../../../store/principals.js'
import useCalendarsStore from '../../../store/calendars.js'
import useCalendarObjectInstanceStore from '../../../store/calendarObjectInstance.js'
import useSettingsStore from '../../../store/settings.js'
import { mapStores, mapState } from 'pinia'
Expand All @@ -102,6 +106,14 @@ export default {
type: Boolean,
required: true,
},
isSharedWithMe: {
type: Boolean,

Check warning on line 110 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L110

Added line #L110 was not covered by tests
required: true,
},
calendar: {
type: Object,
required: true,

Check warning on line 115 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L115

Added line #L115 was not covered by tests
},
calendarObjectInstance: {
type: Object,
required: true,
Expand Down Expand Up @@ -135,7 +147,7 @@ export default {
}
},
computed: {
...mapStores(usePrincipalsStore, useCalendarObjectInstanceStore),
...mapStores(usePrincipalsStore, useCalendarsStore, useCalendarObjectInstanceStore),

Check warning on line 150 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L150

Added line #L150 was not covered by tests
...mapState(useSettingsStore, ['talkEnabled']),
noInviteesMessage() {
return this.$t('calendar', 'No attendees yet')
Expand Down Expand Up @@ -214,10 +226,29 @@ export default {
hasOrganizer() {
return this.calendarObjectInstance.organizer !== null
},
organizerDisplayName() {
return organizerDisplayName(this.calendarObjectInstance.organizer)
},
organizerSelection() {
const organizers = []
const owner = this.principalsStore.getPrincipalByUrl(this.calendar.owner)
const principal = this.principalsStore.getCurrentUserPrincipal
if (owner) {

Check warning on line 236 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L236

Added line #L236 was not covered by tests
organizers.push({
id: owner.id,

Check warning on line 238 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L238

Added line #L238 was not covered by tests
label: owner.displayname,
address: owner.emailAddress

Check warning on line 240 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L240

Added line #L240 was not covered by tests
})
}
if (principal && owner.id !== principal.id) {
organizers.push({
id: principal.id,

Check warning on line 245 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L245

Added line #L245 was not covered by tests
label: principal.displayname,
address: principal.emailAddress
})
}
return organizers
},
isListEmpty() {
return !this.calendarObjectInstance.organizer && this.invitees.length === 0
},
Expand Down Expand Up @@ -268,8 +299,53 @@ export default {
.length,
})
},
selectedOrganizer() {
let organizer = null

Check warning on line 303 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L303

Added line #L303 was not covered by tests
if (this.calendarObjectInstance.organizer) {
const user = this.calendarObjectInstance.organizer
organizer = {
label: user.commonName,

Check warning on line 307 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L307

Added line #L307 was not covered by tests
address: removeMailtoPrefix(user.uri)
}
} else if (this.principalsStore.getCurrentUserPrincipal) {

Check warning on line 310 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L309-L310

Added lines #L309 - L310 were not covered by tests
const user = this.principalsStore.getCurrentUserPrincipal
organizer = {
label: user.displayname,

Check warning on line 313 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L312-L313

Added lines #L312 - L313 were not covered by tests
address: user.emailAddress
}
}
return organizer

Check warning on line 317 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L315-L317

Added lines #L315 - L317 were not covered by tests
},
},
methods: {
changeOrganizer({ id, address, label }, attend) {

Check warning on line 321 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L321

Added line #L321 was not covered by tests
// retrieve current organizer
const current = this.selectedOrganizer
// remove new organizer from attendees
this.calendarObjectInstance.attendees.forEach(function(attendee) {

Check warning on line 325 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L324-L325

Added lines #L324 - L325 were not covered by tests
if (removeMailtoPrefix(attendee.uri) === address || removeMailtoPrefix(attendee.uri) === current.address) {
this.removeAttendee(attendee)
}
}, this)
// determine if current organizer needs to be converted to a attendee
if (attend === true) {

Check warning on line 331 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L331

Added line #L331 was not covered by tests
this.addAttendee({
commonName: current.label,
email: current.address,
calendarUserType: 'INDIVIDUAL',
language: null,

Check warning on line 336 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L335-L336

Added lines #L335 - L336 were not covered by tests
timezoneId: null,
member: null,

Check warning on line 338 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L338

Added line #L338 was not covered by tests
})
}
// set new organizer
this.calendarObjectInstanceStore.setOrganizer({
calendarObjectInstance: this.calendarObjectInstance,

Check warning on line 343 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L342-L343

Added lines #L342 - L343 were not covered by tests
commonName: label,
email: address,
})
this.recentAttendees.push(address)
},

Check warning on line 348 in src/components/Editor/Invitees/InviteesList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/InviteesList.vue#L348

Added line #L348 was not covered by tests
addAttendee({ commonName, email, calendarUserType, language, timezoneId, member }) {
this.calendarObjectInstanceStore.addAttendee({
calendarObjectInstance: this.calendarObjectInstance,
Expand Down
49 changes: 49 additions & 0 deletions src/components/Editor/Invitees/OrganizerListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,65 @@
<div class="invitees-list-item__organizer-hint">
{{ $t('calendar', '(organizer)') }}
</div>
<div class="invitees-list-item__actions">
<NcActions v-if="!isReadOnly && isSharedWithMe">
<template v-for="person in organizerSelection">
<NcActionButton v-if="!selectedOrganizer(person.address)"
:key="person.address + '-1'"
:closeAfterClick = "true"
@click="changeOrganizer(person, false)">
<template #icon>
<Crown :size="20" />
</template>
{{ $t('calendar', 'Make {label} the organizer', {label: person.label}) }}
</NcActionButton>
<NcActionButton v-if="!selectedOrganizer(person.address)"
:key="person.address + '-2'"
:closeAfterClick = "true"
@click="changeOrganizer(person, true)">
<template #icon>

Check warning on line 37 in src/components/Editor/Invitees/OrganizerListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/OrganizerListItem.vue#L36-L37

Added lines #L36 - L37 were not covered by tests
<Crown :size="20" />
</template>
{{ $t('calendar', 'Make {label} the organizer and attend', {label: person.label}) }}
</NcActionButton>
</template>
</NcActions>
</div>

Check warning on line 44 in src/components/Editor/Invitees/OrganizerListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/OrganizerListItem.vue#L44

Added line #L44 was not covered by tests
</div>
</template>

<script>
import AvatarParticipationStatus from '../AvatarParticipationStatus.vue'
import Crown from 'vue-material-design-icons/Crown.vue'
import { removeMailtoPrefix } from '../../../utils/attendee.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'

Check warning on line 53 in src/components/Editor/Invitees/OrganizerListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/OrganizerListItem.vue#L53

Added line #L53 was not covered by tests
export default {
name: 'OrganizerListItem',
components: {
AvatarParticipationStatus,
Crown,
NcActions,
NcActionButton,
},
props: {
organizer: {
type: Object,
required: true,
},
organizerSelection: {
type: Array,

Check warning on line 69 in src/components/Editor/Invitees/OrganizerListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/OrganizerListItem.vue#L68-L69

Added lines #L68 - L69 were not covered by tests
required: true,
},
isReadOnly: {
type: Boolean,
required: true,
},
isSharedWithMe: {
type: Boolean,

Check warning on line 77 in src/components/Editor/Invitees/OrganizerListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/OrganizerListItem.vue#L76-L77

Added lines #L76 - L77 were not covered by tests
required: true,
},
},
computed: {
/**
Expand Down Expand Up @@ -71,6 +109,17 @@ export default {
return false
},
},
methods: {

Check warning on line 112 in src/components/Editor/Invitees/OrganizerListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/OrganizerListItem.vue#L112

Added line #L112 was not covered by tests
selectedOrganizer(address) {
if (removeMailtoPrefix(this.organizer.uri) === address) {
return true
}
return false
},
changeOrganizer(person, attend) {

Check warning on line 119 in src/components/Editor/Invitees/OrganizerListItem.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Invitees/OrganizerListItem.vue#L118-L119

Added lines #L118 - L119 were not covered by tests
this.$emit('change-organizer', person, attend)
},
},
}
</script>
<style lang="scss" scoped>
Expand Down
12 changes: 12 additions & 0 deletions src/mixins/EditorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ export default {

return calendar.readOnly
},
isSharedWithMe() {

Check warning on line 199 in src/mixins/EditorMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/EditorMixin.js#L199

Added line #L199 was not covered by tests
if (!this.calendarObject) {
return true

Check warning on line 201 in src/mixins/EditorMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/EditorMixin.js#L201

Added line #L201 was not covered by tests
}

const calendar = this.calendarsStore.getCalendarById(this.calendarObject.calendarId)

Check warning on line 204 in src/mixins/EditorMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/EditorMixin.js#L204

Added line #L204 was not covered by tests
if (!calendar) {
return true

Check warning on line 206 in src/mixins/EditorMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/EditorMixin.js#L206

Added line #L206 was not covered by tests
}

return calendar.isSharedWithMe

Check warning on line 209 in src/mixins/EditorMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/EditorMixin.js#L209

Added line #L209 was not covered by tests
},
/**
* Returns whether the user is an attendee of the event
*
Expand Down
4 changes: 3 additions & 1 deletion src/views/EditSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,10 @@
</template>
<div class="app-sidebar-tab__content">
<InviteesList v-if="!isLoading"
:calendar="selectedCalendar"
:calendar-object-instance="calendarObjectInstance"
:is-read-only="isReadOnly"
:is-read-only="isReadOnlyOrViewing"
:is-shared-with-me="isSharedWithMe"
:show-header="false"
@update-dates="updateDates" />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/views/EditSimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
:show-header="true"
:is-read-only="isReadOnlyOrViewing"
:is-shared-with-me="isSharedWithMe"
:calendar="selectedCalendar"

Check warning on line 128 in src/views/EditSimple.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSimple.vue#L128

Added line #L128 was not covered by tests
:calendar-object-instance="calendarObjectInstance"
:limit="3" />

Expand Down

0 comments on commit cbfbda2

Please sign in to comment.