From b42b1ea4103b2a49833032bd4b7c39abf2816c6b Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Wed, 1 Jan 2025 05:52:35 +0000 Subject: [PATCH] fix fetch link, add filterItineraryByCase method --- assets/js/app/filter.js | 51 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/assets/js/app/filter.js b/assets/js/app/filter.js index 4b29937..cf60a0c 100644 --- a/assets/js/app/filter.js +++ b/assets/js/app/filter.js @@ -2,7 +2,7 @@ export function filterAddressesByCase() { if (!document.getElementById('case-filter').value) { return; } - fetch('/index.php/api/filter-address-by-case/' + document.getElementById('case-filter').value, { + fetch('/api/filter-address-by-case/' + document.getElementById('case-filter').value, { method: 'POST', header: { 'Content-Type': 'application/json' @@ -47,3 +47,52 @@ export function filterAddressesByCase() { }); } +export function filterItineraryByCase() { + let caseId = null; + let startDate = null; + let endDate = null; + + if (document.getElementById('case-filter').value) { + caseId = document.getElementById('case-filter').value; + } + + if (document.getElementById('start-date-filter').value) { + startDate = document.getElementById('start-date-filter').value; + } + + if (document.getElementById('end-date-filter').value) { + endDate = document.getElementById('end-date-filter').value; + } + + fetch('/api/filter-itinerary-by-case', { + method: 'POST', + header: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + caseId: caseId, + startDate: startDate, + endDate: endDate, + }) + }) + .then(response => response.json()) + .then(result => { + const itineraryList = document.getElementById('itineraryList'); + itineraryList.innerHTML = ''; + console.log(result); + + result.forEach(i => { + itineraryList.innerHTML += ` + + ${i.date} + ${i.case} + ${i.origin.name} + ${i.destination.name} + ${i.duration} + ${i.distance} + + `; + }) + }); +} +