diff --git a/js/train-detail.js b/js/train-detail.js new file mode 100644 index 0000000..efc2277 --- /dev/null +++ b/js/train-detail.js @@ -0,0 +1,68 @@ +versionDisplay() + +let data // Maybe this is a bad idea? + +init() + +async function init() { + const headcode = await getQuery('headcode') + if (headcode == 'false') { + parse([]) // Pass an empty array to parse() + } + const res = await get(headcode) + parse(res) +} + +async function get(headcode) { + const apiPath = `train/headcode/today/${headcode}` + data = await getApi(apiPath, auth = true) + if (!data || typeof data !== 'number') { + log('train-detail.get: Status: ' + data, 'ERR') + return [] + } + log(data, 'DBUG') + return data +} + +async function parse(data) { + if (data.length === 1) { + document.getElementById('train_options').style = 'display:none;' + displayOne(data[0]) + } + displayOptions(data) +} + +async function displayOptions(data) { + return data +} + +async function displayOne(object) { + // Display a single service immediately + const dataHead = ` +

${object['headcode']}

+

${object['pis']}

+ ` + let publicStops = [] + for (const stop of object['stops']) { + if (stop['isPublic']) { + publicStops.push(stop) + } + } + console.log(publicStops) + stopRows = '' + for (const stop of publicStops) { + stopRows += await createStopTableRow(stop) + } + const displayBox = document.getElementById('train_data') + displayBox.insertAdjacentHTML('beforeend', dataHead + stopRows) +} + +async function createStopTableRow(stop) { + return ` + + ${stop['TIPLOC']} + ${stop['arrivalTime']} + ${stop['departureTime']} + + ` +} \ No newline at end of file diff --git a/train-detail.html b/train-detail.html new file mode 100644 index 0000000..77bfd58 --- /dev/null +++ b/train-detail.html @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + OwlBoard - Train Details + + + + + +
+ + + + Home + + +
+ + + + + + OwlBoard Logo + +

Train Details

+
+ +
+
+ +
+ + + + + \ No newline at end of file