Skip to content

Commit

Permalink
feat:select existing talk roomfor convesations
Browse files Browse the repository at this point in the history
Signed-off-by: greta <[email protected]>
  • Loading branch information
GretaD committed Dec 30, 2024
1 parent 476812e commit 15716e3
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 7 deletions.
113 changes: 113 additions & 0 deletions src/components/Editor/AddTalkModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<template>
<NcModal size="normal"
class="modal"
:name="t('calendar', 'Select a Talk Room')"
@open="fetchTalkConversations">
<div class="modal-content">
<h2>{{ t('calendar', 'Select a talk room from the list') }}</h2>
<ul>
<li v-for="conversation in talkConversations" :key="conversation.id">
<NcButton @click="selectConversation(conversation)">
{{ t('calendar', 'Select') }}
</NcButton>
</li>
</ul>
<h2>{{ t('calendar', 'Create a new talk room') }}</h2>
<NcButton @click="createTalkRoom">
{{ t('calendar', 'Create a new talk room') }}
</NcButton>
</div>

Check warning on line 19 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L18-L19

Added lines #L18 - L19 were not covered by tests
</NcModal>
</template>

<script>
import {
NcButton,
NcModal,
} from '@nextcloud/vue'
import axios from '@nextcloud/axios'

Check warning on line 28 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L26-L28

Added lines #L26 - L28 were not covered by tests
import { createTalkRoom } from '../../services/talkService.js'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { generateOcsUrl } from '@nextcloud/router'

Check warning on line 31 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L31

Added line #L31 was not covered by tests
export default {
name: 'AddTalkModal',
components: {
NcButton,
NcModal,

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

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L34-L37

Added lines #L34 - L37 were not covered by tests
},
props: {
calendarObjectInstance: {
type: Object,

Check warning on line 41 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L39-L41

Added lines #L39 - L41 were not covered by tests
required: true,
},
},
data() {
return {
talkConversations: [],
selectedConversation: null,
creatingTalkRoom: false,

Check warning on line 49 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L45-L49

Added lines #L45 - L49 were not covered by tests
}
},
methods: {
async fetchTalkConversations() {

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

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L53

Added line #L53 was not covered by tests
try {
const response = await axios.get(generateOcsUrl('apps/spreed/api/v1/room'))
this.talkConversations = response.data.ocs.data.filter(conversation =>
conversation.joinable || conversation.is_moderator,
)

Check warning on line 58 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L57-L58

Added lines #L57 - L58 were not covered by tests
} catch (error) {
console.error('Error fetching Talk conversations:', error)

Check warning on line 60 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L60

Added line #L60 was not covered by tests
}
},
selectConversation(conversation) {
this.selectedConversation = conversation
this.applyConversationToEvent(conversation)

Check warning on line 65 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L64-L65

Added lines #L64 - L65 were not covered by tests
this.closeModal()
},
applyConversationToEvent(conversation) {
console.debug('Applying conversation to event:', conversation)
this.$emit('update-event', { talkRoom: conversation })

Check warning on line 70 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L70

Added line #L70 was not covered by tests
},
async createTalkRoom() {
const NEW_LINE = '\r\n'

Check warning on line 73 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L73

Added line #L73 was not covered by tests
try {
this.creatingTalkRoom = true

Check warning on line 75 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L75

Added line #L75 was not covered by tests
const url = await createTalkRoom(
this.calendarObjectInstance.title,
this.calendarObjectInstance.description,
)
// Store in LOCATION property if it's missing/empty. Append to description otherwise.
if ((this.calendarObjectInstance.location ?? '').trim() === '') {
this.calendarObjectInstanceStore.changeLocation({
calendarObjectInstance: this.calendarObjectInstance,

Check warning on line 84 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L81-L84

Added lines #L81 - L84 were not covered by tests
location: url,
})
showSuccess(this.$t('calendar', 'Successfully appended link to talk room to location.'))
} else {
if (!this.calendarObjectInstance.description) {
this.calendarObjectInstanceStore.changeDescription({
calendarObjectInstance: this.calendarObjectInstance,
description: url,
})
} else {
this.calendarObjectInstanceStore.changeDescription({
calendarObjectInstance: this.calendarObjectInstance,
description: this.calendarObjectInstance.description + NEW_LINE + NEW_LINE + url + NEW_LINE,
})
}
showSuccess(this.$t('calendar', 'Successfully appended link to talk room to description.'))
}
} catch (error) {
showError(this.$t('calendar', 'Error creating Talk room'))
} finally {
this.creatingTalkRoom = false

Check warning on line 105 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L104-L105

Added lines #L104 - L105 were not covered by tests
}
},
},
}
</script>
<style scoped>
</style>

Check warning on line 113 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L113

Added line #L113 was not covered by tests
105 changes: 98 additions & 7 deletions src/views/EditSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@
@update-end-time="updateEndTime"
@update-end-timezone="updateEndTimezone"
@toggle-all-day="toggleAllDay" />

