|
@@ -7,6 +7,8 @@ let chosenShelves = Array()
|
|
|
|
|
|
|
|
let chosenCluster = -1
|
|
let chosenCluster = -1
|
|
|
|
|
|
|
|
|
|
+let clusterName = "Inte vald"
|
|
|
|
|
+
|
|
|
function getEByID(id) {
|
|
function getEByID(id) {
|
|
|
return document.getElementById(id)
|
|
return document.getElementById(id)
|
|
|
}
|
|
}
|
|
@@ -44,20 +46,8 @@ function shelfClick(id) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-function unselectAll() {
|
|
|
|
|
- chosenCluster = -1
|
|
|
|
|
- chosenShelves.forEach(id => {
|
|
|
|
|
- getEByID("b" + id.toString()).innerText = ""
|
|
|
|
|
- getEByID("b" + id.toString()).classList.remove("selected")
|
|
|
|
|
- })
|
|
|
|
|
- chosenShelves = Array()
|
|
|
|
|
- makeClusterButton.classList.add("hidden")
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
function createCluster() {
|
|
function createCluster() {
|
|
|
- const shelves = JSON.stringify(chosenShelves)
|
|
|
|
|
|
|
+ const shelves = chosenShelves
|
|
|
const numLights = chosenShelves.length
|
|
const numLights = chosenShelves.length
|
|
|
const sendDict = {
|
|
const sendDict = {
|
|
|
["numLights"]: numLights,
|
|
["numLights"]: numLights,
|
|
@@ -79,10 +69,39 @@ function deleteCluster() {
|
|
|
const sendDict = {
|
|
const sendDict = {
|
|
|
["cluster"]: chosenCluster,
|
|
["cluster"]: chosenCluster,
|
|
|
}
|
|
}
|
|
|
|
|
+ chosenCluster = -1
|
|
|
sendWebRequest("http://192.168.1.170/api/delete_cluster", JSON.stringify(sendDict), "POST")
|
|
sendWebRequest("http://192.168.1.170/api/delete_cluster", JSON.stringify(sendDict), "POST")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function changeAnimation(animId) {
|
|
|
|
|
+ const sendDict = {
|
|
|
|
|
+ ["targetCluster"]: chosenCluster,
|
|
|
|
|
+ ["animation"]: animId
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(JSON.stringify(sendDict))
|
|
|
|
|
+ sendWebRequest("http://192.168.1.170/api/change_animation", JSON.stringify(sendDict), "POST")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function changeVar(value, setting) {
|
|
|
|
|
+ let sendValue = 0
|
|
|
|
|
+
|
|
|
|
|
+ if (value.substring(0,3) === "0x") {
|
|
|
|
|
+ sendValue = parseInt(value, 16);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sendValue = Number(value)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!isNaN(sendValue)) {
|
|
|
|
|
+ const sendDict = {
|
|
|
|
|
+ ["targetCluster"]: chosenCluster,
|
|
|
|
|
+ ["newValue"]: sendValue,
|
|
|
|
|
+ ["setting"]: setting
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(JSON.stringify(sendDict))
|
|
|
|
|
+ sendWebRequest("http://192.168.1.170/api/change_setting", JSON.stringify(sendDict), "POST")
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
function sendWebRequest(url, data, method) {
|
|
function sendWebRequest(url, data, method) {
|
|
|
/*const Http = new XMLHttpRequest()
|
|
/*const Http = new XMLHttpRequest()
|
|
@@ -98,14 +117,54 @@ function sendWebRequest(url, data, method) {
|
|
|
method: method,
|
|
method: method,
|
|
|
headers: new Headers({'data': data}),
|
|
headers: new Headers({'data': data}),
|
|
|
//mode: 'no-cors'
|
|
//mode: 'no-cors'
|
|
|
- })
|
|
|
|
|
|
|
+ })
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
console.log(res)
|
|
console.log(res)
|
|
|
- //updateConfig()
|
|
|
|
|
|
|
+ updateConfig()
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function chooseCluster(id) {
|
|
|
|
|
+ if (id < 0) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ unselectAll()
|
|
|
|
|
+ getEByID("c" + id.toString()).classList.add("selected")
|
|
|
|
|
+ chosenCluster = id
|
|
|
|
|
+ let lampId = 0
|
|
|
|
|
+ for (let lamp of clusters[id].lights) {
|
|
|
|
|
+ console.log(lamp)
|
|
|
|
|
+ getEByID("b" + lamp.toString()).classList.add("selected")
|
|
|
|
|
+ getEByID("b" + lamp.toString()).innerText = (lampId + 1).toString()
|
|
|
|
|
+ lampId += 1
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getEByID("a" + clusters[id]["animation"].toString()).classList.add("selected")
|
|
|
|
|
+ chosenShelves = clusters[id].lights
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function unselectAll() {
|
|
|
|
|
+ chosenCluster = -1
|
|
|
|
|
+ chosenShelves.forEach(id => {
|
|
|
|
|
+ getEByID("b" + id.toString()).innerText = ""
|
|
|
|
|
+ getEByID("b" + id.toString()).classList.remove("selected")
|
|
|
|
|
+ })
|
|
|
|
|
+ const clustHTML = getEByID("clusters").children
|
|
|
|
|
+ for (let b of clustHTML) {
|
|
|
|
|
+ b.classList.remove("selected")
|
|
|
|
|
+ }
|
|
|
|
|
+ const animHTML = getEByID("spotlightAnimations").children
|
|
|
|
|
+ for (let b of animHTML) {
|
|
|
|
|
+ b.classList.remove("selected")
|
|
|
|
|
+ }
|
|
|
|
|
+ chosenShelves = Array()
|
|
|
|
|
+ makeClusterButton.classList.add("hidden")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
function updateConfig() {
|
|
function updateConfig() {
|
|
|
|
|
+ const preSelectCluster = chosenCluster
|
|
|
unselectAll()
|
|
unselectAll()
|
|
|
fetch("http://192.168.1.170/api/get_config")
|
|
fetch("http://192.168.1.170/api/get_config")
|
|
|
.then(response => response.json())
|
|
.then(response => response.json())
|
|
@@ -114,6 +173,10 @@ function updateConfig() {
|
|
|
numClusters = data["numClusters"]
|
|
numClusters = data["numClusters"]
|
|
|
clusters = data["clusters"]
|
|
clusters = data["clusters"]
|
|
|
|
|
|
|
|
|
|
+ while (getEByID("clusters").firstChild) {
|
|
|
|
|
+ getEByID("clusters").lastChild.remove()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
occupiedLamps = Array()
|
|
occupiedLamps = Array()
|
|
|
let id = -1
|
|
let id = -1
|
|
|
for (const cluster of data.clusters) {
|
|
for (const cluster of data.clusters) {
|
|
@@ -122,25 +185,17 @@ function updateConfig() {
|
|
|
occupiedLamps.push(lamp)
|
|
occupiedLamps.push(lamp)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const clusterButton = document.createElement("button")
|
|
|
|
|
- clusterButton.innerText = (id+1).toString()
|
|
|
|
|
- clusterButton.onclick = function () {
|
|
|
|
|
- unselectAll()
|
|
|
|
|
- clusterButton.classList.add("selected")
|
|
|
|
|
- chosenCluster = id
|
|
|
|
|
- let lampId = 0
|
|
|
|
|
- for (let lamp of cluster.lights) {
|
|
|
|
|
- console.log(lamp)
|
|
|
|
|
- getEByID("b" + lamp.toString()).classList.add("selected")
|
|
|
|
|
- getEByID("b" + lamp.toString()).innerText = (lampId+1).toString()
|
|
|
|
|
- lampId += 1
|
|
|
|
|
- }
|
|
|
|
|
- chosenShelves = cluster.lights
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ let clusterButton = document.createElement("button")
|
|
|
|
|
+ clusterButton.innerText = (id + 1).toString()
|
|
|
|
|
+ clusterButton.id = "c" + id.toString()
|
|
|
|
|
+ clusterButton.setAttribute("onclick", "chooseCluster(" + id.toString() + ")")
|
|
|
getEByID("clusters").appendChild(clusterButton)
|
|
getEByID("clusters").appendChild(clusterButton)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ chosenCluster = preSelectCluster
|
|
|
|
|
+ chooseCluster(chosenCluster)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
updateConfig()
|
|
updateConfig()
|