diff --git a/composables/useEntities.ts b/composables/useEntities.ts index 9975b02..1a92bb4 100644 --- a/composables/useEntities.ts +++ b/composables/useEntities.ts @@ -36,6 +36,83 @@ export const useEntities = ( return data } + + const selectPaginated = async (options: { + select?: string + filters?: Record + sort?: { field: string; direction?: 'asc' | 'desc' }[] + page?: number + limit?: number + includeArchived?: boolean + noPagination?: boolean, + search?: string, + searchColumns?: string[], + distinctColumns?: string[], + }): Promise<{ data: any[]; meta: any }> => { + const { + select = '*', + filters = {}, + sort = [], + page = 1, + limit = 25, + includeArchived = false, + noPagination = false, + search, + searchColumns = [], + distinctColumns = [], + } = options + + const queryParams: Record = { + select, + page, + limit, + noPagination: noPagination ? 'true' : undefined + } + + // --- 🔍 Search-Parameter (optional) --- + if (search && search.trim().length > 0) { + queryParams.search = search.trim() + } + if (searchColumns.length > 0) queryParams.searchColumns = searchColumns.join(',') + if (distinctColumns.length > 0) queryParams.distinctColumns = distinctColumns.join(',') + + + // --- Sortierung --- + if (sort.length > 0) { + queryParams.sort = sort + .map(s => `${s.field}:${s.direction || 'asc'}`) + .join(',') + } + + // --- Filter --- + for (const [key, value] of Object.entries(filters)) { + if (Array.isArray(value)) { + queryParams[`filter[${key}]`] = value.join(',') + } else { + queryParams[`filter[${key}]`] = value + } + } + + const response = await useNuxtApp().$api(`/api/resource/${relation}/paginated`, { + method: 'GET', + params: queryParams + }) + + if (!response) { + return { data: [], meta: null } + } + + let data = response.data || [] + const meta = response.queryConfig || {} + + // --- Optional: Archivierte ausblenden --- + if (!includeArchived) { + data = data.filter((i: any) => !i.archived) + } + + return { data, meta } + } + const selectSpecial = async ( select: string = "*", sortColumn: string | null = null, @@ -134,7 +211,7 @@ export const useEntities = ( } - return {select, create, update, archive, selectSingle, selectSpecial} + return {select, create, update, archive, selectSingle, selectSpecial, selectPaginated} } diff --git a/pages/standardEntity/[type]/[[mode]]/[[id]].vue b/pages/standardEntity/[type]/[mode]/[[id]].vue similarity index 87% rename from pages/standardEntity/[type]/[[mode]]/[[id]].vue rename to pages/standardEntity/[type]/[mode]/[[id]].vue index 4e9a95e..456a378 100644 --- a/pages/standardEntity/[type]/[[mode]]/[[id]].vue +++ b/pages/standardEntity/[type]/[mode]/[[id]].vue @@ -43,7 +43,12 @@ const setupPage = async (sort_column = null, sort_direction = null) => { console.log(item.value) } else if (mode.value === "list") { //Load Data for List - items.value = await useEntities(type).select(dataType.supabaseSelectWithInformation, sort_column || dataType.supabaseSortColumn, sort_direction === "asc", true) + //items.value = await useEntities(type).select(dataType.supabaseSelectWithInformation, sort_column || dataType.supabaseSortColumn, sort_direction === "asc", true) + items.value = await useEntities(type).select({ + filters: {}, + sort: [], + page:1 + }) } loaded.value = true diff --git a/pages/standardEntity/[type]/index.vue b/pages/standardEntity/[type]/index.vue new file mode 100644 index 0000000..bc0f445 --- /dev/null +++ b/pages/standardEntity/[type]/index.vue @@ -0,0 +1,449 @@ + + + + + \ No newline at end of file diff --git a/stores/data.js b/stores/data.js index 264537a..1d547f4 100644 --- a/stores/data.js +++ b/stores/data.js @@ -214,7 +214,8 @@ export const useDataStore = defineStore('data', () => { }, inputColumn: "Allgemeines", sortable: true, - maxLength: 20 + maxLength: 20, + distinct: true, }, { key: "nameAddition", label: "Firmenname Zusatz", @@ -226,7 +227,8 @@ export const useDataStore = defineStore('data', () => { return item.isCompany }, inputColumn: "Allgemeines", - maxLength: 20 + maxLength: 20, + distinct: true, },{ key: "salutation", label: "Anrede", @@ -253,7 +255,8 @@ export const useDataStore = defineStore('data', () => { return !item.isCompany }, inputColumn: "Allgemeines", - sortable: true + sortable: true, + distinct: true },{ key: "title", label: "Titel", diff --git a/stores/temp.js b/stores/temp.js index 19be026..c62e4fa 100644 --- a/stores/temp.js +++ b/stores/temp.js @@ -6,6 +6,7 @@ export const useTempStore = defineStore('temp', () => { const searchStrings = ref({}) const filters = ref({}) const columns = ref({}) + const pages = ref({}) function modifySearchString(type,input) { searchStrings.value[type] = input @@ -23,6 +24,10 @@ export const useTempStore = defineStore('temp', () => { columns.value[type] = input } + function modifyPages(type,input) { + pages.value[type] = input + } + return { searchStrings, @@ -32,6 +37,8 @@ export const useTempStore = defineStore('temp', () => { modifyFilter, columns, modifyColumns, + modifyPages, + pages }