diff --git a/.gitignore b/.gitignore index b512c09..a7c122d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -node_modules \ No newline at end of file +node_modules +eventmapper_config.json +data \ No newline at end of file diff --git a/assets/scripts/script.js b/assets/scripts/script.js index e69de29..ddffa16 100644 --- a/assets/scripts/script.js +++ b/assets/scripts/script.js @@ -0,0 +1,8 @@ +import "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"; // window.L + +var map = L.map('leaflet-map').setView([0, 0], 2); + +L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { + maxZoom: 19, + attribution: '© OpenStreetMap' +}).addTo(map); \ No newline at end of file diff --git a/assets/styles/styles.css b/assets/styles/styles.css index e69de29..58e7e04 100644 --- a/assets/styles/styles.css +++ b/assets/styles/styles.css @@ -0,0 +1,14 @@ +body, html { + margin: 0; + height: 100vh; + width: 100vw; + box-sizing: border-box; + overflow: hidden; +} + +#leaflet-map { + display: inline-block; + box-sizing: border-box; + height: 100%; + width: 100%; +} \ No newline at end of file diff --git a/modules/extern/ical_moz.js b/modules/extern/ical_moz.js deleted file mode 100644 index c75ed9b..0000000 --- a/modules/extern/ical_moz.js +++ /dev/null @@ -1,9534 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * Portions Copyright (C) Philipp Kewisch, 2021 */ - -/* jshint ignore:start */ -export var ICAL; -(function () { - /* istanbul ignore next */ - if (typeof module === 'object') { - // CommonJS, where exports may be different each time. - ICAL = module.exports; - } else if (typeof HTMLScriptElement !== 'undefined' && 'noModule' in HTMLScriptElement.prototype) { - // Until we use ES6 exports, using - + diff --git a/scripts/server.js b/scripts/server.js index e69de29..acbe08b 100644 --- a/scripts/server.js +++ b/scripts/server.js @@ -0,0 +1,104 @@ +import express from 'express'; + +import config from "../eventmapper_config.json" with { type: "json" }; + +const app = express(); + +app.use("/assets", express.static('assets')); + +app.use("/", express.static('pages')); + +app.use("/dataServer", express.static('data')); // Example data file-server + +app.get('/data/:lang/events', async (req, res) => { + // Get events + let eventsReq = await fetch(new URL("events/events.json", config.data_url)); + let events; + if (eventsReq.ok) + events = await eventsReq.json(); + else + return res.status(400).send("Bad Request"); + + // Get localization + let l10nReq = await fetch(new URL(`localization/${req.params.lang}.json`, config.data_url)); + let l10n; + if (l10nReq.ok) + l10n = await l10nReq.json(); + else + return res.status(404).send("Localization not found!"); + + // Merge events and localization + const merged = events.map(event => { + const localizationKey = l10n.__events[event.id]; + return { + ...event, + ...localizationKey + }; + }); + + return res.send(merged); +}) + +app.get('/data/:lang/map', async (req, res) => { + // Get layers + let layersReq = await fetch(new URL("map/layers.json", config.data_url)); + let layers; + if (layersReq.ok) + layers = await layersReq.json(); + else + return res.status(400).send("Bad Request"); + + // Get localization + let l10nReq = await fetch(new URL(`localization/${req.params.lang}.json`, config.data_url)); + let l10n; + if (l10nReq.ok) + l10n = await l10nReq.json(); + else + return res.status(404).send("Localization not found!"); + + // Merge layers and localization + const merged = layers.map(layer => { + const localizationKey = l10n.__layers[layer.id]; + return { + ...layer, + ...localizationKey + }; + }); + + return res.send(merged); +}) + +app.get('/data/:lang/map/:layer', async (req, res) => { + // Get rooms + let roomsReq = await fetch(new URL(`map/${req.params.layer}.json`, config.data_url)); + let rooms; + if (roomsReq.ok) + rooms = await roomsReq.json(); + else + return res.status(400).send("Bad Request"); + + // Get localization + let l10nReq = await fetch(new URL(`localization/${req.params.lang}.json`, config.data_url)); + let l10n; + if (l10nReq.ok) + l10n = await l10nReq.json(); + else + return res.status(404).send("Localization not found!"); + + // Merge rooms and localization + const merged = rooms.map(room => { + const localizationKey = l10n.__rooms[room.id]; + return { + ...room, + ...localizationKey + }; + }); + + return res.send(merged); +}) + +app.listen(config.port, () => { + const listeningURL = new URL("http://localhost/"); + listeningURL.port = config.port; + console.log(`Example app listening on ${listeningURL.toString()}`) +}) \ No newline at end of file