Initial commit
This commit is contained in:
commit
89f483171a
43 changed files with 2245 additions and 0 deletions
53
static/js/trigger_edit.mjs
Normal file
53
static/js/trigger_edit.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
export class UI {
|
||||
constructor() {
|
||||
document.getElementById('button-run').
|
||||
addEventListener('click', evt=>evt.preventDefault())
|
||||
|
||||
document.addEventListener('keydown', evt=>this.keyHandler(evt))
|
||||
}
|
||||
setTrigger(t) {
|
||||
this.trigger = t
|
||||
}
|
||||
run() {
|
||||
this.trigger.run()
|
||||
}
|
||||
keyHandler(evt) {
|
||||
if (evt.altKey && evt.shiftKey && evt.key == 'R') {
|
||||
evt.preventDefault()
|
||||
evt.stopPropagation()
|
||||
this.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Trigger {
|
||||
constructor(id, name) {
|
||||
this.id = id
|
||||
this.name = name
|
||||
}
|
||||
run() {
|
||||
const result = document.getElementById('run-result')
|
||||
const classes = result.classList
|
||||
const expr = document.getElementById('expr').value
|
||||
|
||||
fetch(`/trigger/run/${this.id}`, {
|
||||
method: 'POST',
|
||||
cache: 'no-cache',
|
||||
body: expr,
|
||||
})
|
||||
.then(data => data.json())
|
||||
.then(json => {
|
||||
if (!json.OK) {
|
||||
classes.remove('ok')
|
||||
classes.add('error')
|
||||
result.innerText = json.Error
|
||||
return
|
||||
}
|
||||
|
||||
classes.remove('error')
|
||||
classes.add('ok')
|
||||
result.innerText = json.Output
|
||||
})
|
||||
.catch(err => alert(err))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue