new version handling; alternative search strings

This commit is contained in:
kritzl 2024-06-07 12:59:09 +02:00
parent 9cfcfaee67
commit 136eabc29b

View file

@ -6,8 +6,13 @@ let geolocationPermission = false;
let geolocation = null;
const openStations = new Set();
let sortByDistance = false;
const version = '0.5.0'
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
}));
}
@ -654,12 +687,15 @@ function filterData() {
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;
})
const filtered = !(matchesSearch && matchesType);
const filtered = !((matchesName || matchesSearchTarget) && matchesType);
document.querySelector(`#station_${stationIndex}`).classList.toggle('hidden', filtered);
if (filtered) filteredStations++;
}
@ -692,11 +728,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')