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