From bffffa64c4fc22c34384cb4d7f9de2a5cc3edd87 Mon Sep 17 00:00:00 2001 From: Vitalii Kulyk Date: Fri, 5 Jun 2026 12:24:09 +0300 Subject: [PATCH 1/4] feat: add next button to show page --- adminforth/modules/restApi.ts | 6 ++++ adminforth/spa/src/stores/core.ts | 4 +++ adminforth/spa/src/utils/listUtils.ts | 5 +-- adminforth/spa/src/views/ListView.vue | 4 +++ adminforth/spa/src/views/ShowView.vue | 47 ++++++++++++++++++++++++++- 5 files changed, 63 insertions(+), 3 deletions(-) diff --git a/adminforth/modules/restApi.ts b/adminforth/modules/restApi.ts index c1eb65229..f4120e185 100644 --- a/adminforth/modules/restApi.ts +++ b/adminforth/modules/restApi.ts @@ -318,6 +318,7 @@ const getResourceDataResponseSchema: AnySchemaObject = createErrorOrSuccessSchem items: genericObjectSchema, }, total: { type: 'number' }, + recordIds: { type: 'array', items: {} }, options: genericObjectSchema, }, additionalProperties: true, @@ -1563,6 +1564,11 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { } } + if (source === 'list') { + const pkField = resource.columns.find((col) => col.primaryKey).name; + (data as any).recordIds = data.data.map((item) => item[pkField]); + } + return data; }, }); diff --git a/adminforth/spa/src/stores/core.ts b/adminforth/spa/src/stores/core.ts index eb0763e71..6ed95b3ec 100644 --- a/adminforth/spa/src/stores/core.ts +++ b/adminforth/spa/src/stores/core.ts @@ -22,6 +22,8 @@ export const useCoreStore = defineStore('core', () => { const isResourceFetching = ref(false); const isInternetError = ref(false); const screenWidth = ref(window.innerWidth); + const listRecordIds: Ref = ref([]); + const listResourceId: Ref = ref(null); onMounted(() => { window.addEventListener('resize', updateWidth); @@ -290,5 +292,7 @@ export const useCoreStore = defineStore('core', () => { isIos, isInternetError, isMobile, + listRecordIds, + listResourceId, } }) diff --git a/adminforth/spa/src/utils/listUtils.ts b/adminforth/spa/src/utils/listUtils.ts index 7fee0fdb9..7a818874f 100644 --- a/adminforth/spa/src/utils/listUtils.ts +++ b/adminforth/spa/src/utils/listUtils.ts @@ -47,11 +47,12 @@ export async function getList(resource: AdminForthResourceFrontend, isPageLoaded return row; }); totalRows = data.total; - + const recordIds = data.recordIds || []; + // if checkboxes have items which are not in current data, remove them checkboxes.value = checkboxes.value.filter((pk: any) => rows.some((r: any) => r._primaryKeyValue === pk)); await nextTick(); - return { rows, totalRows }; + return { rows, totalRows, recordIds }; } diff --git a/adminforth/spa/src/views/ListView.vue b/adminforth/spa/src/views/ListView.vue index 90804acce..02a5a80f4 100644 --- a/adminforth/spa/src/views/ListView.vue +++ b/adminforth/spa/src/views/ListView.vue @@ -394,6 +394,10 @@ async function getListInner() { } rows.value = result.rows; totalRows.value = result.totalRows ?? 0; + if (result.recordIds) { + coreStore.listRecordIds = result.recordIds; + coreStore.listResourceId = coreStore.resource!.resourceId; + } return result.error ? { error: result.error } : {}; } diff --git a/adminforth/spa/src/views/ShowView.vue b/adminforth/spa/src/views/ShowView.vue index 75985e78d..c61eeb1e3 100644 --- a/adminforth/spa/src/views/ShowView.vue +++ b/adminforth/spa/src/views/ShowView.vue @@ -60,10 +60,36 @@ {{ $t('Delete') }} - + +
+ + + + + + + {{ currentIndex + 1 }}/{{ coreStore.listRecordIds.length }} + + + + + + +
{ return coreStore.resource?.columns?.filter(col => col.showIn?.show); }); +const hasPrevNext = computed(() => { + return coreStore.listResourceId === route.params.resourceId && coreStore.listRecordIds.length > 0; +}); + +const currentIndex = computed(() => { + const pk = String(route.params.primaryKey); + return coreStore.listRecordIds.findIndex((id: any) => String(id) === pk); +}); + +const prevRecordId = computed(() => { + const idx = currentIndex.value; + return idx > 0 ? coreStore.listRecordIds[idx - 1] : null; +}); + +const nextRecordId = computed(() => { + const idx = currentIndex.value; + return idx >= 0 && idx < coreStore.listRecordIds.length - 1 ? coreStore.listRecordIds[idx + 1] : null; +}); + const otherColumns = computed(() => { const groupedColumnNames = new Set( groups.value.flatMap(group => group.columns?.map((col: AdminForthResourceColumnCommon) => col.name)) From c4ea87cfc13b6b51c3b6ef3f09c81f714b9bd3be Mon Sep 17 00:00:00 2001 From: Pavlo Kulyk Date: Tue, 9 Jun 2026 14:41:49 +0300 Subject: [PATCH 2/4] fix: change next btn style and logic --- adminforth/spa/src/views/ShowView.vue | 39 +++++++-------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/adminforth/spa/src/views/ShowView.vue b/adminforth/spa/src/views/ShowView.vue index c61eeb1e3..9d4504e7a 100644 --- a/adminforth/spa/src/views/ShowView.vue +++ b/adminforth/spa/src/views/ShowView.vue @@ -10,6 +10,16 @@ :adminUser="coreStore.adminUser" /> + +