mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Implement pagination without a total count
This is necessary, because once we filter the collection, the `countUsers` is not valid anymore.
This commit is contained in:
parent
095a5e7c67
commit
8b1d92ee7e
@ -1,6 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<ds-card :header="$t('admin.users.name')">
|
<ds-card :header="$t('admin.users.name')">
|
||||||
<ds-table v-if="User && User.length" :data="User" :fields="fields" condensed>
|
<ds-table v-if="User && User.length" :data="User" :fields="fields" condensed>
|
||||||
|
<template slot="index" slot-scope="scope">
|
||||||
|
{{ scope.row.index }}.
|
||||||
|
</template>
|
||||||
<template slot="name" slot-scope="scope">
|
<template slot="name" slot-scope="scope">
|
||||||
<nuxt-link
|
<nuxt-link
|
||||||
:to="{
|
:to="{
|
||||||
@ -34,18 +37,16 @@ export default {
|
|||||||
pageSize,
|
pageSize,
|
||||||
first: pageSize,
|
first: pageSize,
|
||||||
User: [],
|
User: [],
|
||||||
|
hasNext: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
hasNext() {
|
|
||||||
const { countUsers } = this.statistics
|
|
||||||
return this.offset < countUsers - this.pageSize
|
|
||||||
},
|
|
||||||
hasPrevious() {
|
hasPrevious() {
|
||||||
return this.offset > 0
|
return this.offset > 0
|
||||||
},
|
},
|
||||||
fields() {
|
fields() {
|
||||||
return {
|
return {
|
||||||
|
index: '#',
|
||||||
name: this.$t('admin.users.table.columns.name'),
|
name: this.$t('admin.users.table.columns.name'),
|
||||||
slug: this.$t('admin.users.table.columns.slug'),
|
slug: this.$t('admin.users.table.columns.slug'),
|
||||||
role: this.$t('admin.users.table.columns.role'),
|
role: this.$t('admin.users.table.columns.role'),
|
||||||
@ -53,11 +54,6 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
statistics: {
|
|
||||||
query() {
|
|
||||||
return gql('query { statistics { countUsers } }')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
User: {
|
User: {
|
||||||
query() {
|
query() {
|
||||||
return gql(`
|
return gql(`
|
||||||
@ -75,17 +71,19 @@ export default {
|
|||||||
const { offset, first } = this
|
const { offset, first } = this
|
||||||
return { first, offset }
|
return { first, offset }
|
||||||
},
|
},
|
||||||
|
update({ User }) {
|
||||||
|
this.hasNext = User && User.length >= this.pageSize
|
||||||
|
if (User.length <= 0) return this.User // edge case, avoid a blank page
|
||||||
|
return User.map((u, i) => Object.assign({}, u, { index: this.offset + i }))
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
back() {
|
back() {
|
||||||
this.offset -= this.pageSize
|
this.offset = Math.max(this.offset - this.pageSize, 0)
|
||||||
this.offset = Math.max(this.offset, 0)
|
|
||||||
},
|
},
|
||||||
next() {
|
next() {
|
||||||
this.offset += this.pageSize
|
this.offset += this.pageSize
|
||||||
const { countUsers } = this.statistics
|
|
||||||
this.offset = Math.min(this.offset, countUsers - this.pageSize)
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user