2023-01-19 16:53:18 +00:00
|
|
|
// Set page headers
|
2023-01-14 11:45:41 +00:00
|
|
|
async function setHeaders(title,time) {
|
2023-01-09 15:05:17 +00:00
|
|
|
var prefix = `OwlBoard - `
|
|
|
|
document.title = `${prefix}${title}`
|
2023-01-23 21:00:53 +00:00
|
|
|
document.getElementById("stn_name").textContent = title
|
|
|
|
document.getElementById("fetch_time").textContent = time.toLocaleTimeString()
|
2022-12-19 23:52:27 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 16:53:18 +00:00
|
|
|
// Determine what should display in 'platform' column
|
2023-01-18 21:37:01 +00:00
|
|
|
async function parsePlatform(svc){
|
|
|
|
if (svc.platform != undefined) {
|
|
|
|
var platform = svc.platform;
|
|
|
|
} else {
|
|
|
|
var platform = "-";
|
|
|
|
}
|
2023-01-23 21:00:53 +00:00
|
|
|
if (svc.platformChanged) { // Not present in public API, ready for staff version.
|
2023-01-18 21:37:01 +00:00
|
|
|
var changed = "changed";
|
|
|
|
} else {
|
|
|
|
var changed = "";
|
|
|
|
}
|
|
|
|
return {num: platform, change: changed}
|
2023-01-18 13:09:15 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 16:53:18 +00:00
|
|
|
// Use different time strings to default to make better on small screens
|
2023-01-18 21:37:01 +00:00
|
|
|
async function parseTime(string){
|
|
|
|
switch (string) {
|
|
|
|
case "Delayed":
|
|
|
|
var output = "LATE";
|
|
|
|
var change = "changed";
|
|
|
|
break;
|
|
|
|
case "Cancelled":
|
|
|
|
var output = "CANC";
|
2023-01-20 20:02:47 +00:00
|
|
|
var change = "cancelled";
|
2023-01-18 21:37:01 +00:00
|
|
|
break;
|
|
|
|
case "On time":
|
|
|
|
var output = "RT";
|
|
|
|
var change = "";
|
|
|
|
break;
|
|
|
|
case "":
|
|
|
|
var output = "-";
|
|
|
|
var change = "";
|
|
|
|
break;
|
|
|
|
case undefined:
|
2023-01-19 16:53:18 +00:00
|
|
|
var output = "-";
|
2023-01-18 21:37:01 +00:00
|
|
|
var change = "";
|
|
|
|
break;
|
2023-01-20 01:27:29 +00:00
|
|
|
case "No report":
|
2023-01-23 21:00:53 +00:00
|
|
|
var output = "-";
|
2023-01-20 01:27:29 +00:00
|
|
|
var change = "";
|
|
|
|
break;
|
2023-01-18 21:37:01 +00:00
|
|
|
default:
|
|
|
|
var output = string;
|
|
|
|
var change = "changed";
|
|
|
|
}
|
|
|
|
return {data: output, changed: change};
|
2023-01-18 13:09:15 +00:00
|
|
|
}
|
|
|
|
|
2023-01-23 21:00:53 +00:00
|
|
|
// Convert multiple Origin/Destinations to single string
|
2023-01-22 10:38:30 +00:00
|
|
|
async function parseName(location) {
|
|
|
|
if (Array.isArray(location)) {
|
|
|
|
var name = `${location[0]['locationName']} & ${location[1]['locationName']}`
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return location.locationName;
|
|
|
|
}
|
2023-01-19 23:42:22 +00:00
|
|
|
}
|
|
|
|
|
2023-01-23 21:00:53 +00:00
|
|
|
// Build calling list: -- This is a string if only one callingPoint is present, needs adapting to work with that
|
2023-01-22 12:37:25 +00:00
|
|
|
async function buildCallLists(data) {
|
2023-01-22 13:49:38 +00:00
|
|
|
try {
|
|
|
|
if (data.previousCallingPoints.callingPointList.callingPoint) {
|
|
|
|
var preCallPoint = data.previousCallingPoints.callingPointList.callingPoint;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log(`Data not found error, ${err}`)
|
2023-01-22 12:37:25 +00:00
|
|
|
}
|
2023-01-22 13:49:38 +00:00
|
|
|
try {
|
|
|
|
if (data.subsequentCallingPoints.callingPointList.callingPoint) {
|
|
|
|
var postCallPoint = data.subsequentCallingPoints.callingPointList.callingPoint;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log(`Data not found error, ${err}`)
|
2023-01-22 12:37:25 +00:00
|
|
|
}
|
|
|
|
var procPre = "";
|
|
|
|
var procPost = "";
|
2023-01-22 13:49:38 +00:00
|
|
|
try {
|
|
|
|
if (preCallPoint) {
|
|
|
|
for(var i = 0; i < preCallPoint.length; i++) {
|
|
|
|
var proc = await buildPastCalls(preCallPoint[i]);
|
|
|
|
procPre = `${procPre}\n${proc}`
|
|
|
|
}
|
2023-01-22 12:37:25 +00:00
|
|
|
}
|
2023-01-22 13:49:38 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.log(`Error reading previous stops. ${err}`)
|
2023-01-22 12:37:25 +00:00
|
|
|
}
|
2023-01-22 13:49:38 +00:00
|
|
|
try {
|
|
|
|
if (postCallPoint) {
|
|
|
|
for (var i = 0; i < postCallPoint.length; i++) {
|
|
|
|
var proc = await buildCalls(postCallPoint[i]);
|
|
|
|
procPost = `${procPost}\n${proc}`
|
|
|
|
}
|
2023-01-22 12:37:25 +00:00
|
|
|
}
|
2023-01-22 13:49:38 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.log(`Error reading next stops. ${err}`)
|
2023-01-22 12:37:25 +00:00
|
|
|
}
|
|
|
|
var div = `
|
|
|
|
<div class="call-data" id="${data.serviceID}">
|
|
|
|
<p class="close-data" onclick="hideCalls('${data.serviceID}')">X</p>
|
|
|
|
<table class="calling-at">
|
|
|
|
<caption>Calling at:</caption>
|
|
|
|
<tr>
|
|
|
|
<th class="detail-name-head">Location</th>
|
|
|
|
<th class="time">Schedule</th>
|
|
|
|
<th class="time">Exp.</th>
|
|
|
|
</tr>
|
|
|
|
${procPost}
|
|
|
|
</table>
|
|
|
|
<table class="called-at">
|
|
|
|
<caption>Previous stops:</caption>
|
|
|
|
<tr>
|
|
|
|
<th class="detail-name-head">Location</th>
|
|
|
|
<th class="time">Schedule</th>
|
|
|
|
<th class="time">Actual</th>
|
|
|
|
</tr>
|
|
|
|
${procPre}
|
|
|
|
</table>
|
|
|
|
</div>`
|
|
|
|
document.body.insertAdjacentHTML("beforeend", div)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-23 21:00:53 +00:00
|
|
|
// Display calling list: - The calling list should be built on demand.
|
2023-01-22 12:37:25 +00:00
|
|
|
async function showCalls(id) {
|
|
|
|
document.getElementById(id).style = "display: block;";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function hideCalls(id) {
|
|
|
|
document.getElementById(id).style = "display: none;";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-19 23:42:22 +00:00
|
|
|
// Display Alert Messages
|
2023-01-20 01:27:29 +00:00
|
|
|
async function displayAlerts(array) {
|
|
|
|
var counter = 0
|
2023-01-23 21:00:53 +00:00
|
|
|
var messages = ""
|
2023-01-20 01:27:29 +00:00
|
|
|
for(var i = 0; i < array.length; i++) {
|
|
|
|
// Increment counter
|
|
|
|
counter += 1;
|
|
|
|
// Reset Vars
|
2023-01-23 21:00:53 +00:00
|
|
|
messages += `<p>${array[i]}</p>`;
|
2023-01-20 01:27:29 +00:00
|
|
|
}
|
2023-01-23 21:00:53 +00:00
|
|
|
document.getElementById("alerts_msg").insertAdjacentHTML("beforeend", messages);
|
2023-01-20 20:02:47 +00:00
|
|
|
if (counter == 1) {
|
2023-01-23 21:00:53 +00:00
|
|
|
document.getElementById("alert_bar_note").textContent = `There is ${counter} active alert`
|
2023-01-20 20:02:47 +00:00
|
|
|
} else if (counter > 1) {
|
2023-01-23 21:00:53 +00:00
|
|
|
document.getElementById("alert_bar_note").textContent = `There are ${counter} active alerts`
|
2023-01-20 20:02:47 +00:00
|
|
|
|
|
|
|
}
|
2023-01-20 01:27:29 +00:00
|
|
|
document.getElementById("alerts").style = "display:block"
|
|
|
|
document.getElementById("alerts_bar").style = "display:block"
|
2023-01-19 23:42:22 +00:00
|
|
|
document.getElementById("output").style = "margin-top:95px" // Adjust margin of train table div.
|
|
|
|
}
|
|
|
|
|
2023-01-20 01:27:29 +00:00
|
|
|
async function inflateAlerts() {
|
|
|
|
document.getElementById("alerts_msg").style = "display:block;";
|
|
|
|
document.getElementById("alert_expand_arrow").style = "transform: rotate(180deg);";
|
2023-01-20 20:02:47 +00:00
|
|
|
document.getElementById("alerts_bar").setAttribute("onclick", "deflateAlerts()")
|
2023-01-19 23:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function deflateAlerts() {
|
2023-01-20 01:27:29 +00:00
|
|
|
document.getElementById("alerts_msg").style = "display.none;";
|
|
|
|
document.getElementById("alert_expand_arrow").style = "transform: rotate(0deg);";
|
2023-01-20 20:02:47 +00:00
|
|
|
document.getElementById("alerts_bar").setAttribute("onclick", "inflateAlerts()")
|
2023-01-22 10:30:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-23 21:00:53 +00:00
|
|
|
/*
|
|
|
|
Compress buildCalls() and buildPastCalls() into a single function
|
|
|
|
that can selectively work with either data.et or data.at.
|
|
|
|
async function buildCalls(data) {
|
|
|
|
if (typeof data.et != "undefined") {
|
|
|
|
var time = await parseTime(data.et)
|
|
|
|
} else if (typeof data.at != "undefined") {
|
|
|
|
var time = await parseTime(data.at)
|
|
|
|
}
|
|
|
|
return `<tr>
|
|
|
|
<td class="detail-name detail-table-content">${data.locationName}</td>
|
|
|
|
<td class="detail-table-content">${data.st}</td>
|
|
|
|
<td class="detail-table-content ${time.changed}">${time.data}</td>
|
|
|
|
</tr>`
|
|
|
|
}
|
|
|
|
*/
|
2023-01-22 12:37:25 +00:00
|
|
|
async function buildCalls(data) {
|
|
|
|
var timeEt = await parseTime(data.et)
|
|
|
|
return `<tr>
|
2023-01-22 13:49:38 +00:00
|
|
|
<td class="detail-name detail-table-content">${data.locationName}</td>
|
|
|
|
<td class="detail-table-content">${data.st}</td>
|
|
|
|
<td class="detail-table-content ${timeEt.changed}">${timeEt.data}</td>
|
|
|
|
</tr>`
|
|
|
|
}
|
|
|
|
|
|
|
|
async function buildPastCalls(data) {
|
|
|
|
var timeEt = await parseTime(data.at)
|
|
|
|
return `<tr>
|
|
|
|
<td class="detail-name detail-table-content">${data.locationName}</td>
|
|
|
|
<td class="detail-table-content">${data.st}</td>
|
|
|
|
<td class="detail-table-content ${timeEt.changed}">${timeEt.data}</td>
|
2023-01-22 12:37:25 +00:00
|
|
|
</tr>`
|
2022-12-19 23:52:27 +00:00
|
|
|
}
|