commit 124306bbe3b9fac35f73f41ec2d25dc8b13dab2f
parent d6f0803447f134421385eb7f9af26819cc462a48
Author: Yureka <yuka@yuka.dev>
Date: Wed, 18 Aug 2021 14:42:57 +0200
parent d6f0803447f134421385eb7f9af26819cc462a48
Author: Yureka <yuka@yuka.dev>
Date: Wed, 18 Aug 2021 14:42:57 +0200
fix cancelled journeys
3 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/client/src/app_functions.js b/client/src/app_functions.js @@ -128,13 +128,14 @@ export const loadDS100 = async () => { export const timeTemplate = (data, mode) => { let delay = 0; - if (!data[mode]) return "-"; + const time = data[mode] || data["planned"+mode.replace(/^\w/, c => c.toUpperCase())]; + if (!time) return "-"; return html` ${data[mode+"Delay"] > 0 ? html` - ${formatDateTime(data[mode])} <b>(+${Math.round(data[mode+"Delay"] / 60)})</b> + ${formatDateTime(time)} <b>(+${Math.round(data[mode+"Delay"] / 60)})</b> ` : html` - ${formatDateTime(data[mode])} + ${formatDateTime(time)} `} `; };
diff --git a/client/src/canvas.js b/client/src/canvas.js @@ -114,8 +114,8 @@ const updateTextCache = () => { let times = []; - if (journey.legs.indexOf(leg) == journey.legs.length - 1) times.push(leg.arrival); - if (journey.legs.indexOf(leg) == 0) times.push(leg.departure); + if (journey.legs.indexOf(leg) == journey.legs.length - 1) times.push(leg.arrival || leg.plannedArrival); + if (journey.legs.indexOf(leg) == 0) times.push(leg.departure || leg.plannedDeparture); for (let time of times) { addTextToCache(formatTime(time), "#fff", 15); } @@ -192,9 +192,9 @@ const renderJourneys = () => { for (let journey of canvasState.journeys) { for (let leg of journey.legs) { - const duration = (leg.arrival - leg.departure) * scaleFactor; + const duration = ((leg.arrival || leg.plannedArrival) - (leg.departure || leg.plannedDeparture)) * scaleFactor; - y = (leg.departure - firstDeparture) * scaleFactor + 32; + y = ((leg.departure || leg.plannedDeparture) - firstDeparture) * scaleFactor + 32; ctx.shadowColor = '#00000060'; ctx.shadowBlur = 5; @@ -237,8 +237,8 @@ const renderJourneys = () => { let time; // note: leg order is reversed at this point in time let times = []; - if (journey.legs.indexOf(leg) == journey.legs.length - 1) times.push([leg.departure, y - 9.5]); - if (journey.legs.indexOf(leg) == 0) times.push([leg.arrival, y + duration + 7.5]); + if (journey.legs.indexOf(leg) == journey.legs.length - 1) times.push([leg.departure || leg.plannedDeparture, y - 9.5]); + if (journey.legs.indexOf(leg) == 0) times.push([leg.arrival || leg.plannedArrival, y + duration + 7.5]); for (let [time, y] of times) { preRenderedText = textCache[formatTime(time)]; ctx.scale(1 / dpr, 1 / dpr);
diff --git a/client/src/journeysView.js b/client/src/journeysView.js @@ -81,7 +81,7 @@ const journeyOverviewTemplate = (settings, entry, slug, key) => { let changesDuration = 0; let cancelled = false; - let duration = Number(lastLeg.arrival) - Number(firstLeg.departure); + let duration = Number(lastLeg.arrival || lastLeg.plannedArrival) - Number(firstLeg.departure || firstLeg.plannedDeparture); for (let leg of entry.legs) { if (leg.cancelled) cancelled = true; @@ -107,9 +107,13 @@ const journeyOverviewTemplate = (settings, entry, slug, key) => { return html` <tr @click=${() => go('/'+slug + '/' + key)}"> - <td><span>${timeTemplate(firstLeg, 'departure')}</span></td> - <td><span>${timeTemplate(lastLeg, 'arrival')}</span></td> - <td title="${changesDuration > 0 ? 'including '+formatDuration(changesDuration)+' transfer durations' : ''}"><span>${formatDuration(duration)}</span></td> + <td class="${cancelled ? "cancelled" : ""}"><span>${timeTemplate(firstLeg, 'departure')}</span></td> + ${cancelled ? html` + <td><span class="cancelled-text">${t('cancelled-ride')}</span></td> + ` : html` + <td><span>${timeTemplate(lastLeg, 'arrival')}</span></td> + `} + <td class="${cancelled ? "cancelled" : ""}" title="${changesDuration > 0 ? 'including '+formatDuration(changesDuration)+' transfer durations' : ''}"><span>${formatDuration(duration)}</span></td> <td><span>${changes-1}</span></td> <td><span>${productsString}</span></td> ${settings.showPrices ? html`<td><span>${formatPrice(entry.price)}</span></td>` : ''} @@ -119,7 +123,6 @@ const journeyOverviewTemplate = (settings, entry, slug, key) => { const formatPrice = price => { if (!price) return '-'; - console.log(price); const currencies = { USD: '$', EUR: '€', GBP: '£' }; let ret = currencies[price.currency] || price.currency; ret += Math.floor(price.amount);