From 7f7ef1a6962e4cc0a3a5a269223e237c35b9d567 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:14:19 +0200 Subject: [PATCH] 453 --- src/App.svelte | 71 +++++++++- src/pages/Login.svelte | 51 ++++--- src/pages/Profile.svelte | 294 +++++++++++++++++---------------------- 3 files changed, 228 insertions(+), 188 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 4525d57..28d6288 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -52,7 +52,7 @@ let preventMove = false; let screenSize; const blobDebug = false; - const devMode = true; + const devMode = false; let percent; @@ -115,6 +115,10 @@ let paramsJson = {}; let userdata = null; + let allmodeinfo = null; + let profile = null; + + let serverOnline = false; let parsed = { itemsJson: false, @@ -207,11 +211,14 @@ }); if (res.ok) { userdata = await res.json(); + serverOnline = true; } else { console.log("error", res.statusText); + serverOnline = true; } } catch (e) { console.log("error", e); + serverOnline = false; } }; @@ -608,9 +615,67 @@ clearParcedFlags(); if (debug) console.log("✔✔", "profile page parced"); pageReady.profile = true; + await getModInfo(); + await getProfile(); } } + const getModInfo = async () => { + try { + let res = await fetch("https://portal.iotmanager.org/compiler/allmodinfo", { + mode: "cors", + method: "GET", + }); + if (res.ok) { + allmodeinfo = await res.json(); + allmodeinfo = allmodeinfo.message; + } else { + console.log("error", res.statusText); + } + } catch (e) { + console.log("error", e); + } + }; + + const getProfile = async () => { + try { + const JWT = Cookies.get("token_iotm2"); + let res = await fetch("https://portal.iotmanager.org/compiler/profile", { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${JWT}`, + }, + mode: "cors", + method: "GET", + }); + if (res.ok) { + profile = await res.json(); + profile = profile.message; + await markProfileAsPerThisDevProfile(); + } else { + console.log("error", res.statusText); + } + } catch (e) { + console.log("error", e); + } + }; + + const markProfileAsPerThisDevProfile = async () => { + for (const [compilerCategory, compilerCategoryModules] of Object.entries(profile.modules)) { + let devCategoryModules = myProfileJson.modules[compilerCategory]; + compilerCategoryModules.forEach((compilerModule) => { + compilerModule.active = false; + if (devCategoryModules) { + devCategoryModules.forEach((devModule) => { + if (devModule.path === compilerModule.path) { + compilerModule.active = devModule.active; + } + }); + } + }); + } + }; + async function initDevList() { if (firstDevListRequest) { //при первом запросе листа устройств запишем его целеком @@ -1307,10 +1372,10 @@ - updateBuild(path)} /> + updateBuild(path)} allmodeinfo={allmodeinfo} profile={profile} serverOnline={serverOnline} /> - + {/if} diff --git a/src/pages/Login.svelte b/src/pages/Login.svelte index 1dd0ed9..ba894e7 100644 --- a/src/pages/Login.svelte +++ b/src/pages/Login.svelte @@ -5,6 +5,7 @@ import { router } from "tinro"; import Cookies from "js-cookie"; export let show = true; + export let serverOnline; let user = {}; let errors = []; @@ -42,28 +43,36 @@ {#if show} -
-
-
-
- - -
-
- - -
- {#each errors as e, i} -

{$t(e.msg)}

- {/each} - -
+ {#if serverOnline} +
+
+
+
+ + +
+
+ + +
+ {#each errors as e, i} +

{$t(e.msg)}

+ {/each} + +
+
-
+ {:else} +
+
+ +
+
+ {/if} {:else} {/if} diff --git a/src/pages/Profile.svelte b/src/pages/Profile.svelte index 330c6b4..3994705 100644 --- a/src/pages/Profile.svelte +++ b/src/pages/Profile.svelte @@ -7,18 +7,19 @@ import Cookies from "js-cookie"; export let show; export let myProfileJson; + export let allmodeinfo; + export let profile; + + export let serverOnline; + export let userdata; export let updateBuild = (path) => {}; import CrossIcon from "../svg/Cross.svelte"; let errors = []; - let allmodeinfo = null; let userBuilds = null; - let profile = null; var updateInterval; onMount(async () => { - await getProfile(); - await getModInfo(); await getUserBuilds(); }); @@ -30,14 +31,16 @@ }; function checkStatus(userBuilds) { - if (userBuilds[0].processed) { - clearInterval(updateInterval); - console.log("no interval - all task done"); - } else { - console.log("non completed task exist!"); - if (!updateInterval) { - console.log("interval checking started"); - updateInterval = setInterval(periodicTask, 10000); + if (userBuilds.length) { + if (userBuilds[0].processed) { + clearInterval(updateInterval); + console.log("no interval - all task done"); + } else { + console.log("non completed task exist!"); + if (!updateInterval) { + console.log("interval checking started"); + updateInterval = setInterval(periodicTask, 10000); + } } } } @@ -46,23 +49,6 @@ await getUserBuilds(); }; - const getModInfo = async () => { - try { - let res = await fetch("https://portal.iotmanager.org/compiler/allmodinfo", { - mode: "cors", - method: "GET", - }); - if (res.ok) { - allmodeinfo = await res.json(); - allmodeinfo = allmodeinfo.message; - } else { - console.log("error", res.statusText); - } - } catch (e) { - console.log("error", e); - } - }; - const getUserBuilds = async () => { try { const JWT = Cookies.get("token_iotm2"); @@ -85,28 +71,6 @@ } }; - const getProfile = async () => { - try { - const JWT = Cookies.get("token_iotm2"); - let res = await fetch("https://portal.iotmanager.org/compiler/profile", { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${JWT}`, - }, - mode: "cors", - method: "GET", - }); - if (res.ok) { - profile = await res.json(); - profile = profile.message; - } else { - console.log("error", res.statusText); - } - } catch (e) { - console.log("error", e); - } - }; - const delBuild = async (ord) => { try { const JWT = Cookies.get("token_iotm2"); @@ -129,9 +93,9 @@ }; const placeOrder = async () => { - delete myProfileJson["_id"]; + delete profile["_id"]; //добавим в тело имя пользователя - myProfileJson.username = userdata.username; + profile.username = userdata.username; const JWT = Cookies.get("token_iotm2"); try { let res = await fetch("https://portal.iotmanager.org/compiler/order", { @@ -141,7 +105,7 @@ "Content-Type": "application/json", Authorization: `Bearer ${JWT}`, }, - body: JSON.stringify(myProfileJson), + body: JSON.stringify(profile), }); const content = await res.json(); if (res.ok) { @@ -166,129 +130,131 @@ {#if show} - {#if allmodeinfo && myProfileJson && profile} -
-
- -
-

{myProfileJson.projectProp.platformio.default_envs}

-

{userdata.username}

-
-
- - {#each profile.modules.virtual_elments as m, i} - {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} -
- -

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

-
- {/if} + {#each profile.modules.virtual_elments as m, i} + {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} +
+ +

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

+
+ {/if} + {/each} + {#each profile.modules.sensors as m, i} + {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} +
+ +

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

+
+ {/if} + {/each} + {#each profile.modules.executive_devices as m, i} + {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} +
+ +

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

+
+ {/if} + {/each} + {#each profile.modules.screens as m, i} + {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} +
+ +

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

+
+ {/if} + {/each} +
+ {#each errors as e, i} +

{$t(e.msg)}

{/each} - {#each profile.modules.sensors as m, i} - {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} -
- -

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

-
- {/if} - {/each} - {#each profile.modules.executive_devices as m, i} - {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} -
- -

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

-
- {/if} - {/each} - {#each profile.modules.screens as m, i} - {#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]} -
- -

(m.active = !m.active)} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{m.path.substring(m.path.lastIndexOf("/") + 1, m.path.length)}

-
- {/if} - {/each} -
- {#each errors as e, i} -

{$t(e.msg)}

- {/each} - - {#if userBuilds} - - - - - - + + {#if userBuilds} +
НазваниеВерсияВремя
+ + + + + - - - - - - - {#each userBuilds as build, i} - {#if build.projectProp.platformio.default_envs === myProfileJson.projectProp.platformio.default_envs} - - - - - {#if build.status.preparation === 0 && build.status.build === 0 && build.status.fs === 0} - - - - - {#if build.status.build === 2 && build.status.preparation === 2 && build.status.fs === 2} - - - {:else} - + + + + + + {#each userBuilds as build, i} + {#if build.projectProp.platformio.default_envs === myProfileJson.projectProp.platformio.default_envs} + + + + + {#if build.status.preparation === 0 && build.status.build === 0 && build.status.fs === 0} - {:else} + + + {#if build.status.build === 2 && build.status.preparation === 2 && build.status.fs === 2} + + + {:else} + + {:else} + - {/if} - {/each} - -
НазваниеВерсияВремяПодготовкаСборка buildСборка fs - -
{build.projectProp.platformio.default_envs}{build.ver}{new Date(build.dateAdded).toLocaleString("ru", { timeZone: "Europe/Vienna" })} -

{"Ожидание очереди..."}

-
- - - {:else} - -
showLog(build, "py.txt")}> - {st[build.status.preparation]} -
-
-
showLog(build, "build.txt")}> - {st[build.status.build]} -
-
-
showLog(build, "fs.txt")}>{st[build.status.fs]}
-
updateBuild("http://portal.iotmanager.org/compiler/userdata/builds/" + build.orderId)} class="tbl-bdy-lg ipt-lg w-full cursor-pointer select-none bg-green-100 hover:bg-green-200"> -

Установить

-
- {/if} - - {#if build.processed} + ПодготовкаСборка buildСборка fs + +
{build.projectProp.platformio.default_envs}{build.ver}{new Date(build.dateAdded).toLocaleString("ru", { timeZone: "Europe/Vienna" })} - delBuild(build)} /> +

{"Ожидание очереди..."}

+ + + {:else} + +
showLog(build, "py.txt")}> + {st[build.status.preparation]} +
+
+
showLog(build, "build.txt")}> + {st[build.status.build]} +
+
+
showLog(build, "fs.txt")}>{st[build.status.fs]}
+
updateBuild("http://portal.iotmanager.org/compiler/userdata/builds/" + build.orderId)} class="tbl-bdy-lg ipt-lg w-full cursor-pointer select-none bg-green-100 hover:bg-green-200"> +

Установить

+
+ {/if} + + {#if build.processed} + + delBuild(build)} /> + + {/if} {/if} - {/if} -
- {/if} - - + + {/if} + {/each} + + + {/if} + + +
- + {/if} {:else}