first commit
This commit is contained in:
commit
3f68f9ae72
25 changed files with 8803 additions and 0 deletions
61
load-app.js
Normal file
61
load-app.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
import show_error from './show-error.mjs';
|
||||
async function init_app() {
|
||||
|
||||
const params = new URLSearchParams(location.search);
|
||||
const station = params.get('station');
|
||||
|
||||
|
||||
const station_names = await (await fetch('stations.json')).json();
|
||||
const station_directions = await (await fetch('station-directions.json')).json();
|
||||
const station_latlons = await (await fetch('station-latlons.json')).json();
|
||||
|
||||
const platforms = await (await fetch('platforms.json')).json();
|
||||
|
||||
station_names['MON'] = 'Monument';
|
||||
station_latlons['MON'] = station_latlons['MTW'];
|
||||
delete station_names['MTW'];
|
||||
delete station_names['MTS'];
|
||||
delete station_latlons['MTW'];
|
||||
delete station_latlons['MTS'];
|
||||
Object.entries(platforms).forEach(([station_key,platforms]) => {
|
||||
platforms.forEach(p => {
|
||||
p.station_key = station_key;
|
||||
});
|
||||
})
|
||||
platforms['MON'] = platforms['MTS'].concat(platforms['MTW']);
|
||||
station_directions['MON'] = Object.assign({}, station_directions['MTS'], station_directions['MTW']);
|
||||
|
||||
const stations = Object.keys(station_names).map(key => {
|
||||
return {key, name: station_names[key], platforms: platforms[key], directions: station_directions[key], latlon: station_latlons[key]};
|
||||
});
|
||||
|
||||
const lines = await (await fetch('lines.json')).json();
|
||||
Object.values(lines).map(stops => stops.forEach(stop => {
|
||||
stop.key = (stop.key == 'MTS' || stop.key == 'MTW') ? 'MON' : stop.key;
|
||||
}))
|
||||
const compilation_error = await show_error;
|
||||
if(compilation_error) {
|
||||
return;
|
||||
}
|
||||
const app = Elm.App.init({node: document.body, flags: {stations, lines, station}});
|
||||
|
||||
app.ports.request_data.subscribe(async ([station,platformNumber]) => {
|
||||
const url = `cgi-bin/platform_data.py?station=${station}&platform=${platformNumber}`;
|
||||
const data = await (await fetch(url)).json();
|
||||
station = (station == 'MTS' || station == 'MTW') ? 'MON' : station;
|
||||
const out = {time: (new Date()).toISOString(), station, platformNumber, data}
|
||||
app.ports.receive_platform_data.send(out);
|
||||
});
|
||||
|
||||
app.ports.request_location.subscribe(async () => {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(r) => {
|
||||
console.log(r);
|
||||
app.ports.receive_location.send(r);
|
||||
},
|
||||
(e) => console.error(e)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
init_app();
|
Loading…
Add table
Add a link
Reference in a new issue