ctucx.git: trainsearch

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

commit abe1020bcc1b60c6733a26e01d4572824bfca004
parent 2fa2cad6d1b718672cca4d563881702a20b61327
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 20 Jan 2025 12:24:14 +0100

move templates to where they belong
6 files changed, 69 insertions(+), 68 deletions(-)
M
src/app_functions.js
|
61
+------------------------------------------------------------
M
src/departuresView.js
|
3
++-
M
src/journeyView.js
|
4
++--
M
src/journeysView.js
|
3
++-
M
src/templates.js
|
62
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
M
src/tripView.js
|
4
++--
diff --git a/src/app_functions.js b/src/app_functions.js
@@ -213,7 +213,7 @@ export const parseName = (point) => {
 	return nameHTML;
 };
 
-const ds100Names = (id) => {
+export const ds100Names = (id) => {
 	if (!settings.showRIL100Names) return '';
 	if (!ds100[Number(id)]) return '';
 	return '('+ds100[Number(id)]+')';

@@ -235,62 +235,3 @@ export const loadDS100 = async () => {
 		}
 	}
 };
-
-export const timeTemplate = (data, mode) => {
-	const fieldsMap = {
-		when: {
-			departure: 'departure',
-			arrival: 'arrival',
-		},
-		plannedWhen: {
-			departure: 'plannedDeparture',
-			arrival: 'plannedArrival',
-		},
-		delay: {
-			departure: 'departureDelay',
-			arrival: 'arrivalDelay',
-		},
-	};
-	const getField = fieldName => data[fieldsMap[fieldName][mode] || fieldName];
-
-	const time = getField('when') || getField('plannedWhen');
-	if (!time) return '-';
-
-	const delayMinutes = Math.round(getField('delay') / 60);
-
-	return html`
-		${delayMinutes != 0 ? html`
-			${formatDateTime(time)} <b>(${delayMinutes > 0 ? '+' : ''}${delayMinutes})</b>
-		` : html`
-			${formatDateTime(time)}
-		`}
-	`;
-};
-
-export const platformTemplate = (data) => {
-	if (data.departurePlatform) {
-		if (data.departurePlatform != data.plannedDeparturePlatform) {
-			return html`<b>${data.departurePlatform}</b>`;
-		} else {
-			return data.plannedDeparturePlatform;
-		}
-	} else if (data.platform) {
-		if (data.platform != data.plannedPlatform) {
-			return html`<b>${data.platform}</b>`;
-		} else {
-			return data.plannedPlatform;
-		}
-	} else if (data.arrivalPlatform) {
-		if (data.arrivalPlatform != data.plannedArrivalPlatform) {
-			return html`<b>${data.arrivalPlatform}</b>`;
-		} else {
-			return data.plannedArrivalPlatform;
-		}
-	} else {
-		return '-';
-	}
-};
-
-export const stopTemplate = (profile, stop) => {
-	return html`<a href="#/d/${profile}/${stop.id}">${stop.name} ${ds100Names(stop.id)}</a>`;
-}
diff --git a/src/departuresView.js b/src/departuresView.js
@@ -1,6 +1,7 @@
 import { settings } from './settings.js';
+import { platformTemplate, timeTemplate } from './templates.js';
 import { showDiv, hideDiv, ElementById, formatDateTime, formatDuration, formatPrice } from './helpers.js';
-import { parseName, t, timeTemplate, processLeg, platformTemplate } from './app_functions.js';
+import { parseName, t, processLeg } from './app_functions.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
 import { html, render } from 'lit-html';
diff --git a/src/journeyView.js b/src/journeyView.js
@@ -1,8 +1,8 @@
 import { cachedCoachSequence } from './reihung';
 import { settings } from './settings.js';
-import { remarksTemplate } from './templates.js';
+import { remarksTemplate, platformTemplate, stopTemplate, timeTemplate } from './templates.js';
 import { showDiv, hideDiv, ElementById, formatDateTime, formatDuration, formatPrice, formatTrainTypes, lineAdditionalName, lineDisplayName } from './helpers.js';
