From 7ae098d7795b88d6c50ef8bbf60e54aebf7ee1d5 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 27 Sep 2023 13:41:50 +0200 Subject: [PATCH 1/8] ref #5417 fix filters and view --- src/components/ui/VnFilterPanel.vue | 32 ++++--- src/composables/useArrayData.js | 20 ++-- src/pages/Customer/CustomerPayments.vue | 53 ++++++++--- src/pages/Customer/CustomerPaymentsFilter.vue | 92 ++++++++++++++++++- 4 files changed, 162 insertions(+), 35 deletions(-) diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 68b3a7676..0e42ae2bf 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -20,6 +20,10 @@ const props = defineProps({ required: false, default: null, }, + showAll: { + type: Boolean, + default: true, + }, }); const emit = defineEmits(['refresh', 'clear']); @@ -38,22 +42,27 @@ onMounted(() => { const isLoading = ref(false); async function search() { - const params = userParams.value; - for (const param in params) { - if (params[param] === '' || params[param] === null) { - delete userParams.value[param]; - delete store.userParams[param]; + if (props.showAll) { + const params = userParams.value; + for (const param in params) { + if (params[param] === '' || params[param] === null) { + delete userParams.value[param]; + delete store.userParams[param]; + } } - } - isLoading.value = true; - await arrayData.addFilter({ params }); - isLoading.value = false; + isLoading.value = true; + await arrayData.addFilter({ params }); + isLoading.value = false; + } else { + store.data = []; + } } async function reload() { isLoading.value = true; - await arrayData.fetch({ append: false }); + if (props.showAll) await arrayData.fetch({ append: false }); + else store.data = []; isLoading.value = false; emit('refresh'); } @@ -61,7 +70,8 @@ async function reload() { async function clearFilters() { userParams.value = {}; isLoading.value = true; - await arrayData.applyFilter({ params: {} }); + if (props.showAll) await arrayData.applyFilter({ params: {} }); + else store.data = []; isLoading.value = false; emit('clear'); diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index c7808f9a8..08e4eb001 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -38,11 +38,11 @@ export function useArrayData(key, userOptions) { 'limit', 'skip', 'userParams', - 'userFilter' + 'userFilter', ]; if (typeof userOptions === 'object') { for (const option in userOptions) { - const isEmpty = userOptions[option] == null || userOptions[option] == '' + const isEmpty = userOptions[option] == null || userOptions[option] == ''; if (isEmpty || !allowedOptions.includes(option)) continue; if (Object.prototype.hasOwnProperty.call(store, option)) { @@ -73,12 +73,11 @@ export function useArrayData(key, userOptions) { Object.assign(params, store.userParams); - store.isLoading = true + store.isLoading = true; const response = await axios.get(store.url, { signal: canceller.signal, params, }); - const { limit } = filter; hasMoreData.value = response.data.length === limit; @@ -94,7 +93,7 @@ export function useArrayData(key, userOptions) { updateStateParams(); } - store.isLoading = false + store.isLoading = false; canceller = null; } @@ -135,8 +134,9 @@ export function useArrayData(key, userOptions) { await fetch({ append: true }); } - async function refresh() { - await fetch({ append: false }); + async function refresh(showAll = true) { + if (showAll) await fetch({ append: false }); + if (!showAll) store.data = []; } function updateStateParams() { @@ -153,8 +153,8 @@ export function useArrayData(key, userOptions) { }); } - const totalRows = computed(() => store.data && store.data.length || 0); - const isLoading = computed(() => store.isLoading || false) + const totalRows = computed(() => (store.data && store.data.length) || 0); + const isLoading = computed(() => store.isLoading || false); return { fetch, @@ -167,6 +167,6 @@ export function useArrayData(key, userOptions) { hasMoreData, totalRows, updateStateParams, - isLoading + isLoading, }; } diff --git a/src/pages/Customer/CustomerPayments.vue b/src/pages/Customer/CustomerPayments.vue index 608aca2af..6b8430d84 100644 --- a/src/pages/Customer/CustomerPayments.vue +++ b/src/pages/Customer/CustomerPayments.vue @@ -110,17 +110,23 @@ function stateColor(row) { - + - +
{{ t('Web Payments') }}