new preset interface

master
cheetah 2 years ago
parent adf0234323
commit b69e7f9c76

@ -15,6 +15,7 @@
<v-app-bar app> <v-app-bar app>
<v-toolbar-title>Testalarm Configuration</v-toolbar-title> <v-toolbar-title>Testalarm Configuration</v-toolbar-title>
<v-spacer></v-spacer> <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-checkbox label="Expert Mode" v-model="EXPERTMODE"></v-checkbox>
</v-app-bar> </v-app-bar>
<v-content> <v-content>
@ -31,8 +32,8 @@
<p>Targets:</p> <p>Targets:</p>
<v-row> <v-row>
<v-btn color="primary" fab dark small icon @click="addAlarm()"> <v-btn color="primary" fab dark small icon @click="addAlarm()">
<v-icon>mdi-plus</v-icon> <v-icon>mdi-plus</v-icon>
</v-btn> </v-btn>
</v-row> </v-row>
<v-row v-for="(alarmConfig, index) in configData.alarms" :key="alarmConfig._id"> <v-row v-for="(alarmConfig, index) in configData.alarms" :key="alarmConfig._id">
@ -61,47 +62,29 @@
</v-col> </v-col>
<hr/> <hr/>
</v-col> </v-col>
<v-col cols="6" sm="6" md="4"> <v-row>
<v-text-field v-model="alarmConfig.name" label="Name"></v-text-field> <v-col cols="6" sm="6" md="6">
<v-textarea v-model="alarmConfig.payload" label="Message"></v-textarea> <v-text-field v-model="alarmConfig.name" label="Name"></v-text-field>
</v-col> <v-autocomplete
<v-col> v-model="alarmConfig.preset"
<v-col cols="12" sm="12" md="6"> :items="presetSearchItems"
<v-select :items="pagerTypes" v-model="alarmConfig.params.type" :loading="!presetSearchItems.length > 0"
item-text="k" item-value="v" label="Delivery Type"></v-select> color="white"
hide-no-data
dense
label="Profile"
placeholder="Start typing to Search"
prepend-icon="mdi-database-search"
></v-autocomplete>
</v-col> </v-col>
<v-row> <v-col cols="6" sm="6" md="6">
<v-col cols="12" sm="12" md="6"> <v-textarea v-model="alarmConfig.payload" label="Message"></v-textarea>
<v-select :items="deviceType" </v-col>
v-model="alarmConfig.params.routing.device" item-text="k" <v-col>
item-value="v" label="Device"></v-select> </v-col>
</v-col> </v-row>
</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-card>
</v-row> </v-row>
<v-row>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
</v-row>
</v-container> </v-container>
</v-tab-item> </v-tab-item>
<v-tab-item key="notificationConfig"> <v-tab-item key="notificationConfig">
@ -112,10 +95,7 @@
<v-text-field label="Daemon Endpoint URL" v-model="configData.pager.url"> <v-text-field label="Daemon Endpoint URL" v-model="configData.pager.url">
</v-text-field> </v-text-field>
</v-col> </v-col>
</v-row>
<v-row>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
</v-row>
</v-container> </v-container>
</v-tab-item> </v-tab-item>
</v-tabs-items> </v-tabs-items>
@ -177,12 +157,24 @@
"menuSupport": false, "menuSupport": false,
"deliveryModes": [] "deliveryModes": []
}, },
presetSearchItems: [],
} }
}, },
created() { created() {
this.loadPresets()
this.loadConfig() this.loadConfig()
}, },
methods: { methods: {
loadPresets() {
this.$http.get('/api/deliveryPresets')
.then(response => {
this.presetSearchItems = response.body.map(x => { return {
text: x.name,
value: x.key,
}})
}, response => {
})
},
loadConfig() { loadConfig() {
this.$http.get('/config').then(response => { this.$http.get('/config').then(response => {
const newConfig = response.body const newConfig = response.body

@ -19,16 +19,16 @@ appConfig.use(express.static(__dirname + '/node_modules/@mdi/font'))
async function minuteCheck() { async function minuteCheck() {
let timeRN = moment() let timeRN = moment()
console.log('timeRN', timeRN.format("HH:mm")) //console.log('timeRN', timeRN.format("HH:mm"))
for (let alarm of config.alarms) { for (let alarm of config.alarms) {
let alarmTime = moment() let alarmTime = moment()
.hours(+alarm.alarmTime.split(':') [ 0 ]) .hours(+alarm.alarmTime.split(':') [ 0 ])
.minutes(+alarm.alarmTime.split(':') [ 1 ]) .minutes(+alarm.alarmTime.split(':') [ 1 ])
let secDiff = alarmTime.diff(timeRN, 'seconds') 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")) { if (alarmTime.format("HH:mm") == timeRN.format("HH:mm")) {
console.log("TRIGGER", alarm.alarmSchedulingMode) //console.log("TRIGGER", alarm.alarmSchedulingMode)
let alarmTrigger = false let alarmTrigger = false
switch (alarm.alarmSchedulingMode) { switch (alarm.alarmSchedulingMode) {
case 'monthlyAtSpecificDate': case 'monthlyAtSpecificDate':
@ -41,15 +41,15 @@ async function minuteCheck() {
while (monthFirstDay.weekday() != alarm.firstOccWeekday) monthFirstDay.add(1, 'day') while (monthFirstDay.weekday() != alarm.firstOccWeekday) monthFirstDay.add(1, 'day')
thisMonthFirstWeekDayOccurance = monthFirstDay.date() thisMonthFirstWeekDayOccurance = monthFirstDay.date()
console.log(monthFirstDay.date(), monthFirstDay.weekday()) //console.log(monthFirstDay.date(), monthFirstDay.weekday())
console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance) //console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance)
alarmTrigger = (timeRN.date() == thisMonthFirstWeekDayOccurance) alarmTrigger = (timeRN.date() == thisMonthFirstWeekDayOccurance)
break; break;
case 'weekly': case 'weekly':
for (let weekDayKey of Object.keys(alarm.weekDay)) { for (let weekDayKey of Object.keys(alarm.weekDay)) {
console.log(weekDayKey, alarm.weekDay) //console.log(weekDayKey, alarm.weekDay)
if (+weekDayKey === +timeRN.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] alarmTrigger = alarm.weekDay[weekDayKey]
break; break;
} }
@ -57,7 +57,10 @@ async function minuteCheck() {
break; break;
} }
if (alarmTrigger === true) { 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) => { appConfig.get('/config', async (req, res) => {
return res.json(JSON.parse(fs.readFileSync('config.json'))) 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) => { appConfig.post('/config', async (req, res) => {
if (!(!!req.body.alarms)) return res.status(403).json(false) if (!(!!req.body.alarms)) return res.status(403).json(false)
if (!(!!req.body.pager)) return res.status(403).json(false) if (!(!!req.body.pager)) return res.status(403).json(false)

Loading…
Cancel
Save