Support the global attribute

pull/123/head
Hieromon Ikasamo 6 years ago
parent eb64c356d5
commit efa0125053
  1. 25
      src/AutoConnectAux.cpp
  2. 1
      src/AutoConnectAux.h
  3. 7
      src/AutoConnectElementBasis.h
  4. 5
      src/AutoConnectElementJson.h
  5. 9
      src/AutoConnectElementJsonImpl.h

@ -142,6 +142,21 @@ AutoConnectElement* AutoConnectAux::getElement(const String& name) {
return nullptr;
}
/**
* Validate all AutoConnectInputs value.
* @return true Validation successfull
* @return false Some elements failed validation.
*/
bool AutoConnectAux::isValid(void) const {
bool rc = true;
for (AutoConnectElement& elm : _addonElm)
if (elm.typeOf() == AC_Input) {
AutoConnectInput& elmInput = reinterpret_cast<AutoConnectInput&>(elm);
rc &= elmInput.isValid();
}
return rc;
}
/**
* Releases the AutoConnectElements with the specified name from
* the AutoConnectAux page. Releases all AutoConnectElements with
@ -530,6 +545,16 @@ void AutoConnectAux::_storeElements(WebServerClass* webServer) {
if (elm.typeOf() == AC_Checkbox)
elmValue = "checked";
setElementValue(elm.name, elmValue);
// Copy a value to other elements declared as global.
if (elm.global) {
AutoConnectAux* aux = _ac->_aux.get();
while (aux) {
if (aux != this)
aux->setElementValue(elm.name, elmValue);
aux = aux->_next.get();
}
}
}
}
}

@ -60,6 +60,7 @@ class AutoConnectAux : public PageBuilder {
AutoConnectElementVT& getElements(void) { return _addonElm; } /**< Get vector of all elements */
void menu(const bool post) { _menu = post; } /**< Set or reset the display as menu item for this aux */
bool isMenu(void) { return _menu; } /**< Return whether embedded in the menu or not */
bool isValid(void) const; /**< Validate all AutoConnectInput value */
bool release(const String& name); /**< Release an AutoConnectElement */
bool setElementValue(const String& name, const String value); /**< Set value to specified element */
bool setElementValue(const String& name, std::vector<String> const& values); /**< Set values collection to specified element */

@ -2,8 +2,8 @@
* Declaration of AutoConnectElement basic class.
* @file AutoConnectElementBasis.h
* @author hieromon@gmail.com
* @version 0.9.11
* @date 2019-06-25
* @version 1.0.0
* @date 2019-09-03
* @copyright MIT license.
*/
@ -71,7 +71,7 @@ typedef enum {
*/
class AutoConnectElementBasis {
public:
explicit AutoConnectElementBasis(const char* name = "", const char* value = "", const ACPosterior_t post = AC_Tag_None) : name(String(name)), value(String(value)), post(post), enable(true) {
explicit AutoConnectElementBasis(const char* name = "", const char* value = "", const ACPosterior_t post = AC_Tag_None) : name(String(name)), value(String(value)), post(post), enable(true), global(false) {
_type = AC_Element;
}
virtual ~AutoConnectElementBasis() {}
@ -87,6 +87,7 @@ class AutoConnectElementBasis {
String value; /**< Element value */
ACPosterior_t post; /**< Tag to be generated with posterior */
bool enable; /**< Enabling the element */
bool global; /**< The value available in global scope */
protected:
ACElement_t _type; /**< Element type identifier */

@ -2,8 +2,8 @@
* Declaration of AutoConnectElement extended classes using JSON.
* @file AutoConnectElementJson.h
* @author hieromon@gmail.com
* @version 0.9.11
* @date 2019-06-25
* @version 1.0.0
* @date 2019-09-03
* @copyright MIT license.
*/
@ -18,6 +18,7 @@
#define AUTOCONNECT_JSON_KEY_CHECKED "checked"
#define AUTOCONNECT_JSON_KEY_ELEMENT "element"
#define AUTOCONNECT_JSON_KEY_FORMAT "format"
#define AUTOCONNECT_JSON_KEY_GLOBAL "global"
#define AUTOCONNECT_JSON_KEY_LABEL "label"
#define AUTOCONNECT_JSON_KEY_LABELPOSITION "labelposition"
#define AUTOCONNECT_JSON_KEY_MENU "menu"

@ -2,8 +2,8 @@
* Implementation of AutoConnectElementJson classes.
* @file AutoConnectElementImpl.h
* @author hieromon@gmail.com
* @version 0.9.11
* @date 2019-06-25
* @version 1.0.0
* @date 2019-09-03
* @copyright MIT license.
*/
@ -72,6 +72,8 @@ void AutoConnectElementJson::_serialize(JsonObject& json) {
}
json[F(AUTOCONNECT_JSON_KEY_POSTERIOR)] = posterior;
}
if (global)
json[F(AUTOCONNECT_JSON_KEY_GLOBAL)] = true;
}
/**
@ -93,6 +95,9 @@ void AutoConnectElementJson::_setMember(const JsonObject& json) {
else
AC_DBG("Warning '%s' loading, unknown posterior '%s'\n", name.c_str(), posterior.c_str());
}
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_GLOBAL))) {
global = json[F(AUTOCONNECT_JSON_KEY_GLOBAL)].as<bool>();
}
}
/**

Loading…
Cancel
Save