ctucx.git: oeffisearch

[nimlang] fast and simple tripplanner

commit 8b370d277dc1e4d15c3b9053810778564797c753
parent 688c782485ad70ae4a4150ae7e3d91dcc1fd5e5f
Author: Milan Pässler <milan@petabyte.dev>
Date: Fri, 11 Sep 2020 20:00:06 +0200

add train type information to journeysView
1 file changed, 13 insertions(+), 4 deletions(-)
M
client/js/journeysView.js
|
17
+++++++++++++----
diff --git a/client/js/journeysView.js b/client/js/journeysView.js
@@ -68,7 +68,8 @@ const journeyOverviewTemplate = (data, key) => {
 	let departure       = data.journeys[key].legs[0].departure;
 	let arrival         = data.journeys[key].legs[data.journeys[key].legs.length - 1].arrival;
 	let changes         = 0;
-	let products        = [];
+	let products        = {};
+	let productsString  = "";
 	let changesDuration = 0;
 	let cancelled       = false;
 

@@ -82,10 +83,18 @@ const journeyOverviewTemplate = (data, key) => {
 		if (leg.isWalking || leg.isTransfer) continue;
 
 		changes = changes+1;
-		products.push(leg.line.productName);
+		if (!products[leg.line.productName]) products[leg.line.productName] = [];
+		if (leg.line && leg.line.trainTypeShort) products[leg.line.productName].push(leg.line.trainTypeShort);
 	}
 
-	products = [...new Set(products)];
+	productsString = Object.entries(products).map(([prod, types]) => {
+		if (types.length >= 2) {
+			prod += " (" + types.join(", ") + ")";
+		} else if (types.length) {
+			prod += " " + types[0];
+		}
+		return prod;
+	}).join(", ");
 
 	return html`
 	<tr @click=${() => go('/'+data.reqId + '/' + key)}">

@@ -93,7 +102,7 @@ const journeyOverviewTemplate = (data, key) => {
 		<td><span>${timeTemplate(arrival, 'arrival')}</span></td>
 		<td title="${changesDuration > 0 ? 'Davon '+formatDuration(changesDuration)+' Umstiegsdauer' : ''}"><span>${formatDuration(duration)}</span></td>
 		<td><span>${changes-1}</span></td>
-		<td><span>${products.join(', ')}</span></td>
+		<td><span>${productsString}</span></td>
 		<td><a class="details-button icon-arrow3"></a></td>
 	</tr>`;
 }