From 2693f259d4617e4fbedaf10558a052efb09abaef Mon Sep 17 00:00:00 2001 From: wbuezas Date: Tue, 13 Feb 2024 10:17:24 -0300 Subject: [PATCH 01/10] Add drag and drop do Travel Extra Community table --- src/pages/Travel/ExtraCommunity.vue | 150 ++++++++++++++++++++++------ 1 file changed, 117 insertions(+), 33 deletions(-) diff --git a/src/pages/Travel/ExtraCommunity.vue b/src/pages/Travel/ExtraCommunity.vue index 4cbb850e1..42c5480f4 100644 --- a/src/pages/Travel/ExtraCommunity.vue +++ b/src/pages/Travel/ExtraCommunity.vue @@ -47,6 +47,10 @@ const arrayData = useArrayData('ExtraCommunity', { }); const rows = computed(() => arrayData.store.data || []); +const draggedRowIndex = ref(null); +const targetRowIndex = ref(null); +const entryRowIndex = ref(null); +const draggedEntry = ref(null); const tableColumnComponents = { id: { @@ -263,6 +267,56 @@ onMounted(async () => { landedTo.value.setHours(23, 59, 59, 59); await getData(); }); + +const handleDragStart = (event, rowIndex, entryIndex) => { + draggedRowIndex.value = rowIndex; + entryRowIndex.value = entryIndex; + event.dataTransfer.effectAllowed = 'move'; +}; + +const handleDragEnter = (_, targetIndex) => { + targetRowIndex.value = targetIndex; +}; + +const handleDragOver = (e) => { + e.preventDefault(); +}; + +const saveRowDrop = async (targetRowIndex) => { + const entryId = draggedEntry.value.id; + const travelId = rows.value[targetRowIndex].id; + await axios.patch(`Entries/${entryId}`, { travelFk: travelId }); +}; + +const moveRow = async (draggedRowIndex, targetRowIndex, entryIndex) => { + try { + if (draggedRowIndex === targetRowIndex) return; + // Remover entry de la row original + draggedEntry.value = rows.value[draggedRowIndex].entries.splice(entryIndex, 1)[0]; + //Si la row de destino por alguna razón no tiene la propiedad entry la creamos + if (!rows.value[targetRowIndex].entries) rows.value[targetRowIndex].entries = []; + // Añadir entry a la row de destino + rows.value[targetRowIndex].entries.push(draggedEntry.value); + + await saveRowDrop(targetRowIndex); + } catch (err) { + cleanDragAndDropData(); + console.error('Error moving row', err); + } +}; + +const handleDrop = () => { + if (!draggedRowIndex.value && !targetRowIndex.value) return; + moveRow(draggedRowIndex.value, targetRowIndex.value, entryRowIndex.value); + cleanDragAndDropData(); +}; + +const cleanDragAndDropData = () => { + draggedRowIndex.value = null; + targetRowIndex.value = null; + entryRowIndex.value = null; + draggedEntry.value = null; +}; + + en: searchExtraCommunity: Search for extra community shipping From ca06140a8da66be7cdd231f3e074a2660880eb40 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Tue, 13 Feb 2024 10:49:27 -0300 Subject: [PATCH 02/10] remove v-if --- src/pages/Travel/ExtraCommunity.vue | 62 ++++++++++++++--------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/pages/Travel/ExtraCommunity.vue b/src/pages/Travel/ExtraCommunity.vue index 42c5480f4..0cf3e04ca 100644 --- a/src/pages/Travel/ExtraCommunity.vue +++ b/src/pages/Travel/ExtraCommunity.vue @@ -442,39 +442,35 @@ const cleanDragAndDropData = () => { entryRowIndex === index && props.rowIndex === draggedRowIndex, }" > - + + {{ entry.id }} + + + + {{ entry.supplierName }} + + + + {{ toCurrency(entry.invoiceAmount) }} + {{ entry.reference }} + {{ entry.stickers }} + + {{ entry.loadedkg }} + {{ entry.volumeKg }} + + + + From fbe8c912f60767cec05d6b7069b6e409b0fd6f68 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Wed, 14 Feb 2024 09:55:18 -0300 Subject: [PATCH 03/10] Fix dragend status --- src/pages/Travel/ExtraCommunity.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pages/Travel/ExtraCommunity.vue b/src/pages/Travel/ExtraCommunity.vue index 0cf3e04ca..5fd33a061 100644 --- a/src/pages/Travel/ExtraCommunity.vue +++ b/src/pages/Travel/ExtraCommunity.vue @@ -306,7 +306,13 @@ const moveRow = async (draggedRowIndex, targetRowIndex, entryIndex) => { }; const handleDrop = () => { - if (!draggedRowIndex.value && !targetRowIndex.value) return; + if ( + !draggedRowIndex.value && + draggedRowIndex.value !== 0 && + !targetRowIndex.value && + draggedRowIndex.value !== 0 + ) + return; moveRow(draggedRowIndex.value, targetRowIndex.value, entryRowIndex.value); cleanDragAndDropData(); }; @@ -357,6 +363,7 @@ const cleanDragAndDropData = () => { :pagination="{ rowsPerPage: 0 }" class="full-width" table-style="user-select: none;" + @dragend="cleanDragAndDropData()" >