2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

incr: add list pagination

This commit is contained in:
18alantom 2022-05-12 11:22:25 +05:30
parent 22b90cd424
commit 86c4889959
5 changed files with 131 additions and 43 deletions

View File

@ -49,7 +49,7 @@ export class JournalEntry extends Transactional {
return { return {
formRoute: (name) => `/edit/JournalEntry/${name}`, formRoute: (name) => `/edit/JournalEntry/${name}`,
columns: [ columns: [
'date', 'name',
{ {
label: t`Status`, label: t`Status`,
fieldtype: 'Select', fieldtype: 'Select',
@ -72,14 +72,7 @@ export class JournalEntry extends Transactional {
}; };
}, },
}, },
{ 'date',
label: t`Entry ID`,
fieldtype: 'Data',
fieldname: 'name',
getValue(doc) {
return doc.name as string;
},
},
'entryType', 'entryType',
'referenceNumber', 'referenceNumber',
], ],

View File

@ -442,7 +442,7 @@ export class Payment extends Transactional {
static getListViewSettings(fyo: Fyo): ListViewSettings { static getListViewSettings(fyo: Fyo): ListViewSettings {
return { return {
columns: [ columns: [
'party', 'name',
{ {
label: t`Status`, label: t`Status`,
fieldname: 'status', fieldname: 'status',
@ -465,7 +465,7 @@ export class Payment extends Transactional {
}; };
}, },
}, },
'paymentType', 'party',
'date', 'date',
'amount', 'amount',
], ],

View File

@ -36,9 +36,9 @@ export class PurchaseInvoice extends Invoice {
return { return {
formRoute: (name) => `/edit/PurchaseInvoice/${name}`, formRoute: (name) => `/edit/PurchaseInvoice/${name}`,
columns: [ columns: [
'party',
'name', 'name',
getTransactionStatusColumn(), getTransactionStatusColumn(),
'party',
'date', 'date',
'grandTotal', 'grandTotal',
'outstandingAmount', 'outstandingAmount',

View File

@ -35,9 +35,9 @@ export class SalesInvoice extends Invoice {
return { return {
formRoute: (name) => `/edit/SalesInvoice/${name}`, formRoute: (name) => `/edit/SalesInvoice/${name}`,
columns: [ columns: [
'party',
'name', 'name',
getTransactionStatusColumn(), getTransactionStatusColumn(),
'party',
'date', 'date',
'grandTotal', 'grandTotal',
'outstandingAmount', 'outstandingAmount',

View File

@ -1,10 +1,10 @@
<template> <template>
<div class="mx-4 pb-16 text-base flex flex-col overflow-y-hidden"> <div class="mx-4 text-base flex flex-col overflow-y-hidden">
<!-- Title Row --> <!-- Title Row -->
<div class="flex"> <div class="flex items-center">
<div class="py-4 mr-3 w-7" v-if="hasImage" /> <p class="w-8 text-right mr-4 text-gray-700">#</p>
<Row <Row
class="flex-1 text-gray-700" class="flex-1 text-gray-700 border-none"
:columnCount="columns.length" :columnCount="columns.length"
gap="1rem" gap="1rem"
> >
@ -22,34 +22,118 @@
</div> </div>
</Row> </Row>
</div> </div>
<hr />
<!-- Data Rows --> <!-- Data Rows -->
<div class="overflow-y-auto" v-if="data.length !== 0"> <div class="overflow-y-auto" v-if="data.length !== 0">
<div class="flex hover:bg-gray-100" v-for="doc in data" :key="doc.name"> <div
<div class="w-7 py-4 mr-3" v-if="hasImage"> v-for="(doc, i) in data.slice((pageNo - 1) * count, pageNo * count)"
<Avatar :imageURL="doc.image" :label="doc.name" /> :key="doc.name"
>
<!-- Row Content -->
<div class="flex hover:bg-gray-100 items-center">
<p class="w-8 text-right mr-4 text-gray-900">
{{ i + 1 + (pageNo - 1) * count }}
</p>
<Row
gap="1rem"
class="cursor-pointer text-gray-900 flex-1 border-none"
@click="openForm(doc)"
:columnCount="columns.length"
>
<ListCell
v-for="column in columns"
:key="column.label"
:class="{
'text-right': ['Float', 'Currency'].includes(column.fieldtype),
}"
:doc="doc"
:column="column"
></ListCell>
</Row>
</div> </div>
<Row <hr v-if="i !== count - 1" />
gap="1rem" </div>
class="cursor-pointer text-gray-900 flex-1" </div>
@click="openForm(doc)"
:columnCount="columns.length" <!-- Pagination Footer -->
<hr v-if="data.length > 20" />
<div
v-if="data.length > 20"
class="my-3 grid grid-cols-3 text-gray-800 text-sm select-none"
>
<!-- Length Display -->
<div class="justify-self-start">
{{
`${(pageNo - 1) * count + 1} - ${Math.min(
pageNo * count,
data.length
)}`
}}
</div>
<!-- Pagination Selector -->
<div class="flex gap-1 items-center justify-self-center">
<feather-icon
name="chevron-left"
class="w-4 h-4"
:class="
pageNo > 1 ? 'text-gray-600 cursor-pointer' : 'text-transparent'
"
@click="pageNo = Math.max(1, pageNo - 1)"
/>
<div class="flex gap-1 bg-gray-100 rounded">
<input
type="number"
class="
w-6
text-right
outline-none
bg-transparent
focus:text-gray-900
"
:value="pageNo"
@change="setPageNo"
@input="setPageNo"
min="1"
:max="maxPages"
/>
<p class="text-gray-600">/</p>
<p class="w-5">
{{ maxPages }}
</p>
</div>
<feather-icon
name="chevron-right"
class="w-4 h-4"
:class="
pageNo < maxPages
? 'text-gray-600 cursor-pointer'
: 'text-transparent'
"
@click="pageNo = Math.min(maxPages, pageNo + 1)"
/>
</div>
<!-- Count Selector -->
<div class="border rounded flex justify-self-end">
<button
v-for="c in allowedCounts"
:key="c + '-count'"
@click="setCount(c)"
class="w-9"
:class="count === c ? 'bg-gray-200' : ''"
> >
<ListCell {{ c }}
v-for="column in columns" </button>
:key="column.label"
:class="{
'text-right': ['Float', 'Currency'].includes(column.fieldtype),
}"
:doc="doc"
:column="column"
></ListCell>
</Row>
</div> </div>
</div> </div>
<!-- Empty State --> <!-- Empty State -->
<div v-else class="flex flex-col items-center justify-center my-auto"> <div
v-if="!data?.length"
class="flex flex-col items-center justify-center my-auto"
>
<img src="@/assets/img/list-empty-state.svg" alt="" class="w-24" /> <img src="@/assets/img/list-empty-state.svg" alt="" class="w-24" />
<p class="my-3 text-gray-800">{{ t`No entries found` }}</p> <p class="my-3 text-gray-800">{{ t`No entries found` }}</p>
<Button type="primary" class="text-white" @click="$emit('makeNewDoc')"> <Button type="primary" class="text-white" @click="$emit('makeNewDoc')">
@ -59,7 +143,6 @@
</div> </div>
</template> </template>
<script> <script>
import Avatar from 'src/components/Avatar';
import Button from 'src/components/Button'; import Button from 'src/components/Button';
import Row from 'src/components/Row'; import Row from 'src/components/Row';
import { fyo } from 'src/initFyo'; import { fyo } from 'src/initFyo';
@ -73,7 +156,6 @@ export default {
components: { components: {
Row, Row,
ListCell, ListCell,
Avatar,
Button, Button,
}, },
watch: { watch: {
@ -87,11 +169,16 @@ export default {
}, },
data() { data() {
return { return {
pageNo: 1,
count: 20,
allowedCounts: [20, 100, 500],
data: [], data: [],
}; };
}, },
mounted() {},
computed: { computed: {
maxPages() {
return Math.ceil(this.data.length / this.count);
},
columns() { columns() {
let columns = this.listConfig?.columns ?? []; let columns = this.listConfig?.columns ?? [];
@ -110,15 +197,23 @@ export default {
}) })
.filter(Boolean); .filter(Boolean);
}, },
hasImage() {
return !!fyo.getField(this.schemaName, 'image');
},
}, },
async mounted() { async mounted() {
await this.updateData(); await this.updateData();
this.setUpdateListeners(); this.setUpdateListeners();
}, },
methods: { methods: {
setPageNo({ target: { value } }) {
value = parseInt(value);
if (isNaN(value)) {
return;
}
this.pageNo = Math.min(Math.max(1, value), this.maxPages);
},
setCount(count) {
this.pageNo = 1;
this.count = count;
},
setUpdateListeners() { setUpdateListeners() {
const listener = (name) => { const listener = (name) => {
this.updateData(); this.updateData();
@ -152,7 +247,7 @@ export default {
this.data = await fyo.db.getAll(this.schemaName, { this.data = await fyo.db.getAll(this.schemaName, {
fields: ['*'], fields: ['*'],
filters, filters,
orderBy: 'created', orderBy: 'modified',
}); });
}, },
}, },