From a35ccb5b5180e731e5e92ef5bc9fa2b8af3cab8a Mon Sep 17 00:00:00 2001 From: wbuezas Date: Thu, 16 May 2024 16:38:27 -0300 Subject: [PATCH 01/18] Zone Locations --- .../Worker}/CreateDepartmentChild.vue | 0 src/pages/Worker/WorkerDepartment.vue | 4 +- .../Worker/WorkerDepartmentTree.vue} | 2 +- src/pages/Zone/Card/ZoneLocations.vue | 10 +- src/pages/Zone/Card/ZoneLocationsTree.vue | 169 ++++++++++++++++++ src/pages/Zone/locale/en.yml | 3 + src/pages/Zone/locale/es.yml | 3 + src/router/modules/zone.js | 2 +- 8 files changed, 188 insertions(+), 5 deletions(-) rename src/{components => pages/Worker}/CreateDepartmentChild.vue (100%) rename src/{components/ui/VnTree.vue => pages/Worker/WorkerDepartmentTree.vue} (99%) create mode 100644 src/pages/Zone/Card/ZoneLocationsTree.vue diff --git a/src/components/CreateDepartmentChild.vue b/src/pages/Worker/CreateDepartmentChild.vue similarity index 100% rename from src/components/CreateDepartmentChild.vue rename to src/pages/Worker/CreateDepartmentChild.vue diff --git a/src/pages/Worker/WorkerDepartment.vue b/src/pages/Worker/WorkerDepartment.vue index 3c0e5fdd0..fe4c23051 100644 --- a/src/pages/Worker/WorkerDepartment.vue +++ b/src/pages/Worker/WorkerDepartment.vue @@ -1,10 +1,10 @@ diff --git a/src/components/ui/VnTree.vue b/src/pages/Worker/WorkerDepartmentTree.vue similarity index 99% rename from src/components/ui/VnTree.vue rename to src/pages/Worker/WorkerDepartmentTree.vue index 13aa05635..09220be7e 100644 --- a/src/components/ui/VnTree.vue +++ b/src/pages/Worker/WorkerDepartmentTree.vue @@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n'; import { useState } from 'src/composables/useState'; import { useQuasar } from 'quasar'; import DepartmentDescriptorProxy from 'src/pages/Department/Card/DepartmentDescriptorProxy.vue'; -import CreateDepartmentChild from '../CreateDepartmentChild.vue'; +import CreateDepartmentChild from './CreateDepartmentChild.vue'; import axios from 'axios'; import useNotify from 'src/composables/useNotify.js'; import { useRouter } from 'vue-router'; diff --git a/src/pages/Zone/Card/ZoneLocations.vue b/src/pages/Zone/Card/ZoneLocations.vue index e4305c898..e04442080 100644 --- a/src/pages/Zone/Card/ZoneLocations.vue +++ b/src/pages/Zone/Card/ZoneLocations.vue @@ -1 +1,9 @@ - + + + diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue new file mode 100644 index 000000000..0940e071d --- /dev/null +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -0,0 +1,169 @@ + + + + + diff --git a/src/pages/Zone/locale/en.yml b/src/pages/Zone/locale/en.yml index 746d3f2e7..39f065496 100644 --- a/src/pages/Zone/locale/en.yml +++ b/src/pages/Zone/locale/en.yml @@ -5,6 +5,7 @@ zone: zoneCreate: Create zone deliveryList: Delivery days upcomingList: Upcoming deliveries + locations: Locations list: clone: Clone id: Id @@ -40,3 +41,5 @@ summary: filterPanel: name: Name agencyModeFk: Agency +zoneLocations: + locations: Locations diff --git a/src/pages/Zone/locale/es.yml b/src/pages/Zone/locale/es.yml index d9266b150..aa7b7d2b4 100644 --- a/src/pages/Zone/locale/es.yml +++ b/src/pages/Zone/locale/es.yml @@ -5,6 +5,7 @@ zone: zoneCreate: Nueva zona deliveryList: Días de entrega upcomingList: Próximos repartos + locations: Localizaciones list: clone: Clonar id: Id @@ -40,3 +41,5 @@ summary: filterPanel: name: Nombre agencyModeFk: Agencia +zoneLocations: + locations: Localizaciones diff --git a/src/router/modules/zone.js b/src/router/modules/zone.js index 9c917c301..0628c00aa 100644 --- a/src/router/modules/zone.js +++ b/src/router/modules/zone.js @@ -79,7 +79,7 @@ export default { path: 'location', meta: { title: 'locations', - icon: 'vn:greuge', + icon: 'my_location', }, component: () => import('src/pages/Zone/Card/ZoneLocations.vue'), }, From b26bf10e7094daddd5563d1df19d23919a1184b7 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Mon, 20 May 2024 15:53:38 -0300 Subject: [PATCH 02/18] Apply searchbar logic --- src/components/common/VnCard.vue | 4 ++++ src/pages/Zone/Card/ZoneCard.vue | 29 ++++++++--------------- src/pages/Zone/Card/ZoneLocationsTree.vue | 18 ++++++++++++-- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/components/common/VnCard.vue b/src/components/common/VnCard.vue index 58cb12708..e836badec 100644 --- a/src/components/common/VnCard.vue +++ b/src/components/common/VnCard.vue @@ -20,6 +20,8 @@ const props = defineProps({ searchUrl: { type: String, default: undefined }, searchbarLabel: { type: String, default: '' }, searchbarInfo: { type: String, default: '' }, + searchCustomRouteRedirect: { type: String, default: undefined }, + searchRedirect: { type: Boolean, default: false }, }); const stateStore = useStateStore(); @@ -62,6 +64,8 @@ watchEffect(() => { :url="props.searchUrl" :label="props.searchbarLabel" :info="props.searchbarInfo" + :custom-route-redirect-name="searchCustomRouteRedirect" + :redirect="searchRedirect" /> diff --git a/src/pages/Zone/Card/ZoneCard.vue b/src/pages/Zone/Card/ZoneCard.vue index 6451fe00c..1abbb78bf 100644 --- a/src/pages/Zone/Card/ZoneCard.vue +++ b/src/pages/Zone/Card/ZoneCard.vue @@ -5,38 +5,29 @@ import { computed } from 'vue'; import VnCard from 'components/common/VnCard.vue'; import ZoneDescriptor from './ZoneDescriptor.vue'; -import VnSearchbar from 'src/components/ui/VnSearchbar.vue'; - -import { useStateStore } from 'stores/useStateStore'; const { t } = useI18n(); -const stateStore = useStateStore(); const route = useRoute(); const routeName = computed(() => route.name); +const customRouteRedirectName = computed(() => { + if (routeName.value === 'ZoneLocations') return null; + return routeName.value; +}); const searchBarDataKeys = { ZoneWarehouses: 'ZoneWarehouses', ZoneSummary: 'ZoneSummary', + ZoneLocations: 'ZoneLocations', }; diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index 0940e071d..df3f8ef25 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -1,18 +1,25 @@ diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index 0bc141efa..6b36b6109 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -159,55 +159,8 @@ onMounted(async () => { class="qtr row justify-between full-width q-pr-md cursor-pointer" > {{ node.name }} - + - - From b408e0daaf4fd9d8a2bbf488f2e5f0e00e505b55 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Mon, 27 May 2024 08:29:52 -0300 Subject: [PATCH 12/18] remove on selected --- src/pages/Zone/Card/ZoneLocationsTree.vue | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index 6b36b6109..69ace53e2 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -81,16 +81,6 @@ const fetchNodeLeaves = async (nodeKey) => { } }; -const onSelected = async (val, node) => { - try { - if (val === null) val = undefined; - const params = { geoId: node.id, isIncluded: val }; - await axios.post(`Zones/${route.params.id}/toggleIsIncluded`, params); - } catch (err) { - console.error('Error updating included', err); - } -}; - function getNodeIds(node) { let ids = []; if (node.id) ids.push(node.id); From f2df252a94ae4d9238ec3c526b0e27802ab5d63d Mon Sep 17 00:00:00 2001 From: wbuezas Date: Mon, 27 May 2024 10:32:10 -0300 Subject: [PATCH 13/18] improvement --- src/pages/Zone/Card/ZoneLocationsTree.vue | 51 +++++++++++++---------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index 69ace53e2..f924a2e21 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -21,7 +21,7 @@ const { store } = arrayData; const storeData = computed(() => store.data); const nodes = ref([ - { id: null, name: t('zoneLocations.locations'), sons: true, children: [{}] }, + { id: null, name: t('zoneLocations.locations'), sons: true, childs: [{}] }, ]); const previousExpandedNodes = ref(new Set()); @@ -30,7 +30,6 @@ const onNodeExpanded = async (nodeKeysArray) => { const nodeKeysSet = new Set(nodeKeysArray); const lastNodeKey = nodeKeysArray.at(-1); const wasExpanded = !previousExpandedNodes.value.has(lastNodeKey); - if (wasExpanded) await fetchNodeLeaves(lastNodeKey); else { const difference = new Set( @@ -48,6 +47,16 @@ const onNodeExpanded = async (nodeKeysArray) => { const formatNodeSelected = (node) => { if (node.selected === 1) node.selected = true; else if (node.selected === 0) node.selected = false; + + if (node.childs && node.childs.length > 0) { + expanded.value.push(node.id); + + node.childs.forEach((childNode) => { + formatNodeSelected(childNode); + }); + } + + if (node.sons > 0 && !node.childs) node.childs = [{}]; }; const fetchNodeLeaves = async (nodeKey) => { @@ -60,16 +69,8 @@ const fetchNodeLeaves = async (nodeKey) => { params, }); if (response.data) { - node.children = response.data.map((n) => { - const hasChildrens = n.sons > 0; - n.children = hasChildrens ? [{}] : null; + node.childs = response.data.map((n) => { formatNodeSelected(n); - - if (n.child && n.child.length > 0) { - n.child.forEach((childNode) => { - formatNodeSelected(childNode); - }); - } return n; }); } @@ -85,24 +86,30 @@ function getNodeIds(node) { let ids = []; if (node.id) ids.push(node.id); - const children = node.childs || node.children; - if (children) { - children.forEach((child) => { + if (node.childs) + node.childs.forEach((child) => { ids = ids.concat(getNodeIds(child)); }); - } return ids; } watch(storeData, async (val) => { // Se triggerea cuando se actualiza el store.data, el cual es el resultado del fetch de la searchbar - nodes.value[0].children = [...val]; + nodes.value[0].childs = [...val]; const fetchedNodeKeys = val.flatMap(getNodeIds); state.set('Tree', [...fetchedNodeKeys]); - for (let n of state.get('Tree')) { - await fetchNodeLeaves(n); + + if (store.userParams?.search === '') { + val.forEach((n) => { + formatNodeSelected(n); + }); + } else { + for (let n of state.get('Tree')) { + await fetchNodeLeaves(n); + } + expanded.value = [null]; } - expanded.value = [null, 1, ...fetchedNodeKeys]; + previousExpandedNodes.value = new Set(expanded.value); }); onMounted(async () => { @@ -111,13 +118,12 @@ onMounted(async () => { return; } const stateTree = state.get('Tree'); - const tree = stateTree ? [...state.get('Tree'), 1] : [null, 1]; + const tree = stateTree ? [...state.get('Tree')] : [null]; const lastStateTree = state.get('TreeState'); if (tree) { for (let n of tree) { await fetchNodeLeaves(n); } - expanded.value = tree; if (lastStateTree) { tree.push(lastStateTree); @@ -130,6 +136,8 @@ onMounted(async () => { document.getElementById(lastStateTree).scrollIntoView(); } }, 1000); + + previousExpandedNodes.value = new Set(expanded.value); }); @@ -139,6 +147,7 @@ onMounted(async () => { :nodes="nodes" node-key="id" label-key="name" + children-key="childs" v-model:expanded="expanded" @update:expanded="onNodeExpanded($event)" :default-expand-all="true" From a2df7b5cf7ede6424d31c39d7b9205eb3e4c0958 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Mon, 27 May 2024 12:32:13 -0300 Subject: [PATCH 14/18] small fix --- src/pages/Zone/Card/ZoneLocationsTree.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index f924a2e21..cea9e654c 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -27,8 +27,11 @@ const nodes = ref([ const previousExpandedNodes = ref(new Set()); const onNodeExpanded = async (nodeKeysArray) => { - const nodeKeysSet = new Set(nodeKeysArray); + let nodeKeysSet = new Set(nodeKeysArray); const lastNodeKey = nodeKeysArray.at(-1); + + if (!nodeKeysSet.has(null)) return; + const wasExpanded = !previousExpandedNodes.value.has(lastNodeKey); if (wasExpanded) await fetchNodeLeaves(lastNodeKey); else { @@ -40,7 +43,6 @@ const onNodeExpanded = async (nodeKeysArray) => { const allNodeIds = getNodeIds(node); expanded.value = expanded.value.filter((id) => !allNodeIds.includes(id)); } - previousExpandedNodes.value = nodeKeysSet; }; From 8d7568d9a2d52879841e58cf6bfc9b4a49af704b Mon Sep 17 00:00:00 2001 From: wbuezas Date: Mon, 27 May 2024 14:40:33 -0300 Subject: [PATCH 15/18] Search childs fix --- src/pages/Zone/Card/ZoneLocationsTree.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index cea9e654c..a42111592 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -6,6 +6,7 @@ import { useRoute } from 'vue-router'; import { useState } from 'src/composables/useState'; import axios from 'axios'; import { useArrayData } from 'composables/useArrayData'; +import { onUnmounted } from 'vue'; const { t } = useI18n(); const route = useRoute(); @@ -109,7 +110,7 @@ watch(storeData, async (val) => { for (let n of state.get('Tree')) { await fetchNodeLeaves(n); } - expanded.value = [null]; + expanded.value = [null, ...fetchedNodeKeys]; } previousExpandedNodes.value = new Set(expanded.value); }); @@ -141,6 +142,10 @@ onMounted(async () => { previousExpandedNodes.value = new Set(expanded.value); }); + +onUnmounted(() => { + state.set('Tree', undefined); +});