pixelserver2/html/index.html

88 lines
2.0 KiB
HTML
Raw Normal View History

2018-08-22 19:14:11 +00:00
<html>
<head>
<meta charset="utf-8">
2018-08-22 20:05:49 +00:00
<style type="text/css">
textarea {
width: 500px;
height: 500px;
}
2018-08-22 19:14:11 +00:00
2018-08-22 20:05:49 +00:00
</style>
2018-08-22 19:14:11 +00:00
</head>
<body>
<div id='container'>
<form id='in'>
</form>
</div>
2018-08-22 19:47:16 +00:00
<div id='log'>
<textarea id='logs'>
</textarea>
</div>
2018-08-22 19:14:11 +00:00
<script>
function generateInput(parameters){
let container = document.getElementById('in');
let list = document.createElement("select");
list.id = "list_";
container.appendChild(list);
//let json = JSON.parse(parameters);
parameters.map ( e => {
let element = document.createElement("option");
element.value = e;
element.innerHTML = e;
list.appendChild(element);
})
let arguments = document.createElement("input");
arguments.id = "args";
container.appendChild(arguments);
let button = document.createElement("Button");
button.innerHTML = "Execute";
container.appendChild(button);
button.onclick = request;
//container.appendChild(foo);
}
function request(){
let app = document.querySelector('#list_');
let val = app.options[app.selectedIndex].value;
let parameter = document.getElementById('args').value;
console.log(parameter);
fetch("/apps/start/" + val + "/" + parameter).then(console.log);
}
2018-08-22 19:47:16 +00:00
//async function initLog(){
// socket = new WebSocket ( "/logs" );
// socket.onmessage = function ( evt ) { document.getElementById('logs').innerHTML += evt.data; };
//}
var sleep = time => new Promise(resolve => setTimeout(resolve, time))
var poll = (promiseFn, time) => promiseFn().then(
sleep(time).then(() => poll(promiseFn, time)))
2018-08-22 20:05:49 +00:00
poll(() => new Promise(() => fetch("/apps/log").then(res => res.text().then(e => { document.getElementById('logs').innerHTML = e;})) ), 1000)
2018-08-22 19:47:16 +00:00
2018-08-22 19:14:11 +00:00
let apps = fetch("/apps/list").then(res => res.json().then(generateInput));
//generateInput("[ \"bla\", \"foo\", \"baz\" ]");
</script>
</body>
</html>