From af63266744c8080f2282ec056c2e2e48fa5ee800 Mon Sep 17 00:00:00 2001 From: cheetah Date: Sat, 3 Dec 2022 13:53:42 +0100 Subject: [PATCH] added new level selections and profile selection --- html/index.html | 188 ++++++++++++++++++++++++++++++------------------ index.js | 21 ++++-- 2 files changed, 134 insertions(+), 75 deletions(-) diff --git a/html/index.html b/html/index.html index f990bff..0a3981a 100644 --- a/html/index.html +++ b/html/index.html @@ -15,6 +15,7 @@ DWD Module Configuration + Store & Restart @@ -22,41 +23,52 @@ Regions - Notification Configuration + Notification Configuration - +

Regions:

- mdi-plus Add + + mdi-plus + - - - - - - - - - - - - - - mdi-delete - + + + + + + + + + - - - Store & Restart + + + + + + + mdi-delete +
@@ -64,33 +76,9 @@ Routing Paramters: - - - - - - - - - - - - - Delivery Targets: - Add - - - - - - + + - - mdi-delete - - - - Store & Restart @@ -102,7 +90,7 @@
Hilfe (de)
DWD ID auf WettWarn generieren und 3 stelligen Code einfügen - + Warnstufen
@@ -122,28 +110,6 @@ return { EXPERTMODE: false, configTab: null, - pagerTypes: [ - {k: 'Simple', v: 'simple'}, - {k: 'Duplex', v: 'duplex'}, - ], - deviceType: [ - {k: 'Generic', v: 'generic'}, - {k: 'Birdy Slim (IoT)', v: 'birdyslim'}, - ], - connectorTypes: [ - {k: 'Dummy', v: 'dummy'}, - {k: 'POCSAG GW', v: 'pocsag'}, - {k: 'DAPNET', v: 'dapnet'}, - - {k: 'e*Cityruf inetgw', v: 'ecityruf'}, - {k: 'e*Cityruf Puppeteer', v: 'em-p-cityruf'}, - {k: 'e*Cityruf alertManager', v: 'em-a-cityruf'}, - - {k: 'e*2wayS Puppeteer', v: 'em-p-twoways'}, - {k: 'e*2wayS alertManager', v: 'em-a-twoways'}, - - {k: 'LoRaWAN TTNv3', v: 'lorawan'}, - ], configData: { "pager": { "url": "", @@ -158,12 +124,93 @@ "menuSupport": false, "regions": [] }, + presetSearchItems: [], + dwdTypes1: [ + { n: 4, k: 'Wind / Sturm / Orkan', u: 'wind_storm', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 1 or higher', value: 1 }, + { text: 'Level 2 or higher', value: 2 }, + { text: 'Level 3 or higher', value: 3 }, + { text: 'Level 4', value: 4 }, + ] + }, + { n: 4, k: 'Gewitter', u: 'thunderstorm', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 1 or higher', value: 1 }, + { text: 'Level 2 or higher', value: 2 }, + { text: 'Level 3 or higher', value: 3 }, + { text: 'Level 4', value: 4 }, + ] + }, + { n: 4, k: 'Starkregen', u: 'rain1', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 2 or higher', value: 2 }, + { text: 'Level 3 or higher', value: 3 }, + { text: 'Level 4', value: 4 }, + ] + }, + { n: 4, k: 'Dauerregen', u: 'rain2', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 2 or higher', value: 2 }, + { text: 'Level 3 or higher', value: 3 }, + { text: 'Level 4', value: 4 }, + ] + }, + ], + dwdTypes2: [ + { n: 4, k: 'Schneefall/-verwehungen', u: 'snow', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 1 or higher', value: 1 }, + { text: 'Level 2 or higher', value: 2 }, + { text: 'Level 3 or higher', value: 3 }, + { text: 'Level 4', value: 4 }, + ] + }, + { n: 4, k: 'Glaette', u: 'ice', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 1 or higher', value: 1 }, + { text: 'Level 2 or higher', value: 2 }, + { text: 'Level 3 or higher', value: 3 }, + { text: 'Level 4', value: 4 }, + ] + }, + { n: 2, k: 'Frost', u: 'frost', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 1 or higher', value: 1 }, + { text: 'Level 2', value: 2 }, + ] + }, + { n: 1, k: 'Nebel', u: 'fog', + i: [ + { text: 'ignore', value: 666 }, + { text: 'Level 1', value: 1 }, + ] + }, + ], } }, created() { + this.loadPresets() this.loadConfig() }, methods: { + loadPresets() { + this.$http.get('/api/deliveryPresets') + .then(response => { + this.presetSearchItems = response.body.map(x => { return { + text: x.name, + value: x.key, + }}) + }, response => { + }) + }, loadConfig() { this.$http.get('/config').then(response => { const newConfig = response.body @@ -192,6 +239,7 @@ this.configData.regions.push({ name: "", active: true, + levels: [], dwdID: "", }) }, diff --git a/index.js b/index.js index 7b064ae..51798a3 100644 --- a/index.js +++ b/index.js @@ -45,9 +45,16 @@ function replaceUmlaute(str) { ); } -async function sendPage(payload) { - console.log(payload) - return (await axios.post(config.pager.url, Object.assign({ ...config.pager.params }, { payload }))) +async function sendPage(preset, payload) { + console.log(preset, payload) + try { + + await axios.post(new URL(config.pager.url).origin + '/api/message/' + (!!preset ? 'preset' : 'advanced'), Object.assign( !!preset + ? { preset } + : { ...config.pager.params } // backward compatibility + , { payload: payload })) + +} catch (e) {} } async function checkDWD() { for (region of config.regions) { @@ -68,14 +75,14 @@ async function checkDWD() { if (!!stateMachine[ region.dwdID ]) { if (stateMachine [ region.dwdID ] != msg) { - await sendPage( msg ) + await sendPage( region.preset, msg ) stateMachine [ region.dwdID ] = msg } } else { stateMachine [ region.dwdID ] = msg // if initial state is unknown and we have an alert, send it anyway if (msg.indexOf('Es sind keine Warnungen') == -1) { - await sendPage( msg ) + await sendPage( region.preset, msg ) } } } @@ -106,6 +113,10 @@ appConfig.use(express.static(__dirname + '/node_modules/@mdi/font')) appConfig.get('/config', async (req, res) => { return res.json(JSON.parse(fs.readFileSync('config.json'))) }) +appConfig.get('/api/deliveryPresets', async (req, res) => { + const presets = await axios.get(new URL(config.pager.url).origin + '/api/deliveryPresets') + return res.json(presets.data) +}) appConfig.post('/config', async (req, res) => { if (!(!!req.body.pager)) return res.status(403).json(false) if (!(!!req.body.regions)) return res.status(403).json(false)