99 lines
2.5 KiB
HTML
99 lines
2.5 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<script>
|
|
function status(msg) {
|
|
document.getElementById('status').textContent = msg
|
|
}
|
|
async function queryParams() {
|
|
const req = await fetch('/api/params')
|
|
const json = await req.json()
|
|
//console.log(json)
|
|
//console.log(Object.keys(json))
|
|
status('parameter query successful!')
|
|
const paramList = document.getElementById('param-list')
|
|
while (paramList.firstChild) {
|
|
paramList.removeChild(paramList.lastChild)
|
|
}
|
|
Object.keys(json).forEach((name) => {
|
|
const elem = document.createElement('div')
|
|
elem.textContent = name + " = " + json[name]
|
|
paramList.appendChild(elem)
|
|
})
|
|
}
|
|
|
|
async function setParam(auth, name, value) {
|
|
const msg = JSON.stringify({
|
|
auth: auth,
|
|
data: {
|
|
set_params: {
|
|
name: name,
|
|
value: value
|
|
}
|
|
}
|
|
})
|
|
console.log('set param fetch pre')
|
|
const resp = await fetch('/api/admin', {
|
|
method: 'POST',
|
|
body: msg
|
|
})
|
|
console.log('set param fetch post')
|
|
if (!resp.ok) {
|
|
var err_msg = null
|
|
if (resp.body != null) {
|
|
err_msg = await resp.text()
|
|
}
|
|
if (err_msg != null) {
|
|
status("set failed: " + resp.status + " " + err_msg)
|
|
} else {
|
|
status("set failed: " + resp.status)
|
|
}
|
|
} else {
|
|
status("parameter set successful!")
|
|
await queryParams()
|
|
}
|
|
}
|
|
|
|
window.onload = () => {
|
|
document.getElementById('query-params').addEventListener('click', (e) => {
|
|
queryParams()
|
|
})
|
|
|
|
document.getElementById('set-param').addEventListener('click', (e) => {
|
|
const auth = document.getElementById('password').value
|
|
const name = document.getElementById('name').value
|
|
const value = parseFloat(document.getElementById('value').value)
|
|
if (isNaN(value)) {
|
|
status('invalid value set')
|
|
return
|
|
}
|
|
setParam(auth, name, value)
|
|
})
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<fieldset>
|
|
<legend>Status</legend>
|
|
<div id=status></div>
|
|
</fieldset>
|
|
<form>
|
|
<fieldset>
|
|
<legend>Parameter list</legend>
|
|
<div id=param-list></div>
|
|
<input id=query-params type=button value="Query params"></input><br />
|
|
</fieldset>
|
|
<label for=password>Auth password: </label>
|
|
<input id=password type=password></input><br />
|
|
<fieldset>
|
|
<legend>Set parameter</legend>
|
|
<label for=name>Name: </label>
|
|
<input id=name type=text></input><br />
|
|
<label for=value>Value: </label>
|
|
<input id=value type=text></input><br />
|
|
<input id=set-param type=button value="Set parameter"></input><br />
|
|
</fieldset>
|
|
</form>
|
|
</body>
|
|
</html>
|