delete output implemented

This commit is contained in:
Marcus 2024-10-27 01:33:10 +02:00
parent 1419d625a4
commit 9af343bd3e
7 changed files with 66 additions and 6 deletions

View file

@ -207,8 +207,8 @@ struct Config_System_Output {
char name[Max_Outputs][32]; char name[Max_Outputs][32];
bool enabled[Max_Outputs]; bool enabled[Max_Outputs];
byte gpio[Max_Outputs]; byte gpio[Max_Outputs];
bool gpio_invert[Max_Outputs];
bool gpio_pwm[Max_Outputs]; bool gpio_pwm[Max_Outputs];
bool gpio_invert[Max_Outputs];
char i2c[Max_Outputs][8]; char i2c[Max_Outputs][8];
char webcall_host[Max_Outputs][32]; char webcall_host[Max_Outputs][32];
char webcall_path_on[Max_Outputs][32]; char webcall_path_on[Max_Outputs][32];

View file

@ -353,7 +353,7 @@ bool SaveConfig(bool writeToSerial = false) {
file.close(); file.close();
} else { } else {
Serial.printf(":: [LittleFS:SaveConfig] --- %s ---\n", CANGROW_CFG); Serial.printf(":: [LittleFS:SaveConfig] --- %s ---\n", CANGROW_CFG);
serializeJson(doc, Serial); serializeJsonPretty(doc, Serial);
Serial.println(""); Serial.println("");
Serial.printf(":: [LittleFS:SaveConfig] ----------------------\n", CANGROW_CFG); Serial.printf(":: [LittleFS:SaveConfig] ----------------------\n", CANGROW_CFG);
} }

View file

@ -209,6 +209,16 @@ input[type=text], input[type=date], input[type=number], input[type=password], se
border-radius: 3px; border-radius: 3px;
} }
.linkForm {
display: inline-block;
}
.linkForm input[type=submit] {
background: #262B27;
padding: 5px;
}
.hidden { .hidden {
display: none; display: none;
} }

View file