<PropertyText class="property-location"
:is-read-only="isReadOnly"
:prop-model="rfcProps.location"
:value="location"
:linkify-links="true"
@update:value="updateLocation" />
<div class="location-container">
<PropertyText class="property-location"
:is-read-only="isReadOnly"
:prop-model="rfcProps.location"
:value="location"
:linkify-links="true"
@update:value="updateLocation" />
<AddTalkModal v-if="isModalOpen"
:conversations="talkConversations"
@close="closeModal" />
<NcButton :disabled="isCreateTalkRoomButtonDisabled"
class="add-talk-button"

Check warning on line 96 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L96

Added line #L96 was not covered by tests
@click="openModal">
{{ t('calendar','Add Talk') }}
</NcButton>

Check warning on line 99 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L99

Added line #L99 was not covered by tests
</div>
<PropertyText class="property-description"
:is-read-only="isReadOnly"
:prop-model="rfcProps.description"
Expand Down Expand Up @@ -314,10 +323,14 @@ import usePrincipalsStore from '../store/principals.js'
import useSettingsStore from '../store/settings.js'
import useCalendarObjectInstanceStore from '../store/calendarObjectInstance.js'
import { mapStores, mapState } from 'pinia'
import AddTalkModal from '../components/Editor/AddTalkModal.vue'
import { createTalkRoom, doesContainTalkLink } from '../services/talkService.js'
import { showError, showSuccess } from '@nextcloud/dialogs'

Check warning on line 328 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L326-L328

Added lines #L326 - L328 were not covered by tests

export default {
name: 'EditSidebar',
components: {
AddTalkModal,
ResourceList,
PropertyColor,
PropertySelectMultiple,
Expand Down Expand Up @@ -361,6 +374,10 @@ export default {
showModalUsers: [],
sharedProgress: 0,
showPreloader: false,
isModalOpen: false,
talkConversations: [],
selectedConversation: null,

Check warning on line 379 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L378-L379

Added lines #L378 - L379 were not covered by tests

}
},
computed: {
Expand Down Expand Up @@ -406,6 +423,21 @@ export default {
currentUser() {
return this.principalsStore.getCurrentUserPrincipal || null
},
isCreateTalkRoomButtonDisabled() {
if (this.creatingTalkRoom) {
return true
}

if (doesContainTalkLink(this.calendarObjectInstance.location)) {
return true
}
return doesContainTalkLink(this.calendarObjectInstance.description)

},

Check warning on line 436 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L436

Added line #L436 was not covered by tests
isCreateTalkRoomButtonVisible() {
return this.talkEnabled
},

Check warning on line 439 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L439

Added line #L439 was not covered by tests

},
mounted() {
window.addEventListener('keydown', this.keyboardCloseEditor)
Expand All @@ -420,6 +452,55 @@ export default {
window.removeEventListener('keydown', this.keyboardDuplicateEvent)
},
methods: {
selectConversation(conversation) {
this.selectedConversation = conversation
this.applyConversationToEvent(conversation)
this.closeModal()
},
openModal() {
this.isModalOpen = true
},

closeModal() {
this.isModalOpen = false
},

async createTalkRoom() {
const NEW_LINE = '\r\n'
try {
this.creatingTalkRoom = true
const url = await createTalkRoom(
this.calendarObjectInstance.title,
this.calendarObjectInstance.description,

Check warning on line 474 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L474

Added line #L474 was not covered by tests
)

// Store in LOCATION property if it's missing/empty. Append to description otherwise.

Check warning on line 477 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L477

Added line #L477 was not covered by tests
if ((this.calendarObjectInstance.location ?? '').trim() === '') {
this.calendarObjectInstanceStore.changeLocation({
calendarObjectInstance: this.calendarObjectInstance,
location: url,
})

Check warning on line 482 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L481-L482

Added lines #L481 - L482 were not covered by tests
showSuccess(this.$t('calendar', 'Successfully appended link to talk room to location.'))
} else {
if (!this.calendarObjectInstance.description) {
this.calendarObjectInstanceStore.changeDescription({
calendarObjectInstance: this.calendarObjectInstance,
description: url,
})
} else {

Check warning on line 490 in src/views/EditSidebar.vue

View check run for this annotation

Codecov / codecov/patch

src/views/EditSidebar.vue#L489-L490

Added lines #L489 - L490 were not covered by tests
this.calendarObjectInstanceStore.changeDescription({
calendarObjectInstance: this.calendarObjectInstance,
description: this.calendarObjectInstance.description + NEW_LINE + NEW_LINE + url + NEW_LINE,
})
}
showSuccess(this.$t('calendar', 'Successfully appended link to talk room to description.'))
}
} catch (error) {
showError(this.$t('calendar', 'Error creating Talk room'))
} finally {
this.creatingTalkRoom = false
}
},
/**
* Update the start and end date of this event
*
Expand Down Expand Up @@ -676,8 +757,18 @@ export default {
height: auto;
border-radius: var(--border-radius);
}
.location-container{
display: flex;
align-items: center;
gap: 4px;
}
.add-talk-button {
flex-shrink: 0;
}
.property-location {
margin-top: 10px;
margin-left: -43px;
flex-grow: 1;
}
.property-description {
margin-bottom: 10px;
Expand Down

0 comments on commit 15716e3

Please sign in to comment.