Init project

This commit is contained in:
2025-06-18 15:26:47 +02:00
commit 1bdc9dacb6
11 changed files with 2428 additions and 0 deletions

39
web/journeys-search.js Normal file
View File

@@ -0,0 +1,39 @@
import { fetchJourneys } from './api.js';
import { attachLocationsSearch } from './locations-search.js';
let element_from = document.querySelector("#journey-search-from");
let element_to = document.querySelector("#journey-search-to");
let element_submit = document.querySelector("#journey-search-submit");
let element_result = document.querySelector("#journey-search-result");
export function setupJourneysSearch() {
attachLocationsSearch(element_from);
attachLocationsSearch(element_to);
element_submit.addEventListener("click", event => {
element_result.innerText = "Loading…";
fetchJourneys(element_from.dataset.locationId, element_to.dataset.locationId).then(result => {
for (let journey of result.journeys) {
element_result.appendChild(createJourneyElement(journey));
}
});
});
}
function createJourneyElement(journey) {
let el = document.createElement("div");
for (let leg of journey.legs) {
el.appendChild(createJourneyLegElement(leg));
}
return el;
}
function createJourneyLegElement(leg) {
let el = document.createElement("div");
el.innerText = JSON.stringify(leg);
el.innerText = leg?.line?.name + ": " + leg.origin.name + " > " + leg.destination.name;
return el;
}