ctucx.git: trainsearch

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

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 import { html, nothing } from 'lit-html';
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
import { formatDateTime, lineAdditionalName } from './formatters.js';
import { showModal } from './overlays.js';
import { settings } from './settings.js';
import { ds100Name } from './app_functions.js';
import { t } from './languages.js';

export const remarksModalTemplate = (remarks) => html`
	<div class="remarksView">
		${remarks.map(remark => html`
			<div class="flex-row">
				<span class="icon-${remark.type}"></span>
				<span>${unsafeHTML(remark.text)}</span>
			</div>
		`)}
	</div>
`;

export const stopTemplate = (profile, stop) => {
	const ds100 = ds100Name(stop.id);
	return html`<a class="flex-center" href="#/d/${profile}/${stop.id}">${stop.name} ${ds100 !== null ? ` (${ds100})` : nothing}</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)}
		`}
	`;
};


export const footerTemplate = html`
	<footer class="center">
		<a href="https://git.ctu.cx/trainsearch" title="commit ${COMMIT} from ${COMMITDATE}">Source-Code (${VERSION})</a>
		<a href="https://ctu.cx/imprint.html">Imprint</a>
	</footer>
`;