From 1d402e01436e0b92267bb7c3dba4ea5142c4c545 Mon Sep 17 00:00:00 2001 From: asift798 Date: Wed, 2 Feb 2022 18:51:32 +0530 Subject: [PATCH 1/8] add scroll to load invoices and fixed limited category and customer issue in payment and expense --- resources/scripts/admin/stores/category.js | 1 + resources/scripts/admin/stores/customer.js | 1 + .../scripts/admin/views/expenses/Create.vue | 37 +++++++++++- .../scripts/admin/views/invoices/View.vue | 60 ++++++++++++++++--- .../scripts/admin/views/payments/Create.vue | 6 +- .../base/BaseCustomerSelectInput.vue | 7 +++ 6 files changed, 100 insertions(+), 12 deletions(-) diff --git a/resources/scripts/admin/stores/category.js b/resources/scripts/admin/stores/category.js index a1c35b3b..787f61b4 100644 --- a/resources/scripts/admin/stores/category.js +++ b/resources/scripts/admin/stores/category.js @@ -17,6 +17,7 @@ export const useCategoryStore = (useWindow = false) => { name: '', description: '', }, + editCategory: null }), getters: { diff --git a/resources/scripts/admin/stores/customer.js b/resources/scripts/admin/stores/customer.js index 0069961e..ffb3b58d 100644 --- a/resources/scripts/admin/stores/customer.js +++ b/resources/scripts/admin/stores/customer.js @@ -25,6 +25,7 @@ export const useCustomerStore = (useWindow = false) => { currentCustomer: { ...customerStub(), }, + editCustomer: null }), getters: { diff --git a/resources/scripts/admin/views/expenses/Create.vue b/resources/scripts/admin/views/expenses/Create.vue index ca36c8ad..8f689a7d 100644 --- a/resources/scripts/admin/views/expenses/Create.vue +++ b/resources/scripts/admin/views/expenses/Create.vue @@ -77,6 +77,7 @@ label="name" track-by="id" :options="searchCategory" + v-if="!isFetchingInitialData" :filter-results="false" resolve-on-load :delay="500" @@ -180,6 +181,7 @@ label="name" track-by="id" :options="searchCustomer" + v-if="!isFetchingInitialData" :filter-results="false" resolve-on-load :delay="500" @@ -280,7 +282,7 @@ diff --git a/resources/scripts/admin/views/invoices/View.vue b/resources/scripts/admin/views/invoices/View.vue index 9e0a3078..22c98ad3 100644 --- a/resources/scripts/admin/views/invoices/View.vue +++ b/resources/scripts/admin/views/invoices/View.vue @@ -40,6 +40,10 @@ const isSendingEmail = ref(false) const isRequestOnGoing = ref(false) const isSearching = ref(false) const isLoading = ref(false) +const invoiceList = ref(null) +const page_no = ref(1) +const last_page_no = ref(1) +const isLoadMore = ref(false) const searchData = reactive({ orderBy: null, @@ -118,14 +122,38 @@ function hasActiveUrl(id) { return route.params.id == id } -async function loadInvoices() { - isLoading.value = true - await invoiceStore.fetchInvoices() +async function loadInvoices(params, isScroll=false) { + if(isScroll) { + isLoadMore.value = true + } + else { + isLoading.value = true + } + let invoice = await invoiceStore.fetchInvoices(params) isLoading.value = false + isLoadMore.value = false + let invoice_list = invoiceList.value ? invoiceList.value : [] + + for (const key in invoice.data.data) { + invoice_list.push(invoice.data.data[key]) + } + invoiceList.value = invoice_list - setTimeout(() => { - scrollToInvoice() - }, 500) + page_no.value = params ? params.page : 1 + last_page_no.value = invoice.data.meta.last_page + let isInvoiceExist = invoiceList.value.find(inv=>inv.id==route.params.id) + + if(isScroll==false && !isInvoiceExist && page_no.value { + if(isScroll==false) { + scrollToInvoice() + } + }, 500) + } } function scrollToInvoice() { @@ -133,9 +161,21 @@ function scrollToInvoice() { if (el) { el.scrollIntoView({ behavior: 'smooth' }) el.classList.add('shake') + addScrollListner() } } +function addScrollListner() { + let el = document.getElementById("scroll_load") + el.addEventListener('scroll', (ev) => { + if(ev.target.scrollTop>0 && (ev.target.scrollTop == ev.target.scrollHeight - ev.target.clientHeight)) { + if(page_no.value
-
+ +
diff --git a/resources/scripts/admin/views/payments/Create.vue b/resources/scripts/admin/views/payments/Create.vue index 663a69c0..39888302 100644 --- a/resources/scripts/admin/views/payments/Create.vue +++ b/resources/scripts/admin/views/payments/Create.vue @@ -84,9 +84,9 @@ { - if(ev.target.scrollTop>0 && (ev.target.scrollTop == ev.target.scrollHeight - ev.target.clientHeight)) { - if(page_no.value 0 && + ev.target.scrollTop == ev.target.scrollHeight - ev.target.clientHeight + ) { + if (currentPageNumber.value < lastPageNumber.value) { + loadInvoices({ page: ++currentPageNumber.value }, true) } } }) @@ -251,7 +242,6 @@ onSearched = debounce(onSearched, 500) invoiceData.status === 'DRAFT' && userStore.hasAbilities(abilities.SEND_INVOICE) " - :disabled="isSendingEmail" variant="primary" class="text-sm" @click="onSendInvoice" @@ -399,7 +389,7 @@ onSearched = debounce(onSearched, 500)
-
From 3f2c774f91de5c1935224448b5fd46cc0cfebca6 Mon Sep 17 00:00:00 2001 From: asift798 Date: Tue, 8 Feb 2022 11:57:47 +0530 Subject: [PATCH 4/8] refactor and apply scroll to load data in estimates, invoices and payments --- .../scripts/admin/views/estimates/View.vue | 96 ++++++++++------ .../scripts/admin/views/invoices/View.vue | 22 ++-- .../scripts/admin/views/payments/View.vue | 100 +++++++++++------ .../partials/RecurringInvoiceViewSidebar.vue | 103 +++++++++++------- 4 files changed, 200 insertions(+), 121 deletions(-) diff --git a/resources/scripts/admin/views/estimates/View.vue b/resources/scripts/admin/views/estimates/View.vue index fc631891..6d3f624b 100644 --- a/resources/scripts/admin/views/estimates/View.vue +++ b/resources/scripts/admin/views/estimates/View.vue @@ -23,7 +23,6 @@ estimateData.status === 'DRAFT' && userStore.hasAbilities(abilities.SEND_ESTIMATE) " - :disabled="isSendingEmail" :content-loading="isLoadingEstimate" variant="primary" class="text-sm" @@ -45,7 +44,7 @@ hidden h-full pt-16 - pb-4 + pb-[6.4rem] ml-56 bg-white xl:ml-64 @@ -156,18 +155,17 @@
-
+
- +
+

import { useI18n } from 'vue-i18n' -import { computed, reactive, ref, watch, inject } from 'vue' +import { computed, reactive, ref, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' -import EstimateDropDown from '@/scripts/admin/components/dropdowns/EstimateIndexDropdown.vue' import { debounce } from 'lodash' + import { useEstimateStore } from '@/scripts/admin/stores/estimate' import { useModalStore } from '@/scripts/stores/modal' -import { useNotificationStore } from '@/scripts/stores/notification' import { useDialogStore } from '@/scripts/stores/dialog' import { useUserStore } from '@/scripts/admin/stores/user' + +import EstimateDropDown from '@/scripts/admin/components/dropdowns/EstimateIndexDropdown.vue' import SendEstimateModal from '@/scripts/admin/components/modal-components/SendEstimateModal.vue' import LoadingIcon from '@/scripts/components/icons/LoadingIcon.vue' + import abilities from '@/scripts/admin/stub/abilities' const modalStore = useModalStore() const estimateStore = useEstimateStore() -const notificationStore = useNotificationStore() const dialogStore = useDialogStore() const userStore = useUserStore() const { t } = useI18n() -const utils = inject('$utils') -const id = ref(null) -const count = ref(null) const estimateData = ref(null) -const currency = ref(null) const route = useRoute() const router = useRouter() -const status = ref([ - 'DRAFT', - 'SENT', - 'VIEWED', - 'EXPIRED', - 'ACCEPTED', - 'REJECTED', -]) const isMarkAsSent = ref(false) -const isSendingEmail = ref(false) -const isRequestOnGoing = ref(false) const isSearching = ref(false) const isLoading = ref(false) const isLoadingEstimate = ref(false) +const estimateList = ref(null) +const currentPageNumber = ref(1) +const lastPageNumber = ref(1) +const estimateListSection = ref(null) + const searchData = reactive({ orderBy: null, orderByField: null, @@ -374,14 +361,40 @@ function hasActiveUrl(id) { return route.params.id == id } -async function loadEstimates() { +async function loadEstimates(params, isScroll = false) { + if (isLoading.value) { + return + } + isLoading.value = true - await estimateStore.fetchEstimates(route.params.id) + let response = await estimateStore.fetchEstimates(params) isLoading.value = false - setTimeout(() => { - scrollToEstimate() - }, 500) + estimateList.value = estimateList.value ? estimateList.value : [] + + estimateList.value = [...estimateList.value, ...response.data.data] + + currentPageNumber.value = params ? params.page : 1 + lastPageNumber.value = response.data.meta.last_page + let isEstimateExist = estimateList.value.find( + (est) => est.id == route.params.id + ) + + if ( + isScroll == false && + !isEstimateExist && + currentPageNumber.value < lastPageNumber.value + ) { + loadEstimates({ page: ++currentPageNumber.value }) + } + + if (isEstimateExist) { + setTimeout(() => { + if (isScroll == false) { + scrollToEstimate() + } + }, 500) + } } function scrollToEstimate() { @@ -389,9 +402,24 @@ function scrollToEstimate() { if (el) { el.scrollIntoView({ behavior: 'smooth' }) el.classList.add('shake') + addScrollListner() } } +function addScrollListner() { + estimateListSection.value.addEventListener('scroll', (ev) => { + if ( + ev.target.scrollTop > 0 && + ev.target.scrollTop + ev.target.clientHeight > + ev.target.scrollHeight - 200 + ) { + if (currentPageNumber.value < lastPageNumber.value) { + loadEstimates({ page: ++currentPageNumber.value }, true) + } + } + }) +} + async function loadEstimate() { isLoadingEstimate.value = true let response = await estimateStore.fetchEstimate(route.params.id) diff --git a/resources/scripts/admin/views/invoices/View.vue b/resources/scripts/admin/views/invoices/View.vue index 274cb62e..d9f8607a 100644 --- a/resources/scripts/admin/views/invoices/View.vue +++ b/resources/scripts/admin/views/invoices/View.vue @@ -1,6 +1,6 @@