diff --git a/elevators.js b/elevators.js
index ea999f4..02c98f1 100644
--- a/elevators.js
+++ b/elevators.js
@@ -6,8 +6,13 @@ let geolocationPermission = false;
let geolocation = null;
const openStations = new Set();
let sortByDistance = false;
+const version = '0.5.1'
+const minorVersion = version.split('.').splice(0, 2).join('.');
+const numberFormat = new Intl.NumberFormat('de-DE', {
+ maximumFractionDigits: 1
+});
-const substituteCoordinates = [
+const substituteData = [
{
name: 'Borgweg (Stadtpark)',
coordinates: [53.5907696, 10.0147719],
@@ -24,6 +29,26 @@ const substituteCoordinates = [
name: 'Hagenbecks Tierpark',
coordinates: [53.5925874, 9.9440359],
},
+ {
+ name: 'Hamburg Hbf',
+ searchTarget: "Hauptbahnhof",
+ },
+ {
+ name: 'Jungfernstieg',
+ searchTarget: "Rathaus",
+ },
+ {
+ name: 'Rathaus',
+ searchTarget: "Jungfernstieg",
+ },
+ {
+ name: 'Stephansplatz (Oper/CCH)',
+ searchTarget: "Dammtor (Messe/CCH)",
+ },
+ {
+ name: 'Dammtor (Messe/CCH)',
+ searchTarget: "Stephansplatz (Oper/CCH)",
+ },
{
name: 'Hauptbahnhof Nord',
coordinates: [53.5541197, 10.0061270],
@@ -89,6 +114,13 @@ async function loadElevators() {
for (const station of stations) {
const stationName = station['mainSubStation']['stationName'];
const stationComment = station['mainSubStation']['comment'];
+ let searchTarget = undefined;
+
+ const substitute = substituteData.filter(subs => subs.name === stationName)
+
+ if (substitute.length && substitute[0].hasOwnProperty('searchTarget')) {
+ searchTarget = substitute[0].searchTarget;
+ }
const lines = new Set();
const elevators = [];
for (const elevatorKey of Object.keys(station.elevators)) {
@@ -157,6 +189,7 @@ async function loadElevators() {
internalData.stations[stationIndex++] = {
name: stationName,
comment: stationComment,
+ searchTarget: searchTarget,
state: stationState,
lines: stationLines,
types: stationTypes,
@@ -165,7 +198,7 @@ async function loadElevators() {
}
localStorage.setItem("internal_data", JSON.stringify({
- api: 'v1',
+ api: minorVersion,
...internalData
}));
}
@@ -217,20 +250,20 @@ async function loadOsmData() {
}
if (!internalData.stations[stationIndex].hasOwnProperty('coordinates')) {
- const substitute = substituteCoordinates.filter(subs => subs.name === internalData.stations[stationIndex].name)
- if (substitute.length) {
+ const substitute = substituteData.filter(subs => subs.name === internalData.stations[stationIndex].name)
+ if (substitute.length && substitute.hasOwnProperty('coordinates')) {
internalData.stations[stationIndex]['coordinates'] = substitute[0].coordinates;
}
}
}
localStorage.setItem("osm_data", JSON.stringify({
- api: 'v1',
+ api: minorVersion,
lastUpdate: new Date(),
nodes: osmNodes
}));
localStorage.setItem("internal_data", JSON.stringify({
- api: 'v1',
+ api: minorVersion,
...internalData
}));
}
@@ -370,7 +403,17 @@ function renderData(location = null) {
document.querySelector('#filters').classList.remove('hidden');
document.querySelector('#initialLoad').classList.add('hidden');
const dateContainer = document.querySelector('#lastUpdated');
- dateContainer.innerHTML = dateTimeStyle.format(new Date(internalData.lastUpdate));
+ const oldDataWarning = document.querySelector('#oldDataWarning');
+
+ const lastUpdate = new Date(internalData.lastUpdate);
+ const now = new Date();
+ dateContainer.innerHTML = dateTimeStyle.format(lastUpdate);
+ oldDataWarning.classList.add('hidden');
+ if (now - lastUpdate > 86400 * 1000) {
+ const days = numberFormat.format((now - lastUpdate) / (86400 * 1000));
+ oldDataWarning.classList.remove('hidden');
+ oldDataWarning.innerHTML = `Daten ${days} Tag${days !== '1' ? 'e' : ''} alt!`;
+ }
const listContainer = document.querySelector('#stationList');
//clear list before update
@@ -646,22 +689,25 @@ function filterData() {
const typeA = document.querySelector('button.typeChip[data-type="A"]');
const typeR = document.querySelector('button.typeChip[data-type="R"]');
const activeTypes = [];
- if(typeU.dataset.pressed === 'true') activeTypes.push('U');
- if(typeS.dataset.pressed === 'true') activeTypes.push('S');
- if(typeA.dataset.pressed === 'true') activeTypes.push('A');
- if(typeR.dataset.pressed === 'true') activeTypes.push('R');
+ if (typeU.dataset.pressed === 'true') activeTypes.push('U');
+ if (typeS.dataset.pressed === 'true') activeTypes.push('S');
+ if (typeA.dataset.pressed === 'true') activeTypes.push('A');
+ if (typeR.dataset.pressed === 'true') activeTypes.push('R');
const stationCount = internalData.stations.length;
let filteredStations = 0;
if (internalData) {
for (const stationIndex in internalData.stations) {
- const matchesSearch = internalData.stations[stationIndex].name.toLowerCase().search(searchString.toLowerCase()) >= 0;
+ const matchesName = internalData.stations[stationIndex].name.toLowerCase().search(searchString.toLowerCase()) >= 0;
+ const matchesSearchTarget = internalData.stations[stationIndex].hasOwnProperty('searchTarget')
+ ? internalData.stations[stationIndex].searchTarget.toLowerCase().search(searchString.toLowerCase()) >= 0
+ : false;
let matchesType = false;
internalData.stations[stationIndex].types.forEach(type => {
- if(activeTypes.includes(type)) matchesType = true;
+ if (activeTypes.includes(type)) matchesType = true;
})
- const filtered = !(matchesSearch && matchesType);
+ const filtered = !((matchesName || matchesSearchTarget) && matchesType);
document.querySelector(`#station_${stationIndex}`).classList.toggle('hidden', filtered);
- if(filtered) filteredStations++;
+ if (filtered) filteredStations++;
}
document.querySelector('#stationCount').innerHTML = stationCount;
@@ -692,11 +738,14 @@ function closeDialog(selector) {
document.querySelector(selector).classList.add('hidden')
}
+// set version
+document.querySelector('#version').innerHTML = `v${version}`;
+
// data api version check
const check_internal = JSON.parse(localStorage.getItem("internal_data"));
const check_osm = JSON.parse(localStorage.getItem("osm_data"));
-if (check_internal === null || check_internal.hasOwnProperty('api') && check_internal.api === 'v1') {
- if (check_osm === null || check_osm.hasOwnProperty('api') && check_osm.api === 'v1') {
+if (check_internal === null || check_internal.hasOwnProperty('api') && check_internal.api === minorVersion) {
+ if (check_osm === null || check_osm.hasOwnProperty('api') && check_osm.api === minorVersion) {
renderData();
} else {
console.log('osm_data: version mismatch')
diff --git a/index.html b/index.html
index b676958..4af499c 100644
--- a/index.html
+++ b/index.html
@@ -28,10 +28,11 @@
Liste aller Stationen mit Aufzug im HVV
Stand:
+
+
@@ -65,7 +66,7 @@