Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/automatic-groups/AutomaticGroupsAdmin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
description="Überwachung und Verwaltung aller automatischen Gruppen"
searchable
search-placeholder="Gruppen durchsuchen..."
:search-fields="['name', 'groupTypeId']"
:search-fields="['name', 'groupTypeName']"
default-sort-field="id"
loading-text="Lade automatische Gruppen..."
empty-text="Keine automatischen Gruppen gefunden."
Expand Down Expand Up @@ -83,7 +83,7 @@ const adminTableRef = ref()
// Table configuration
const tableColumns: TableColumn[] = [
{ key: 'id', label: 'Gruppen-ID', sortable: true, resizable: true, width: 100 },
{ key: 'groupTypeId', label: 'Gruppentyp', sortable: true, resizable: true, width: 120 },
{ key: 'groupTypeName', label: 'Gruppentyp', sortable: true, resizable: true, width: 120 },
{
key: 'name',
label: 'Name',
Expand Down
77 changes: 60 additions & 17 deletions src/composables/useAutomaticGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { churchtoolsClient } from '@churchtools/churchtools-client'
export interface AutomaticGroup {
id: number
name: string
groupTypeId?: string
groupTypeId: number
groupTypeName: string
dynamicGroupStatus: string
lastExecution: string | null
executionStatus: 'success' | 'error' | 'running' | 'pending' | 'unknown'
Expand All @@ -29,6 +30,36 @@ function determineExecutionStatus(group: any): AutomaticGroup['executionStatus']
}

async function fetchAutomaticGroups(): Promise<AutomaticGroup[]> {
// First, fetch all group types to create a mapping
let groupTypeMap = new Map<number, string>()

try {
const groupTypesResponse = await churchtoolsClient.get('/group/grouptypes')

// Handle different response structures
let groupTypes: any[] = []
if (
groupTypesResponse &&
(groupTypesResponse as any).data &&
Array.isArray((groupTypesResponse as any).data)
) {
groupTypes = (groupTypesResponse as any).data
} else if (Array.isArray(groupTypesResponse)) {
groupTypes = groupTypesResponse
} else {
console.warn('Unexpected group types response structure:', groupTypesResponse)
}

groupTypes.forEach((groupType: any) => {
if (groupType.id && groupType.name) {
groupTypeMap.set(groupType.id, groupType.name)
}
})
} catch (error) {
console.warn('Failed to fetch group types:', error)
// Continue without group type mapping
}

let allGroups: any[] = []
let page = 1
const limit = 100
Expand All @@ -37,16 +68,16 @@ async function fetchAutomaticGroups(): Promise<AutomaticGroup[]> {
// Fetch all groups with proper pagination
while (hasMore) {
const response = await churchtoolsClient.get(
`/groups?include=settings&limit=${limit}&page=${page}`
`/groups?include=settings,domainAttributes&limit=${limit}&page=${page}`
)

let pageGroups: any[] = []
if (Array.isArray(response)) {
pageGroups = response
} else if (response && (response as any).data && Array.isArray((response as any).data)) {
if (response && (response as any).data && Array.isArray((response as any).data)) {
pageGroups = (response as any).data
} else if (response && Array.isArray((response as any).groups)) {
pageGroups = (response as any).groups
} else if (Array.isArray(response)) {
pageGroups = response
} else {
console.warn('Unexpected groups response structure:', response)
}

if (pageGroups.length === 0) {
Expand All @@ -70,16 +101,28 @@ async function fetchAutomaticGroups(): Promise<AutomaticGroup[]> {
group.settings.dynamicGroupStatus !== 'none' &&
group.settings.dynamicGroupStatus !== null
)
.map((group) => ({
id: group.id,
name: group.name || `Gruppe ${group.id}`,
groupTypeId: group.groupTypeId || group.groupType?.name || 'N/A',
dynamicGroupStatus: group.settings?.dynamicGroupStatus || 'none',
lastExecution: group.settings?.dynamicGroupUpdateFinished || null,
executionStatus: determineExecutionStatus(group),
dynamicGroupUpdateStarted: group.settings?.dynamicGroupUpdateStarted || null,
dynamicGroupUpdateFinished: group.settings?.dynamicGroupUpdateFinished || null,
}))
.map((group) => {
// Try different possible locations for groupTypeId
const groupTypeId =
group.information?.groupTypeId ||
group.domainAttributes?.groupTypeId ||
group.groupTypeId ||
0

const groupTypeName = groupTypeMap.get(groupTypeId) || 'Unbekannter Typ'

return {
id: group.id,
name: group.name || `Gruppe ${group.id}`,
groupTypeId,
groupTypeName,
dynamicGroupStatus: group.settings?.dynamicGroupStatus || 'none',
lastExecution: group.settings?.dynamicGroupUpdateFinished || null,
executionStatus: determineExecutionStatus(group),
dynamicGroupUpdateStarted: group.settings?.dynamicGroupUpdateStarted || null,
dynamicGroupUpdateFinished: group.settings?.dynamicGroupUpdateFinished || null,
}
})

return automaticGroups
}
Expand Down