refactor: standardize provider

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-25 00:17:21 -05:00
parent 3d59a10daa
commit 676254b23d
6 changed files with 369 additions and 270 deletions
+54 -154
View File
@@ -1,12 +1,9 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { computed, onMounted } from 'vue'
import { storeToRefs } from 'pinia'
import { useDisplay } from 'vuetify'
import { useModuleStore } from '@KTXC/stores/moduleStore'
import { useCollectionsStore } from '@PeopleManager/stores/collectionsStore'
import { useEntitiesStore } from '@PeopleManager/stores/entitiesStore'
import { ServiceObject } from '@PeopleManager/models/service';
import { CollectionObject } from '@PeopleManager/models/collection';
import { EntityObject } from '@PeopleManager/models/entity';
import { usePeopleStore } from '@/stores/peopleStore'
import CollectionList from '@/components/CollectionList.vue'
import CollectionEditor from '@/components/CollectionEditor.vue'
import PersonList from '@/components/PersonList.vue'
@@ -15,148 +12,50 @@ import PersonEditor from '@/components/PersonEditor.vue'
// Vuetify display
const display = useDisplay()
// View state
const sidebarVisible = ref(true)
// Check if people manager is available
const moduleStore = useModuleStore()
const isPeopleManagerAvailable = computed(() => {
return moduleStore.has('people_manager') || moduleStore.has('PeopleManager')
})
// Local state for UI selections
const collectionsStore = useCollectionsStore()
const entitiesStore = useEntitiesStore()
const selectedCollection = ref<CollectionObject | null>(null)
const selectedEntity = ref<EntityObject | null>(null)
const entityEditorMode = ref<'edit' | 'view'>('view')
// Store
const peopleStore = usePeopleStore()
// Collection editor state
const showCollectionEditor = ref(false)
const editingCollection = ref<CollectionObject | null>(null)
const collectionEditorMode = ref<'create' | 'edit'>('create')
const CollectionListRef = ref<InstanceType<typeof CollectionList> | null>(null)
const {
sidebarVisible,
loading,
selectedCollection,
selectedEntity,
entityEditorMode,
showCollectionEditor,
editingCollection,
collectionEditorMode,
collections,
} = storeToRefs(peopleStore)
// Handlers
const handleEditorEdit = () => {
console.log('[People] - Editor editing started')
entityEditorMode.value = 'edit'
}
const {
initialize,
selectCollection,
openEditCollection,
openCreateCollection,
selectEntity,
createEntity,
startEditingEntity,
cancelEditingEntity,
closeEntityEditor,
saveEntity,
deleteEntity,
saveCollection,
deleteCollection,
} = peopleStore
const handleEditorCancel = () => {
console.log('[People] - Editor editing cancelled')
entityEditorMode.value = 'view'
}
const handleEditorClose = () => {
console.log('[People] - Editor closed')
selectedEntity.value = null
entityEditorMode.value = 'view'
}
const handleCollectionSelect = (collection: CollectionObject) => {
console.log('[People] - Collection selected', collection)
selectedCollection.value = collection ?? null
selectedEntity.value = null
}
const handleCollectionEdit = (collection: CollectionObject) => {
console.log('[People] - Collection edit', collection)
editingCollection.value = collection
collectionEditorMode.value = 'edit'
showCollectionEditor.value = true
}
const onCollectionFresh = () => {
console.log('[People] - Collection new')
editingCollection.value = collectionsStore.fresh()
collectionEditorMode.value = 'create'
showCollectionEditor.value = true
}
const handleCollectionSave = async (collection: CollectionObject, service: ServiceObject) => {
console.log('[People] - Collection save', collection)
if (collectionEditorMode.value === 'create') {
await handleCollectionCreate(collection, service)
} else {
await handleCollectionModify(collection)
onMounted(async () => {
try {
await initialize()
} catch (error) {
console.error('[People] - Failed to load data from PeopleManager:', error)
}
await CollectionListRef.value?.refresh()
}
const handleCollectionCreate = async (collection: CollectionObject, service: ServiceObject) => {
console.log('[People] - Collection created', collection)
const result = await collectionsStore.create(service, collection)
if (result instanceof CollectionObject) {
selectedCollection.value = result
} else {
selectedCollection.value = null
}
selectedEntity.value = null
}
const handleCollectionModify = async (collection: CollectionObject) => {
console.log('[People] - Collection modified', collection)
await collectionsStore.modify(collection)
}
const handleCollectionDelete = async (collection: CollectionObject) => {
console.log('[People] - Collection deleted', collection)
await collectionsStore.destroy(collection)
selectedCollection.value = null
selectedEntity.value = null
await CollectionListRef.value?.refresh()
}
const handleEntitySelect = (entity: EntityObject) => {
console.log('[People] - Entity selected', entity)
selectedEntity.value = entity
entityEditorMode.value = 'view'
}
const onEntityFresh = (type: string) => {
console.log('[People] - Entity create', type)
selectedEntity.value = entitiesStore.fresh(type)
entityEditorMode.value = 'edit'
}
const handleEntitySave = async (entity: EntityObject, collection?: CollectionObject | null) => {
console.log('[People] - Entity save', entity)
if (!(collection instanceof CollectionObject)) {
collection = selectedCollection.value
}
if (!collection) {
console.warn('[People] - Invalid collection object cannot save entity')
return
}
if (entity.id === null) {
console.log('[People] - Entity create', entity)
entity.data.created = new Date();
selectedEntity.value = await entitiesStore.create(collection, entity)
} else if (entity.id !== null) {
console.log('[People] - Entity modify', entity)
entity.data.modified = new Date();
selectedEntity.value = await entitiesStore.modify(collection, entity)
}
entityEditorMode.value = 'view'
}
const handleEntityDelete = async (entity: EntityObject, collection?: CollectionObject | null) => {
console.log('[People] - Entity deleted', entity)
if (!(collection instanceof CollectionObject)) {
collection = selectedCollection.value
}
if (!collection) {
console.warn('[People] - Invalid collection object cannot delete entity')
return
}
await entitiesStore.destroy(collection, entity)
selectedEntity.value = null
entityEditorMode.value = 'view'
}
})
</script>
<template>
@@ -191,10 +90,11 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
>
<div class="pa-4 d-flex flex-column h-100">
<CollectionList
ref="CollectionListRef"
:collections="collections"
:loading="loading"
:selected-collection="selectedCollection"
@select="handleCollectionSelect"
@edit="handleCollectionEdit"
@select="selectCollection"
@edit="openEditCollection"
/>
<v-divider class="my-2" />
@@ -211,7 +111,7 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
block
class="justify-start"
:disabled="!selectedCollection"
@click="onEntityFresh('individual')"
@click="createEntity('individual')"
>
Individual
</v-btn>
@@ -222,7 +122,7 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
block
class="justify-start"
:disabled="!selectedCollection"
@click="onEntityFresh('organization')"
@click="createEntity('organization')"
>
Organization
</v-btn>
@@ -233,7 +133,7 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
block
class="justify-start"
:disabled="!selectedCollection"
@click="onEntityFresh('group')"
@click="createEntity('group')"
>
Group
</v-btn>
@@ -243,7 +143,7 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
size="small"
block
class="justify-start"
@click="onCollectionFresh"
@click="openCreateCollection"
>
Address Book
</v-btn>
@@ -281,8 +181,8 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
<PersonList
:selected-collection="selectedCollection"
:selected-entity="selectedEntity"
@select="handleEntitySelect"
@fresh="onEntityFresh"
@select="selectEntity"
@fresh="createEntity"
/>
</div>
<div class="people-editor-panel">
@@ -290,11 +190,11 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
:mode="entityEditorMode"
:selected-collection="selectedCollection"
:selected-entity="selectedEntity"
@save="handleEntitySave"
@delete="handleEntityDelete"
@edit="handleEditorEdit"
@cancel="handleEditorCancel"
@close="handleEditorClose"
@save="saveEntity"
@delete="deleteEntity"
@edit="startEditingEntity"
@cancel="cancelEditingEntity"
@close="closeEntityEditor"
/>
</div>
</div>
@@ -306,8 +206,8 @@ const handleEntityDelete = async (entity: EntityObject, collection?: CollectionO
v-model="showCollectionEditor"
:collection="editingCollection"
:mode="collectionEditorMode"
@save="handleCollectionSave"
@delete="handleCollectionDelete"
@save="saveCollection"
@delete="deleteCollection"
/>
</div>
</template>