Compare commits

...

6 Commits

10 changed files with 117 additions and 14 deletions

View File

@@ -81,6 +81,14 @@ export class LegsDataStore {
this.write();
}
forget(trip_id, origin_location_id, destination_location_id) {
this.data = this.data.filter((leg) => {
return !(leg.trip_id == trip_id && leg.origin_location_id == origin_location_id && leg.destination_location_id == destination_location_id);
});
this.write();
}
}
export class TripsDataStore {

View File

@@ -11,5 +11,7 @@ export function EL(type, properties) {
Object.assign(el.style, properties.style);
}
el.on = (event_name, callback) => el.addEventListener(event_name, callback);
return el;
}

View File

@@ -1,5 +1,5 @@
import { EL } from "./dom.js";
import { displayTripDetails } from "./trip-details.js";
import { displayLegDetails } from "./leg-details.js";
import { fetchTrip } from './api.js';
let element_board = document.querySelector("#drafting-board-content");
@@ -63,6 +63,40 @@ export function drawDraftingBoard() {
return leg;
});
display_legs = display_legs.toSorted((leg_a, leg_b) => {
if (leg_a.origin_location_id == leg_b.origin_location_id) {
if (leg_a.origin_location.departure > leg_b.origin_location.departure) {
return 1;
} else {
return -1;
}
} else if (leg_a.destination_location_id == leg_b.destination_location_id) {
if (leg_a.destination_location.arrival > leg_b.destination_location.arrival) {
return 1;
} else {
return -1;
}
} else if (leg_a.destination_location_id == leg_b.origin_location_id) {
if (leg_a.destination_location.arrival > leg_b.origin_location.departure) {
return 1;
} else {
return -1;
}
} else if (leg_a.origin_location_id == leg_b.destination_location_id) {
if (leg_a.origin_location.departure > leg_b.destination_location.arrival) {
return 1;
} else {
return -1;
}
} else {
if (leg_a.origin_location.departure > leg_b.origin_location.departure) {
return 1;
} else {
return -1;
}
}
});
let rows = display_legs.length;
element_board.style.setProperty("--drafting-board-number-locations", display_locations.length);
@@ -127,8 +161,7 @@ export function drawDraftingBoard() {
el_leg.innerText = display_leg.trip?.line?.name;
el_leg.addEventListener("click", event => {
console.log(display_leg.trip_id);
displayTripDetails(display_leg.trip_id);
displayLegDetails(display_leg.trip_id, display_leg.origin_location_id, display_leg.destination_location_id);
});
element_board.appendChild(el_leg);
@@ -162,6 +195,9 @@ export function getLocationWithLeastInboundTrips(locations, legs) {
let n_a = numberOfInboundLegs(location_a);
let n_b = numberOfInboundLegs(location_b);
// 1: b vor a
// -1: a vor b
if (n_a == n_b) {
return 0;
} else if (n_a > n_b) {
@@ -182,7 +218,7 @@ export function sortLocations(sorted_locations, unsorted_locations, legs) {
let selected_location_id = getLocationWithLeastInboundTrips(unsorted_locations, legs);
unsorted_locations = unsorted_locations.filter(location_id => location_id != selected_location_id);
legs = legs.filter(leg => leg.destination_id != selected_location_id && leg.origin_id != selected_location_id);
legs = legs.filter(leg => leg.destination_location_id != selected_location_id && leg.origin_location_id != selected_location_id);
return sortLocations(sorted_locations.concat([ selected_location_id ]), unsorted_locations, legs);
}

View File

@@ -21,7 +21,7 @@
<div id="drafting-board-content"></div>
</div>
<div id="journeys-search" class="popup">
<div id="journeys-search" class="popup popup-hidden">
<div class="popup-close">&times;</div>
<div id="journeys-search-content" class="popup-content">
<div class="container">
@@ -33,7 +33,7 @@
</div>
</div>
<div id="locations-search" class="popup">
<div id="locations-search" class="popup popup-hidden">
<div class="popup-close">&times;</div>
<div id="locations-search-content" class="popup-content">
<div class="container">
@@ -43,7 +43,16 @@
</div>
</div>
<div id="trip-details" class="popup">
<div id="leg-details" class="popup popup-hidden">
<div class="popup-close">&times;</div>
<div id="leg-details-content" class="popup-content">
<div class="container">
<div id="leg-details-response"></div>
</div>
</div>
</div>
<div id="trip-details" class="popup popup-hidden">
<div class="popup-close">&times;</div>
<div id="trip-details-content" class="popup-content">
<div class="container">

View File

@@ -51,6 +51,6 @@ export function attachJourneysSearch(search_element) {
element_from.value = "";
element_to.value = "";
element_result.innerText = "";
element_journeys_search.style.display = "block";
element_journeys_search.popupShow();
});
}

37
web/leg-details.js Normal file
View File

@@ -0,0 +1,37 @@
import { EL } from "./dom.js";
import { displayTripDetails } from "./trip-details.js";
import { drawDraftingBoard } from './drafting-board.js';
let element_leg_details = document.querySelector("#leg-details");
let element_response = document.querySelector("#leg-details-response");
export function displayLegDetails(trip_id, origin_location_id, destination_location_id) {
let trip = window.dataStore.trips.data[trip_id];
let origin_location = window.dataStore.locations.data[origin_location_id];
let destination_location = window.dataStore.locations.data[destination_location_id];
element_response.innerText = "";
let el_headline = EL("h1", {});
el_headline.innerText = trip.line.name + ": " + origin_location.name + " -> " + destination_location.name;
element_response.appendChild(el_headline);
let el_display_trip = EL("div", {});
el_display_trip.innerText = "Display full trip";
el_display_trip.on("click", event => {
displayTripDetails(trip_id);
});
element_response.appendChild(el_display_trip);
let el_remove_leg = EL("div", {});
el_remove_leg.innerText = "Remove leg";
el_remove_leg.on("click", event => {
window.dataStore.legs.forget(trip_id, origin_location_id, destination_location_id);
drawDraftingBoard();
element_leg_details.popupHide();
});
element_response.appendChild(el_remove_leg);
element_leg_details.popupShow();
}

View File

@@ -26,7 +26,7 @@ function createLocationElement(location) {
location_element.addEventListener("click", event => {
window.dataStore.recent_locations.remember(event.target.dataset.locationId);
element_locations_search.locationSelectedCallback(event.target.innerText, event.target.dataset.locationId);
element_locations_search.style.display = "none";
element_locations_search.popupHide();
});
return location_element;
@@ -46,6 +46,6 @@ export function attachLocationsSearch(search_element) {
let el = createLocationElement(location);
element_response.appendChild(el);
}
element_locations_search.style.display = "block";
element_locations_search.popupShow();
});
}

View File

@@ -1,7 +1,15 @@
export function setupPopups() {
document.querySelectorAll(".popup").forEach(element => {
element.popupShow = () => {
element.classList.remove("popup-hidden");
};
element.popupHide = () => {
element.classList.add("popup-hidden");
};
});
document.querySelectorAll(".popup-close").forEach(element => {
element.addEventListener("click", event => {
event.target.parentElement.style.display="none";
event.target.parentElement.popupHide();
});
});
}

View File

@@ -61,11 +61,13 @@ body {
background-color: rgba(0, 0, 0, 0.9);
color: white;
display: none;
overflow: scroll;
}
.popup-hidden {
display: none;
}
#journeys-search {
z-index: 8000;
}

View File

@@ -6,9 +6,10 @@ let element_response = document.querySelector("#trip-details-response");
export function displayTripDetails(trip_id) {
element_response.innerHTML = "Loading…";
element_trip_details.style.display = "block";
element_trip_details.popupShow();
fetchTrip(trip_id).then(result => {
window.dataStore.trips.remember(result.trip);
element_response.innerText = "";
let el_headline = EL("h1", {});