customizations, swap shortname and fullname, using id as unique shortname

This commit is contained in:
Proddy
2022-05-27 09:49:32 +02:00
parent 8824f4f3da
commit 1e082f941a
4 changed files with 124 additions and 127 deletions

View File

@@ -716,11 +716,9 @@ void EMSdevice::generate_values_web(JsonObject & output) {
auto mask = Helpers::hextoa((uint8_t)(dv.state >> 4), false); // create mask to a 2-char string
// add name, prefixing the tag if it exists. This is the id used for the table sorting
// add name, prefixing the tag if it exists. This is the id used in the WebUI table and must be unique
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
obj["id"] = mask + read_flash_string(dv.full_name);
} else if (dv.tag < DeviceValueTAG::TAG_HC1) {
obj["id"] = mask + tag_to_string(dv.tag) + " " + read_flash_string(dv.full_name);
} else {
obj["id"] = mask + tag_to_string(dv.tag) + " " + read_flash_string(dv.full_name);
}
@@ -831,30 +829,27 @@ void EMSdevice::generate_values_web_customization(JsonArray & output) {
obj["v"] = (divider > 0) ? time_value / divider : time_value * factor; // sometimes we need to divide by 60
}
}
} else {
obj["v"] = ""; // must always have v for sorting to work in web
}
// shortname
std::string shortname;
// id holds the shortname and must always have a value for the WebUI table to work
if (dv.tag >= DeviceValueTAG::TAG_HC1) {
shortname = tag_to_string(dv.tag) + "/" + read_flash_string(dv.short_name);
obj["id"] = tag_to_string(dv.tag) + "/" + read_flash_string(dv.short_name);
} else {
shortname = read_flash_string(dv.short_name);
obj["id"] = read_flash_string(dv.short_name);
}
obj["s"] = shortname;
// id is the fullname, or the shortname (it must exist for the web table to work)
if (dv.full_name) {
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
obj["id"] = dv.full_name;
} else {
char name[50];
snprintf(name, sizeof(name), "%s %s", tag_to_string(dv.tag).c_str(), read_flash_string(dv.full_name).c_str());
obj["id"] = name;
// n is the fullname, and can be optional
// don't add the fullname if its a command
if (dv.type != DeviceValueType::CMD) {
if (dv.full_name) {
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
obj["n"] = dv.full_name;
} else {
char name[50];
snprintf(name, sizeof(name), "%s %s", tag_to_string(dv.tag).c_str(), read_flash_string(dv.full_name).c_str());
obj["n"] = name;
}
}
} else {
obj["id"] = shortname; // fullname/id is same as shortname
}
obj["m"] = dv.state >> 4; // send back the mask state. We're only interested in the high nibble