mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 23:12:34 +03:00
запуск лк
This commit is contained in:
@@ -27,9 +27,10 @@
|
||||
import ConnectionPage from "./pages/Connection.svelte";
|
||||
import ListPage from "./pages/List.svelte";
|
||||
import SystemPage from "./pages/System.svelte";
|
||||
//import Login from "./pages/Login.svelte";
|
||||
import Login from "./pages/Login.svelte";
|
||||
import Profile from "./pages/Profile.svelte";
|
||||
import { t, locale, locales } from "./i18n";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
//import UtilitiesPage from "./pages/Utilities.svelte";
|
||||
//import LogPage from "./pages/Log.svelte";
|
||||
@@ -109,6 +110,8 @@
|
||||
let layoutJson = [];
|
||||
let paramsJson = {};
|
||||
|
||||
let userdata = null;
|
||||
|
||||
let parsed = {
|
||||
itemsJson: false,
|
||||
widgetsJson: false,
|
||||
@@ -178,6 +181,7 @@
|
||||
//*******************************************************initialisation********************************************************************/
|
||||
onMount(async () => {
|
||||
console.log("[i]", "mounted");
|
||||
await getUser();
|
||||
selectedDeviceDataRefresh();
|
||||
//флаг первого запроса списка устройств
|
||||
firstDevListRequest = true;
|
||||
@@ -187,6 +191,27 @@
|
||||
//sortingLayout();
|
||||
});
|
||||
|
||||
const getUser = async () => {
|
||||
try {
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
let res = await fetch("https://portal.iotmanager.org/api/user/email", {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${JWT}`,
|
||||
},
|
||||
mode: "cors",
|
||||
method: "GET",
|
||||
});
|
||||
if (res.ok) {
|
||||
userdata = await res.json();
|
||||
} else {
|
||||
console.log("error", res.statusText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error", e);
|
||||
}
|
||||
};
|
||||
|
||||
//****************************************************web sockets section******************************************************/
|
||||
function connectToAllDevices() {
|
||||
getSelectedDeviceData(selectedWs);
|
||||
@@ -199,13 +224,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
//function closeAllConnection() {
|
||||
// let s;
|
||||
// for (s in socket) {
|
||||
// socket[s].close();
|
||||
// }
|
||||
//}
|
||||
|
||||
function printAllCreatedWs() {
|
||||
if (socket) {
|
||||
for (let i = 0; i < socket.length; i++) {
|
||||
@@ -1111,8 +1129,10 @@
|
||||
//console.log("width", width);
|
||||
if (width < 900) {
|
||||
preventMove = true;
|
||||
//opened = false;
|
||||
} else {
|
||||
preventMove = false;
|
||||
//opened = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1212,21 +1232,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
//function selectToMarker(str, found) {
|
||||
// let p = str.indexOf(found);
|
||||
// return str.substring(0, p);
|
||||
//}
|
||||
|
||||
//function deleteBeforeDelimiter(str, found) {
|
||||
// let p = str.indexOf(found) + found.length;
|
||||
// return str.substring(p);
|
||||
//}
|
||||
|
||||
//function getMillis() {
|
||||
// const d = new Date();
|
||||
// return d.getMilliseconds();
|
||||
//}
|
||||
|
||||
function moduleOrder(id, key, value) {
|
||||
console.log("order: ", id, key, value);
|
||||
let json = {
|
||||
@@ -1237,14 +1242,6 @@
|
||||
console.log(json);
|
||||
wsSendMsg(selectedWs, "/order|" + JSON.stringify(json));
|
||||
}
|
||||
|
||||
//function checkPassword(pass) {
|
||||
// if (pass === settingsJson.passw) {
|
||||
// settingsJson.pass = false;
|
||||
// authorization = false;
|
||||
// saveSett();
|
||||
// }
|
||||
//}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col h-screen bg-gray-50">
|
||||
@@ -1302,9 +1299,15 @@
|
||||
<li>
|
||||
<a class="menu__item" href="/list">{"Устройства"}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="menu__item" href="/profile">{"Модули"}</a>
|
||||
</li>
|
||||
{#if userdata}
|
||||
<li>
|
||||
<a class="menu__item" href="/profile">{"Модули"}</a>
|
||||
</li>
|
||||
{:else}
|
||||
<li>
|
||||
<a class="menu__item" href="/login">{"Вход"}</a>
|
||||
</li>
|
||||
{/if}
|
||||
<li class="flex flex-col pl-6 pt-3 w-full h-screen">
|
||||
<!--<select class="border border-indigo-500 border-1 h-6 w-12" bind:value={$locale}>
|
||||
{#each locales as l}
|
||||
@@ -1338,7 +1341,10 @@
|
||||
</Route>
|
||||
|
||||
<Route path="/profile">
|
||||
<Profile show={pageReady.profile} myProfileJson={myProfileJson} />
|
||||
<Profile show={pageReady.profile} myProfileJson={myProfileJson} userdata={userdata} />
|
||||
</Route>
|
||||
<Route path="/login">
|
||||
<Login show={true} />
|
||||
</Route>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
18
src/lang.js
18
src/lang.js
@@ -6,6 +6,15 @@ export default {
|
||||
"profile.update": "Обновить",
|
||||
ok_success: "Задача запущена",
|
||||
err_order_exist: "Ваша задача выполняется! Cледующию задачу можно будет запустить после завершения",
|
||||
err_of_login: "Ошибка входа в систему",
|
||||
err_user_not_exist: "Такой пользователь не был зарегестрирован",
|
||||
err_pass: "Неправильный пароль",
|
||||
err_empty_fullname: "Пустое поле имени",
|
||||
err_empty_user: "Пустое поле Email адреса",
|
||||
err_not_email: "Неправильно введен Email",
|
||||
err_pass_lenth: "Пароль должен быть от 4 до 10 символов",
|
||||
ok_success_login: "Вы вошли в систему",
|
||||
"profile.exit": "Выйти",
|
||||
},
|
||||
en: {
|
||||
"login.email": "Email",
|
||||
@@ -14,5 +23,14 @@ export default {
|
||||
"profile.update": "Update",
|
||||
ok_success: "Задача запущена",
|
||||
err_order_exist: "Ваша задача выполняется! Cледующию задачу можно будет запустить после завершения",
|
||||
err_of_login: "Ошибка входа в систему",
|
||||
err_user_not_exist: "Такой пользователь не был зарегестрирован",
|
||||
err_pass: "Неправильный пароль",
|
||||
err_empty_fullname: "Пустое поле имени",
|
||||
err_empty_user: "Пустое поле Email адреса",
|
||||
err_not_email: "Неправильно введен Email",
|
||||
err_pass_lenth: "Пароль должен быть от 4 до 10 символов",
|
||||
ok_success_login: "Вы вошли в систему",
|
||||
"profile.exit": "Выйти",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import Card from "../components/Card.svelte";
|
||||
import Alarm from "../components/Alarm.svelte";
|
||||
import { t, locale, locales } from "../i18n";
|
||||
import { router } from "tinro";
|
||||
import Cookies from "js-cookie";
|
||||
export let show = true;
|
||||
|
||||
let user = {};
|
||||
@@ -20,7 +22,6 @@
|
||||
body: JSON.stringify(user),
|
||||
});
|
||||
const content = await res.json();
|
||||
//console.log(content);
|
||||
if (res.ok) {
|
||||
errors = [{ msg: "ok_success_login" }];
|
||||
saveToken(content.message);
|
||||
@@ -33,7 +34,10 @@
|
||||
};
|
||||
|
||||
const saveToken = async (token) => {
|
||||
Cookies.set("token_iotm2", token);
|
||||
console.log("token to be saved: ", token);
|
||||
router.goto("/profile");
|
||||
location.reload();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
import Card from "../components/Card.svelte";
|
||||
import Alarm from "../components/Alarm.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { router } from "tinro";
|
||||
import { t, locale, locales } from "../i18n";
|
||||
import Cookies from "js-cookie";
|
||||
export let show;
|
||||
export let myProfileJson;
|
||||
export let userdata;
|
||||
|
||||
let errors = [];
|
||||
|
||||
@@ -32,13 +35,13 @@
|
||||
};
|
||||
|
||||
const update = async () => {
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
try {
|
||||
let res = await fetch("https://portal.iotmanager.org/compiler/esporder", {
|
||||
mode: "cors",
|
||||
let res = await fetch("https://portal.iotmanager.org/compiler/order", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${JWT}`,
|
||||
},
|
||||
body: JSON.stringify(myProfileJson),
|
||||
});
|
||||
@@ -54,70 +57,69 @@
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
|
||||
const exit = async () => {
|
||||
Cookies.remove("token_iotm2");
|
||||
router.goto("/login");
|
||||
location.reload();
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if show}
|
||||
{#if myProfileJson.username}
|
||||
{#if allmodeinfo && myProfileJson}
|
||||
<div class="my-4">
|
||||
<div class="grd-1col1">
|
||||
<Card title="">
|
||||
<div class="grid grid-cols-2">
|
||||
<p class="text-center">{myProfileJson.projectProp.platformio.default_envs}</p>
|
||||
<p class="text-center">{myProfileJson.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 myProfileJson.modules.virtual_elments as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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 myProfileJson.modules.sensors as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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 myProfileJson.modules.executive_devices as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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 myProfileJson.modules.screens as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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>
|
||||
{#if allmodeinfo && myProfileJson}
|
||||
<div class="my-4">
|
||||
<div class="grd-1col1">
|
||||
<Card title="">
|
||||
<div class="grid grid-cols-2">
|
||||
<p class="text-center">{myProfileJson.projectProp.platformio.default_envs}</p>
|
||||
<p class="text-center">{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 myProfileJson.modules.virtual_elments as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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}
|
||||
<button class="btn-lg mt-6" on:click={() => update()}>{$t("profile.update")}</button>
|
||||
</Card>
|
||||
</div>
|
||||
{#each myProfileJson.modules.sensors as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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 myProfileJson.modules.executive_devices as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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 myProfileJson.modules.screens as m, i}
|
||||
{#if allmodeinfo[m.path]?.usedLibs[myProfileJson.projectProp.platformio.default_envs]}
|
||||
<div>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<p on:click={() => ((m.active = !m.active), (m.touched = true))} class="{m.active ? 'bg-green-100' : ''} cursor-pointer select-none {m.touched ? 'border border-gray-400' : 'border border-green-100'} 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>
|
||||
{/each}
|
||||
<button class="btn-lg mt-6" on:click={() => update()}>{$t("profile.update")}</button>
|
||||
<button class="btn-lg mt-6" on:click={() => exit()}>{$t("profile.exit")}</button>
|
||||
</Card>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="my-4">
|
||||
<div class="grd-1col1">
|
||||
<Card title="Сервер недоступен" />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="my-4">
|
||||
<div class="grd-1col1">
|
||||
<Card title="Укажите Ваш email который вы использовали при регистрации" />
|
||||
<Card title="Сервер недоступен" />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
export let click = () => {};
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<svg on:click={click()} class="h-6 w-6 text-red-400 cursor-pointer" viewBox="0 -2 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="18" y1="6" x2="6" y2="18" />
|
||||
<line x1="6" y1="6" x2="18" y2="18" /></svg>
|
||||
|
||||
Reference in New Issue
Block a user