2023-10-04 18:56:24 +02:00
|
|
|
|
<script>
|
|
|
|
|
|
import Card from "../components/Card.svelte";
|
|
|
|
|
|
import Alarm from "../components/Alarm.svelte";
|
|
|
|
|
|
import { onMount } from "svelte";
|
2023-10-05 01:39:15 +02:00
|
|
|
|
import { router } from "tinro";
|
2023-10-04 18:56:24 +02:00
|
|
|
|
import { t, locale, locales } from "../i18n";
|
2023-10-05 01:39:15 +02:00
|
|
|
|
import Cookies from "js-cookie";
|
2026-02-08 22:41:16 +01:00
|
|
|
|
import * as portal from "../api/portal.js";
|
2023-10-04 18:56:24 +02:00
|
|
|
|
export let show;
|
2023-10-11 01:50:08 +02:00
|
|
|
|
export let flashProfileJson;
|
|
|
|
|
|
export let otaJson;
|
2023-10-10 16:14:19 +02:00
|
|
|
|
export let allmodeinfo;
|
|
|
|
|
|
export let profile;
|
|
|
|
|
|
|
|
|
|
|
|
export let serverOnline;
|
|
|
|
|
|
|
2023-10-05 01:39:15 +02:00
|
|
|
|
export let userdata;
|
2023-10-05 19:10:32 +02:00
|
|
|
|
export let updateBuild = (path) => {};
|
2023-10-05 18:52:49 +02:00
|
|
|
|
import CrossIcon from "../svg/Cross.svelte";
|
2023-10-04 18:56:24 +02:00
|
|
|
|
let errors = [];
|
2023-10-05 14:38:57 +02:00
|
|
|
|
let userBuilds = null;
|
|
|
|
|
|
var updateInterval;
|
2023-10-04 18:56:24 +02:00
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
2023-10-05 14:38:57 +02:00
|
|
|
|
await getUserBuilds();
|
2023-10-04 18:56:24 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2023-10-05 14:38:57 +02:00
|
|
|
|
const st = {
|
|
|
|
|
|
0: "",
|
|
|
|
|
|
1: "В процессе",
|
|
|
|
|
|
2: "Ок",
|
|
|
|
|
|
3: "Ошибка",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function checkStatus(userBuilds) {
|
2023-10-10 16:14:19 +02:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2023-10-05 14:38:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const periodicTask = async () => {
|
|
|
|
|
|
await getUserBuilds();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getUserBuilds = async () => {
|
2026-02-08 22:41:16 +01:00
|
|
|
|
const JWT = Cookies.get("token_iotm2");
|
|
|
|
|
|
const res = await portal.getUserOrders(JWT);
|
|
|
|
|
|
if (res.ok && res.userBuilds != null) {
|
|
|
|
|
|
userBuilds = res.userBuilds;
|
|
|
|
|
|
checkStatus(userBuilds);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("error", "getUserOrders");
|
2023-10-05 14:38:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-10-05 18:52:49 +02:00
|
|
|
|
const delBuild = async (ord) => {
|
2026-02-08 22:41:16 +01:00
|
|
|
|
const JWT = Cookies.get("token_iotm2");
|
|
|
|
|
|
const res = await portal.deleteBuild(JWT, ord.orderId);
|
|
|
|
|
|
if (res.ok) await getUserBuilds();
|
|
|
|
|
|
else console.log("error", "deleteBuild");
|
2023-10-05 18:52:49 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const placeOrder = async () => {
|
2023-10-10 16:14:19 +02:00
|
|
|
|
delete profile["_id"];
|
|
|
|
|
|
profile.username = userdata.username;
|
2023-10-06 23:54:58 +02:00
|
|
|
|
const JWT = Cookies.get("token_iotm2");
|
2026-02-08 22:41:16 +01:00
|
|
|
|
const res = await portal.placeOrder(JWT, profile);
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
|
errors = [{ msg: "ok_success" }];
|
|
|
|
|
|
await getUserBuilds();
|
|
|
|
|
|
} else if (res.errors) {
|
|
|
|
|
|
errors = res.errors;
|
2023-10-04 18:56:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-10-05 01:39:15 +02:00
|
|
|
|
|
|
|
|
|
|
const exit = async () => {
|
|
|
|
|
|
Cookies.remove("token_iotm2");
|
|
|
|
|
|
router.goto("/login");
|
|
|
|
|
|
location.reload();
|
|
|
|
|
|
};
|
2023-10-05 14:38:57 +02:00
|
|
|
|
|
|
|
|
|
|
const showLog = async (ord, file) => {};
|
2023-10-04 18:56:24 +02:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
{#if show}
|
2023-10-10 16:14:19 +02:00
|
|
|
|
{#if serverOnline}
|
2023-10-11 01:50:08 +02:00
|
|
|
|
{#if allmodeinfo && flashProfileJson && profile}
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<div class="my-4">
|
|
|
|
|
|
<div class="grd-1col1">
|
|
|
|
|
|
<Card title="">
|
|
|
|
|
|
<div class="grid grid-cols-2">
|
2023-10-11 01:50:08 +02:00
|
|
|
|
<p class="text-center text-gray-500 font-bold">{flashProfileJson.projectProp.platformio.default_envs}</p>
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<p class="text-center text-gray-500 font-bold">{userdata.username}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="grid my-4 grid-cols-2 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 xl:grid-cols-12 2xl:grid-cols-12 gap-4">
|
|
|
|
|
|
<!--{#each Object.entries(allmodeinfo) as [key, param]}
|
2023-10-10 12:26:09 +02:00
|
|
|
|
<div>
|
|
|
|
|
|
|
|
|
|
|
|
<p class="cursor-pointer select-none text-black text-xs font-medium mr-2 px-0.5 py-0.5 rounded text-center">{key.substring(key.lastIndexOf("/") + 1, key.length)}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/each}-->
|
|
|
|
|
|
|
2023-10-10 16:14:19 +02:00
|
|
|
|
{#each profile.modules.virtual_elments as m, i}
|
|
|
|
|
|
{#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
|
|
<p on:click={() => (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)}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
{#each profile.modules.sensors as m, i}
|
|
|
|
|
|
{#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
|
|
<p on:click={() => (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)}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
{#each profile.modules.executive_devices as m, i}
|
|
|
|
|
|
{#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
|
|
<p on:click={() => (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)}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
{#each profile.modules.screens as m, i}
|
|
|
|
|
|
{#if allmodeinfo[m.path]?.usedLibs[profile.projectProp.platformio.default_envs]}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
|
|
<p on:click={() => (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)}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{#each errors as e, i}
|
|
|
|
|
|
<p class="text-red-500 p-0 m-0 font-bold text-xs italic">{$t(e.msg)}</p>
|
2023-10-05 01:39:15 +02:00
|
|
|
|
{/each}
|
2023-10-11 01:50:08 +02:00
|
|
|
|
<button class="btn-lg mt-4 mb-4" on:click={() => placeOrder()}>{$t("profile.update")}</button>
|
|
|
|
|
|
{#if Object.keys(otaJson).length !== 0}
|
|
|
|
|
|
<div class="grid grid-cols-2 mb-4">
|
|
|
|
|
|
<p class="text-center text-gray-500 font-bold truncate">Статус последнего обновления:</p>
|
|
|
|
|
|
<p class="{otaJson.build === 0 && otaJson.fs === 0 ? 'text-green-500' : 'text-red-500'} text-center font-bold truncate">{otaJson.build === 0 && otaJson.fs === 0 ? "успешно" : "ошибка"}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
2023-10-10 16:14:19 +02:00
|
|
|
|
{#if userBuilds}
|
2023-10-11 01:50:08 +02:00
|
|
|
|
<table class="tbl mb-0">
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<thead class="bg-gray-100">
|
|
|
|
|
|
<tr class="txt-sz txt-pad">
|
|
|
|
|
|
<th class="tbl-hd">Название</th>
|
|
|
|
|
|
<th class="tbl-hd">Версия</th>
|
|
|
|
|
|
<th class="tbl-hd">Время</th>
|
2023-10-05 14:38:57 +02:00
|
|
|
|
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<th class="tbl-hd">Подготовка</th>
|
|
|
|
|
|
<th class="tbl-hd">Сборка build</th>
|
|
|
|
|
|
<th class="tbl-hd">Сборка fs</th>
|
|
|
|
|
|
<th class="tbl-hd" />
|
|
|
|
|
|
<th class="tbl-hd w-7" />
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody class="bg-white">
|
|
|
|
|
|
{#each userBuilds as build, i}
|
2023-10-11 01:50:08 +02:00
|
|
|
|
{#if build.projectProp.platformio.default_envs === flashProfileJson.projectProp.platformio.default_envs}
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<tr class="txt-sz txt-pad">
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">{build.projectProp.platformio.default_envs}</td>
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">{build.ver}</td>
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">{new Date(build.dateAdded).toLocaleString("ru", { timeZone: "Europe/Vienna" })}</td>
|
|
|
|
|
|
{#if build.status.preparation === 0 && build.status.build === 0 && build.status.fs === 0}
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">
|
|
|
|
|
|
<p class="text-green-500 font-bold truncate">{"Ожидание очереди..."}</p>
|
2023-10-05 18:52:49 +02:00
|
|
|
|
</td>
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full" />
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full" />
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full" />
|
|
|
|
|
|
{:else}
|
2023-10-05 18:52:49 +02:00
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<div onClick={() => showLog(build, "py.txt")}>
|
|
|
|
|
|
{st[build.status.preparation]}
|
|
|
|
|
|
</div>
|
2023-10-05 18:52:49 +02:00
|
|
|
|
</td>
|
2023-10-10 16:14:19 +02:00
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">
|
|
|
|
|
|
<div onClick={() => showLog(build, "build.txt")}>
|
|
|
|
|
|
{st[build.status.build]}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">
|
|
|
|
|
|
<div onClick={() => showLog(build, "fs.txt")}>{st[build.status.fs]}</div>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
{#if build.status.build === 2 && build.status.preparation === 2 && build.status.fs === 2}
|
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
|
|
<td on:click={() => 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">
|
|
|
|
|
|
<p class="w-fill">Установить</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
{:else}
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full" />
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
|
|
{#if build.processed}
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full">
|
|
|
|
|
|
<CrossIcon click={() => delBuild(build)} />
|
|
|
|
|
|
</td>
|
|
|
|
|
|
{:else}
|
|
|
|
|
|
<td class="tbl-bdy-lg ipt-lg w-full" />
|
|
|
|
|
|
{/if}
|
2023-10-05 18:52:49 +02:00
|
|
|
|
{/if}
|
2023-10-10 16:14:19 +02:00
|
|
|
|
</tr>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
{/if}
|
2023-10-11 01:50:08 +02:00
|
|
|
|
<button class="btn-lg mt-4" on:click={() => exit()}>{$t("profile.exit")}</button>
|
2023-10-10 16:14:19 +02:00
|
|
|
|
</Card>
|
|
|
|
|
|
</div>
|
2023-10-04 21:17:55 +02:00
|
|
|
|
</div>
|
2023-10-10 16:14:19 +02:00
|
|
|
|
{/if}
|
2023-10-04 18:56:24 +02:00
|
|
|
|
{:else}
|
|
|
|
|
|
<div class="my-4">
|
|
|
|
|
|
<div class="grd-1col1">
|
2023-10-05 01:39:15 +02:00
|
|
|
|
<Card title="Сервер недоступен" />
|
2023-10-04 18:56:24 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{:else}
|
|
|
|
|
|
<Alarm title="Загрузка..." />
|
|
|
|
|
|
{/if}
|