From b69e7f9c76f9cd725658e423d15a031092d45f8b Mon Sep 17 00:00:00 2001 From: cheetah Date: Thu, 1 Dec 2022 13:01:11 +0100 Subject: [PATCH] new preset interface --- html/index.html | 80 ++++++++++++++++++++++--------------------------- index.js | 23 +++++++++----- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/html/index.html b/html/index.html index 439e8c0..f6727a9 100644 --- a/html/index.html +++ b/html/index.html @@ -15,6 +15,7 @@ Testalarm Configuration + Store & Restart @@ -31,8 +32,8 @@

Targets:

- mdi-plus - + mdi-plus + @@ -61,47 +62,29 @@
- - - - - - - + + + + - - - - - - Delivery Targets: - Add - - - - - - - - - - mdi-delete - - - - + + + + + +
- - Store & Restart - @@ -112,10 +95,7 @@ - - - Store & Restart - + @@ -177,12 +157,24 @@ "menuSupport": false, "deliveryModes": [] }, + presetSearchItems: [], } }, 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 diff --git a/index.js b/index.js index 50c5d21..5e8ad71 100644 --- a/index.js +++ b/index.js @@ -19,16 +19,16 @@ appConfig.use(express.static(__dirname + '/node_modules/@mdi/font')) async function minuteCheck() { let timeRN = moment() - console.log('timeRN', timeRN.format("HH:mm")) + //console.log('timeRN', timeRN.format("HH:mm")) for (let alarm of config.alarms) { let alarmTime = moment() .hours(+alarm.alarmTime.split(':') [ 0 ]) .minutes(+alarm.alarmTime.split(':') [ 1 ]) let secDiff = alarmTime.diff(timeRN, 'seconds') // - console.log(alarmTime.format("HH:mm"), secDiff) + //console.log(alarmTime.format("HH:mm"), secDiff) if (alarmTime.format("HH:mm") == timeRN.format("HH:mm")) { - console.log("TRIGGER", alarm.alarmSchedulingMode) + //console.log("TRIGGER", alarm.alarmSchedulingMode) let alarmTrigger = false switch (alarm.alarmSchedulingMode) { case 'monthlyAtSpecificDate': @@ -41,15 +41,15 @@ async function minuteCheck() { while (monthFirstDay.weekday() != alarm.firstOccWeekday) monthFirstDay.add(1, 'day') thisMonthFirstWeekDayOccurance = monthFirstDay.date() - console.log(monthFirstDay.date(), monthFirstDay.weekday()) - console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance) + //console.log(monthFirstDay.date(), monthFirstDay.weekday()) + //console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance) alarmTrigger = (timeRN.date() == thisMonthFirstWeekDayOccurance) break; case 'weekly': for (let weekDayKey of Object.keys(alarm.weekDay)) { - console.log(weekDayKey, alarm.weekDay) + //console.log(weekDayKey, alarm.weekDay) if (+weekDayKey === +timeRN.weekday()) { - console.log('weekday match', 'result is', alarm.weekDay[weekDayKey] ) + //console.log('weekday match', 'result is', alarm.weekDay[weekDayKey] ) alarmTrigger = alarm.weekDay[weekDayKey] break; } @@ -57,7 +57,10 @@ async function minuteCheck() { break; } if (alarmTrigger === true) { - await axios.post(config.pager.url, Object.assign({ ...alarm.params }, { payload: alarm.payload })) + await axios.post(config.pager.url, Object.assign( !!alarm.preset + ? { ...alarm.params } // backward compatibility + : { preset: alarm.preset } + , { payload: alarm.payload })) } } } @@ -75,6 +78,10 @@ main() 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.alarms)) return res.status(403).json(false) if (!(!!req.body.pager)) return res.status(403).json(false)