This commit is contained in:
IoT Manager
2024-08-25 01:26:34 +02:00
parent 032e55d30c
commit d03d964f45
2 changed files with 14 additions and 52 deletions

View File

@@ -38,6 +38,9 @@
const wsManager = new WebSocketManager(deviceList, debug); const wsManager = new WebSocketManager(deviceList, debug);
let layoutJson = wsManager.layoutJson;
$: layoutJson = wsManager.layoutJson;
router.subscribe(handleNavigation); router.subscribe(handleNavigation);
function handleNavigation() { function handleNavigation() {
@@ -283,7 +286,7 @@
<Alarm title="Подключение через {wsManager.remainingTimeout} сек." /> <Alarm title="Подключение через {wsManager.remainingTimeout} сек." />
{:else} {:else}
<Route path="/"> <Route path="/">
<DashboardPage show={wsManager.pageReady.dash} layoutJson={wsManager.layoutJson} pages={wsManager.pages} wsPush={(ws, topic, status) => wsManager.wsPush(ws, topic, status)} /> <DashboardPage show={wsManager.pageReady.dash} layoutJson={layoutJson} pages={wsManager.pages} wsPush={(ws, topic, status) => wsManager.wsPush(ws, topic, status)} />
</Route> </Route>
<!--<Route path="/config"> <!--<Route path="/config">
<ConfigPage show={pageReady.config} bind:configJson={configJson} bind:scenarioTxt={scenarioTxt} widgetsJson={widgetsJson} itemsJson={itemsJson} saveConfig={() => saveConfig()} cleanLogs={() => cleanLogs()} rebootEsp={() => rebootEsp()} moduleOrder={(id, key, value) => moduleOrder(id, key, value)} userdata={userdata} /> <ConfigPage show={pageReady.config} bind:configJson={configJson} bind:scenarioTxt={scenarioTxt} widgetsJson={widgetsJson} itemsJson={itemsJson} saveConfig={() => saveConfig()} cleanLogs={() => cleanLogs()} rebootEsp={() => rebootEsp()} moduleOrder={(id, key, value) => moduleOrder(id, key, value)} userdata={userdata} />

View File

@@ -346,6 +346,10 @@ class WebSocketManager {
sortingLayout(ws) { sortingLayout(ws) {
this.layoutJson.sort((a, b) => a.descr.localeCompare(b.descr)); this.layoutJson.sort((a, b) => a.descr.localeCompare(b.descr));
this.pages = Array.from(new Set(this.layoutJson.map(({ page }) => page)))
.map((page) => ({ page }))
.sort((a, b) => a.page.localeCompare(b.page));
console.log("[3]", ws, "layout sort, requested params...");
this.wsSendMsg(ws, "/params|"); this.wsSendMsg(ws, "/params|");
} }
@@ -500,11 +504,8 @@ class WebSocketManager {
}); });
} }
//слияние layout-ов всех устройств в общий layout
async combineLayoutsInOne(ws, devLayout) { async combineLayoutsInOne(ws, devLayout) {
for (let i = 0; i < devLayout.length; i++) { devLayout.forEach((item) => (item.ws = ws));
devLayout[i].ws = ws;
}
this.layoutJson = this.layoutJson.concat(devLayout); this.layoutJson = this.layoutJson.concat(devLayout);
console.log("[2]", ws, "devLayout pushed to layout"); console.log("[2]", ws, "devLayout pushed to layout");
this.sortingLayout(ws); this.sortingLayout(ws);
@@ -512,61 +513,19 @@ class WebSocketManager {
updateAllStatuses(ws) { updateAllStatuses(ws) {
for (const [key, value] of Object.entries(this.paramsJson)) { for (const [key, value] of Object.entries(this.paramsJson)) {
for (let i = 0; i < this.layoutJson.length; i++) { this.layoutJson.forEach((item) => {
let topic = this.layoutJson[i].topic; let topic = item.topic;
if (topic) { if (topic) {
//this.layoutJson[i].ws = ws; topic = topic.substring(topic.lastIndexOf("/") + 1);
topic = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
if (key === topic) { if (key === topic) {
console.log("[i]", "updated =>" + topic, value); console.log("[i]", "updated =>" + topic, value);
this.layoutJson[i].status = value; item.status = value;
break;
}
} }
} }
});
} }
this.wsSendMsg(ws, "/charts|"); this.wsSendMsg(ws, "/charts|");
} }
sortingLayout(ws) {
//сортируем весь layout по алфавиту
this.layoutJson.sort(function (a, b) {
if (a.descr < b.descr) {
return -1;
}
if (a.descr > b.descr) {
return 1;
}
return 0;
});
//формируем json всех карточек
this.pages = [];
const newPage = Array.from(new Set(Array.from(this.layoutJson, ({ page }) => page)));
newPage.forEach((item, i, arr) => {
this.pages = [
...this.pages,
JSON.parse(
JSON.stringify({
page: item,
})
),
];
});
//сортируем карточки по алфавиту
this.pages.sort(function (a, b) {
if (a.page < b.page) {
return -1;
}
if (a.page > b.page) {
return 1;
}
return 0;
});
this.layoutJson = this.layoutJson;
console.log("[3]", ws, "layout sort, requested params...");
this.wsSendMsg(ws, "/params|");
}
} }
export default WebSocketManager; export default WebSocketManager;