From 81e0a67f68c39a0123c8bea04cc1074e0fcbb1ee Mon Sep 17 00:00:00 2001 From: NGPixel Date: Sun, 11 Feb 2024 21:38:48 +0000 Subject: [PATCH] feat: admin users search + pagination --- server/graph/resolvers/user.mjs | 8 +++- server/graph/schemas/user.graphql | 7 ++- ux/src/pages/AdminUsers.vue | 77 ++++++++++++++++++++++--------- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/server/graph/resolvers/user.mjs b/server/graph/resolvers/user.mjs index 8d2cd034..dd1d1d91 100644 --- a/server/graph/resolvers/user.mjs +++ b/server/graph/resolvers/user.mjs @@ -28,7 +28,8 @@ export default { } // -> Fetch Users - return WIKI.db.users.query() + const total = await WIKI.db.users.query().count('id').first() + const users = await WIKI.db.users.query() .select('id', 'email', 'name', 'isSystem', 'isActive', 'createdAt', 'lastLoginAt') .where(builder => { if (args.filter) { @@ -39,6 +40,11 @@ export default { .orderBy(args.orderBy ?? 'name', args.orderByDirection ?? 'asc') .offset((offset - 1) * limit) .limit(limit) + + return { + users, + total: total.count + } }, /** * FETCH A SINGLE USER diff --git a/server/graph/schemas/user.graphql b/server/graph/schemas/user.graphql index e31289f9..29907006 100644 --- a/server/graph/schemas/user.graphql +++ b/server/graph/schemas/user.graphql @@ -10,7 +10,7 @@ extend type Query { orderByDirection: OrderByDirection # Filter by name / email filter: String - ): [UserMinimal] + ): UserResults userById( id: UUID! @@ -122,6 +122,11 @@ type UserLastLogin { lastLoginAt: Date } +type UserResults { + users: [UserMinimal] + total: Int +} + type UserMinimal { id: UUID name: String diff --git a/ux/src/pages/AdminUsers.vue b/ux/src/pages/AdminUsers.vue index 706435c4..259226b9 100644 --- a/ux/src/pages/AdminUsers.vue +++ b/ux/src/pages/AdminUsers.vue @@ -64,13 +64,13 @@ q-page.admin-groups :rows-per-page-options='[0]' :loading='state.loading > 0' ) - template(v-slot:body-cell-id='props') + template(#body-cell-id='props') q-td(:props='props') q-icon(name='las la-user', color='primary', size='sm') - template(v-slot:body-cell-name='props') + template(#body-cell-name='props') q-td(:props='props') .flex.items-center - strong {{props.value}} + strong {{ props.value }} q-icon.q-ml-sm( v-if='props.row.isSystem' name='las la-lock' @@ -81,10 +81,10 @@ q-page.admin-groups name='las la-ban' color='pink' ) - template(v-slot:body-cell-email='props') + template(#body-cell-email='props') q-td(:props='props') em {{ props.value }} - template(v-slot:body-cell-date='props') + template(#body-cell-date='props') q-td(:props='props') i18n-t.text-caption(keypath='admin.users.createdAt', tag='div') template(#date) @@ -96,7 +96,7 @@ q-page.admin-groups ) template(#date) strong {{ humanizeDate(props.row.lastLoginAt) }} - template(v-slot:body-cell-edit='props') + template(#body-cell-edit='props') q-td(:props='props') q-btn.acrylic-btn.q-mr-sm( v-if='!props.row.isSystem' @@ -114,11 +114,19 @@ q-page.admin-groups color='negative' @click='deleteUser(props.row)' ) + .flex.flex-center.q-mt-lg(v-if='state.totalPages > 1') + q-pagination( + v-model='state.currentPage' + :max='state.totalPages' + :max-pages='9' + boundary-numbers + direction-links + )