feat: implement resources and rooms overview

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
This commit is contained in:
Richard Steinmetz 2024-04-26 13:27:59 +02:00
parent afa3de9885
commit 78c37f1d88
No known key found for this signature in database
GPG Key ID: 27137D9E7D273FB2
3 changed files with 67 additions and 0 deletions

View File

@ -2,6 +2,7 @@
* @copyright Copyright (c) 2020 Georg Ehrke
*
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license AGPL-3.0-or-later
*
@ -265,6 +266,17 @@ const findPrincipalByUrl = async (url) => {
return getClient().findPrincipal(url)
}
/**
* Finds all principals in a collection at the given URL
*
* @param {string} url The URL of the principal collection
* @param {object} options Passed to cdav-library/Principal::getPropFindList()
* @return {Promise<Principal[]>}
*/
const findPrincipalsInCollection = async (url, options = {}) => {
return getClient().findPrincipalsInCollection(url, options)
}
export {
initializeClientForUserView,
initializeClientForPublicView,
@ -281,4 +293,5 @@ export {
principalPropertySearchByDisplaynameOrEmail,
advancedPrincipalPropertySearch,
findPrincipalByUrl,
findPrincipalsInCollection,
}

View File

@ -2,6 +2,7 @@
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license AGPL-3.0-or-later
*
@ -23,12 +24,14 @@ import Vue from 'vue'
import {
findPrincipalByUrl,
getCurrentUserPrincipal,
findPrincipalsInCollection,
} from '../services/caldavService.js'
import logger from '../utils/logger.js'
import {
getDefaultPrincipalObject,
mapDavToPrincipal,
} from '../models/principal.js'
import { generateRemoteUrl } from '@nextcloud/router'
const state = {
principals: [],
@ -117,6 +120,22 @@ const getters = {
* @return {string|undefined}
*/
getCurrentUserPrincipalEmail: (state) => state.principalsById[state.currentUserPrincipal]?.emailAddress,
/**
* Gets all room principals
*
* @param {object} state the store data
* @return {object[]}
*/
getRoomPrincipals: (state) => state.principals.filter((principal) => principal.isCalendarRoom),
/**
* Gets all resource principals
*
* @param {object} state the store data
* @return {object[]}
*/
getResourcePrincipals: (state) => state.principals.filter((principal) => principal.isCalendarResource),
}
const actions = {
@ -145,6 +164,35 @@ const actions = {
})
},
/**
* Fetches all principals of all rooms and resources from the DAV server and commits it to the state
*
* @param {object} context The vuex context
* @return {Promise<void>}
*/
async fetchRoomAndResourcePrincipals(context) {
const options = {
enableCalDAVResourceBooking: true,
}
const principalCollections = await Promise.all([
findPrincipalsInCollection(generateRemoteUrl('dav/principals/calendar-rooms/'), options),
findPrincipalsInCollection(generateRemoteUrl('dav/principals/calendar-resources/'), options),
])
for (const principals of principalCollections) {
if (!principals) {
// TODO - handle error
continue
}
logger.debug('Fetched principals', { principals })
for (const principal of principals) {
context.commit('addPrincipal', {
principal: mapDavToPrincipal(principal),
})
}
}
},
/**
* Fetches the current-user-principal
*

View File

@ -335,6 +335,12 @@ export default {
}
await this.loadMomentLocale()
await this.$store.dispatch('fetchRoomAndResourcePrincipals')
logger.debug('Fetched rooms and resources', {
rooms: this.$store.getters.getRoomPrincipals,
resources: this.$store.getters.getResourcePrincipals,
})
},
methods: {
/**