Add features:

- Frontend Fetch API
  - Frontend Parse Title
  - Frontend Parse Time
This commit is contained in:
Fred Boniface 2023-01-09 15:05:17 +00:00
parent 90138179e0
commit 18659bcbfb
3 changed files with 59 additions and 14 deletions

View File

@ -16,15 +16,16 @@
<body>
<div id="content">
<div id="header">
<h1 id="station_name" class="hide-when-loading">SVRNBCH</h1>
<h1 id="station_name"></h1>
<p class="header-right">Data from:</p>
<p id="fetch_time" class="header-right">Loading...</p>
</div>
<div id="loading">
<div class="spinner">
</div>
<p>Loading <span id="station"></span></p>
<p>
Loading
</p>
</div>
<div id="output">

View File

@ -1,12 +1,56 @@
async function getStation(search){
var params = new URLSearchParams(search);
var stn = params.get('stn')
console.log(`Searching for ${stn}`)
return stn;
init()
/* Fetch response from {window.location.server-addr}:{port}/api/v1/ldb/validation/{stn} */
/* Supporting Functions */
async function init() {
var stn = await getQuery("stn");
console.log(`Looking up: ${stn}`);
var sv = await getQuery("sv");
console.log(`Staff Verstion: ${sv}`);
if (sv === 'true') {
console.log("Staff Version not supported yet")
} else {
try {
var data = await publicLdb(stn)
console.log("Fetched LDB Data")
} catch (err) {
var data = null
console.log("Unable to fetch LDB data")
} finally {
console.log(data)
parseLdb(data)
}
}
}
async function getStaff(search){
var params = new URLSearchParams(search);
var sv = params.get('sv')
return sv;
async function getQuery(param) {
var params = new URLSearchParams(window.location.search)
var query = params.get(param)
if (query) {
return query
} else {
return 'false'
}
}
async function publicLdb(stn) {
var url = `http://${window.location.host}/api/v1/ldb/${stn}`;
var resp = await fetch(url);
return await resp.json();
}
async function setHeaders(title,time){
var prefix = `OwlBoard - `
document.title = `${prefix}${title}`
document.getElementById("station_name").innerHTML = title
}
async function parseLdb(data) {
var stationName = data.GetStationBoardResult.locationName;
console.log(`Data ready for ${stationName}`);
var generateTime = await data.GetStationBoardResult.generatedAt;
console.log(`Data prepared at ${generateTime}`)
setHeaders(stationName, generateTime);
}

View File

@ -51,9 +51,9 @@
#station_name {
position: absolute;
font-size: 15pt;
left: 10px;
top: -15px;
text-transform: uppercase;
text-transform: capitalize;
}
.header-right {