refactor: standardize provider
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -31,8 +31,15 @@ const filteredEntities = computed(() => {
|
||||
}
|
||||
const query = searchQuery.value.toLowerCase()
|
||||
return collectionEntities.value.filter(entity => {
|
||||
const name = `${entity.data?.names.family || ''} ${entity.data?.names.given || ''}`.toLowerCase()
|
||||
const email = (entity.data?.emails?.[0]?.address || '').toLowerCase()
|
||||
const props = (entity.properties as any)
|
||||
const given = props?.names?.given || ''
|
||||
const family = props?.names?.family || ''
|
||||
const full = props?.names?.full || ''
|
||||
const label = props?.label || ''
|
||||
const name = `${given} ${family} ${full} ${label}`.toLowerCase()
|
||||
const emails = props?.emails
|
||||
const firstEmail = emails ? Object.values(emails)[0] as any : null
|
||||
const email = (firstEmail?.address || '').toLowerCase()
|
||||
return name.includes(query) || email.includes(query)
|
||||
})
|
||||
})
|
||||
@@ -42,13 +49,17 @@ watch(() => props.selectedCollection, async (newCollection) => {
|
||||
if (newCollection) {
|
||||
loading.value = true
|
||||
try {
|
||||
collectionEntities.value = await entitiesStore.list(
|
||||
newCollection.provider,
|
||||
newCollection.service,
|
||||
newCollection.id
|
||||
);
|
||||
const sources = {
|
||||
[newCollection.provider]: {
|
||||
[String(newCollection.service)]: {
|
||||
[String(newCollection.identifier)]: true as const,
|
||||
},
|
||||
},
|
||||
}
|
||||
const result = await entitiesStore.list(sources)
|
||||
collectionEntities.value = Object.values(result)
|
||||
} catch (error) {
|
||||
console.error('[People] - Failed to load contacts:', error);
|
||||
console.error('[People] - Failed to load contacts:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -56,11 +67,11 @@ watch(() => props.selectedCollection, async (newCollection) => {
|
||||
collectionEntities.value = []
|
||||
loading.value = false
|
||||
}
|
||||
}, { immediate: true });
|
||||
}, { immediate: true })
|
||||
|
||||
// Functions
|
||||
function entityType(entity: EntityObject): string {
|
||||
return entity.data?.type || 'individual'
|
||||
return (entity.properties as any)?.type || 'individual'
|
||||
}
|
||||
|
||||
function entityIcon(entity: EntityObject): string {
|
||||
@@ -76,62 +87,65 @@ function entityIcon(entity: EntityObject): string {
|
||||
}
|
||||
|
||||
function entityPhoto(entity: EntityObject): string | null {
|
||||
// TODO: Implement photo retrieval from entity data
|
||||
// TODO: Implement photo retrieval from entity properties
|
||||
return null
|
||||
}
|
||||
|
||||
function entityInitials(entity: EntityObject): string {
|
||||
const type = entityType(entity)
|
||||
|
||||
const props = (entity.properties as any)
|
||||
|
||||
if (type === 'organization') {
|
||||
const name = (entity.data as any)?.names?.full || entity.data?.label || ''
|
||||
const name = props?.names?.full || props?.label || ''
|
||||
return name.substring(0, 2).toUpperCase() || 'OR'
|
||||
}
|
||||
|
||||
|
||||
if (type === 'group') {
|
||||
const name = (entity.data as any)?.names?.full || entity.data?.label || ''
|
||||
const name = props?.names?.full || props?.label || ''
|
||||
return name.substring(0, 2).toUpperCase() || 'GR'
|
||||
}
|
||||
|
||||
|
||||
// Individual
|
||||
const given = (entity.data as any)?.names?.given
|
||||
const family = (entity.data as any)?.names?.family
|
||||
const given = props?.names?.given
|
||||
const family = props?.names?.family
|
||||
const initials = `${given?.[0] || ''}${family?.[0] || ''}`.toUpperCase()
|
||||
return initials || '?'
|
||||
}
|
||||
|
||||
function entityLabel(entity: EntityObject): string {
|
||||
const type = entityType(entity)
|
||||
|
||||
const props = (entity.properties as any)
|
||||
|
||||
if (type === 'organization' || type === 'group') {
|
||||
return entity.data?.label || (entity.data as any)?.names?.full || 'Unknown'
|
||||
return props?.label || props?.names?.full || 'Unknown'
|
||||
}
|
||||
|
||||
|
||||
// Individual
|
||||
return entity.data?.label || `${(entity.data as any)?.names?.given || ''} ${(entity.data as any)?.names?.family || ''}`.trim() || 'Unknown'
|
||||
const given = props?.names?.given || ''
|
||||
const family = props?.names?.family || ''
|
||||
return props?.label || `${given} ${family}`.trim() || 'Unknown'
|
||||
}
|
||||
|
||||
function entityEmail(entity: EntityObject): string | null {
|
||||
const emails = (entity.data as any)?.emails
|
||||
const emails = (entity.properties as any)?.emails
|
||||
if (!emails) return null
|
||||
const emailEntries = Object.values(emails)
|
||||
const emailEntries = Object.values(emails) as any[]
|
||||
if (emailEntries.length === 0) return null
|
||||
// Sort by priority (assuming lower number = higher priority)
|
||||
emailEntries.sort((a: any, b: any) => (a.priority || 999) - (b.priority || 999))
|
||||
return (emailEntries[0] as any).address || null
|
||||
emailEntries.sort((a, b) => (a.priority || 999) - (b.priority || 999))
|
||||
return emailEntries[0].address || null
|
||||
}
|
||||
|
||||
function entityOrganization(entity: EntityObject): string | null {
|
||||
const organizations = (entity.data as any)?.organizations
|
||||
const organizations = (entity.properties as any)?.organizations
|
||||
if (!organizations || Object.keys(organizations).length === 0) return null
|
||||
const orgEntries = Object.values(organizations)
|
||||
return (orgEntries[0] as any).Label || null
|
||||
const orgEntries = Object.values(organizations) as any[]
|
||||
return orgEntries[0].label || null
|
||||
}
|
||||
|
||||
function entityMemberCount(entity: EntityObject): number | null {
|
||||
const type = entityType(entity)
|
||||
if (type !== 'group') return null
|
||||
const members = (entity.data as any)?.members
|
||||
const members = (entity.properties as any)?.members
|
||||
if (!members) return 0
|
||||
return Object.keys(members).length
|
||||
}
|
||||
@@ -179,8 +193,8 @@ function entityAvatarColor(entity: EntityObject): string {
|
||||
<v-list v-else density="compact" nav>
|
||||
<v-list-item
|
||||
v-for="entity in filteredEntities"
|
||||
:key="entity.id"
|
||||
:value="entity.id"
|
||||
:key="entity.identifier"
|
||||
:value="entity.identifier"
|
||||
@click="$emit('select', entity)">
|
||||
|
||||
<template #prepend>
|
||||
|
||||
Reference in New Issue
Block a user