refactor: use unified manager design
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -64,7 +64,7 @@ const onOpen = async () => {
|
||||
if (props.collection.identifier) {
|
||||
// Edit mode - find the service
|
||||
editingCollectionService.value = services.value.find(s =>
|
||||
s.provider === props.collection!.provider && s.identifier === props.collection!.service
|
||||
`${s.provider}:${s.identifier}` === String(props.collection!.service)
|
||||
) || null
|
||||
} else {
|
||||
// Create mode - use first service that can create
|
||||
@@ -233,7 +233,7 @@ watch(() => props.modelValue, async (newValue) => {
|
||||
<v-card-actions class="justify-space-between align-center">
|
||||
<div>
|
||||
<v-btn
|
||||
v-if="mode === 'edit' && editingCollectionService?.capable('CollectionDestroy')"
|
||||
v-if="mode === 'edit' && editingCollectionService?.capable('CollectionDelete')"
|
||||
color="error"
|
||||
variant="text"
|
||||
@click="onDelete"
|
||||
|
||||
@@ -22,7 +22,15 @@ const emit = defineEmits<{
|
||||
// State
|
||||
const loading = ref(false)
|
||||
const searchQuery = ref('')
|
||||
const collectionEntities = ref<EntityObject[]>([])
|
||||
|
||||
// Entities belonging to the selected collection, sourced live from the manager store
|
||||
const collectionEntities = computed<EntityObject[]>(() => {
|
||||
const collection = props.selectedCollection
|
||||
if (!collection) {
|
||||
return []
|
||||
}
|
||||
return entitiesStore.entitiesForCollection(collection.identifier)
|
||||
})
|
||||
|
||||
// Computed
|
||||
const filteredEntities = computed(() => {
|
||||
@@ -46,25 +54,15 @@ const filteredEntities = computed(() => {
|
||||
|
||||
// Watchers
|
||||
watch(() => props.selectedCollection, async (newCollection) => {
|
||||
if (newCollection) {
|
||||
loading.value = true
|
||||
try {
|
||||
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)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
} else {
|
||||
collectionEntities.value = []
|
||||
if (!newCollection) {
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
await entitiesStore.list([newCollection.identifier])
|
||||
} catch (error) {
|
||||
console.error('[People] - Failed to load contacts:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
@@ -8,8 +8,10 @@ import { GroupObject } from '@PeopleManager/models/group'
|
||||
import type { ServiceObject } from '@PeopleManager/models/service'
|
||||
import { useCollectionsStore } from '@PeopleManager/stores/collectionsStore'
|
||||
import { useEntitiesStore } from '@PeopleManager/stores/entitiesStore'
|
||||
import { useServicesStore } from '@PeopleManager/stores/servicesStore'
|
||||
|
||||
export const usePeopleStore = defineStore('peopleStore', () => {
|
||||
const servicesStore = useServicesStore()
|
||||
const collectionsStore = useCollectionsStore()
|
||||
const entitiesStore = useEntitiesStore()
|
||||
|
||||
@@ -56,15 +58,12 @@ export const usePeopleStore = defineStore('peopleStore', () => {
|
||||
if (collectionEditorMode.value === 'create') {
|
||||
const created = await collectionsStore.create(
|
||||
service.provider,
|
||||
service.identifier || '',
|
||||
null,
|
||||
service.identifier ?? '',
|
||||
collection.properties,
|
||||
)
|
||||
selectedCollection.value = created
|
||||
} else {
|
||||
await collectionsStore.update(
|
||||
collection.provider,
|
||||
collection.service,
|
||||
collection.identifier,
|
||||
collection.properties,
|
||||
)
|
||||
@@ -74,7 +73,7 @@ export const usePeopleStore = defineStore('peopleStore', () => {
|
||||
}
|
||||
|
||||
async function deleteCollection(collection: CollectionObject) {
|
||||
await collectionsStore.delete(collection.provider, collection.service, collection.identifier)
|
||||
await collectionsStore.delete(collection.identifier)
|
||||
|
||||
if (selectedCollection.value?.identifier === collection.identifier) {
|
||||
selectedCollection.value = null
|
||||
@@ -132,8 +131,6 @@ export const usePeopleStore = defineStore('peopleStore', () => {
|
||||
// Create
|
||||
entity.properties.created = new Date()
|
||||
selectedEntity.value = await entitiesStore.create(
|
||||
targetCollection.provider,
|
||||
targetCollection.service,
|
||||
targetCollection.identifier,
|
||||
entity.properties,
|
||||
)
|
||||
@@ -141,9 +138,6 @@ export const usePeopleStore = defineStore('peopleStore', () => {
|
||||
// Update
|
||||
entity.properties.modified = new Date()
|
||||
selectedEntity.value = await entitiesStore.update(
|
||||
targetCollection.provider,
|
||||
targetCollection.service,
|
||||
targetCollection.identifier,
|
||||
entity.identifier,
|
||||
entity.properties,
|
||||
)
|
||||
@@ -162,12 +156,7 @@ export const usePeopleStore = defineStore('peopleStore', () => {
|
||||
throw new Error('[People] - No collection selected, cannot delete entity')
|
||||
}
|
||||
|
||||
await entitiesStore.delete(
|
||||
targetCollection.provider,
|
||||
targetCollection.service,
|
||||
targetCollection.identifier,
|
||||
entity.identifier,
|
||||
)
|
||||
await entitiesStore.delete([entity.identifier])
|
||||
|
||||
closeEntityEditor()
|
||||
}
|
||||
@@ -177,6 +166,7 @@ export const usePeopleStore = defineStore('peopleStore', () => {
|
||||
async function initialize() {
|
||||
loading.value = true
|
||||
try {
|
||||
await servicesStore.list()
|
||||
await collectionsStore.list()
|
||||
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user