Merge pull request #221 from bobbycar-graz/webserver-newsettings-enum-types

Webserver newsettings enum types
This commit is contained in:
2022-01-03 22:15:54 +01:00
committed by GitHub

View File

@ -23,6 +23,8 @@
// local includes
#include "newsettings.h"
#include "webserver_lock.h"
#include "ledstrip.h"
#include "handbremse.h"
#ifdef FEATURE_WEBSERVER
using namespace std::chrono_literals;
@ -51,7 +53,10 @@ typename std::enable_if<
!std::is_same_v<T, std::optional<wifi_stack::mac_t>> &&
!std::is_same_v<T, wifi_auth_mode_t> &&
!std::is_same_v<T, sntp_sync_mode_t> &&
!std::is_same_v<T, espchrono::DayLightSavingMode>
!std::is_same_v<T, espchrono::DayLightSavingMode> &&
!std::is_same_v<T, OtaAnimationModes> &&
!std::is_same_v<T, LedstripAnimation> &&
!std::is_same_v<T, HandbremseMode>
, void>::type
showInputForSetting(std::string_view key, T value, std::string &body)
{
@ -198,6 +203,48 @@ showInputForSetting(std::string_view key, T value, std::string &body)
body += esphttpdutils::htmlentities(enumKey);
});
}
template<typename T>
typename std::enable_if<
std::is_same_v<T, OtaAnimationModes>
, void>::type
showInputForSetting(std::string_view key, T value, std::string &body)
{
HtmlTag select{"select", fmt::format("name=\"{}\"", esphttpdutils::htmlentities(key)), body};
iterateOtaAnimationModes([&](T enumVal, std::string_view enumKey){
HtmlTag option{"option", fmt::format("value=\"{}\"{}", std::to_underlying(enumVal), value == enumVal ? " selected" : ""), body};
body += esphttpdutils::htmlentities(enumKey);
});
}
template<typename T>
typename std::enable_if<
std::is_same_v<T, LedstripAnimation>
, void>::type
showInputForSetting(std::string_view key, T value, std::string &body)
{
HtmlTag select{"select", fmt::format("name=\"{}\"", esphttpdutils::htmlentities(key)), body};
iterateLedstripAnimation([&](T enumVal, std::string_view enumKey){
HtmlTag option{"option", fmt::format("value=\"{}\"{}", std::to_underlying(enumVal), value == enumVal ? " selected" : ""), body};
body += esphttpdutils::htmlentities(enumKey);
});
}
template<typename T>
typename std::enable_if<
std::is_same_v<T, HandbremseMode>
, void>::type
showInputForSetting(std::string_view key, T value, std::string &body)
{
HtmlTag select{"select", fmt::format("name=\"{}\"", esphttpdutils::htmlentities(key)), body};
iterateHandbremseMode([&](T enumVal, std::string_view enumKey){
HtmlTag option{"option", fmt::format("value=\"{}\"{}", std::to_underlying(enumVal), value == enumVal ? " selected" : ""), body};
body += esphttpdutils::htmlentities(enumKey);
});
}
} // namespace
esp_err_t webserver_newSettings_handler(httpd_req_t *req)
@ -343,7 +390,10 @@ typename std::enable_if<
!std::is_same_v<T, std::optional<wifi_stack::mac_t>> &&
!std::is_same_v<T, wifi_auth_mode_t> &&
!std::is_same_v<T, sntp_sync_mode_t> &&
!std::is_same_v<T, espchrono::DayLightSavingMode>
!std::is_same_v<T, espchrono::DayLightSavingMode> &&
!std::is_same_v<T, OtaAnimationModes> &&
!std::is_same_v<T, LedstripAnimation> &&
!std::is_same_v<T, HandbremseMode>
, tl::expected<void, std::string>>::type
saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
{
@ -426,7 +476,10 @@ template<typename T>
typename std::enable_if<
std::is_same_v<T, wifi_auth_mode_t> ||
std::is_same_v<T, sntp_sync_mode_t> ||
std::is_same_v<T, espchrono::DayLightSavingMode>
std::is_same_v<T, espchrono::DayLightSavingMode> ||
std::is_same_v<T, OtaAnimationModes> ||
std::is_same_v<T, LedstripAnimation> ||
std::is_same_v<T, HandbremseMode>
, tl::expected<void, std::string>>::type
saveSetting(ConfigWrapper<T> &config, std::string_view newValue)
{