add automatic id so table renders

This commit is contained in:
Proddy
2023-02-26 15:20:55 +01:00
parent 0985cea3d3
commit 471d18f7fa
2 changed files with 6 additions and 1 deletions

View File

@@ -36,8 +36,11 @@ void WebSchedulerService::begin() {
// this creates the scheduler file, saving it to the FS // this creates the scheduler file, saving it to the FS
void WebScheduler::read(WebScheduler & webScheduler, JsonObject & root) { void WebScheduler::read(WebScheduler & webScheduler, JsonObject & root) {
JsonArray schedule = root.createNestedArray("schedule"); JsonArray schedule = root.createNestedArray("schedule");
uint8_t count = 0;
char s[3];
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) { for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
JsonObject si = schedule.createNestedObject(); JsonObject si = schedule.createNestedObject();
si["id"] = Helpers::smallitoa(s, count++); // create unique ID as a string
si["active"] = scheduleItem.active; si["active"] = scheduleItem.active;
si["flags"] = scheduleItem.flags; si["flags"] = scheduleItem.flags;
si["time"] = scheduleItem.time; si["time"] = scheduleItem.time;
@@ -71,6 +74,7 @@ StateUpdateResult WebScheduler::update(JsonObject & root, WebScheduler & webSche
// create each schedule item, overwriting any previous settings // create each schedule item, overwriting any previous settings
// ignore the id (as this is only used in the web for table rendering) // ignore the id (as this is only used in the web for table rendering)
auto si = ScheduleItem(); auto si = ScheduleItem();
si.id = schedule["id"].as<std::string>();
si.active = schedule["active"]; si.active = schedule["active"];
si.flags = schedule["flags"]; si.flags = schedule["flags"];
si.time = schedule["time"].as<std::string>(); si.time = schedule["time"].as<std::string>();

View File

@@ -28,6 +28,7 @@ namespace emsesp {
class ScheduleItem { class ScheduleItem {
public: public:
std::string id; // unqiue id
boolean active; boolean active;
uint8_t flags; uint8_t flags;
uint16_t elapsed_min; // total mins from 00:00 uint16_t elapsed_min; // total mins from 00:00
@@ -60,7 +61,7 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
HttpEndpoint<WebScheduler> _httpEndpoint; HttpEndpoint<WebScheduler> _httpEndpoint;
FSPersistence<WebScheduler> _fsPersistence; FSPersistence<WebScheduler> _fsPersistence;
std::list<ScheduleItem> * scheduleItems; std::list<ScheduleItem> * scheduleItems; // pointer to the list of schedule events
}; };
} // namespace emsesp } // namespace emsesp