mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
add automatic id so table renders
This commit is contained in:
@@ -36,8 +36,11 @@ void WebSchedulerService::begin() {
|
||||
// this creates the scheduler file, saving it to the FS
|
||||
void WebScheduler::read(WebScheduler & webScheduler, JsonObject & root) {
|
||||
JsonArray schedule = root.createNestedArray("schedule");
|
||||
uint8_t count = 0;
|
||||
char s[3];
|
||||
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
|
||||
JsonObject si = schedule.createNestedObject();
|
||||
si["id"] = Helpers::smallitoa(s, count++); // create unique ID as a string
|
||||
si["active"] = scheduleItem.active;
|
||||
si["flags"] = scheduleItem.flags;
|
||||
si["time"] = scheduleItem.time;
|
||||
@@ -71,6 +74,7 @@ StateUpdateResult WebScheduler::update(JsonObject & root, WebScheduler & webSche
|
||||
// create each schedule item, overwriting any previous settings
|
||||
// ignore the id (as this is only used in the web for table rendering)
|
||||
auto si = ScheduleItem();
|
||||
si.id = schedule["id"].as<std::string>();
|
||||
si.active = schedule["active"];
|
||||
si.flags = schedule["flags"];
|
||||
si.time = schedule["time"].as<std::string>();
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace emsesp {
|
||||
|
||||
class ScheduleItem {
|
||||
public:
|
||||
std::string id; // unqiue id
|
||||
boolean active;
|
||||
uint8_t flags;
|
||||
uint16_t elapsed_min; // total mins from 00:00
|
||||
@@ -60,7 +61,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
|
||||
HttpEndpoint<WebScheduler> _httpEndpoint;
|
||||
FSPersistence<WebScheduler> _fsPersistence;
|
||||
|
||||
std::list<ScheduleItem> * scheduleItems;
|
||||
std::list<ScheduleItem> * scheduleItems; // pointer to the list of schedule events
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
Reference in New Issue
Block a user