mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 14:42:18 +03:00
начал добавление виджетов
This commit is contained in:
@@ -7,14 +7,16 @@ void createWidget(String& parameters) {
|
||||
String page = jsonReadStr(parameters, "page");
|
||||
String descr = jsonReadStr(parameters, "descr");
|
||||
|
||||
SerialPrint(F("i"), F("Widget"), "Start create widget: " + widget);
|
||||
|
||||
if (widget != "na") {
|
||||
String buf = "{}";
|
||||
if (!loadWidget(widget, buf)) {
|
||||
return;
|
||||
}
|
||||
// if (_cnt != "") {
|
||||
// if (widget.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
|
||||
// }
|
||||
// if (_cnt != "") {
|
||||
// if (widget.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
|
||||
// }
|
||||
|
||||
#ifdef GATE_MODE
|
||||
jsonWriteStr(buf, "info", " ");
|
||||
@@ -25,21 +27,37 @@ void createWidget(String& parameters) {
|
||||
jsonWriteStr(buf, "descr", descr);
|
||||
jsonWriteStr(buf, "topic", prex + "/" + id);
|
||||
|
||||
SerialPrint(F("i"), F("Widget"), buf);
|
||||
|
||||
#ifdef LAYOUT_IN_RAM
|
||||
all_widgets += widget + "\r\n";
|
||||
#else
|
||||
addFileLn("layout.txt", buf);
|
||||
addFileLn("layout.json", buf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
bool loadWidget(const String& widget, String& buf) {
|
||||
buf = readFile(getWidgetFile(widget), 2048);
|
||||
bool res = !(buf == "Failed" || buf == "Large");
|
||||
if (!res) {
|
||||
SerialPrint("E", "module", "on load" + widget);
|
||||
File file = seekFile("/widgets.json");
|
||||
file.find("[");
|
||||
bool ret = false;
|
||||
while (file.available()) {
|
||||
String jsonArrayElement = file.readStringUntil('}') + "}";
|
||||
if (jsonArrayElement.startsWith(",")) {
|
||||
jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии
|
||||
}
|
||||
String name;
|
||||
if (!jsonRead(jsonArrayElement, F("name"), name)) { //если нет такого ключа в представленном json или он не валидный
|
||||
SerialPrint(F("E"), F("Config"), "json error " + name);
|
||||
continue;
|
||||
} else {
|
||||
if (name == widget) {
|
||||
buf = jsonArrayElement;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const String getWidgetFile(const String& name) {
|
||||
|
||||
Reference in New Issue
Block a user