diff --git a/UpNext.md b/UpNext.md index 43cdfaf..e96a50b 100644 --- a/UpNext.md +++ b/UpNext.md @@ -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 \ No newline at end of file +* Rewrite sanitizing functions to remove external dependancy. \ No newline at end of file diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index 78ad6b1..0f1c9e0 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -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; } diff --git a/static/board.html b/static/board.html index 79414ff..a5c1c04 100644 --- a/static/board.html +++ b/static/board.html @@ -60,9 +60,10 @@ Exp Dep. -
-

There are no scheduled train services from this station

-
+ + +
+

There are no scheduled train services from this station

diff --git a/static/index.html b/static/index.html index 32a9728..194f41c 100644 --- a/static/index.html +++ b/static/index.html @@ -62,7 +62,7 @@ diff --git a/static/js/lib.board.js b/static/js/lib.board.js index 84c4e47..e669a93 100644 --- a/static/js/lib.board.js +++ b/static/js/lib.board.js @@ -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 += `

${array[i]}

`; } - 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}` diff --git a/static/js/simple-board.js b/static/js/simple-board.js index 22c2084..6f48549 100644 --- a/static/js/simple-board.js +++ b/static/js/simple-board.js @@ -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]) } } diff --git a/static/styles/boards.css b/static/styles/boards.css index 6619299..12c4d34 100644 --- a/static/styles/boards.css +++ b/static/styles/boards.css @@ -16,6 +16,8 @@ #no_services { width: 75%; margin: auto; + margin-top: 110px; + margin-bottom: 30px; font-size: 20px; font-weight: 900; } diff --git a/static/sw.js b/static/sw.js index 52892bb..a386707 100644 --- a/static/sw.js +++ b/static/sw.js @@ -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 = [