-import { parseName, t, timeTemplate, getJourney, refreshJourney, platformTemplate, stopTemplate } from './app_functions.js';
+import { parseName, t, getJourney, refreshJourney } from './app_functions.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
 import { html, render } from 'lit-html';
diff --git a/src/journeysView.js b/src/journeysView.js
@@ -1,5 +1,6 @@
 import { showDiv, hideDiv, ElementById, formatDuration, formatFromTo, getFrom, getTo, padZeros, formatPrice } from './helpers.js';
-import { parseName, t, timeTemplate, getJourneys, getMoreJourneys, refreshJourneys } from './app_functions.js';
+import { parseName, t, getJourneys, getMoreJourneys, refreshJourneys } from './app_functions.js';
+import { timeTemplate } from './templates.js';
 import { settings, modifySettings } from './settings.js';
 import { setupCanvas } from './canvas.js';
 import { go } from './router.js';
diff --git a/src/templates.js b/src/templates.js
@@ -1,8 +1,8 @@
-import { lineAdditionalName } from './helpers.js';
+import { formatDateTime, lineAdditionalName } from './helpers.js';
 import { showModal } from './overlays.js';
 import { html } from 'lit-html';
 import { settings } from './settings.js';
-import { t } from './app_functions.js';
+import { t, ds100Names } from './app_functions.js';
 
 export const remarksModalTemplate = (type, remarks) => html`
 	<table class="remarks">

@@ -25,3 +25,61 @@ export const remarksTemplate = ([type, remarks]) => !!remarks.length ? html`
 	<a class="link icon-${type}" @click=${() => showRemarksModal(type, remarks)}></a>
 ` : '';
 
+export const stopTemplate = (profile, stop) => {
+	return html`<a href="#/d/${profile}/${stop.id}">${stop.name} ${ds100Names(stop.id)}</a>`;
+}
+
+export const platformTemplate = (data) => {
+	if (data.departurePlatform) {
+		if (data.departurePlatform != data.plannedDeparturePlatform) {
+			return html`<b>${data.departurePlatform}</b>`;
+		} else {
+			return data.plannedDeparturePlatform;
+		}
+	} else if (data.platform) {
+		if (data.platform != data.plannedPlatform) {
+			return html`<b>${data.platform}</b>`;
+		} else {
+			return data.plannedPlatform;
+		}
+	} else if (data.arrivalPlatform) {
+		if (data.arrivalPlatform != data.plannedArrivalPlatform) {
+			return html`<b>${data.arrivalPlatform}</b>`;
+		} else {
+			return data.plannedArrivalPlatform;
+		}
+	} else {
+		return '-';
+	}
+};
+
+export const timeTemplate = (data, mode) => {
+	const fieldsMap = {
+		when: {
+			departure: 'departure',
+			arrival: 'arrival',
+		},
+		plannedWhen: {
+			departure: 'plannedDeparture',
+			arrival: 'plannedArrival',
+		},
+		delay: {
+			departure: 'departureDelay',
+			arrival: 'arrivalDelay',
+		},
+	};
+	const getField = fieldName => data[fieldsMap[fieldName][mode] || fieldName];
+
+	const time = getField('when') || getField('plannedWhen');
+	if (!time) return '-';
+
+	const delayMinutes = Math.round(getField('delay') / 60);
+
+	return html`
+		${delayMinutes != 0 ? html`
+			${formatDateTime(time)} <b>(${delayMinutes > 0 ? '+' : ''}${delayMinutes})</b>
+		` : html`
+			${formatDateTime(time)}
+		`}
+	`;
+};
diff --git a/src/tripView.js b/src/tripView.js
@@ -1,7 +1,7 @@
 import { settings } from './settings.js';
-import { remarksTemplate } from './templates.js';
+import { remarksTemplate, platformTemplate, stopTemplate, timeTemplate } from './templates.js';
 import { showDiv, hideDiv, ElementById, formatDateTime, formatDuration, formatPrice, lineAdditionalName, lineDisplayName } from './helpers.js';
-import { parseName, t, timeTemplate, processLeg, platformTemplate, stopTemplate } from './app_functions.js';
+import { parseName, t, processLeg } from './app_functions.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
 import { html, render } from 'lit-html';