typescript changes
This commit is contained in:
parent
8bd2cb72d0
commit
92299665b6
@ -1,54 +1,65 @@
|
|||||||
|
interface NetworkConfig {
|
||||||
|
ap_ssid: string,
|
||||||
|
ssid: string,
|
||||||
|
password: string,
|
||||||
|
mqtt_url: string,
|
||||||
|
base_topic: 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 {
|
interface PlantControllerConfig {
|
||||||
ap_ssid: string,
|
network: NetworkConfig,
|
||||||
ssid: string,
|
tank: TankConfig,
|
||||||
password: string,
|
nightLamp: NightLampConfig,
|
||||||
mqtt_url: string,
|
plants: PlantConfig[]
|
||||||
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 PlantConfig {
|
||||||
}
|
mode: string,
|
||||||
|
target_moisture: number,
|
||||||
interface PlantConfig{
|
pump_time_s: number,
|
||||||
mode: string,
|
pump_cooldown_min: number,
|
||||||
target_moisture: number,
|
pump_hour_start: number,
|
||||||
pump_time_s: number,
|
pump_hour_end: number,
|
||||||
pump_cooldown_min: number,
|
sensor_b: boolean,
|
||||||
pump_hour_start: number,
|
max_consecutive_pump_count: number,
|
||||||
pump_hour_end: number,
|
}
|
||||||
sensor_b: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface SSIDList {
|
interface SSIDList {
|
||||||
ssids: [string]
|
ssids: [string]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TestPump {
|
interface TestPump {
|
||||||
pump: number
|
pump: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SetTime {
|
interface SetTime {
|
||||||
time: string
|
time: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GetData {
|
interface GetData {
|
||||||
rtc: string,
|
rtc: string,
|
||||||
native: string,
|
native: string,
|
||||||
moisture_a: [number],
|
moisture_a: [number],
|
||||||
moisture_b: [number],
|
moisture_b: [number],
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VersionInfo {
|
interface VersionInfo {
|
||||||
git_hash: string,
|
git_hash: string,
|
||||||
build_time: string
|
build_time: string
|
||||||
}
|
}
|
@ -5,14 +5,17 @@ console.log("Url is " + PUBLIC_URL);
|
|||||||
|
|
||||||
import { TimeView } from "./timeview";
|
import { TimeView } from "./timeview";
|
||||||
import { PlantView, PlantViews } from "./plant";
|
import { PlantView, PlantViews } from "./plant";
|
||||||
|
import { NetworkConfigView } from "./network";
|
||||||
|
|
||||||
|
|
||||||
export class Controller{
|
export class Controller {
|
||||||
private readonly timeView: TimeView
|
readonly timeView: TimeView
|
||||||
readonly plantViews:PlantViews
|
readonly plantViews: PlantViews
|
||||||
constructor(){
|
readonly networkView: NetworkConfigView;
|
||||||
|
constructor() {
|
||||||
this.timeView = new TimeView()
|
this.timeView = new TimeView()
|
||||||
this.plantViews = new PlantViews(this)
|
this.plantViews = new PlantViews(this)
|
||||||
|
this.networkView = new NetworkConfigView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
configChanged() {
|
configChanged() {
|
||||||
@ -108,50 +111,70 @@ function addTimeOptions(select: HTMLSelectElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ap_ssid = (document.getElementById("ap_ssid") as HTMLInputElement);
|
class TankConfigView {
|
||||||
ap_ssid.onchange = updateJson
|
max_consecutive_pump_count: HTMLInputElement;
|
||||||
var ssid = (document.getElementById("ssid") as HTMLInputElement);
|
tank_useable_ml: HTMLInputElement;
|
||||||
ssid.onchange = updateJson
|
tank_empty_percent: HTMLInputElement;
|
||||||
var password = (document.getElementById("password") as HTMLInputElement);
|
tank_full_percent: HTMLInputElement;
|
||||||
password.onchange = updateJson
|
tank_warn_percent: HTMLInputElement;
|
||||||
let mqtt_url = document.getElementById("mqtt_url") as HTMLInputElement;
|
tank_sensor_enabled: HTMLInputElement;
|
||||||
mqtt_url.onchange = updateJson
|
tank_allow_pumping_if_sensor_error: HTMLInputElement;
|
||||||
let base_topic = document.getElementById("base_topic") as HTMLInputElement;
|
|
||||||
base_topic.onchange = updateJson
|
constructor(controller:Controller){
|
||||||
let max_consecutive_pump_count = document.getElementById("max_consecutive_pump_count") as HTMLInputElement;
|
this.max_consecutive_pump_count = document.getElementById("max_consecutive_pump_count") as HTMLInputElement;
|
||||||
max_consecutive_pump_count.onchange = updateJson
|
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() {
|
function updateJson() {
|
||||||
var current: PlantControllerConfig = {
|
var current: PlantControllerConfig = {
|
||||||
ap_ssid: ap_ssid.value,
|
network: controller.networkView.getConfig(),
|
||||||
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,
|
|
||||||
tank_sensor_enabled: tank_sensor_enabled.checked,
|
tank_sensor_enabled: tank_sensor_enabled.checked,
|
||||||
tank_useable_ml: +tank_useable_ml.value,
|
tank_useable_ml: +tank_useable_ml.value,
|
||||||
tank_warn_percent: +tank_warn_percent.value,
|
tank_warn_percent: +tank_warn_percent.value,
|
||||||
@ -255,7 +278,7 @@ export function uploadFile() {
|
|||||||
var status = document.getElementById("status") as HTMLElement;
|
var status = document.getElementById("status") as HTMLElement;
|
||||||
var answer = document.getElementById("answer") as HTMLElement;
|
var answer = document.getElementById("answer") as HTMLElement;
|
||||||
|
|
||||||
if (file1.files == null){
|
if (file1.files == null) {
|
||||||
//TODO error dialog here
|
//TODO error dialog here
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
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>
|
"Pump Hour End": <select id="plant_${plantId}_pump_hour_end">19</select>
|
||||||
<br>
|
<br>
|
||||||
Sensor B installed: <input id="plant_${plantId}_sensor_b" type="checkbox">
|
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>
|
</div>
|
@ -33,6 +33,7 @@ export class PlantView {
|
|||||||
private readonly mode: HTMLSelectElement;
|
private readonly mode: HTMLSelectElement;
|
||||||
private readonly moistureA: HTMLElement;
|
private readonly moistureA: HTMLElement;
|
||||||
private readonly moistureB: HTMLElement;
|
private readonly moistureB: HTMLElement;
|
||||||
|
private readonly maxConsecutivePumpCount: HTMLInputElement;
|
||||||
|
|
||||||
|
|
||||||
constructor(plantId: number, parent:HTMLDivElement, controller:Controller) {
|
constructor(plantId: number, parent:HTMLDivElement, controller:Controller) {
|
||||||
@ -105,6 +106,11 @@ export class PlantView {
|
|||||||
this.sensorBInstalled.onchange = function(){
|
this.sensorBInstalled.onchange = function(){
|
||||||
controller.configChanged()
|
controller.configChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.maxConsecutivePumpCount = document.getElementById("plant_"+plantId+"_max_consecutive_pump_count") as HTMLInputElement;
|
||||||
|
this.maxConsecutivePumpCount.onchange = function(){
|
||||||
|
controller.configChanged()
|
||||||
|
}
|
||||||
console.log(this)
|
console.log(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,17 +123,19 @@ export class PlantView {
|
|||||||
this.pumpHourStart.value = plantConfig.pump_hour_start.toString();
|
this.pumpHourStart.value = plantConfig.pump_hour_start.toString();
|
||||||
this.pumpHourEnd.value = plantConfig.pump_hour_end.toString();
|
this.pumpHourEnd.value = plantConfig.pump_hour_end.toString();
|
||||||
this.sensorBInstalled.checked = plantConfig.sensor_b
|
this.sensorBInstalled.checked = plantConfig.sensor_b
|
||||||
|
this.maxConsecutivePumpCount.value = plantConfig.max_consecutive_pump_count.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
getConfig() :PlantConfig {
|
getConfig() :PlantConfig {
|
||||||
const rv:PlantConfig = {
|
const rv:PlantConfig = {
|
||||||
mode: this.mode.value,
|
mode: this.mode.value,
|
||||||
target_moisture: +this.targetMoisture.value,
|
target_moisture: this.targetMoisture.valueAsNumber,
|
||||||
pump_time_s: +this.pumpTimeS.value,
|
pump_time_s: this.pumpTimeS.valueAsNumber,
|
||||||
pump_cooldown_min: +this.pumpCooldown.value,
|
pump_cooldown_min: this.pumpCooldown.valueAsNumber,
|
||||||
pump_hour_start: +this.pumpHourStart.value,
|
pump_hour_start: +this.pumpHourStart.value,
|
||||||
pump_hour_end: +this.pumpHourEnd.value,
|
pump_hour_end: +this.pumpHourEnd.value,
|
||||||
sensor_b: this.sensorBInstalled.checked,
|
sensor_b: this.sensorBInstalled.checked,
|
||||||
|
max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber
|
||||||
}
|
}
|
||||||
return rv
|
return rv
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user