Fix cases for Public LDB service detail where previousStops or subsequentStops is not an Array

This commit is contained in:
Fred Boniface 2023-06-26 22:13:05 +01:00
parent 6803438c63
commit fe31a8a8d1

View File

@ -104,7 +104,6 @@
} }
async function loadService(sid) { async function loadService(sid) {
console.log(`Loading: ${sid}`);
for (const service of services) { for (const service of services) {
if (service.serviceID == sid) { if (service.serviceID == sid) {
serviceDetail = service serviceDetail = service
@ -112,6 +111,14 @@
} }
} }
async function loadBusService(sid) {
for (const service of busServices) {
if (service.serviceID == sid) {
serviceDetail = service
}
}
}
async function closeService() { async function closeService() {
serviceDetail = null; serviceDetail = null;
} }
@ -141,7 +148,7 @@
</tr> </tr>
{#each services as service} {#each services as service}
<tr> <tr>
<td class="origdest from" on:click={loadService(service.serviceID)}> <td class="origdest from" on:click={loadService(service.serviceID)} on:keypress={loadService(service.serviceID)}>
{#if Array.isArray(service.origin?.location)} {#if Array.isArray(service.origin?.location)}
{service.origin.location[0]['locationName'] + {service.origin.location[0]['locationName'] +
" & " + " & " +
@ -150,7 +157,7 @@
{service.origin?.location?.locationName || ''} {service.origin?.location?.locationName || ''}
{/if} {/if}
</td> </td>
<td class="origdest to" on:click={loadService(service.serviceID)}> <td class="origdest to" on:click={loadService(service.serviceID)} on:keypress={loadService(service.serviceID)}>
{#if Array.isArray(service.destination?.location)} {#if Array.isArray(service.destination?.location)}
{service.destination.location[0]['locationName'] + {service.destination.location[0]['locationName'] +
" & " + " & " +
@ -200,8 +207,8 @@
</tr> </tr>
{#each busServices as service} {#each busServices as service}
<tr> <tr>
<td class="origdest from">{service.origin?.location?.locationName || ''}</td> <td class="origdest from" on:click={loadBusService(service.serviceID)} on:keypress={loadBusService(service.serviceID)}>{service.origin?.location?.locationName || ''}</td>
<td class="origdest to">{service.destination?.location?.locationName || ''}</td> <td class="origdest to" on:click={loadBusService(service.serviceID)} on:keypress={loadBusService(service.serviceID)}>{service.destination?.location?.locationName || ''}</td>
<td class="time">{parseTime(service.sta).data}</td> <td class="time">{parseTime(service.sta).data}</td>
<td class="time {parseTime(service.eta).changed}">{parseTime(service.eta).data}</td> <td class="time {parseTime(service.eta).changed}">{parseTime(service.eta).data}</td>
<td class="time">{parseTime(service.std).data}</td> <td class="time">{parseTime(service.std).data}</td>
@ -272,6 +279,7 @@
<th>Exp</th> <th>Exp</th>
</tr> </tr>
{#if serviceDetail?.previousCallingPoints?.callingPointList?.callingPoint} {#if serviceDetail?.previousCallingPoints?.callingPointList?.callingPoint}
{#if Array.isArray(serviceDetail?.previousCallingPoints?.callingPointList?.callingPoint)}
{#each serviceDetail.previousCallingPoints.callingPointList.callingPoint as prevPoint} {#each serviceDetail.previousCallingPoints.callingPointList.callingPoint as prevPoint}
<tr> <tr>
<td>{prevPoint.locationName}</td> <td>{prevPoint.locationName}</td>
@ -279,6 +287,13 @@
<td class="time {parseTime(prevPoint.at || prevPoint.et).changed}">{parseTime(prevPoint.at || prevPoint.et).data}</td> <td class="time {parseTime(prevPoint.at || prevPoint.et).changed}">{parseTime(prevPoint.at || prevPoint.et).data}</td>
</tr> </tr>
{/each} {/each}
{:else}
<tr>
<td>{serviceDetail.previousCallingPoints.callingPointList.callingPoint.locationName}</td>
<td>{serviceDetail.previousCallingPoints.callingPointList.callingPoint.st}</td>
<td class="time {parseTime(serviceDetail.previousCallingPoints.callingPointList.callingPoint.at || serviceDetail.previousCallingPoints.callingPointList.callingPoint.et).changed}">{parseTime(serviceDetail.previousCallingPoints.callingPointList.callingPoint.at || serviceDetail.previousCallingPoints.callingPointList.callingPoint.et).data}</td>
</tr>
{/if}
{/if} {/if}
<tr class="thisStop"> <tr class="thisStop">
<td>{title}</td> <td>{title}</td>
@ -286,6 +301,7 @@
<td class="time {parseTime(serviceDetail.etd || serviceDetail.eta).changed}">{parseTime(serviceDetail.etd || serviceDetail.eta).data}</td> <td class="time {parseTime(serviceDetail.etd || serviceDetail.eta).changed}">{parseTime(serviceDetail.etd || serviceDetail.eta).data}</td>
</tr> </tr>
{#if serviceDetail?.subsequentCallingPoints?.callingPointList?.callingPoint} {#if serviceDetail?.subsequentCallingPoints?.callingPointList?.callingPoint}
{#if Array.isArray(serviceDetail?.subsequentCallingPoints?.callingPointList?.callingPoint)}
{#each serviceDetail.subsequentCallingPoints.callingPointList.callingPoint as nextPoint} {#each serviceDetail.subsequentCallingPoints.callingPointList.callingPoint as nextPoint}
<tr> <tr>
<td>{nextPoint.locationName}</td> <td>{nextPoint.locationName}</td>
@ -293,6 +309,13 @@
<td class="time {parseTime(nextPoint.et).changed}">{parseTime(nextPoint.et).data}</td> <td class="time {parseTime(nextPoint.et).changed}">{parseTime(nextPoint.et).data}</td>
</tr> </tr>
{/each} {/each}
{:else}
<tr>
<td>{serviceDetail.subsequentCallingPoints.callingPointList.callingPoint.locationName}</td>
<td>{serviceDetail.subsequentCallingPoints.callingPointList.callingPoint.st}</td>
<td class="time {parseTime(serviceDetail.subsequentCallingPoints.callingPointList.callingPoint.et).changed}">{parseTime(serviceDetail.subsequentCallingPoints.callingPointList.callingPoint.et).data}</td>
</tr>
{/if}
{/if} {/if}
</table> </table>
</OverlayIsland> </OverlayIsland>