FullStack: makeArray function moved to frontend

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-02-03 20:43:03 +00:00
parent 52acd5c61f
commit f25d0648c7
8 changed files with 41 additions and 60 deletions

View File

@ -25,9 +25,9 @@
- "corpus": NLCDESC(TEXT)
* Build metrics page
* Responsive text sizes for boards.
* Undo changed to make everything an array - frontend code to handle this.
* Explore compression of API Responses
## Backend:
* Rewrite sanitizing functions to remove external dependancy.
* Undo changed to make everything an array - frontend code to handle this.
* Explore compression of API Responses
* Rewrite sanitizing functions to remove external dependancy.

View File

@ -28,29 +28,6 @@ async function get(body, id){
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`)
var data = {ERROR:'NOT_FOUND',description:'The entered station was not found. Please check and try again.'};
}
try {
if (data.GetStationBoardResult.nrccMessages) {
var msg = await util.cleanMessages(data.GetStationBoardResult.nrccMessages);
data.GetStationBoardResult.nrccMessages.message = msg;
}
if (data.GetStationBoardResult.trainServices && !Array.isArray(data.GetStationBoardResult.trainServices.service)) {
log.out(`ldbService.get: Transforming trainServices`)
var services = await util.cleanServices(data.GetStationBoardResult.trainServices.service)
data.GetStationBoardResult.trainServices.service = services;
}
if (data.GetStationBoardResult.ferryServices && !Array.isArray(data.GetStationBoardResult.ferryServices.service)) {
log.out(`ldbService.get: Transforming ferryServices`)
var services = await util.cleanServices(data.GetStationBoardResult.ferryServices.service)
data.GetStationBoardResult.ferryServices.service = services;
}
if (data.GetStationBoardResult.busServices && !Array.isArray(data.GetStationBoardResult.busServices.service)) {
log.out(`ldbService.get: Transforming busServices`)
var services = await util.cleanServices(data.GetStationBoardResult.busServices.service)
data.GetStationBoardResult.busServices.service = services;
}
} catch (err) {
log.out(`ldbService.get: Error transforming upstream data: ${err}`)
}
return data;
}

View File

@ -60,9 +60,10 @@
<th class="time">Exp Dep.</th>
</tr>
</table>
<div id="no_services" class="main-notice hidden-whille-loading">
<p>There are no scheduled train services from this station</p>
</div>
</div>
<div id="no_services" class="main-notice hidden-whille-loading">
<p>There are no scheduled train services from this station</p>
</div>
<div id="ferry" class="hide-when-loading secondary-table">

View File

@ -62,7 +62,7 @@
<!-- Footer -->
<footer>
<p>Created by <a href="https://fredboniface.co.uk" target="_blank" rel="noreferrer noopener">Fred Boniface</a> - 0.0.1-dev-2023020202</p>
<p>Created by <a href="https://fredboniface.co.uk" target="_blank" rel="noreferrer noopener">Fred Boniface</a> - 0.0.1-dev-2023020302</p>
</footer>
</body>

View File

@ -16,8 +16,9 @@ async function setHeaders(title,time) {
/* Display No Trains Message */
async function displayNoTrains() {
log("No Trains", "WARN")
document.getElementById('no_services').style = "display: block;";
clearLoading();
hideLoading();
}
/* Parse the value of `platform` to account for unknown platforms */
@ -95,16 +96,18 @@ async function displayAlerts(array) {
// Reset Vars
messages += `<p>${array[i]}</p>`;
}
document.getElementById("alerts_msg").insertAdjacentHTML("beforeend", messages);
if (counter == 1) {
document.getElementById("alert_bar_note").textContent = `There is ${counter} active alert`
} else if (counter > 1) {
document.getElementById("alert_bar_note").textContent = `There are ${counter} active alerts`
if (counter > 0) {
document.getElementById("alerts_msg").insertAdjacentHTML("beforeend", messages)
document.getElementById("alerts").style = "display:block"
document.getElementById("alerts_bar").style = "display:block"
if (counter == 1) {
document.getElementById("alert_bar_note").textContent = `There is ${counter} active alert`
} else if (counter > 1) {
document.getElementById("alert_bar_note").textContent = `There are ${counter} active alerts`
}
return true;
}
document.getElementById("output").style = "margin-top:195px;" /* The margin for the train table needs to be adjusted if the alert box exists. */
document.getElementById("alerts").style = "display:block"
document.getElementById("alerts_bar").style = "display:block"
return false;
}
@ -168,7 +171,6 @@ async function showCalls(id) {
var thisEtd = await parseTime(svcDetail.etd);
var thisSta = await parseTime(svcDetail.sta);
var thisEta = await parseTime(svcDetail.eta);
var thisPlat = await parsePlatform(svcDetail.plat);
/* Prepare data for this station */
if (thisStd.data != "-") {
var sTime = `${thisStd.data}`

View File

@ -57,7 +57,7 @@ async function parseLdb(data) {
// Build and Display Functions
async function buildPage(data) {
setLoadingDesc('Loading\nTrains')
setLoadingDesc('Loading\nData')
var stationName = data.GetStationBoardResult.locationName;
log(`buildPage: Data ready for ${stationName}`);
var generateTime = new Date(await data.GetStationBoardResult.generatedAt);
@ -66,51 +66,50 @@ async function buildPage(data) {
// Check for notices and if true pass to function
if (data.GetStationBoardResult.nrccMessages) {
setLoadingDesc('Loading\nAlerts')
displayAlerts(data.GetStationBoardResult.nrccMessages.message);
await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message));
}
if (typeof data.GetStationBoardResult.trainServices == 'undefined') {
displayNoTrains()
if (data.GetStationBoardResult.trainServices) {
setLoadingDesc('Loading\nTrains')
displayTrains(await makeArray(data.GetStationBoardResult.trainServices.service))
} else {
displayTrains(data)
displayNoTrains()
}
if (data.GetStationBoardResult.ferryServices) {
setLoadingDesc('Loading\nFerries')
displayFerry(data.GetStationBoardResult.ferryServices)
displayFerry(await makeArray(data.GetStationBoardResult.ferryServices.service))
}
if (data.GetStationBoardResult.busServices) {
setLoadingDesc('Loading\nBusses')
displayBus(data.GetStationBoardResult.busServices)
displayBus(await makeArray(data.GetStationBoardResult.busServices.service))
}
console.timeEnd("Loading Time")
}
async function displayTrains(data) {
log(`Inserting data in DOM`)
for(var i = 0; i < data.GetStationBoardResult.trainServices.service.length; i++) {
log(`simple-board.displayTrains: Inserting data in DOM`)
for(var i = 0; i < data.length; i++) {
// Reset Vars
var svc = data.GetStationBoardResult.trainServices.service[i];
var svc = data[i];
displayService(svc);
buildCallLists(svc);
}
hideLoading();
document.getElementById("output").style = "display:block;";
log(`Insertion complete`)
log(`simple-board.displayTrains: Insertion complete`)
}
async function displayFerry(ferrySvc) {
log(JSON.stringify(ferrySvc))
for(var i = 0; i < ferrySvc.service.length; i++) {
displayFerryService(ferrySvc.service[i])
for(var i = 0; i < ferrySvc.length; i++) {
displayFerryService(ferrySvc[i])
}
}
async function displayBus(busSvc) {
log(JSON.stringify(busSvc))
for(var i = 0; i < busSvc.service.length; i++) {
displayBusService(busSvc.service[i])
buildCallLists(busSvc.service[i])
for(var i = 0; i < busSvc.length; i++) {
displayBusService(busSvc[i])
buildCallLists(busSvc[i])
}
}

View File

@ -16,6 +16,8 @@
#no_services {
width: 75%;
margin: auto;
margin-top: 110px;
margin-bottom: 30px;
font-size: 20px;
font-weight: 900;
}

View File

@ -1,6 +1,6 @@
/* Service Worker */
const appVersion = "0.0.1-dev-2023020202"
const appVersion = "0.0.1-dev-2023020316"
const cacheName = `owlboard-${appVersion}`
const cacheIDs = [cacheName]
const cacheFiles = [