mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-10-27 06:21:26 +00:00
[WebUI] Add divs even for empty values, so they can be updated later
This commit is contained in:
1 parent
74e2c6ee53
commit
e83c23e8b2
3 files changed
+70
-59
No files matched your search
@@ -27,9 +27,7 @@ TaskValuesWriterHelper::TaskValuesWriterHelper(struct EventStruct *e)
|
||||
void TaskValuesWriterHelper::clear()
|
||||
{
|
||||
valName.clear();
|
||||
valName_id.clear();
|
||||
value.clear();
|
||||
value_id.clear();
|
||||
attribute.clear();
|
||||
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
uom.clear();
|
||||
@@ -45,28 +43,33 @@ void TaskValuesWriterHelper::clear()
|
||||
|
||||
bool TaskValuesWriterHelper::isEmpty() const
|
||||
{
|
||||
return valName.isEmpty() && value.isEmpty();
|
||||
return valName.isEmpty() && value.isEmpty();
|
||||
}
|
||||
|
||||
void TaskValuesWriterHelper::setID(uint8_t varNr)
|
||||
String TaskValuesWriterHelper::format_ID(ID_type id) const
|
||||
{
|
||||
if (!validDeviceIndex(deviceIndex)) { return; }
|
||||
valueNumber = varNr;
|
||||
const String id_postfix = strformat(F("%u_%u"), event->TaskIndex, varNr);
|
||||
valName_id = concat(F("valuename_"), id_postfix);
|
||||
value_id = concat(F("value_"), id_postfix);
|
||||
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
if (!validDeviceIndex(deviceIndex)) { return EMPTY_STRING; }
|
||||
const __FlashStringHelper *id_str = F("");
|
||||
|
||||
if (!uom.isEmpty()) {
|
||||
uom_id = concat(F("uom_"), id_postfix);
|
||||
}
|
||||
switch (id)
|
||||
{
|
||||
case ID_type::ValueName: id_str = F("valuename_");
|
||||
break;
|
||||
case ID_type::Value: id_str = F("value_");
|
||||
break;
|
||||
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
case ID_type::UoM: id_str = F("uom_");
|
||||
break;
|
||||
#endif // if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
#if FEATURE_STRING_VARIABLES
|
||||
|
||||
if (hasPresentation) {
|
||||
presentation_id = concat(F("pres_"), id_postfix);
|
||||
}
|
||||
case ID_type::Presentation: id_str = F("pres_");
|
||||
break;
|
||||
#endif // if FEATURE_STRING_VARIABLES
|
||||
default:
|
||||
return EMPTY_STRING;
|
||||
}
|
||||
const String id_postfix = strformat(F("%u_%u"), event->TaskIndex, valueNumber);
|
||||
return concat(id_str, id_postfix);
|
||||
}
|
||||
|
||||
void TaskValuesWriterHelper::write()
|
||||
@@ -107,15 +110,15 @@ void TaskValuesWriterHelper::writeCustom(uint8_t varNr, const __FlashStringHelpe
|
||||
|
||||
void TaskValuesWriterHelper::writeCustom(uint8_t varNr, const String& label, const String& val, bool isLast)
|
||||
{
|
||||
writeCustom(varNr, label, val, EMPTY_STRING, isLast);
|
||||
writeCustom(varNr, label, val, EMPTY_STRING, isLast);
|
||||
}
|
||||
|
||||
void TaskValuesWriterHelper::writeCustom(
|
||||
uint8_t varNr,
|
||||
const String& label,
|
||||
const String& val,
|
||||
const String& attr,
|
||||
bool isLast)
|
||||
uint8_t varNr,
|
||||
const String& label,
|
||||
const String& val,
|
||||
const String& attr,
|
||||
bool isLast)
|
||||
{
|
||||
if (!validDeviceIndex(deviceIndex)) { return; }
|
||||
|
||||
@@ -125,11 +128,11 @@ void TaskValuesWriterHelper::writeCustom(
|
||||
writeDerivedTaskValues();
|
||||
#endif
|
||||
}
|
||||
_isLast = isLast;
|
||||
valName = label;
|
||||
value = val;
|
||||
valueNumber = varNr;
|
||||
_isLast = isLast;
|
||||
valName = label;
|
||||
value = val;
|
||||
attribute = attr;
|
||||
setID(varNr);
|
||||
write();
|
||||
}
|
||||
|
||||
@@ -164,7 +167,7 @@ void TaskValuesWriterHelper::writeDerivedTaskValues()
|
||||
|
||||
while (it != customStringVar.end()) {
|
||||
if (it->first.startsWith(search) && it->first.endsWith(postfix)) {
|
||||
// clear();
|
||||
// clear();
|
||||
valName = it->first.substring(search.length(), it->first.indexOf('-'));
|
||||
String vType;
|
||||
const String vname2 = getDerivedValueNameUomAndVType(taskName, valName, uom, vType);
|
||||
@@ -174,6 +177,7 @@ void TaskValuesWriterHelper::writeDerivedTaskValues()
|
||||
}
|
||||
|
||||
if (!it->second.isEmpty()) {
|
||||
valueNumber = varNr;
|
||||
value = it->second;
|
||||
|
||||
// FIXME TD-er: Why these differences between JSON and Web?
|
||||
@@ -204,7 +208,6 @@ void TaskValuesWriterHelper::writeDerivedTaskValues()
|
||||
}
|
||||
}
|
||||
|
||||
setID(varNr);
|
||||
write();
|
||||
++varNr;
|
||||
}
|
||||
@@ -226,7 +229,7 @@ void TaskValuesWriterHelper::pluginWebformShowValue()
|
||||
if (!validDeviceIndex(deviceIndex)) { return; }
|
||||
|
||||
if ((valueNumber == 0) && _monoSpaced) {
|
||||
addHtml(F("<pre>")); // To keep spaces etc. in the shown output
|
||||
addHtml(F("<pre>")); // To keep spaces etc. in the shown output
|
||||
}
|
||||
|
||||
if (valueNumber > 0) {
|
||||
@@ -242,16 +245,13 @@ void TaskValuesWriterHelper::pluginWebformShowValue()
|
||||
}
|
||||
#endif // if FEATURE_STRING_VARIABLES
|
||||
|
||||
addHtmlDiv(F("div_l"), valName, valName_id, attribute);
|
||||
|
||||
if (!value_tmp.isEmpty()) {
|
||||
addHtmlDiv(F("div_r"), value_tmp, value_id);
|
||||
}
|
||||
addHtmlDiv(F("div_l"), valName, format_ID(ID_type::ValueName), attribute);
|
||||
addHtmlDiv(F("div_r"), value_tmp, format_ID(ID_type::Value));
|
||||
|
||||
if (_isLast && _monoSpaced) {
|
||||
addHtml(F("</pre>")); // To keep spaces etc. in the shown output
|
||||
_monoSpaced = false;
|
||||
_isLast = false;
|
||||
_isLast = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ bool TaskValuesWriterHelper::initRegularTaskValue(uint8_t varNr)
|
||||
valueNumber = varNr;
|
||||
|
||||
// Make sure we can re-use the same struct for multiple task values
|
||||
clear(); // TODO TD-er: Still needed, now we call clear() at the end of write() ?
|
||||
clear(); // TODO TD-er: Still needed, now we call clear() at the end of write() ?
|
||||
|
||||
// Need to produce the 'regular' task values
|
||||
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
@@ -291,7 +291,6 @@ bool TaskValuesWriterHelper::initRegularTaskValue(uint8_t varNr)
|
||||
}
|
||||
#endif // if FEATURE_STRING_VARIABLES
|
||||
valName = Cache.getTaskDeviceValueName(event->TaskIndex, varNr);
|
||||
setID(varNr);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -10,27 +10,41 @@
|
||||
// The call to PLUGIN_WEBFORM_SHOW_VALUES should only return success = true when no regular values should be displayed
|
||||
// Note that the varNr of the custom values should not conflict with the existing variable numbers (e.g. start at VARS_PER_TASK)
|
||||
struct TaskValuesWriterHelper {
|
||||
|
||||
enum class ID_type {
|
||||
ValueName,
|
||||
Value,
|
||||
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
UoM,
|
||||
#endif
|
||||
#if FEATURE_STRING_VARIABLES
|
||||
Presentation
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
TaskValuesWriterHelper(struct EventStruct *event);
|
||||
|
||||
void clear();
|
||||
void clear();
|
||||
|
||||
bool isEmpty() const;
|
||||
bool isEmpty() const;
|
||||
|
||||
void setID(uint8_t varNr);
|
||||
String format_ID(ID_type id) const;
|
||||
|
||||
void setWriteRegularTaskValuesFirst() { _writeRegularTaskValuesFirst = true; }
|
||||
void setWriteRegularTaskValuesFirst() { _writeRegularTaskValuesFirst = true; }
|
||||
|
||||
void setMonoSpaced() { _monoSpaced = true; }
|
||||
void setMonoSpaced() { _monoSpaced = true; }
|
||||
|
||||
|
||||
void write();
|
||||
void write();
|
||||
|
||||
void writeTaskValues();
|
||||
void writeTaskValues();
|
||||
|
||||
void writeCustom(uint8_t varNr,
|
||||
const __FlashStringHelper *label,
|
||||
const String & val,
|
||||
bool isLast = false);
|
||||
void writeCustom(uint8_t varNr,
|
||||
const __FlashStringHelper *label,
|
||||
const String & val,
|
||||
bool isLast = false);
|
||||
void writeCustom(uint8_t varNr,
|
||||
const String& label,
|
||||
const String& val,
|
||||
@@ -42,8 +56,6 @@ struct TaskValuesWriterHelper {
|
||||
const String& attr,
|
||||
bool isLast = false);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void writeRegularTaskValues();
|
||||
@@ -58,12 +70,12 @@ private:
|
||||
public:
|
||||
|
||||
EventStruct * const event = nullptr;
|
||||
String valName, valName_id, value, value_id, attribute;
|
||||
String valName, value, attribute;
|
||||
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
String uom, uom_id;
|
||||
String uom;
|
||||
#endif
|
||||
#if FEATURE_STRING_VARIABLES
|
||||
String presentation, presentation_id;
|
||||
String presentation;
|
||||
bool hasPresentation = false;
|
||||
#endif // if FEATURE_STRING_VARIABLES
|
||||
|
||||
|
||||
@@ -625,12 +625,12 @@ void handle_json_stream_task_value_data(TaskValuesWriterHelper*data)
|
||||
|
||||
{
|
||||
KeyValueStruct kv(F("Name"), data->valName, format);
|
||||
kv.setID(data->valName_id);
|
||||
kv.setID(data->format_ID(TaskValuesWriterHelper::ID_type::ValueName));
|
||||
writer->write(kv);
|
||||
}
|
||||
{
|
||||
KeyValueStruct kv(F("Value"), data->value, format);
|
||||
kv.setID(data->value_id);
|
||||
kv.setID(data->format_ID(TaskValuesWriterHelper::ID_type::Value));
|
||||
writer->write(kv);
|
||||
}
|
||||
|
||||
@@ -638,16 +638,16 @@ void handle_json_stream_task_value_data(TaskValuesWriterHelper*data)
|
||||
writer->write({ F("NrDecimals"), nrDecimals });
|
||||
# if FEATURE_STRING_VARIABLES
|
||||
|
||||
if (!data->presentation.isEmpty()) {
|
||||
if (!data->hasPresentation) {
|
||||
KeyValueStruct kv(F("Presentation"), data->presentation);
|
||||
kv.setID(data->presentation_id);
|
||||
kv.setID(data->format_ID(TaskValuesWriterHelper::ID_type::Presentation));
|
||||
writer->write(kv);
|
||||
}
|
||||
# endif // if FEATURE_STRING_VARIABLES
|
||||
#if FEATURE_TASKVALUE_UNIT_OF_MEASURE
|
||||
if (!data->uom.isEmpty()) {
|
||||
KeyValueStruct kv(F("UoM"), data->uom);
|
||||
kv.setID(data->uom_id);
|
||||
kv.setID(data->format_ID(TaskValuesWriterHelper::ID_type::UoM));
|
||||
writer->write(kv);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user