Skip to content

Commit

Permalink
Update unit page, remove unused strings
Browse files Browse the repository at this point in the history
  • Loading branch information
floatplane committed Mar 12, 2024
1 parent 41f319b commit 224a8bd
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 113 deletions.
16 changes: 16 additions & 0 deletions scripts/webserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ def render(path, context = {})
wifi_access_point: "the_ssid",
wifi_signal_strength: "-66",
})
when "/unit" then res.body = render("unit", {
min_temp: "16",
max_temp: "30",
temp_step: "0.5",
temp_unit_c: true,
mode_selection_all: true,
login_password: "",
})
when "/unit_alt" then res.body = render("unit", {
min_temp: "55",
max_temp: "72",
temp_step: "1",
temp_unit_c: false,
mode_selection_all: false,
login_password: "abc123",
})
when "/upgrade" then res.body = render("upgrade")
when "/upload" then res.body = render("upload")
when "/wifi" then res.body = render("wifi", {access_point: "the_ssid", hostname: "the_hostname", password: "abc123"})
Expand Down
46 changes: 46 additions & 0 deletions src/frontend/en-us/views/unit.mst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{> header}}
<main>
<h2>Unit configuration</h2>
<form method='post'>
<p>
<b>Temperature unit</b>
<select name="tu">
<option value="cel"{{#temp_unit_c}} selected{{/temp_unit_c}}>Celsius</option>
<option value="fah"{{^temp_unit_c}} selected{{/temp_unit_c}}>Fahrenheit</option>
</select>
</p>
<p>
<b>Minimum temperature</b>
<br>
<input type="number" id="min_temp" name="min_temp" placeholder=" " value="{{min_temp}}">
</p>
<p>
<b>Maximum temperature</b>
<br>
<input type="number" id="max_temp" name="max_temp" placeholder=" " value="{{max_temp}}">
</p>
<p>
<b>Temperature step</b>
<br>
<input type="number" id="temp_step" step="0.1" name="temp_step" placeholder=" " value="{{temp_step}}">
</p>
<p>
<b>Mode support</b>
<select name="md">
<option value="all"{{#mode_selection_all}} selected{{/mode_selection_all}}>All modes</option>
<option value="nht"{{^mode_selection_all}} selected{{/mode_selection_all}}>All modes except heat</option>
</select>
</p>
<p>
<b>Web password</b>
<br>
<input id="lpw" name="lpw" type="password" placeholder=" " value="{{login_password}}">
</p>
<br/>
<div class="buttons">
<a class="buttonLink" href='/setup'>&lt; Back</a>
<button name='save' type='submit' class='button bgrn'>Save & Reboot</button>
</div>
</form>
</main>
{{> footer}}
2 changes: 2 additions & 0 deletions src/frontend/templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ INCTXT(reboot, "src/frontend/" STRINGIFY(LANGUAGE) "/views/reboot.mst");
INCTXT(reset, "src/frontend/" STRINGIFY(LANGUAGE) "/views/reset.mst");
INCTXT(setup, "src/frontend/" STRINGIFY(LANGUAGE) "/views/setup.mst");
INCTXT(status, "src/frontend/" STRINGIFY(LANGUAGE) "/views/status.mst");
INCTXT(unit, "src/frontend/" STRINGIFY(LANGUAGE) "/views/unit.mst");
INCTXT(upgrade, "src/frontend/" STRINGIFY(LANGUAGE) "/views/upgrade.mst");
INCTXT(upload, "src/frontend/" STRINGIFY(LANGUAGE) "/views/upload.mst");
INCTXT(wifi, "src/frontend/" STRINGIFY(LANGUAGE) "/views/wifi.mst");
Expand Down Expand Up @@ -57,6 +58,7 @@ const __FlashStringHelper *reboot = FPSTR(rebootData);
const __FlashStringHelper *reset = FPSTR(resetData);
const __FlashStringHelper *setup = FPSTR(setupData);
const __FlashStringHelper *status = FPSTR(statusData);
const __FlashStringHelper *unit = FPSTR(unitData);
const __FlashStringHelper *upgrade = FPSTR(upgradeData);
const __FlashStringHelper *upload = FPSTR(uploadData);
const __FlashStringHelper *wifi = FPSTR(wifiData);
Expand Down
1 change: 1 addition & 0 deletions src/frontend/templates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern const __FlashStringHelper *reboot;
extern const __FlashStringHelper *reset;
extern const __FlashStringHelper *setup;
extern const __FlashStringHelper *status;
extern const __FlashStringHelper *unit;
extern const __FlashStringHelper *upgrade;
extern const __FlashStringHelper *upload;
extern const __FlashStringHelper *wifi;
Expand Down
47 changes: 0 additions & 47 deletions src/html_pages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,53 +123,6 @@ const char html_page_control[] PROGMEM =
;
// clang-format on

const char html_page_unit[] PROGMEM =
// clang-format off
"<div id='l1' name='l1'>"
"<fieldset>"
"<legend><b>&nbsp; _TXT_UNIT_TITLE_ &nbsp;</b></legend>"
"<form method='post'>"
"<p>"
"<b>_TXT_UNIT_TEMP_</b>"
"<select name='tu'>"
"<option value='cel' _TU_CEL_>_TXT_F_CELSIUS_</option>"
"<option value='fah' _TU_FAH_>_TXT_F_FH_</option>"
"</select>"
"</p>"
"<p><b>_TXT_UNIT_MINTEMP_</b>"
"<br/>"
"<input type='number' id='min_temp' name='min_temp' placeholder=' ' value='_MIN_TEMP_'>"
"</p>"
"<p><b>_TXT_UNIT_MAXTEMP_</b>"
"<br/>"
"<input type='number' id='max_temp' name='max_temp' placeholder=' ' value='_MAX_TEMP_'>"
"</p>"
"<p><b>_TXT_UNIT_STEPTEMP_</b>"
"<br/>"
"<input type='number' id='temp_step' step='0.1' name='temp_step' placeholder=' ' value='_TEMP_STEP_'>"
"</p>"
"<p>"
"<b>_TXT_UNIT_MODES_</b>"
"<select name='md'>"
"<option value='all' _MD_ALL_>_TXT_F_ALLMODES_</option>"
"<option value='nht' _MD_NONHEAT_>_TXT_F_NOHEAT_</option>"
"</select>"
"</p>"
"<p><b>_TXT_UNIT_PASSWORD_</b>"
"<br/>"
"<input id='lpw' name='lpw' type='password' placeholder=' ' value='_LOGIN_PASSWORD_'>"
"</p>"
"<br/>"
"<button name='save' type='submit' class='button bgrn'>_TXT_SAVE_</button>"
"</form>"
"</fieldset>"
"<p>"
"<a class='button' href='/setup' class='back'>_TXT_BACK_</a>"
"</p>"
"</div>"
;
// clang-format on

const char html_page_login[] PROGMEM =
// clang-format off
"<script>"
Expand Down
35 changes: 0 additions & 35 deletions src/languages/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@
#pragma once
#include <Arduino.h>

// Main Menu
const char txt_control[] PROGMEM = "Control";
const char txt_setup[] PROGMEM = "Setup";
const char txt_status[] PROGMEM = "Status";
const char txt_firmware_upgrade[] PROGMEM = "Firmware Upgrade";
const char txt_reboot[] PROGMEM = "Reboot";

// Setup Menu
const char txt_MQTT[] PROGMEM = "MQTT";
const char txt_WIFI[] PROGMEM = "WIFI";
const char txt_unit[] PROGMEM = "Unit";
const char txt_others[] PROGMEM = "Others";
const char txt_reset[] PROGMEM = "Reset configuration";
const char txt_reset_confirm[] PROGMEM = "Do you really want to reset this unit?";

// Buttons
const char txt_back[] PROGMEM = "Back";
const char txt_save[] PROGMEM = "Save & Reboot";
Expand All @@ -49,10 +34,6 @@ const char txt_f_quiet[] PROGMEM = "QUIET";
const char txt_f_speed[] PROGMEM = "SPEED";
const char txt_f_swing[] PROGMEM = "SWING";
const char txt_f_pos[] PROGMEM = "POSITION";
const char txt_f_celsius[] PROGMEM = "Celsius";
const char txt_f_fh[] PROGMEM = "Fahrenheit";
const char txt_f_allmodes[] PROGMEM = "All modes";
const char txt_f_noheat[] PROGMEM = "All modes except heat";

// Page Control
const char txt_ctrl_title[] PROGMEM = "Control Unit";
Expand All @@ -64,25 +45,9 @@ const char txt_ctrl_vane[] PROGMEM = "Vane";
const char txt_ctrl_wvane[] PROGMEM = "Wide Vane";
const char txt_ctrl_ctemp[] PROGMEM = "Current temperature";

// Page Unit
const char txt_unit_title[] PROGMEM = "Unit configuration";
const char txt_unit_temp[] PROGMEM = "Temperature unit";
const char txt_unit_maxtemp[] PROGMEM = "Maximum temperature";
const char txt_unit_mintemp[] PROGMEM = "Minimum temperature";
const char txt_unit_steptemp[] PROGMEM = "Temperature step";
const char txt_unit_modes[] PROGMEM = "Mode support";
const char txt_unit_password[] PROGMEM = "Web password";

// Page Login
const char txt_login_title[] PROGMEM = "Authentication";
const char txt_login_password[] PROGMEM = "Password";
const char txt_login_sucess[] PROGMEM =
"Login successful, you will be redirected in a few seconds.";
const char txt_login_fail[] PROGMEM = "Wrong username/password! Try again.";

// Page Init
const char txt_init_title[] PROGMEM = "Initial setup";
const char txt_init_reboot_mes[] PROGMEM =
"Rebooting and connecting to your WiFi network! You should see it listed "
"in on your access point.";
const char txt_init_reboot[] PROGMEM = "Rebooting...";
40 changes: 9 additions & 31 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,37 +841,15 @@ void handleUnitGet() {

LOG(F("handleUnitGet()"));

String unitPage = FPSTR(html_page_unit);
unitPage.replace("_TXT_SAVE_", FPSTR(txt_save));
unitPage.replace("_TXT_BACK_", FPSTR(txt_back));
unitPage.replace("_TXT_UNIT_TITLE_", FPSTR(txt_unit_title));
unitPage.replace("_TXT_UNIT_TEMP_", FPSTR(txt_unit_temp));
unitPage.replace("_TXT_UNIT_MINTEMP_", FPSTR(txt_unit_mintemp));
unitPage.replace("_TXT_UNIT_MAXTEMP_", FPSTR(txt_unit_maxtemp));
unitPage.replace("_TXT_UNIT_STEPTEMP_", FPSTR(txt_unit_steptemp));
unitPage.replace("_TXT_UNIT_MODES_", FPSTR(txt_unit_modes));
unitPage.replace("_TXT_UNIT_PASSWORD_", FPSTR(txt_unit_password));
unitPage.replace("_TXT_F_CELSIUS_", FPSTR(txt_f_celsius));
unitPage.replace("_TXT_F_FH_", FPSTR(txt_f_fh));
unitPage.replace("_TXT_F_ALLMODES_", FPSTR(txt_f_allmodes));
unitPage.replace("_TXT_F_NOHEAT_", FPSTR(txt_f_noheat));
unitPage.replace(F("_MIN_TEMP_"), config.unit.minTemp.toString(config.unit.tempUnit));
unitPage.replace(F("_MAX_TEMP_"), config.unit.maxTemp.toString(config.unit.tempUnit));
unitPage.replace(F("_TEMP_STEP_"), String(config.unit.tempStep));
// temp
if (config.unit.tempUnit == TempUnit::F) {
unitPage.replace(F("_TU_FAH_"), F("selected"));
} else {
unitPage.replace(F("_TU_CEL_"), F("selected"));
}
// mode
if (config.unit.supportHeatMode) {
unitPage.replace(F("_MD_ALL_"), F("selected"));
} else {
unitPage.replace(F("_MD_NONHEAT_"), F("selected"));
}
unitPage.replace(F("_LOGIN_PASSWORD_"), config.unit.login_password);
sendWrappedHTML(unitPage);
JsonDocument data;
data[F("min_temp")] = config.unit.minTemp.toString(config.unit.tempUnit);
data[F("max_temp")] = config.unit.maxTemp.toString(config.unit.tempUnit);
data[F("temp_step")] = config.unit.tempStep;
data[F("temp_unit_c")] = config.unit.tempUnit == TempUnit::C;
data[F("mode_selection_all")] = config.unit.supportHeatMode;
data[F("login_password")] = config.unit.login_password;
renderView(Ministache(views::unit), data,
{{"header", partials::header}, {"footer", partials::footer}});
}

void handleUnitPost() {
Expand Down

0 comments on commit 224a8bd

Please sign in to comment.