This commit is contained in:
IoT Manager
2023-10-10 16:14:19 +02:00
parent 9181cf6201
commit 7f7ef1a696
3 changed files with 228 additions and 188 deletions

View File

@@ -52,7 +52,7 @@
let preventMove = false; let preventMove = false;
let screenSize; let screenSize;
const blobDebug = false; const blobDebug = false;
const devMode = true; const devMode = false;
let percent; let percent;
@@ -115,6 +115,10 @@
let paramsJson = {}; let paramsJson = {};
let userdata = null; let userdata = null;
let allmodeinfo = null;
let profile = null;
let serverOnline = false;
let parsed = { let parsed = {
itemsJson: false, itemsJson: false,
@@ -207,11 +211,14 @@
}); });
if (res.ok) { if (res.ok) {
userdata = await res.json(); userdata = await res.json();
serverOnline = true;
} else { } else {
console.log("error", res.statusText); console.log("error", res.statusText);
serverOnline = true;
} }
} catch (e) { } catch (e) {
console.log("error", e); console.log("error", e);
serverOnline = false;
} }
}; };
@@ -608,9 +615,67 @@
clearParcedFlags(); clearParcedFlags();
if (debug) console.log("✔✔", "profile page parced"); if (debug) console.log("✔✔", "profile page parced");
pageReady.profile = true; 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() { async function initDevList() {
if (firstDevListRequest) { if (firstDevListRequest) {
//при первом запросе листа устройств запишем его целеком //при первом запросе листа устройств запишем его целеком
@@ -1307,10 +1372,10 @@
</Route> </Route>
<Route path="/profile"> <Route path="/profile">
<Profile show={pageReady.profile} myProfileJson={myProfileJson} userdata={userdata} updateBuild={(path) => updateBuild(path)} /> <Profile show={pageReady.profile} myProfileJson={myProfileJson} userdata={userdata} updateBuild={(path) => updateBuild(path)} allmodeinfo={allmodeinfo} profile={profile} serverOnline={serverOnline} />
</Route> </Route>
<Route path="/login"> <Route path="/login">
<Login show={true} /> <Login show={true} serverOnline={serverOnline} />
</Route> </Route>
{/if} {/if}
</div> </div>

View File

@@ -5,6 +5,7 @@
import { router } from "tinro"; import { router } from "tinro";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
export let show = true; export let show = true;
export let serverOnline;
let user = {}; let user = {};
let errors = []; let errors = [];
@@ -42,6 +43,7 @@
</script> </script>
{#if show} {#if show}
{#if serverOnline}
<div class="flex h-screen m-2 md:m-4 lg:m-8 items-start justify-center"> <div class="flex h-screen m-2 md:m-4 lg:m-8 items-start justify-center">
<div class="w-full max-w-lg"> <div class="w-full max-w-lg">
<form class="bg-white shadow-2xl rounded-xl px-8 pt-6 pb-8 mb-4"> <form class="bg-white shadow-2xl rounded-xl px-8 pt-6 pb-8 mb-4">
@@ -64,6 +66,13 @@
</form> </form>
</div> </div>
</div> </div>
{:else}
<div class="my-4">
<div class="grd-1col1">
<Card title="Сервер недоступен" />
</div>
</div>
{/if}
{:else} {:else}
<Alarm title="Загрузка..." /> <Alarm title="Загрузка..." />
{/if} {/if}

View File

@@ -7,18 +7,19 @@
import Cookies from "js-cookie"; import Cookies from "js-cookie";
export let show; export let show;
export let myProfileJson; export let myProfileJson;
export let allmodeinfo;
export let profile;
export let serverOnline;
export let userdata; export let userdata;
export let updateBuild = (path) => {}; export let updateBuild = (path) => {};
import CrossIcon from "../svg/Cross.svelte"; import CrossIcon from "../svg/Cross.svelte";
let errors = []; let errors = [];
let allmodeinfo = null;
let userBuilds = null; let userBuilds = null;
let profile = null;
var updateInterval; var updateInterval;
onMount(async () => { onMount(async () => {
await getProfile();
await getModInfo();
await getUserBuilds(); await getUserBuilds();
}); });
@@ -30,6 +31,7 @@
}; };
function checkStatus(userBuilds) { function checkStatus(userBuilds) {
if (userBuilds.length) {
if (userBuilds[0].processed) { if (userBuilds[0].processed) {
clearInterval(updateInterval); clearInterval(updateInterval);
console.log("no interval - all task done"); console.log("no interval - all task done");
@@ -41,28 +43,12 @@
} }
} }
} }
}
const periodicTask = async () => { const periodicTask = async () => {
await getUserBuilds(); 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 () => { const getUserBuilds = async () => {
try { try {
const JWT = Cookies.get("token_iotm2"); 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) => { const delBuild = async (ord) => {
try { try {
const JWT = Cookies.get("token_iotm2"); const JWT = Cookies.get("token_iotm2");
@@ -129,9 +93,9 @@
}; };
const placeOrder = async () => { const placeOrder = async () => {
delete myProfileJson["_id"]; delete profile["_id"];
//добавим в тело имя пользователя //добавим в тело имя пользователя
myProfileJson.username = userdata.username; profile.username = userdata.username;
const JWT = Cookies.get("token_iotm2"); const JWT = Cookies.get("token_iotm2");
try { try {
let res = await fetch("https://portal.iotmanager.org/compiler/order", { let res = await fetch("https://portal.iotmanager.org/compiler/order", {
@@ -141,7 +105,7 @@
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${JWT}`, Authorization: `Bearer ${JWT}`,
}, },
body: JSON.stringify(myProfileJson), body: JSON.stringify(profile),
}); });
const content = await res.json(); const content = await res.json();
if (res.ok) { if (res.ok) {
@@ -166,6 +130,7 @@
</script> </script>
{#if show} {#if show}
{#if serverOnline}
{#if allmodeinfo && myProfileJson && profile} {#if allmodeinfo && myProfileJson && profile}
<div class="my-4"> <div class="my-4">
<div class="grd-1col1"> <div class="grd-1col1">
@@ -289,6 +254,7 @@
</Card> </Card>
</div> </div>
</div> </div>
{/if}
{:else} {:else}
<div class="my-4"> <div class="my-4">
<div class="grd-1col1"> <div class="grd-1col1">