Add features:
- Frontend Fetch API - Frontend Parse Title - Frontend Parse Time
This commit is contained in:
parent
90138179e0
commit
18659bcbfb
@ -16,15 +16,16 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<div id="header">
|
<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 class="header-right">Data from:</p>
|
||||||
<p id="fetch_time" class="header-right">Loading...</p>
|
<p id="fetch_time" class="header-right">Loading...</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="loading">
|
<div id="loading">
|
||||||
<div class="spinner">
|
<div class="spinner">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<p>Loading <span id="station"></span></p>
|
<p>
|
||||||
|
Loading
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="output">
|
<div id="output">
|
||||||
|
@ -1,12 +1,56 @@
|
|||||||
async function getStation(search){
|
init()
|
||||||
var params = new URLSearchParams(search);
|
|
||||||
var stn = params.get('stn')
|
/* Fetch response from {window.location.server-addr}:{port}/api/v1/ldb/validation/{stn} */
|
||||||
console.log(`Searching for ${stn}`)
|
|
||||||
return 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){
|
async function getQuery(param) {
|
||||||
var params = new URLSearchParams(search);
|
var params = new URLSearchParams(window.location.search)
|
||||||
var sv = params.get('sv')
|
var query = params.get(param)
|
||||||
return sv;
|
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);
|
||||||
}
|
}
|
@ -51,9 +51,9 @@
|
|||||||
|
|
||||||
#station_name {
|
#station_name {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
font-size: 15pt;
|
||||||
left: 10px;
|
left: 10px;
|
||||||
top: -15px;
|
text-transform: capitalize;
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-right {
|
.header-right {
|
||||||
|
Reference in New Issue
Block a user