mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
b simulators
if diff contains multiple changes in the same UI_item it was pushed in multiple times now we use a set to check if it is already in the changed or not
This commit is contained in:
+10
-2
@@ -1,4 +1,5 @@
|
|||||||
#include "simulators.hpp"
|
#include "simulators.hpp"
|
||||||
|
#include <unordered_set>
|
||||||
#include "test_sim.hpp"
|
#include "test_sim.hpp"
|
||||||
#include "can_debugger.hpp"
|
#include "can_debugger.hpp"
|
||||||
|
|
||||||
@@ -112,12 +113,19 @@ json Simulators::changed_UI_items()
|
|||||||
|
|
||||||
// diff to ui items list
|
// diff to ui items list
|
||||||
// get index out of each item in diff /UI_items/0/**
|
// get index out of each item in diff /UI_items/0/**
|
||||||
|
// but the index can be the same for multiple items
|
||||||
// Then push the ui_item at that index to the changed json
|
// Then push the ui_item at that index to the changed json
|
||||||
|
std::unordered_set<size_t> addedIndices;
|
||||||
|
|
||||||
for (auto& item : diff)
|
for (auto& item : diff)
|
||||||
{
|
{
|
||||||
std::string path = item["path"];
|
std::string path = item["path"];
|
||||||
std::string index_s = path.substr(10, path.find("/", 10) - 10);
|
size_t index = std::stoul(path.substr(10, path.find("/", 10) - 10));
|
||||||
changed["event"]["UI_items"].push_back(after["UI_items"][std::stoul(index_s)]);
|
if (addedIndices.find(index) != addedIndices.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
changed["event"]["UI_items"].push_back(after["UI_items"][index]);
|
||||||
|
addedIndices.insert(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_before = after;
|
m_before = after;
|
||||||
|
|||||||
Reference in New Issue
Block a user