summaryrefslogtreecommitdiffstats
path: root/prog/jelka/templates/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'prog/jelka/templates/index.html')
-rw-r--r--prog/jelka/templates/index.html88
1 files changed, 88 insertions, 0 deletions
diff --git a/prog/jelka/templates/index.html b/prog/jelka/templates/index.html
new file mode 100644
index 0000000..f73d0b7
--- /dev/null
+++ b/prog/jelka/templates/index.html
@@ -0,0 +1,88 @@
+<meta name=viewport content='width=device-width, initial-scale=1.0'>
+<title>jelka na fmf</title>
+<h1>jelka na fmf</h1>
+<label for=geslo>geslo: </label><input id=geslo type=text placeholder=geslo /> (geslo najdete na LED zaslonu)
+<br>
+<label for=čas>čas vzorca v sekundah: </label><input id=čas type=number placeholder=10 min=1 max=300 /> <button onclick=nastavi_čas()>nastavi!</button>
+<br>
+<!-- enkrat poženi poljuben vzorec: <input type=file id=file /> <button id=poženi>poženi</button> -->
+<ul id=vzorci></ul>
+<script>
+ function nastavi_čas() {
+ if (geslo.value == "") {
+ alert("nastavite geslo!");
+ return;
+ }
+ fetch(geslo.value, {
+ method: "POST",
+ body: JSON.stringify({
+ "čas": Number(čas.value)
+ }),
+ }).then(data => {
+ data.json().then(json => {
+ if (Object.keys(json).includes("napaka")) {
+ alert(json.napaka.besedilo)
+ }
+ })
+ });
+ }
+ geslo.value = location.hash.substr(1);
+ const evt = new EventSource("stream/");
+ evt.onmessage = (e) => {
+ data = JSON.parse(e.data);
+ console.log(data);
+ vzorci.innerHTML = "";
+ for (let i = 0; i < data.vzorci.length; i++) {
+ const li = document.createElement("li");
+ const začni = document.createElement("button");
+ const a = document.createElement("a");
+ if (data["trenuten"] == data.vzorci[i])
+ li.innerText = "trenuten: ";
+ začni.innerText = "začni";
+ a.innerText = data.vzorci[i];
+ a.href = "vzorci/" + data.vzorci[i];
+ li.appendChild(a);
+ začni.onclick = () => {
+ if (geslo.value == "") {
+ alert("nastavite geslo!");
+ return;
+ }
+ fetch(geslo.value, {
+ method: "POST",
+ body: JSON.stringify({
+ "začni": data.vzorci[i]
+ }),
+ }).then(data => {
+ data.json().then(json => {
+ if (Object.keys(json).includes("napaka")) {
+ alert(a.napaka.besedilo)
+ }
+ })
+ });
+ };
+ li.appendChild(začni);
+ const stanje = document.createElement("button");
+ stanje.innerText = "onemogoči";
+ if (data.onemogočeni.includes(data.vzorci[i]))
+ stanje.innerText = "omogoči";
+ stanje.onclick = () => {
+ if (geslo.value == "") {
+ alert("nastavite geslo!");
+ return;
+ }
+ fetch(geslo.value, {
+ method: "POST",
+ body: "{\"" + stanje.innerText + "\": [\"" + data.vzorci[i] + "\"]}",
+ }).then(data => {
+ data.json().then(json => {
+ if (Object.keys(json).includes("napaka")) {
+ alert(a.napaka.besedilo)
+ }
+ })
+ });
+ };
+ li.appendChild(stanje);
+ vzorci.appendChild(li);
+ }
+ }
+</script>