new preset ui update

master
cheetah 2 years ago
parent 9f63b292b9
commit 911aaea0a3

@ -6,23 +6,7 @@
"deliveryModes": [ "deliveryModes": [
{ {
"name": "Normal", "name": "Normal",
"params": { "preset": ""
"type": "duplex",
"routing": {
"device": "birdyslim",
"connectors": [
[
"em-p-twoways",
"1234567"
],
[
"pocsag",
"424242"
]
]
}
},
"_id": ""
} }
] ]
} }

@ -15,6 +15,7 @@
<v-app-bar app> <v-app-bar app>
<v-toolbar-title>Telegram Bot Configuration</v-toolbar-title> <v-toolbar-title>Telegram Bot 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>
@ -34,7 +35,7 @@
</v-row> </v-row>
<p>Targets:</p> <p>Targets:</p>
<v-row> <v-row>
<v-btn color="success" @click="addRegionCMD()">Add</v-btn> <v-btn color="success" @click="addDeliveryMode()">Add</v-btn>
</v-row> </v-row>
<v-row v-for="(deliveryMode, index) in configData.deliveryModes" :key="deliveryMode._id" style="border-bottom: 2px solid black;"> <v-row v-for="(deliveryMode, index) in configData.deliveryModes" :key="deliveryMode._id" style="border-bottom: 2px solid black;">
<pre>Index: {{ index }}</pre> <pre>Index: {{ index }}</pre>
@ -43,35 +44,18 @@
</v-col> </v-col>
<v-col cols="6" sm="6" md="4"> <v-col cols="6" sm="6" md="4">
<v-text-field v-model="deliveryMode.name" label="Name"></v-text-field> <v-text-field v-model="deliveryMode.name" label="Name"></v-text-field>
<v-autocomplete
v-model="deliveryMode.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>
<v-col>
<v-col cols="12" sm="12" md="6">
<v-select :items="pagerTypes" v-model="deliveryMode.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="deliveryMode.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 deliveryMode.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="deliveryMode.params.routing.connectors.splice(index, 1)" icon><v-icon>mdi-delete</v-icon></v-btn>
</v-col>
</v-row>
</v-col>
</v-row>
<v-row>
<v-btn color="success" @click="storeConfig()">Store & Restart</v-btn>
</v-row> </v-row>
</v-container> </v-container>
</v-tab-item> </v-tab-item>
@ -82,10 +66,6 @@
<v-col cols="12" sm="12" md="6"> <v-col cols="12" sm="12" md="6">
<v-text-field label="Daemon Endpoint URL" v-model="configData.pager.url"></v-text-field> <v-text-field label="Daemon Endpoint URL" v-model="configData.pager.url"></v-text-field>
</v-col> </v-col>
<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>
@ -106,28 +86,6 @@
return { return {
EXPERTMODE: false, EXPERTMODE: false,
configTab: null, 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: { configData: {
"bottoken": "", "bottoken": "",
"pager": { "pager": {
@ -136,12 +94,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
@ -155,6 +125,10 @@
}, },
storeConfig() { storeConfig() {
const storeConfig = JSON.parse(JSON.stringify(this.configData)) const storeConfig = JSON.parse(JSON.stringify(this.configData))
storeConfig.deliveryModes = storeConfig.deliveryModes.map((x) => {
delete x._id
return x
})
this.$http.post('/config', storeConfig).then(response => { this.$http.post('/config', storeConfig).then(response => {
}) })
.then(this.$http.post('/restart')) .then(this.$http.post('/restart'))
@ -163,19 +137,10 @@
setTimeout(() => window.location.reload(), 1e3) setTimeout(() => window.location.reload(), 1e3)
}) })
}, },
addDeliveryTarget(index) { addDeliveryMode() {
this.configData.deliveryModes[ index ].params.routing.connectors.push(["connectorName","connectorParam"])
},
addRegionCMD() {
this.configData.deliveryModes.push({ this.configData.deliveryModes.push({
name: "", name: "",
params: { preset: null
"type": "simple",
"routing": {
"device": "generic",
"connectors": []
}
},
}) })
}, },
} }

@ -15,8 +15,12 @@ function filter(txt) {
return txt.replace(/[^\x00-\x7F]/g, "") return txt.replace(/[^\x00-\x7F]/g, "")
} }
function editStatus(msgId, msg) { function editStatus(msgId, msg) {
if (!assoc[msgId]) return if (!assoc[msgId]) return
const sPass = Math.floor( (new Date().valueOf() - assoc[msgId].date.valueOf() ) / 1e3)
msg = `+${ sPass }s> ${ msg }`
console.log(assoc[msgId]) console.log(assoc[msgId])
const [tgChatId, tgMsgId] = [assoc[msgId].tgchat, assoc[msgId].tgmsg] const [tgChatId, tgMsgId] = [assoc[msgId].tgchat, assoc[msgId].tgmsg]
assoc[msgId].newText = assoc[msgId].newText + '\n' + msg assoc[msgId].newText = assoc[msgId].newText + '\n' + msg
@ -57,8 +61,17 @@ for (let deliveryModeIndex in config.deliveryModes) {
const origText = ctx.update.callback_query.message.text.substring(8+1) const origText = ctx.update.callback_query.message.text.substring(8+1)
await ctx.answerCbQuery() await ctx.answerCbQuery()
await ctx.editMessageReplyMarkup(undefined) await ctx.editMessageReplyMarkup(undefined)
let msgId = (await axios.post(config.pager.url, Object.assign({ ...config.deliveryModes[ deliveryModeIndex ].params }, { payload: origText }))).data
const deliveryModeData = config.deliveryModes[ deliveryModeIndex ]
let msgId = (
await axios.post(config.pager.url, Object.assign( !!deliveryModeData.preset
? { ...deliveryModeData.params } // backward compatibility
: { preset: deliveryModeData.preset }
, { payload: origText }))
).data
assoc[msgId] = { assoc[msgId] = {
date: new Date(),
tgmsg: ctx.update.callback_query.message.message_id, tgmsg: ctx.update.callback_query.message.message_id,
text: origText, text: origText,
newText: `Preview: ${ origText }\n\n--[${ msgId }]--\n`, newText: `Preview: ${ origText }\n\n--[${ msgId }]--\n`,
@ -85,6 +98,10 @@ appConfig.use(express.static(__dirname + '/node_modules/@mdi/font'))
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.bottoken)) return res.status(403).json(false) if (!(!!req.body.bottoken)) 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