{
println!("{uri} get {param_name}");
let parsed = Url::parse(&format!("http://127.0.0.1/{uri}")).unwrap();
- let value = parsed.query_pairs().filter(|it| it.0 == param_name).next();
+ let value = parsed.query_pairs().find(|it| it.0 == param_name);
match value {
Some(found) => {
- return Some(found.1.into_owned());
+ Some(found.1.into_owned())
}
- None => return None,
+ None => None,
}
}
@@ -694,7 +692,7 @@ fn cors_response(
let mut response = request.into_response(status, None, &headers)?;
response.write(body.as_bytes())?;
response.flush()?;
- return anyhow::Ok(());
+ anyhow::Ok(())
}
type AnyhowHandler =
@@ -719,7 +717,7 @@ fn handle_error_to500(
cors_response(request, 500, &error_text)?;
}
}
- return anyhow::Ok(());
+ anyhow::Ok(())
}
fn read_up_to_bytes_from_request(
diff --git a/rust/src_webpack/src/fileview.ts b/rust/src_webpack/src/fileview.ts
index 69645e2..2d5e870 100644
--- a/rust/src_webpack/src/fileview.ts
+++ b/rust/src_webpack/src/fileview.ts
@@ -1,4 +1,4 @@
-import { Controller } from "./main";
+import {Controller} from "./main";
const regex = /[^a-zA-Z0-9_.]/g;
@@ -24,7 +24,7 @@ export class FileView {
let fileuploadname = document.getElementById("fileuploadname") as HTMLInputElement
let fileuploadbtn = document.getElementById("fileuploadbtn") as HTMLInputElement
fileuploadfile.onchange = () => {
- var selectedFile = fileuploadfile.files?.[0];
+ const selectedFile = fileuploadfile.files?.[0];
if (selectedFile == null) {
//TODO error dialog here
return
@@ -42,7 +42,7 @@ export class FileView {
}
fileuploadbtn.onclick = () => {
- var selectedFile = fileuploadfile.files?.[0];
+ const selectedFile = fileuploadfile.files?.[0];
if (selectedFile == null) {
//TODO error dialog here
return
@@ -77,8 +77,7 @@ class FileEntry {
this.view.classList.add("fileentryouter")
const template = require('./fileviewentry.html') as string;
- const fileRaw = template.replaceAll("${fileid}", String(fileid));
- this.view.innerHTML = fileRaw
+ this.view.innerHTML = template.replaceAll("${fileid}", String(fileid))
let name = document.getElementById("file_" + fileid + "_name") as HTMLElement;
let size = document.getElementById("file_" + fileid + "_size") as HTMLElement;
diff --git a/rust/src_webpack/src/main.html b/rust/src_webpack/src/main.html
index 91b8b92..33f82cc 100644
--- a/rust/src_webpack/src/main.html
+++ b/rust/src_webpack/src/main.html
@@ -45,7 +45,7 @@
display: inline-block;
height: 100%;
animation: indeterminateAnimation 1s infinite linear;
- transform-origin: 0% 50%;
+ transform-origin: 0 50%;
}
diff --git a/rust/src_webpack/src/main.ts b/rust/src_webpack/src/main.ts
index e369a32..dd4dcec 100644
--- a/rust/src_webpack/src/main.ts
+++ b/rust/src_webpack/src/main.ts
@@ -1,4 +1,3 @@
-
import { deepEqual } from 'fast-equals';
declare var PUBLIC_URL: string;
@@ -8,7 +7,7 @@ document.body.innerHTML = require('./main.html') as string;
import { TimeView } from "./timeview";
-import { PlantView, PlantViews } from "./plant";
+import { PlantViews } from "./plant";
import { NetworkConfigView } from "./network";
import { NightLampView } from "./nightlightview";
import { TankConfigView } from "./tankview";
@@ -261,7 +260,6 @@ export class Controller {
configChanged() {
const current = controller.getConfig();
var pretty = JSON.stringify(current, undefined, 0);
- var initial = JSON.stringify(this.initialConfig, undefined, 0);
controller.submitView.setJson(pretty);
if (deepEqual(current, controller.initialConfig)) {
@@ -307,7 +305,7 @@ export class Controller {
})
.then(response => response.text())
.then(
- text => {
+ _ => {
clearTimeout(timerId);
controller.progressview.removeProgress("test_pump");
}
@@ -507,3 +505,16 @@ controller.populateTimezones().then(_ => {
controller.progressview.removeProgress("rebooting");
+window.addEventListener("beforeunload", (event) => {
+ const currentConfig = controller.getConfig();
+
+ // Check if the current state differs from the initial configuration
+ if (!deepEqual(currentConfig, controller.initialConfig)) {
+ const confirmationMessage = "You have unsaved changes. Are you sure you want to leave this page?";
+
+ // Standard behavior for displaying the confirmation dialog
+ event.preventDefault();
+ event.returnValue = confirmationMessage; // This will trigger the browser's default dialog
+ return confirmationMessage;
+ }
+});
\ No newline at end of file
diff --git a/rust/src_webpack/src/network.ts b/rust/src_webpack/src/network.ts
index e7870fe..8f04063 100644
--- a/rust/src_webpack/src/network.ts
+++ b/rust/src_webpack/src/network.ts
@@ -3,9 +3,9 @@ import { Controller } from "./main";
export class NetworkConfigView {
setScanResult(ssidList: SSIDList) {
this.ssidlist.innerHTML = ''
- for (var ssid of ssidList.ssids) {
- var wi = document.createElement("option");
- wi.value = ssid;
+ for (const ssid of ssidList.ssids) {
+ const wi = document.createElement("option");
+ wi.value = ssid;
this.ssidlist.appendChild(wi);
}
}
diff --git a/rust/src_webpack/src/ota.ts b/rust/src_webpack/src/ota.ts
index a533e02..670f9e4 100644
--- a/rust/src_webpack/src/ota.ts
+++ b/rust/src_webpack/src/ota.ts
@@ -17,7 +17,7 @@ export class OTAView {
const file = document.getElementById("firmware_file") as HTMLInputElement;
this.file1Upload = file
this.file1Upload.onchange = () => {
- var selectedFile = file.files?.[0];
+ const selectedFile = file.files?.[0];
if (selectedFile == null) {
//TODO error dialog here
return
diff --git a/rust/src_webpack/src/plant.html b/rust/src_webpack/src/plant.html
index 8acdc1b..b653193 100644
--- a/rust/src_webpack/src/plant.html
+++ b/rust/src_webpack/src/plant.html
@@ -14,7 +14,7 @@
}
.plantcheckbox{
min-width: 20px;
- margin: 0px;
+ margin: 0;
}
@@ -59,7 +59,7 @@
diff --git a/rust/src_webpack/src/plant.ts b/rust/src_webpack/src/plant.ts
index 100e11e..e44ad7a 100644
--- a/rust/src_webpack/src/plant.ts
+++ b/rust/src_webpack/src/plant.ts
@@ -1,7 +1,7 @@
const PLANT_COUNT = 8;
-import { Controller } from "./main";
+import {Controller} from "./main";
export class PlantViews {
private readonly measure_moisture: HTMLButtonElement;
@@ -61,12 +61,10 @@ export class PlantView {
constructor(plantId: number, parent:HTMLDivElement, controller:Controller) {
- const dummy = this;
- this.plantId = plantId;
+ this.plantId = plantId;
this.plantDiv = document.createElement("div")! as HTMLDivElement
const template = require('./plant.html') as string;
- const plantRaw = template.replaceAll("${plantId}", String(plantId));
- this.plantDiv.innerHTML = plantRaw
+ this.plantDiv.innerHTML = template.replaceAll("${plantId}", String(plantId))
this.plantDiv.classList.add("plantcontainer")
parent.appendChild(this.plantDiv)
@@ -184,7 +182,7 @@ export class PlantView {
}
getConfig(): PlantConfig {
- const rv: PlantConfig = {
+ return {
mode: this.mode.value,
target_moisture: this.targetMoisture.valueAsNumber,
pump_time_s: this.pumpTimeS.valueAsNumber,
@@ -196,14 +194,5 @@ export class PlantView {
moisture_sensor_min_frequency: this.moistureSensorMinFrequency.valueAsNumber || undefined,
moisture_sensor_max_frequency: this.moistureSensorMaxFrequency.valueAsNumber || undefined,
};
- return rv;
- }
-
- setMoistureA(a: number) {
- this.moistureA.innerText = String(a);
- }
-
- setMoistureB(b: number) {
- this.moistureB.innerText = String(b);
}
}
\ No newline at end of file
diff --git a/rust/src_webpack/src/tankview.html b/rust/src_webpack/src/tankview.html
index 0234d86..e4d1475 100644
--- a/rust/src_webpack/src/tankview.html
+++ b/rust/src_webpack/src/tankview.html
@@ -1,14 +1,14 @@