Browse Source

Add train notes

master
Kenneth Bruen 2 years ago
parent
commit
c60c20a736
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 2
      items.js
  2. 2
      sw.js
  3. 11
      view-train.css
  4. 31
      view-train.js

2
items.js

@ -15,6 +15,7 @@ function nav(offset) {
} }
function handleKeyDown(e) { function handleKeyDown(e) {
if (e.target.classList.contains('items')) {
switch (e.key) { switch (e.key) {
case 'ArrowUp': case 'ArrowUp':
e.preventDefault() e.preventDefault()
@ -27,6 +28,7 @@ function handleKeyDown(e) {
nav(1) nav(1)
break break
} }
}
} }
window.addEventListener('load', function (e) { window.addEventListener('load', function (e) {

2
sw.js

@ -1,4 +1,4 @@
const VERSION = 'v5' const VERSION = 'v6'
const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/' const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/'
const API_TRAINS = `${API_ORIGIN}v3/trains` const API_TRAINS = `${API_ORIGIN}v3/trains`
const API_STATIONS = `${API_ORIGIN}v2/stations` const API_STATIONS = `${API_ORIGIN}v2/stations`

11
view-train.css

@ -38,7 +38,8 @@
grid-template-areas: grid-template-areas:
"arr name dep" "arr name dep"
"arr km dep" "arr km dep"
"arr platform dep"; "arr platform dep"
"arr notes dep";
padding: 4px 0; padding: 4px 0;
} }
@ -87,6 +88,14 @@
grid-area: platform; grid-area: platform;
} }
.stationItem .notes {
grid-area: notes;
}
.stationItem .note {
text-align: center;
}
.last-refreshed { .last-refreshed {
font-size: 12px; font-size: 12px;
text-transform: none; text-transform: none;

31
view-train.js

@ -257,6 +257,37 @@ function onTrainData(data) {
stationPlatform.textContent = `platform ${station.platform}` stationPlatform.textContent = `platform ${station.platform}`
stationPlatform.classList.add('thi', 'platform') stationPlatform.classList.add('thi', 'platform')
} }
if (station.notes && station.notes.length > 0) {
var stationNotes = document.createElement('div')
stationItem.appendChild(stationNotes)
stationNotes.classList.add('notes')
station.notes.forEach(function (note) {
var noteP = document.createElement('p')
stationNotes.appendChild(noteP)
noteP.classList.add('note', 'thi')
switch (note.kind) {
case 'departsAs': {
noteP.textContent = `Train departs as ${note.rank} ${note.number}`
break
}
case 'detachingWagons': {
noteP.textContent = `Detaching wagons to ${note.station}`
break
}
case 'receivingWagons': {
noteP.textContent = `Receiving wagons from ${note.station}`
break
}
case 'trainNumberChange': {
noteP.textContent = `Train changes number to ${note.rank} ${note.number}`
break
}
}
})
}
}) })
lastSuccessfulFetch = new Date() lastSuccessfulFetch = new Date()

Loading…
Cancel
Save