From 17657484225c7d3d0ceaeada111d8b38ebbf4c82 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 24 Oct 2024 16:53:21 +0200 Subject: [PATCH] implemented highlighting active nav entry --- Arduino/CanGrow/include/Webserver/Common.h | 49 ++++++++++++++++--- .../include/Webserver/File_cangrow_CSS.h | 8 +-- Arduino/CanGrow/include/Webserver/Header.h | 10 ++-- .../CanGrow/include/Webserver/Page_system.h | 6 +-- Arduino/CanGrow/include/Webserver/Page_wifi.h | 2 +- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/Arduino/CanGrow/include/Webserver/Common.h b/Arduino/CanGrow/include/Webserver/Common.h index 74935a2..05a3a72 100644 --- a/Arduino/CanGrow/include/Webserver/Common.h +++ b/Arduino/CanGrow/include/Webserver/Common.h @@ -30,6 +30,10 @@ #include "Common_HTML.h" +/* + * TestHeaderFooter - checks if the given var from the webserver processor + * is actual a template variable from header or footer. + */ bool TestHeaderFooter(const String& var) { #ifdef DEBUG Serial.print(":: [Webserver:Page:root:proc:hf] var: "); @@ -37,20 +41,40 @@ bool TestHeaderFooter(const String& var) { #endif if( - (var == "HEADER") || - (var == "FOOTER") || - (var == "CGVER") || - (var == "CGBUILD") || - (var == "GROWNAME") || - (var == "CANGROW_CSS") || - (var == "NEED_RESTART")) { + (var == "HEADER") || + (var == "FOOTER") || + (var == "CGVER") || + (var == "CGBUILD") || + (var == "GROWNAME") || + (var == "CANGROW_CSS") || + (var == "NEED_RESTART") || + (var == "ACTIVE_NAV_GROW") || + (var == "ACTIVE_NAV_SYSTEM") || + (var == "ACTIVE_NAV_WIFI") || + (var == "ACTIVE_NAV_HELP") || + (var == "PLACEHOLDER")) { return true; } else { return false; } } -String AddHeaderFooter(const String& var) { + +/* + * AddHeaderFooter - processor for header and footer template variables + * + * String& var: + * the string we receive from the processor is the actual + * variable name we replace here. + * byte activeNav: + * contains the number representing which page is active + * 1 - grow settings + * 2 - system settings + * 3 - wifi settings + * 4 - help page + */ +String AddHeaderFooter(const String& var, byte activeNav = 0) { + String activeNav_ClassName = "activeNav"; if(var == "HEADER") { return String(Header_HTML); } else if(var == "FOOTER") { @@ -63,12 +87,21 @@ String AddHeaderFooter(const String& var) { return String(config.grow.growName); } else if(var == "CANGROW_CSS") { return String(File_cangrow_CSS); + } else if((var == "ACTIVE_NAV_GROW") && (activeNav == 1)) { + return activeNav_ClassName; + } else if((var == "ACTIVE_NAV_SYSTEM") && (activeNav == 2)) { + return activeNav_ClassName; + } else if((var == "ACTIVE_NAV_WIFI") && (activeNav == 3)) { + return activeNav_ClassName; + } else if((var == "ACTIVE_NAV_HELP") && (activeNav == 4)) { + return activeNav_ClassName; } else if(var == "NEED_RESTART") { if(needRestart == true) { return String(Common_HTML_NEED_RESTART); } else { return String(); } + } else { return String(); } diff --git a/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h b/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h index fe75a7e..7355efe 100644 --- a/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h +++ b/Arduino/CanGrow/include/Webserver/File_cangrow_CSS.h @@ -137,7 +137,7 @@ a:active { } .subnav li { - /*background: #026b45;*/ + background: #262B27; list-style: none; border-radius: 3px; margin-bottom: 3px; @@ -163,7 +163,7 @@ a:active { padding: 5px 10px; } -.nav li a:hover, .subnav li a:hover, .activeMenu, .button:link:hover, .button:visited:hover, input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover { +.nav li a:hover, .subnav li a:hover, .activeNav, .button:link:hover, .button:visited:hover, input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover { background: #04AA6D; color: #fff; border-radius: 3px; @@ -174,11 +174,11 @@ a:active { color: #cae0d0; } -.activeMenu { +.activeNav { background: #444; } -.MenuTime { +.navTime { background: #292929; } diff --git a/Arduino/CanGrow/include/Webserver/Header.h b/Arduino/CanGrow/include/Webserver/Header.h index 3636124..8b39888 100644 --- a/Arduino/CanGrow/include/Webserver/Header.h +++ b/Arduino/CanGrow/include/Webserver/Header.h @@ -40,11 +40,11 @@ const char* Header_HTML PROGMEM = R"(
diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h index 5e5fc94..94edb1c 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system.h +++ b/Arduino/CanGrow/include/Webserver/Page_system.h @@ -38,7 +38,7 @@ // https://techtutorialsx.com/2018/07/23/esp32-arduino-http-server-template-processing-with-multiple-placeholders/ String Proc_WebPage_system(const String& var) { if(TestHeaderFooter(var)) { - return AddHeaderFooter(var); + return AddHeaderFooter(var, 2); } else if(var == "SUBNAV") { return String(Page_system_HTML_SUBNAV); } else { @@ -99,7 +99,7 @@ void WebPage_system(AsyncWebServerRequest *request) { */ String Proc_WebPage_system_restart(const String& var) { if(TestHeaderFooter(var)) { - return AddHeaderFooter(var); + return AddHeaderFooter(var, 2); } else if(var == "SUBNAV") { return String(Page_system_HTML_SUBNAV); } else if(var == "RESTART_MSG") { @@ -173,7 +173,7 @@ void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String fi String Proc_WebPage_system_update(const String& var) { if(TestHeaderFooter(var)) { - return AddHeaderFooter(var); + return AddHeaderFooter(var, 2); } else if(var == "SUBNAV") { return String(Page_system_HTML_SUBNAV); } else { diff --git a/Arduino/CanGrow/include/Webserver/Page_wifi.h b/Arduino/CanGrow/include/Webserver/Page_wifi.h index 76ee5bc..14a45c8 100644 --- a/Arduino/CanGrow/include/Webserver/Page_wifi.h +++ b/Arduino/CanGrow/include/Webserver/Page_wifi.h @@ -55,7 +55,7 @@ String WebPage_wifi_ScanNetworks() { // https://techtutorialsx.com/2018/07/23/esp32-arduino-http-server-template-processing-with-multiple-placeholders/ String Proc_WebPage_wifi(const String& var) { if(TestHeaderFooter(var)) { - return AddHeaderFooter(var); + return AddHeaderFooter(var, 3); //CURRENT_SETTINGS } else if(var == "CURRENT_SETTINGS") { if(strlen(config.wifi.ssid) > 0) {