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) - "corpus": NLCDESC(TEXT)
* Build metrics page * Build metrics page
* Responsive text sizes for boards. * Responsive text sizes for boards.
* Undo changed to make everything an array - frontend code to handle this.
* Explore compression of API Responses
## Backend: ## Backend:
* Rewrite sanitizing functions to remove external dependancy. * Rewrite sanitizing functions to remove external dependancy.
* Undo changed to make everything an array - frontend code to handle this.
* Explore compression of API Responses

View File

@ -28,29 +28,6 @@ async function get(body, id){
log.out(`ldbService.get: Error, Unable to find CRS: ${err}`) 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.'}; 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; return data;
} }

View File

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

View File

@ -62,7 +62,7 @@
<!-- Footer --> <!-- Footer -->
<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> </footer>
</body> </body>

View File

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

View File

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

View File

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

View File

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