@ -58,6 +58,10 @@ function showSelect(selectId, prefix, hideClass = '') {
if(document.getElementById(toggleId) !== null ) { if(document.getElementById(toggleId) !== null ) {
toggleDisplay(toggleId); toggleDisplay(toggleId);
} }
}
function confirmDelete(name) {
return confirm('Delete ' + name + '?');
})"; })";
void WebFile_cangrow_JS(AsyncWebServerRequest *request) { void WebFile_cangrow_JS(AsyncWebServerRequest *request) {

View file

@ -306,7 +306,9 @@ String Proc_WebPage_system_output(const String& var) {
String output_tr_td; String output_tr_td;
for(byte i=0; i < Max_Outputs; i++) { for(byte i=0; i < Max_Outputs; i++) {
if(config.system.output.type[i] > 0) { if(config.system.output.type[i] > 0) {
#ifndef DEBUG
Serial.printf("DB [Webserver:system:output(Proc)] OutputID %d Type %d\n", i, config.system.output.type[i]); Serial.printf("DB [Webserver:system:output(Proc)] OutputID %d Type %d\n", i, config.system.output.type[i]);
#endif
output_tr_td += "<tr><td>"; output_tr_td += "<tr><td>";
output_tr_td += i; output_tr_td += i;
output_tr_td += "</td><td>"; output_tr_td += "</td><td>";
@ -317,11 +319,26 @@ String Proc_WebPage_system_output(const String& var) {
output_tr_td += Output_Device_descr[config.system.output.device[i]]; output_tr_td += Output_Device_descr[config.system.output.device[i]];
output_tr_td += "</td><td>"; output_tr_td += "</td><td>";
output_tr_td += config.system.output.enabled[i]; output_tr_td += config.system.output.enabled[i];
output_tr_td += "</td><td><a href='#"; output_tr_td += "</td><td>";
// edit button
output_tr_td += "<form class='linkForm' action='/system/output/add' method='get'>";
output_tr_td += "<input type='hidden' name='edit' value='";
output_tr_td += i; output_tr_td += i;
output_tr_td += "'>&#x270F;&#xFE0F;</a> <a href='#"; output_tr_td += "'>";
output_tr_td += "<input type='submit' value='&#x270F;&#xFE0F;'></form> ";
// delete button
output_tr_td += "<form class='linkForm' action='/system/output/' method='post'>";
output_tr_td += "<input type='hidden' name='delete_output' value='";
output_tr_td += i; output_tr_td += i;
output_tr_td += "'>&#x274C;</a></td></tr>"; output_tr_td += "'>";
output_tr_td += "<input type='submit' value='&#x274C;' onclick=\"return confirmDelete('";
output_tr_td += config.system.output.name[i];;
output_tr_td += "')\"></form>";
output_tr_td += "</td></tr>";
} }
} }
@ -341,6 +358,34 @@ String Proc_WebPage_system_output_POST(const String& var) {
void WebPage_system_output(AsyncWebServerRequest *request) { void WebPage_system_output(AsyncWebServerRequest *request) {
if(request->method() == HTTP_POST) { if(request->method() == HTTP_POST) {
if(request->hasParam("delete_output", true)) {
byte outputId;
const AsyncWebParameter* p_delete_output = request->getParam("delete_output", true);
Serial.printf(":: [Webserver:system:output] POST[%s]: %s\n", p_delete_output->name().c_str(), p_delete_output->value().c_str());
outputId = p_delete_output->value().toInt();
Serial.printf(":: [Webserver:system:output] Deleting output: %d\n", outputId);
// we ensure that every field is empty
config.system.output.type[outputId] = 0;
config.system.output.device[outputId] = 0;
// set every field of char array to 0x00 with memset
memset(config.system.output.name[outputId], '\0', sizeof config.system.output.name[outputId]);
config.system.output.enabled[outputId] = 0;
config.system.output.gpio[outputId] = 0;
config.system.output.gpio_pwm[outputId] = 0;
config.system.output.gpio_invert[outputId] = 0;
memset(config.system.output.i2c[outputId], '\0', sizeof config.system.output.i2c[outputId]);
memset(config.system.output.webcall_host[outputId], '\0', sizeof config.system.output.webcall_host[outputId]);
memset(config.system.output.webcall_path_on[outputId], '\0', sizeof config.system.output.webcall_path_on[outputId]);
memset(config.system.output.webcall_path_off[outputId], '\0', sizeof config.system.output.webcall_path_off[outputId]);
SaveConfig();
}
request->send_P(200, "text/html", Page_system_output_HTML, Proc_WebPage_system_output_POST); request->send_P(200, "text/html", Page_system_output_HTML, Proc_WebPage_system_output_POST);
Serial.println(":: [Webserver:system:output] [POST] hello"); Serial.println(":: [Webserver:system:output] [POST] hello");

View file

@ -137,6 +137,7 @@ const char* Page_system_wipe_HTML_WIPE_MSG_POST PROGMEM = R"(Restarting...)";
*/ */
const char* Page_system_output_HTML PROGMEM = R"(%HEADER% const char* Page_system_output_HTML PROGMEM = R"(%HEADER%
%SUBNAV% %SUBNAV%
%SAVE_MSG%
<a class='button' href='/system/output/add'>&#10133; Add output</a> <a class='button' href='/system/output/add'>&#10133; Add output</a>
<table class='centered'> <table class='centered'>
<tr> <tr>

View file

@ -127,7 +127,7 @@
</form> </form>
<form class='linkForm' method='post' action='index.html'> <form class='linkForm' method='post' action='index.html'>
<input type='hidden' name='del' value='0'> <input type='hidden' name='del' value='0'>
<input class='linkForm' type='submit' value='&#x274C;' onclick="return confirmDelete('Tasmota LED1')"> <input type='submit' value='&#x274C;' onclick="return confirmDelete('Tasmota LED1')">
</form> </form>
</td></tr><tr><td>6</td> </td></tr><tr><td>6</td>
<td>Test</td> <td>Test</td>