From 3cc5595e141c9ccde3d150359eb7799c4daabba3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 14 Jan 2025 13:08:52 +0100 Subject: [PATCH 1/6] refactor: refs #8198 simplify data fetching and filtering logic --- src/pages/Item/Card/ItemLastEntries.vue | 67 +++++++++++++++---------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/pages/Item/Card/ItemLastEntries.vue b/src/pages/Item/Card/ItemLastEntries.vue index c2df553c3..7d8890c2b 100644 --- a/src/pages/Item/Card/ItemLastEntries.vue +++ b/src/pages/Item/Card/ItemLastEntries.vue @@ -36,18 +36,7 @@ const exprBuilder = (param, value) => { } }; -const where = { - itemFk: route.params.id, -}; - -const arrayData = useArrayData('ItemLastEntries', { - url: 'Items/lastEntriesFilter', - order: ['landed DESC', 'buyFk DESC'], - exprBuilder: exprBuilder, - userFilter: { - where: where, - }, -}); +let arrayData = useArrayData('ItemLastEntries'); const itemLastEntries = ref([]); const columns = computed(() => [ @@ -161,25 +150,51 @@ const getDate = (date, type) => { }; const updateFilter = async () => { - let filter; - if (!from.value && to.value) filter = { lte: to.value }; - else if (from.value && !to.value) filter = { gte: from.value }; - else if (from.value && to.value) filter = { between: [from.value, to.value] }; - - const userFilter = arrayData.store.userFilter.where; - - userFilter.landed = filter; + let landed; + if (!from.value && to.value) landed = { lte: to.value }; + else if (from.value && !to.value) landed = { gte: from.value }; + else if (from.value && to.value) landed = { between: [from.value, to.value] }; + arrayData.store.filter.where.landed = landed; await fetchItemLastEntries(); }; onMounted(async () => { - const _from = Date.vnNew(); - _from.setDate(_from.getDate() - 75); - from.value = getDate(_from, 'from'); - const _to = Date.vnNew(); - _to.setDate(_to.getDate() + 10); - to.value = getDate(_to, 'to'); + const landed = arrayData.store.filter.where?.landed; + arrayData = useArrayData('ItemLastEntries', { + url: 'Items/lastEntriesFilter', + order: ['landed DESC', 'buyFk DESC'], + exprBuilder: exprBuilder, + filter: { + where: { + itemFk: route.params.id, + landed, + }, + }, + }); + + if (landed) { + const key = Object.keys(landed)[0]; + switch (key) { + case 'gte': + from.value = landed.gte; + break; + case 'lte': + to.value = landed.lte; + break; + case 'between': + from.value = landed.between[0]; + to.value = landed.between[1]; + break; + } + } else { + const _from = Date.vnNew(); + _from.setDate(_from.getDate() - 75); + from.value = getDate(_from, 'from'); + const _to = Date.vnNew(); + _to.setDate(_to.getDate() + 10); + to.value = getDate(_to, 'to'); + } updateFilter(); From df9e5f805945c3856c4dcb8bbd4be57582b48028 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 14 Jan 2025 17:13:59 +0100 Subject: [PATCH 2/6] refactor: refs #8198 simplify state management and data fetching in ItemDiary component --- src/pages/Item/Card/ItemDiary.vue | 92 +++++++++++++------------------ 1 file changed, 37 insertions(+), 55 deletions(-) diff --git a/src/pages/Item/Card/ItemDiary.vue b/src/pages/Item/Card/ItemDiary.vue index 96a003a09..c2f2c19a0 100644 --- a/src/pages/Item/Card/ItemDiary.vue +++ b/src/pages/Item/Card/ItemDiary.vue @@ -1,7 +1,7 @@