typescript changes
This commit is contained in:
		| @@ -1,54 +1,65 @@ | ||||
| interface PlantControllerConfig { | ||||
|     ap_ssid: string, | ||||
|     ssid: string, | ||||
|     password: string, | ||||
|     mqtt_url: string, | ||||
|     base_topic: string, | ||||
|     tank_sensor_enabled: boolean, | ||||
|     tank_allow_pumping_if_sensor_error: boolean, | ||||
|     tank_useable_ml: number, | ||||
|     tank_warn_percent: number, | ||||
|     tank_empty_percent: number, | ||||
|     tank_full_percent: number, | ||||
|     night_lamp_hour_start: number, | ||||
|     night_lamp_hour_end: number, | ||||
|     night_lamp_only_when_dark: boolean, | ||||
|     max_consecutive_pump_count: number, | ||||
|    | ||||
|     plants: PlantConfig[] | ||||
|   } | ||||
| interface NetworkConfig { | ||||
|   ap_ssid: string, | ||||
|   ssid: string, | ||||
|   password: string, | ||||
|   mqtt_url: string, | ||||
|   base_topic: string | ||||
| } | ||||
|  | ||||
|   interface PlantConfig{ | ||||
|     mode: string, | ||||
|     target_moisture: number, | ||||
|     pump_time_s: number, | ||||
|     pump_cooldown_min: number, | ||||
|     pump_hour_start: number, | ||||
|     pump_hour_end: number, | ||||
|     sensor_b: boolean | ||||
|   } | ||||
|    | ||||
|    | ||||
|   interface SSIDList { | ||||
|     ssids: [string] | ||||
|   } | ||||
|    | ||||
|   interface TestPump { | ||||
|     pump: number | ||||
|   } | ||||
|    | ||||
|   interface SetTime { | ||||
|     time: string | ||||
|   } | ||||
|    | ||||
|   interface GetData { | ||||
|     rtc: string, | ||||
|     native: string, | ||||
|     moisture_a: [number], | ||||
|     moisture_b: [number], | ||||
|   } | ||||
|    | ||||
|   interface VersionInfo { | ||||
|     git_hash: string, | ||||
|     build_time: string | ||||
|   } | ||||
| interface NightLampConfig { | ||||
|   night_lamp_hour_start: number, | ||||
|   night_lamp_hour_end: number, | ||||
|   night_lamp_only_when_dark: boolean, | ||||
| } | ||||
|  | ||||
| interface TankConfig { | ||||
|   tank_sensor_enabled: boolean, | ||||
|   tank_allow_pumping_if_sensor_error: boolean, | ||||
|   tank_useable_ml: number, | ||||
|   tank_warn_percent: number, | ||||
|   tank_empty_percent: number, | ||||
|   tank_full_percent: number, | ||||
| } | ||||
|  | ||||
| interface PlantControllerConfig { | ||||
|   network: NetworkConfig, | ||||
|   tank: TankConfig, | ||||
|   nightLamp: NightLampConfig, | ||||
|   plants: PlantConfig[] | ||||
| } | ||||
|  | ||||
| interface PlantConfig { | ||||
|   mode: string, | ||||
|   target_moisture: number, | ||||
|   pump_time_s: number, | ||||
|   pump_cooldown_min: number, | ||||
|   pump_hour_start: number, | ||||
|   pump_hour_end: number, | ||||
|   sensor_b: boolean, | ||||
|   max_consecutive_pump_count: number, | ||||
| } | ||||
|  | ||||
|  | ||||
| interface SSIDList { | ||||
|   ssids: [string] | ||||
| } | ||||
|  | ||||
| interface TestPump { | ||||
|   pump: number | ||||
| } | ||||
|  | ||||
| interface SetTime { | ||||
|   time: string | ||||
| } | ||||
|  | ||||
| interface GetData { | ||||
|   rtc: string, | ||||
|   native: string, | ||||
|   moisture_a: [number], | ||||
|   moisture_b: [number], | ||||
| } | ||||
|  | ||||
| interface VersionInfo { | ||||
|   git_hash: string, | ||||
|   build_time: string | ||||
| } | ||||
| @@ -5,14 +5,17 @@ console.log("Url is " + PUBLIC_URL); | ||||
|  | ||||
| import { TimeView } from "./timeview"; | ||||
| import { PlantView, PlantViews } from "./plant"; | ||||
| import { NetworkConfigView } from "./network"; | ||||
|  | ||||
|  | ||||
| export class Controller{ | ||||
|   private readonly timeView: TimeView | ||||
|   readonly plantViews:PlantViews | ||||
|   constructor(){ | ||||
| export class Controller { | ||||
|   readonly timeView: TimeView | ||||
|   readonly plantViews: PlantViews | ||||
|   readonly networkView: NetworkConfigView; | ||||
|   constructor() { | ||||
|     this.timeView = new TimeView() | ||||
|     this.plantViews = new PlantViews(this) | ||||
|     this.networkView = new NetworkConfigView(this) | ||||
|   } | ||||
|  | ||||
|   configChanged() { | ||||
| @@ -38,14 +41,14 @@ export class Controller{ | ||||
|       .then(json => json as GetData) | ||||
|       .then(time => { | ||||
|         controller.timeView.update(time.native, time.rtc) | ||||
|    | ||||
|  | ||||
|         time.moisture_a.forEach((a, index) => { | ||||
|           controller.plantViews.getPlant(index).setMoistureA(a); | ||||
|         }) | ||||
|         time.moisture_b.forEach((b, index) => { | ||||
|           controller.plantViews.getPlant(index).setMoistureB(b); | ||||
|         }) | ||||
|    | ||||
|  | ||||
|         setTimeout(controller.updateRealTimeData, 1000); | ||||
|       }) | ||||
|       .catch(error => { | ||||
| @@ -108,50 +111,70 @@ function addTimeOptions(select: HTMLSelectElement) { | ||||
|   } | ||||
| } | ||||
|  | ||||
| var ap_ssid = (document.getElementById("ap_ssid") as HTMLInputElement); | ||||
| ap_ssid.onchange = updateJson | ||||
| var ssid = (document.getElementById("ssid") as HTMLInputElement); | ||||
| ssid.onchange = updateJson | ||||
| var password = (document.getElementById("password") as HTMLInputElement); | ||||
| password.onchange = updateJson | ||||
| let mqtt_url = document.getElementById("mqtt_url") as HTMLInputElement; | ||||
| mqtt_url.onchange = updateJson | ||||
| let base_topic = document.getElementById("base_topic") as HTMLInputElement; | ||||
| base_topic.onchange = updateJson | ||||
| let max_consecutive_pump_count = document.getElementById("max_consecutive_pump_count") as HTMLInputElement; | ||||
| max_consecutive_pump_count.onchange = updateJson | ||||
| class TankConfigView { | ||||
|   max_consecutive_pump_count: HTMLInputElement; | ||||
|   tank_useable_ml: HTMLInputElement; | ||||
|   tank_empty_percent: HTMLInputElement; | ||||
|   tank_full_percent: HTMLInputElement; | ||||
|   tank_warn_percent: HTMLInputElement; | ||||
|   tank_sensor_enabled: HTMLInputElement; | ||||
|   tank_allow_pumping_if_sensor_error: HTMLInputElement; | ||||
|  | ||||
|   constructor(controller:Controller){ | ||||
|     this.max_consecutive_pump_count = document.getElementById("max_consecutive_pump_count") as HTMLInputElement; | ||||
|     this.max_consecutive_pump_count.onchange = controller.configChanged | ||||
|     this.tank_useable_ml = document.getElementById("tank_useable_ml") as HTMLInputElement; | ||||
|     this.tank_useable_ml.onchange = controller.configChanged | ||||
|     this.tank_empty_percent = document.getElementById("tank_empty_percent") as HTMLInputElement; | ||||
|     this.tank_empty_percent.onchange = controller.configChanged | ||||
|     this.tank_full_percent = document.getElementById("tank_full_percent") as HTMLInputElement; | ||||
|     this.tank_full_percent.onchange = controller.configChanged | ||||
|     this.tank_warn_percent = document.getElementById("tank_warn_percent") as HTMLInputElement; | ||||
|     this.tank_warn_percent.onchange = controller.configChanged | ||||
|     this.tank_sensor_enabled = document.getElementById("tank_sensor_enabled") as HTMLInputElement; | ||||
|     this.tank_sensor_enabled.onchange = controller.configChanged | ||||
|     this.tank_allow_pumping_if_sensor_error = document.getElementById("tank_allow_pumping_if_sensor_error") as HTMLInputElement; | ||||
|     this.tank_allow_pumping_if_sensor_error.onchange = controller.configChanged | ||||
|   } | ||||
| } | ||||
|  | ||||
| class NightLampView { | ||||
|   night_lamp_only_when_dark: HTMLInputElement; | ||||
|   night_lamp_time_start: HTMLSelectElement; | ||||
|   night_lamp_time_end: HTMLSelectElement; | ||||
|   constructor(){ | ||||
|     this.night_lamp_only_when_dark = document.getElementById("night_lamp_only_when_dark") as HTMLInputElement; | ||||
|     this.night_lamp_only_when_dark.onchange = updateJson | ||||
|     this.night_lamp_time_start = document.getElementById("night_lamp_time_start") as HTMLSelectElement; | ||||
|     this.night_lamp_time_start.onchange = updateJson | ||||
|     for (let i = 0; i < 24; i++) { | ||||
|       let option = document.createElement("option"); | ||||
|       if (i == 20){ | ||||
|           option.selected = true | ||||
|       } | ||||
|       option.innerText = i.toString(); | ||||
|       this.night_lamp_time_start.appendChild(option); | ||||
|     } | ||||
|     this.night_lamp_time_end = document.getElementById("night_lamp_time_end") as HTMLSelectElement; | ||||
|     this.night_lamp_time_end.onchange = updateJson | ||||
|  | ||||
|  | ||||
|     for (let i = 0; i < 24; i++) { | ||||
|       let option = document.createElement("option"); | ||||
|       if (i == 1){ | ||||
|           option.selected = true | ||||
|       } | ||||
|       option.innerText = i.toString(); | ||||
|       this.night_lamp_time_end.appendChild(option); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| let tank_useable_ml = document.getElementById("tank_useable_ml") as HTMLInputElement; | ||||
| tank_useable_ml.onchange = updateJson | ||||
| let tank_empty_percent = document.getElementById("tank_empty_percent") as HTMLInputElement; | ||||
| tank_empty_percent.onchange = updateJson | ||||
| let tank_full_percent = document.getElementById("tank_full_percent") as HTMLInputElement; | ||||
| tank_full_percent.onchange = updateJson | ||||
| let tank_warn_percent = document.getElementById("tank_warn_percent") as HTMLInputElement; | ||||
| tank_warn_percent.onchange = updateJson | ||||
| let tank_sensor_enabled = document.getElementById("tank_sensor_enabled") as HTMLInputElement; | ||||
| tank_sensor_enabled.onchange = updateJson | ||||
| let tank_allow_pumping_if_sensor_error = document.getElementById("tank_allow_pumping_if_sensor_error") as HTMLInputElement; | ||||
| tank_allow_pumping_if_sensor_error.onchange = updateJson | ||||
| let night_lamp_only_when_dark = document.getElementById("night_lamp_only_when_dark") as HTMLInputElement; | ||||
| night_lamp_only_when_dark.onchange = updateJson | ||||
| let night_lamp_time_start = document.getElementById("night_lamp_time_start") as HTMLSelectElement; | ||||
| night_lamp_time_start.onchange = updateJson | ||||
| addTimeOptions(night_lamp_time_start); | ||||
| let night_lamp_time_end = document.getElementById("night_lamp_time_end") as HTMLSelectElement; | ||||
| night_lamp_time_end.onchange = updateJson | ||||
| addTimeOptions(night_lamp_time_end); | ||||
|  | ||||
|  | ||||
| function updateJson() { | ||||
|   var current: PlantControllerConfig = { | ||||
|     ap_ssid: ap_ssid.value, | ||||
|     ssid: ssid.value, | ||||
|     password: password.value, | ||||
|     max_consecutive_pump_count: +max_consecutive_pump_count.value, | ||||
|     mqtt_url: mqtt_url.value, | ||||
|     base_topic: base_topic.value, | ||||
|     tank_allow_pumping_if_sensor_error: tank_allow_pumping_if_sensor_error.checked, | ||||
|     network: controller.networkView.getConfig(), | ||||
|     tank_sensor_enabled: tank_sensor_enabled.checked, | ||||
|     tank_useable_ml: +tank_useable_ml.value, | ||||
|     tank_warn_percent: +tank_warn_percent.value, | ||||
| @@ -183,7 +206,7 @@ let fromWrapper = (() => { | ||||
|  | ||||
|   let json = document.getElementById('json') as HTMLInputElement | ||||
|  | ||||
|    | ||||
|  | ||||
|   function sync(current: PlantControllerConfig) { | ||||
|     plantcount = current.plants.length | ||||
|  | ||||
| @@ -255,9 +278,9 @@ export function uploadFile() { | ||||
|   var status = document.getElementById("status") as HTMLElement; | ||||
|   var answer = document.getElementById("answer") as HTMLElement; | ||||
|  | ||||
|   if (file1.files == null){ | ||||
|   if (file1.files == null) { | ||||
|     //TODO error dialog here | ||||
|     return  | ||||
|     return | ||||
|   } | ||||
|  | ||||
|   var file = file1.files[0]; | ||||
|   | ||||
							
								
								
									
										32
									
								
								rust/src_webpack/src/network.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								rust/src_webpack/src/network.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| import { Controller } from "."; | ||||
|  | ||||
| export class NetworkConfigView { | ||||
|     getConfig(): NetworkConfig { | ||||
|       return { | ||||
|         ap_ssid: this.ap_ssid.value, | ||||
|         ssid: this.ssid.value, | ||||
|         password: this.password.value, | ||||
|         mqtt_url: this.mqtt_url.value, | ||||
|         base_topic: this.base_topic.value | ||||
|       } | ||||
|     } | ||||
|     private readonly ap_ssid: HTMLInputElement; | ||||
|     private readonly ssid: HTMLInputElement; | ||||
|     private readonly password: HTMLInputElement; | ||||
|     private readonly mqtt_url: HTMLInputElement; | ||||
|     private readonly base_topic: HTMLInputElement; | ||||
|    | ||||
|     constructor(controller: Controller) { | ||||
|       this.ap_ssid = (document.getElementById("ap_ssid") as HTMLInputElement); | ||||
|       this.ap_ssid.onchange = controller.configChanged | ||||
|    | ||||
|       this.ssid = (document.getElementById("ssid") as HTMLInputElement); | ||||
|       this.ssid.onchange = controller.configChanged | ||||
|       this.password = (document.getElementById("password") as HTMLInputElement); | ||||
|       this.password.onchange = controller.configChanged | ||||
|       this.mqtt_url = document.getElementById("mqtt_url") as HTMLInputElement; | ||||
|       this.mqtt_url.onchange = controller.configChanged | ||||
|       this.base_topic = document.getElementById("base_topic") as HTMLInputElement; | ||||
|       this.base_topic.onchange = controller.configChanged | ||||
|     } | ||||
|   } | ||||
| @@ -27,5 +27,9 @@ Mode: <select id="plant_${plantId}_mode"> | ||||
|     "Pump Hour End": <select id="plant_${plantId}_pump_hour_end">19</select> | ||||
|         <br> | ||||
|     Sensor B installed: <input id="plant_${plantId}_sensor_b" type="checkbox"> | ||||
|     <br> | ||||
|     Max Consecutive Pump Count: <input id="plant_${plantId}_max_consecutive_pump_count" type="number" min="1", max="50", placeholder="10"> | ||||
|  | ||||
|  | ||||
|      | ||||
| </div> | ||||
| @@ -33,6 +33,7 @@ export class PlantView { | ||||
|     private readonly mode: HTMLSelectElement; | ||||
|     private readonly moistureA: HTMLElement; | ||||
|     private readonly moistureB: HTMLElement; | ||||
|     private readonly maxConsecutivePumpCount: HTMLInputElement; | ||||
|    | ||||
|    | ||||
|     constructor(plantId: number, parent:HTMLDivElement, controller:Controller) { | ||||
| @@ -105,6 +106,11 @@ export class PlantView { | ||||
|       this.sensorBInstalled.onchange = function(){ | ||||
|         controller.configChanged() | ||||
|       } | ||||
|  | ||||
|       this.maxConsecutivePumpCount = document.getElementById("plant_"+plantId+"_max_consecutive_pump_count") as HTMLInputElement; | ||||
|       this.maxConsecutivePumpCount.onchange = function(){ | ||||
|         controller.configChanged() | ||||
|       } | ||||
|       console.log(this) | ||||
|     } | ||||
|    | ||||
| @@ -117,17 +123,19 @@ export class PlantView { | ||||
|         this.pumpHourStart.value = plantConfig.pump_hour_start.toString(); | ||||
|         this.pumpHourEnd.value = plantConfig.pump_hour_end.toString(); | ||||
|         this.sensorBInstalled.checked = plantConfig.sensor_b | ||||
|         this.maxConsecutivePumpCount.value = plantConfig.max_consecutive_pump_count.toString(); | ||||
|     } | ||||
|  | ||||
|     getConfig() :PlantConfig { | ||||
|       const rv:PlantConfig = { | ||||
|         mode: this.mode.value, | ||||
|         target_moisture: +this.targetMoisture.value, | ||||
|         pump_time_s: +this.pumpTimeS.value, | ||||
|         pump_cooldown_min: +this.pumpCooldown.value, | ||||
|         target_moisture: this.targetMoisture.valueAsNumber, | ||||
|         pump_time_s: this.pumpTimeS.valueAsNumber, | ||||
|         pump_cooldown_min: this.pumpCooldown.valueAsNumber, | ||||
|         pump_hour_start: +this.pumpHourStart.value, | ||||
|         pump_hour_end: +this.pumpHourEnd.value, | ||||
|         sensor_b: this.sensorBInstalled.checked, | ||||
|         max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber | ||||
|       } | ||||
|       return rv | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user