new preset interface

master
cheetah 2 years ago
parent adf0234323
commit b69e7f9c76

@ -15,6 +15,7 @@
<v-app-bar app>
<v-toolbar-title>Testalarm Configuration</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
<v-checkbox label="Expert Mode" v-model="EXPERTMODE"></v-checkbox>
</v-app-bar>
<v-content>
@ -61,47 +62,29 @@
</v-col>
<hr/>
</v-col>
<v-col cols="6" sm="6" md="4">
<v-row>
<v-col cols="6" sm="6" md="6">
<v-text-field v-model="alarmConfig.name" label="Name"></v-text-field>
<v-autocomplete
v-model="alarmConfig.preset"
:items="presetSearchItems"
:loading="!presetSearchItems.length > 0"
color="white"
hide-no-data
dense
label="Profile"
placeholder="Start typing to Search"
prepend-icon="mdi-database-search"
></v-autocomplete>
</v-col>
<v-col cols="6" sm="6" md="6">
<v-textarea v-model="alarmConfig.payload" label="Message"></v-textarea>
</v-col>
<v-col>
<v-col cols="12" sm="12" md="6">
<v-select :items="pagerTypes" v-model="alarmConfig.params.type"
item-text="k" item-value="v" label="Delivery Type"></v-select>
</v-col>
<v-row>
<v-col cols="12" sm="12" md="6">
<v-select :items="deviceType"
v-model="alarmConfig.params.routing.device" item-text="k"
item-value="v" label="Device"></v-select>
</v-col>
</v-row>
<b>Delivery Targets:</b>
<v-btn color="success" @click="addDeliveryTarget(index)">Add</v-btn>
<v-row v-for="(connector, index) in alarmConfig.params.routing.connectors"
:key="index">
<v-col cols="6" sm="4" md="4">
<v-select :items="connectorTypes" v-model="connector[0]" item-text="k"
item-value="v" label="Gateway"></v-select>
</v-col>
<v-col cols="6" sm="4" md="4">
<v-text-field v-model="connector[1]" label="Call ID"></v-text-field>
</v-col>
<v-col cols="6" sm="4" md="4">
<v-btn color="error"
@click="alarmConfig.params.routing.connectors.splice(index, 1)"
icon>
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-col>
</v-row>
</v-col>
</v-card>
</v-row>
<v-row>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
</v-row>
</v-container>
</v-tab-item>
<v-tab-item key="notificationConfig">
@ -112,9 +95,6 @@
<v-text-field label="Daemon Endpoint URL" v-model="configData.pager.url">
</v-text-field>
</v-col>
<v-row>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
</v-row>
</v-container>
</v-tab-item>
@ -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

@ -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)

Loading…
Cancel
Save