diff --git a/.gitignore b/.gitignore index c197b54..adf6828 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ build/ /update.sh /.env /influx/ +/src/main/ardoino/ESP8622_DS18B20_http/.theia/launch.json diff --git a/src/main/kotlin/de/lrprojects/tempserver/controller/ViewController.kt b/src/main/kotlin/de/lrprojects/tempserver/controller/ViewController.kt index f1104e1..b9b8691 100644 --- a/src/main/kotlin/de/lrprojects/tempserver/controller/ViewController.kt +++ b/src/main/kotlin/de/lrprojects/tempserver/controller/ViewController.kt @@ -47,6 +47,15 @@ class ViewController( return "config-sensor-categories" } + @GetMapping(CONFIG_SENSOR_TYPES) + fun configSensorTypes(model: Model): String { + val types = typeService.getAllTypes() + val sensors = sensorService.getAllSensors() + model.addAttribute("types", types) + model.addAttribute("sensors", sensors) + return "config-sensor-types" + } + companion object { const val BASE = "/" const val DISPLAY = "/display" diff --git a/src/main/resources/static/javascript/config-sensor-types.js b/src/main/resources/static/javascript/config-sensor-types.js new file mode 100644 index 0000000..f8f4ca6 --- /dev/null +++ b/src/main/resources/static/javascript/config-sensor-types.js @@ -0,0 +1,94 @@ +/** + * logic + */ + +function select(sensor_type, sensor_type_id, sensor_type_unit) { + const editElement = document.getElementById("typeName"); + editElement.value = sensor_type; + editElement.setAttribute("data-id", sensor_type_id); + const editElement2 = document.getElementById("typeUnit"); + editElement.setAttribute("data-id", sensor_type_id); + editElement2.value = sensor_type_unit; +} + + +function submitData() { + const sensor_type = document.getElementById("typeName").value; + const sensor_type_id = document.getElementById("typeName").getAttribute("data-id"); + const sensor_type_unit = document.getElementById("typeUnit").value; + const ajax = new XMLHttpRequest(); + + let json; + if (sensor_type_id !== "" ) { + ajax.open("PUT", "/rest/v1/types/" + sensor_type_id, true); + json = {typeName : sensor_type, id :sensor_type_id, description: sensor_type_unit} + } else if (sensor_type_id === "") { + ajax.open("POST", "/rest/v1/types", true); + json = {typeName : sensor_type, description: sensor_type_unit} + } + if (json !== undefined && sensor_type.length > 0) { + ajax.setRequestHeader("Content-Type", "application/json"); + ajax.send(JSON.stringify(json)); + ajax.onreadystatechange = function () { + if (ajax.readyState === 4) { + if (ajax.status === 200 || ajax.status === 201) { + updateTypes(); + + } else { + alert(ajax.responseText); + } + } + }; + } +} + +function updateTypes() { + const ajax = new XMLHttpRequest(); + ajax.open("GET", "/rest/v1/types", true); + ajax.send(); + ajax.onreadystatechange = function() { + if (ajax.readyState === 4) { + if(ajax.status === 200) { + const listElement = document.getElementById("list"); + listElement.textContent = ''; + const data = JSON.parse(ajax.responseText); + for (let i = 0; i < data.length + 1; i++) { + let btn = document.createElement("button"); + btn.classList.add('list-group-item','list-group-item-action'); + if (i === data.length) btn.classList.add('active'); + btn.id = "list_" + (i === data.length ? "new" : data[i].id); + btn.setAttribute("type", "button"); + btn.setAttribute("data-toggle", "list"); + btn.setAttribute("onclick", (i === data.length ? "select('','','')" : "select('" + data[i].typeName + "','" + data[i].id + "','" + data[i].description + "')")); + btn.innerHTML = (i === data.length ? "+" : data[i].typeName); + listElement.appendChild(btn); + } + document.getElementById("typeName").value = ""; + document.getElementById("typeUnit").value = ""; + document.getElementById("typeName").setAttribute("data-id", ""); + } else { + alert(ajax.responseText); + } + } + }; +} + +document.getElementById("submit").addEventListener("click", function () { + submitData(); +}); + +document.getElementById("delete").addEventListener("click", function () { + const sensor_type_id = document.getElementById("typeName").getAttribute("data-id"); + const ajax = new XMLHttpRequest(); + ajax.open("DELETE", "/rest/v1/types" + sensor_type_id, true); + ajax.send(); + ajax.onreadystatechange = function () { + if (ajax.readyState === 4) { + if (ajax.status === 200) { + updateTypes(); + } else { + alert(ajax.responseText); + } + } + } +}); \ No newline at end of file diff --git a/src/main/resources/templates/config-local-sensors.html b/src/main/resources/templates/config-local-sensors.html index 88040e0..375b366 100644 --- a/src/main/resources/templates/config-local-sensors.html +++ b/src/main/resources/templates/config-local-sensors.html @@ -45,6 +45,11 @@ +
  • +
    + +
    +
  • @@ -144,7 +149,7 @@

    LOADING...

    -

    https://github.com/lr101/SpringServer

    +

    https://github.com/lr101/TempServer

    diff --git a/src/main/resources/templates/config-sensor-categories.html b/src/main/resources/templates/config-sensor-categories.html index d65271e..d5cf4d8 100644 --- a/src/main/resources/templates/config-sensor-categories.html +++ b/src/main/resources/templates/config-sensor-categories.html @@ -45,6 +45,11 @@
  • +
  • +
    + +
    +
  • @@ -100,7 +105,7 @@

    Sensor Category

    -

    https://github.com/lr101/SpringServer

    +

    https://github.com/lr101/TempServer

    diff --git a/src/main/resources/templates/config-sensor-types.html b/src/main/resources/templates/config-sensor-types.html new file mode 100644 index 0000000..3189f8c --- /dev/null +++ b/src/main/resources/templates/config-sensor-types.html @@ -0,0 +1,123 @@ + + + + + + + + + Configuration + + +
    + +
    + +
    +
    +
    +
    +

    Configure Types

    +
    +
    +
    + +
    + +
    +
    +
    +

    Selection

    +
    + + +
    +
    +
    +
    +
    +

    Sensor Type

    +
    + +
    + +
    + +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +

    https://github.com/lr101/TempServer

    +
    +
    +
    + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/display.html b/src/main/resources/templates/display.html index 53b1f43..9660b1a 100644 --- a/src/main/resources/templates/display.html +++ b/src/main/resources/templates/display.html @@ -44,6 +44,11 @@
  • +
  • +
    + +
    +
  • @@ -108,7 +113,7 @@

    diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 0cf3023..c253d71 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -44,6 +44,11 @@

  • +
  • +
    + +
    +
  • @@ -100,7 +105,7 @@

    Data Display

    -

    https://github.com/lr101/SpringServer

    +

    https://github.com/lr101/TempServer

    diff --git a/src/test/kotlin/de/lrprojects/tempserver/SpringServerApplicationTests.kt b/src/test/kotlin/de/lrprojects/tempserver/SpringServerApplicationTests.kt index e15c343..4701fce 100644 --- a/src/test/kotlin/de/lrprojects/tempserver/SpringServerApplicationTests.kt +++ b/src/test/kotlin/de/lrprojects/tempserver/SpringServerApplicationTests.kt @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest @SpringBootTest -class SpringServerApplicationTests { +class TempServerApplicationTests { @Test fun contextLoads() { }