ctucx.git: trainsearch

web based trip-planner, fork of https://cyberchaos.dev/yuka/trainsearch

commit 52890604e9643527b38740d3c5ebd98efa81dab3
parent e6af1e9b59d73615b65ea080dbb0349d1d0d1491
Author: Katja (ctucx) <git@ctu.cx>
Date: Sat, 25 Jan 2025 20:11:00 +0100

cleanup some stuff
8 files changed, 39 insertions(+), 73 deletions(-)
M
src/app_functions.js
|
9
---------
M
src/departuresView.js
|
6
+++---
M
src/journeyView.js
|
24
+++++++++++-------------
M
src/journeysView.js
|
21
+++++++++------------
M
src/main.js
|
11
-----------
M
src/searchView.js
|
14
+++++++-------
M
src/settingsView.js
|
15
++++-----------
M
src/tripView.js
|
12
+++++-------
diff --git a/src/app_functions.js b/src/app_functions.js
@@ -47,15 +47,6 @@ const addJourneys = async data => {
 	};
 
 	await db.addJourneys(journeyEntries, journeysOverviewEntry, historyEntry);
-
-	//const lastHistoryEntry = (await getJourneysHistory()).slice(-1);
-	//if (lastHistoryEntry[0]
-	//	&& JSON.stringify(lastHistoryEntry[0].fromPoint) === JSON.stringify(getFrom(data.journeys))
-	//	&& JSON.stringify(lastHistoryEntry[0].toPoint) === JSON.stringify(getTo(data.journeys))) {
-	//	dataStorage.journeysHistory[dataStorage.journeysHistory.length-1].slug = data.slug;										
-	//	dataStorage.journeysHistory[dataStorage.journeysHistory.length-1].journeyId = '';
-	//} else {
-	//}
 };
 
 const processJourneys = data => {
diff --git a/src/departuresView.js b/src/departuresView.js
@@ -5,7 +5,7 @@ import { t, processLeg } from './app_functions.js';
 import { formatDateTime, formatDuration, formatPrice } from './formatters.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
-import { html, render } from 'lit-html';
+import { html, nothing, render } from 'lit-html';
 import { getHafasClient, client } from './hafas_client';
 
 const departuresTemplate = (data, profile) => {

@@ -34,8 +34,8 @@ const departuresTemplate = (data, profile) => {
 				<tbody>
 					${(data.departures || []).map(departure => html`
 						<tr class="departure" @click=${() => go(`/t/${profile}/${departure.tripId}`)}>
-							<td class="${departure.cancelled ? 'cancelled' : ''}"><span>${timeTemplate(departure)}</span></td>
-							<td class="${departure.cancelled ? 'cancelled' : ''}"><span>${departure.line.name}${departure.direction ? html` → ${departure.direction}` : ''}</span></td>
+							<td class="${departure.cancelled ? 'cancelled' : nothing}"><span>${timeTemplate(departure)}</span></td>
+							<td class="${departure.cancelled ? 'cancelled' : nothing}"><span>${departure.line.name}${departure.direction ? html` → ${departure.direction}` : nothing}</span></td>
 							${departure.cancelled ? html`
 								<td><span class="cancelled-text">${t('cancelled-ride')}</span></td>
 							` : html`
diff --git a/src/journeyView.js b/src/journeyView.js
@@ -6,7 +6,7 @@ import { t, getJourney, refreshJourney } from './app_functions.js';
 import { formatName, formatDateTime, formatDuration, formatPrice, formatTrainTypes, formatLineAdditionalName, formatLineDisplayName } from './formatters.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
-import { html, render } from 'lit-html';
+import { html, nothing, render } from 'lit-html';
 
 const legTemplate = (leg, profile) => {
 	const remarks = leg.remarks || [];

@@ -24,11 +24,11 @@ const legTemplate = (leg, profile) => {
 				<thead>
 					<tr>
 						<td colspan="4">
-							<div class="center"><a href="#/t/${profile}/${leg.tripId}">${formatLineDisplayName(leg.line)}${leg.direction ? html` → ${leg.direction}` : ''}</a>
-							${leg.cancelled ? html`<b class="cancelled-text">${t('cancelled-ride')}</b>` : ''}
+							<div class="center"><a href="#/t/${profile}/${leg.tripId}">${formatLineDisplayName(leg.line)}${leg.direction ? html` → ${leg.direction}` : nothing}</a>
+							${leg.cancelled ? html`<b class="cancelled-text">${t('cancelled-ride')}</b>` : nothing}
 							${!!remarks.length ? html`
 								<a class="link icon-hint" @click=${() => showModal(t('remarks'), remarksModalTemplate(remarks))}></a>
-							` : ''}</div>
+							` : nothing}</div>
 						</td>
 					</tr>
 					<tr>

@@ -38,22 +38,22 @@ const legTemplate = (leg, profile) => {
 									<div>
 										Trip: ${formatLineAdditionalName(leg.line)}
 									</div>
-								` : ''}
+								` : nothing}
 								${leg.line.trainType ? html`
 									<div>
 										Train type: ${leg.line.trainType}
 									</div>
-								` : ''}
+								` : nothing}
 								${(leg.arrival && leg.departure) ? html`
 									<div>
 										${t('duration')}: ${formatDuration(leg.arrival - leg.departure)}
 									</div>
-								` : ''}
+								` : nothing}
 								${leg.loadFactor ? html`
 									<div>
 										${t("load-"+leg.loadFactor)}
 									</div>
-								` : ''}
+								` : nothing}
 							</div>
 						</td>
 					</tr>

@@ -66,7 +66,7 @@ const legTemplate = (leg, profile) => {
 				</thead>
 				<tbody>
 					${(leg.stopovers || []).map(stop => html`
-						<tr class="stop ${stop.cancelled ? 'cancelled' : ''}">
+						<tr class="stop ${stop.cancelled ? 'cancelled' : nothing}">
 							<td><span>${timeTemplate(stop, 'arrival')}</span></td>
 							<td><span>${timeTemplate(stop, 'departure')}</span></td>
 							<td>${stopTemplate(profile, stop.stop)}</td>

@@ -119,12 +119,10 @@ const journeyTemplate = (data, profile) => {
 	return html`
 		<div class="journeyView column">
 			<header>
-				${data.slug ? html`
-					<a class="icon-back" href="#/${data.slug}/${settings.journeysViewMode}" title="${t('back')}">${t('back')}</a>
-				` : ''}
+				${data.slug ? html`<a class="icon-back" href="#/${data.slug}/${settings.journeysViewMode}" title="${t('back')}">${t('back')}</a>` : nothing}
 				<div class="content">
 					<h3>${formatName(data.legs[0].origin)} → ${formatName(data.legs[data.legs.length - 1].destination)}</h3>
-					<p><b>${t('duration')}: ${formatDuration(duration)} | ${t('changes')}: ${changes-1} | ${t('date')}: ${formatDateTime(data.legs[0].plannedDeparture, 'date')}${settings.showPrices && data.price ? html` | ${t('price')}: <td><span>${formatPrice(data.price)}</span></td>` : ''}</b></p>
+					<p><b>${t('duration')}: ${formatDuration(duration)} | ${t('changes')}: ${changes-1} | ${t('date')}: ${formatDateTime(data.legs[0].plannedDeparture, 'date')}${settings.showPrices && data.price ? html` | ${t('price')}: <td><span>${formatPrice(data.price)}</span></td>` : nothing}</b></p>
 				</div>
 				<a class="icon-reload" title="${t("reload")}" @click=${() => refreshJourneyView(data.refreshToken, profile)}>${t("reload")}</a>
 			</header>
diff --git a/src/journeysView.js b/src/journeysView.js
@@ -5,7 +5,7 @@ import { timeTemplate } from './templates.js';
 import { settings, modifySettings } from './settings.js';
 import { setupCanvas } from './canvas.js';
 import { go } from './router.js';
-import { html, render } from 'lit-html';
+import { html, nothing, render } from 'lit-html';
 import { showAlertModal, showLoader, hideOverlay } from './overlays.js';
 
 const journeysTemplate = (data) => html`

@@ -33,11 +33,10 @@ const journeysTemplate = (data) => html`
 			<div id="journeysCanvas">
 				<canvas id="canvas"></canvas>
 			</div>
-		` : ''}
+		` : nothing}
+
 		${settings.journeysViewMode === 'table' ? html`
-			${data.earlierRef ? html`
-				<a class="arrowButton flipped icon-arrow2" title="${t('label_earlier')}" @click=${() => moreJourneys(data.slug, 'earlier')}></a>
-			` : ''}
+			${data.earlierRef ? html`<a class="arrowButton flipped icon-arrow2" title="${t('label_earlier')}" @click=${() => moreJourneys(data.slug, 'earlier')}></a>` : nothing}
 
 			<div class="card">
 			<table>

@@ -48,20 +47,18 @@ const journeysTemplate = (data) => html`
 						<th>${t('duration')}</th>
 						<th>${t('changes')}</th>
 						<th>${t('products')}</th>
-						${settings.showPrices ? html`<th>${t('price')}</th>` : ''}
+						${settings.showPrices ? html`<th>${t('price')}</th>` : nothing}
 						<th></th>
 					</tr>
 				</thead>
 				<tbody>
-					${Object.entries(data.journeys).map(([key, val]) => journeyOverviewTemplate(data.profile || "db", val, data.slug, key - data.indexOffset))}
+					${Object.entries(data.journeys).map(([key, value]) => journeyOverviewTemplate(data.profile || "db", value, data.slug, key - data.indexOffset))}
 				</tbody>
 			</table>
 			</div>
 
-			${data.laterRef ? html`
-				<a class="arrowButton icon-arrow2" title="${t('label_later')}" @click=${() => moreJourneys(data.slug, 'later')}></a>
-			` : ''}
-		` : ''}
+			${data.laterRef ? html`<a class="arrowButton icon-arrow2" title="${t('label_later')}" @click=${() => moreJourneys(data.slug, 'later')}></a>` : nothing}
+		` : nothing}
 	</div>
 `;
 

@@ -109,7 +106,7 @@ const journeyOverviewTemplate = (profile, entry, slug, key) => {
 		<td class="${cancelled ? 'cancelled' : ''}" title="${changesDuration > 0 ? 'including '+formatDuration(changesDuration)+' transfer durations' : ''}">${formatDuration(duration)}</td>
 		<td>${changes-1}</td>
 		<td>${productsString}</td>
-		${settings.showPrices ? html`<td>${formatPrice(entry.price)}</td>` : ''}
+		${settings.showPrices ? html`<td>${formatPrice(entry.price)}</td>` : nothing}
 		<td><a class="icon-arrow1"></a></td>
 	</tr>`;
 };
diff --git a/src/main.js b/src/main.js
@@ -11,7 +11,6 @@ import { tripView } from './tripView.js';
 import { departuresView } from './departuresView.js';
 
 (async () => {
-	// read settings from indexeddb
 	await initDataStorage();
 	await initSettings();
 	await initHafasClient(settings.profile || "db");

@@ -32,13 +31,3 @@ import { departuresView } from './departuresView.js';
 	if (!window.location.hash.length) go('/');
 	start();
 }) ();
-
-//const sw = navigator.serviceWorker;
-//export let registration;
-//if (sw) {
-//	sw.register('service-worker.js', {
-//		scope: './'
-//	}).then(function(reg) {
-//		registration = reg;
-//	});
-//}
diff --git a/src/searchView.js b/src/searchView.js
@@ -175,7 +175,7 @@ export const searchView = async () => {
 
 	if (viaValue !== '') toggleVia('show');
 
-	ElementById('form').addEventListener("submit", search);
+	ElementById('form').addEventListener("submit", submitForm);
 	ElementById('from').focus();
 
 	for (const [product, enabled] of Object.entries(settings.products)) {

@@ -186,7 +186,7 @@ export const searchView = async () => {
 	}
 };
 
-export const search = async (event) => {
+const submitForm = async (event) => {
 	event.preventDefault();
 
 	await modifySettings(settings => {

@@ -324,7 +324,7 @@ export const search = async (event) => {
 	go(`/${responseData.slug}/${settings.journeysViewMode}`);
 };
 
-export const toggleHistory = () => {
+const toggleHistory = () => {
 	const historyElement = ElementById('history');
 	const buttonElement  = ElementById('historyButton');
 

@@ -337,7 +337,7 @@ export const toggleHistory = () => {
 	}
 }
 
-export const toggleVia = ( mode ) => {
+const toggleVia = ( mode ) => {
 	const rowElement    = ElementById('viaRow');
 	const buttonElement = ElementById('viaButton');
 

@@ -351,7 +351,7 @@ export const toggleVia = ( mode ) => {
 	}
 }
 
-export const swapFromTo = () => {
+const swapFromTo = () => {
 	suggestions.from = [suggestions.to, suggestions.to = suggestions.from][0];
 
 	const from = ElementById('from');

@@ -360,7 +360,7 @@ export const swapFromTo = () => {
 	from.value = [to.value, to.value = from.value][0];
 };
 
-export const setFromHistory = async id => {
+const setFromHistory = async id => {
 	const entry = (await db.getJourneysHistory())[id];
 	if (!entry) return;
 

@@ -384,7 +384,7 @@ const setDateTimeNow = () => {
 	ElementById('datetime').value = dateTimeValue;
 };
 
-export const readProductSelection = settings => {
+const readProductSelection = settings => {
 	const productsMap = {};
 
 	for (const prod of client.profile.products) {
diff --git a/src/settingsView.js b/src/settingsView.js
@@ -7,9 +7,7 @@ import { html, render } from 'lit-html';
 import { searchView } from './searchView.js';
 import { initHafasClient } from './hafas_client';
 
-export const showSettings = async () => {
-	showModal(t('settings'), settingsTemplate());
-};
+export const showSettings = async () => showModal(t('settings'), settingsTemplate());
 
 const settingsTemplate = () => html`
 	<div class="settingsView">

@@ -37,9 +35,9 @@ const settingsTemplate = () => html`
 		<div class="row">
 			<label>${t('options')}:</label>
 			<div>
-				<label><input type="checkbox" ?checked=${settings.showDS100} id="showDS100"> ${t('showds100')}</label><br>
-				<label><input type="checkbox" ?checked=${settings.showPrices} id="showPrices"> ${t('show-prices')} (${t("experimental")})</label><br>
-				<label><input type="checkbox" ?checked=${settings.combineDateTime} id="combineDateTime"> ${t('combineDateTime')}</label>
+				<label><input type="checkbox" id="showDS100" ?checked=${settings.showDS100}> ${t('showds100')}</label><br>
+				<label><input type="checkbox" id="showPrices" ?checked=${settings.showPrices}> ${t('show-prices')} (${t("experimental")})</label><br>
+				<label><input type="checkbox" id="combineDateTime" ?checked=${settings.combineDateTime}> ${t('combineDateTime')}</label>
 			</div>
 		</div>
 

@@ -55,11 +53,6 @@ const clearStorage = () => {
 	location.reload();
 };
 
-const rebuildCach = () => {
-	registration.update();
-	location.reload();
-};
-
 const saveSettings = async () => {
 	await modifySettings(settings => {
 		settings.combineDateTime = ElementById('combineDateTime').checked;
diff --git a/src/tripView.js b/src/tripView.js
@@ -5,7 +5,7 @@ import { t, processLeg } from './app_functions.js';
 import { formatDateTime, formatDuration, formatPrice, formatLineAdditionalName, formatLineDisplayName } from './formatters.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
-import { html, render } from 'lit-html';
+import { html, nothing, render } from 'lit-html';
 import { getHafasClient, client } from './hafas_client';
 
 const tripTemplate = (data, profile) => {

@@ -43,9 +43,7 @@ const tripTemplate = (data, profile) => {
 								${formatLineDisplayName(data.line)}${data.direction ? html` → ${data.direction}` : ''}
 							`}
 							${data.cancelled ? html`<b class="cancelled-text">${t('cancelled-ride')}</b>` : ''}
-							${!!remarks.length ? html`
-								<a class="link icon-hint" @click=${() => showModal(t('remarks'), remarksModalTemplate(remarks))}></a>
-							` : ''}</div>
+							${!!remarks.length ? html`<a class="link icon-hint" @click=${() => showModal(t('remarks'), remarksModalTemplate(remarks))}></a>` : nothing}</div>
 						</td>
 					</tr>
 					<tr>

@@ -55,12 +53,12 @@ const tripTemplate = (data, profile) => {
 									<div>
 										Trip: ${formatLineAdditionalName(data.line)}
 									</div>
-								` : ''}
+								` : nothing}
 								${data.line.trainType ? html`
 									<div>
 										Train type: ${data.line.trainType}
 									</div>
-								` : ''}
+								` : nothing}
 								<div ${data.cancelled ? 'cancelled' : ''}">
 									${t('duration')}: ${formatDuration(data.arrival - (data.departure ? data.departure : data.plannedDeparture))} ${data.departure ? '' : ('(' + t('planned') + ')')}
 								</div>

@@ -68,7 +66,7 @@ const tripTemplate = (data, profile) => {
 									<div
 										${t("load-"+data.loadFactor)}
 									</div>
-								` : ''}
+								` : nothing}
 							</div>
 						</td>
 					</tr>