mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 23:12:34 +03:00
working version
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
import OpenIcon from "../svg/Open.svelte";
|
||||
import Alarm from "../components/Alarm.svelte";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
import Cookies from "js-cookie";
|
||||
import * as portal from "../api/portal.js";
|
||||
|
||||
export let configJson;
|
||||
export let widgetsJson;
|
||||
@@ -206,16 +206,10 @@
|
||||
export let moduleOrder = (id, key, value) => {};
|
||||
|
||||
const makePost = async () => {
|
||||
let iotmpostDefault = {
|
||||
const body = {
|
||||
category: "",
|
||||
topic: {
|
||||
ru: "",
|
||||
en: "",
|
||||
},
|
||||
text: {
|
||||
ru: "",
|
||||
en: "",
|
||||
},
|
||||
topic: { ru: "", en: "" },
|
||||
text: { ru: "", en: "" },
|
||||
config: configJson,
|
||||
scenario: scenarioTxt,
|
||||
gallery: [],
|
||||
@@ -223,51 +217,25 @@
|
||||
username: userdata.username,
|
||||
};
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
try {
|
||||
let res = await fetch("https://portal.iotmanager.org/api/configurations/add", {
|
||||
mode: "cors",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${JWT}`,
|
||||
},
|
||||
body: JSON.stringify(iotmpostDefault),
|
||||
});
|
||||
const content = await res.json();
|
||||
if (res.ok) {
|
||||
console.log(content.result);
|
||||
if (content.result.acknowledged) {
|
||||
window.open("https://portal.iotmanager.org/configs?id=" + content.result.insertedId + "&token=" + Cookies.get("token_iotm2"), "_blank");
|
||||
}
|
||||
errors = [{ msg: "ok_success" }];
|
||||
} else {
|
||||
errors = content.message;
|
||||
const res = await portal.addConfiguration(JWT, body);
|
||||
if (res.ok && res.data && res.data.result) {
|
||||
console.log(res.data.result);
|
||||
if (res.data.result.acknowledged) {
|
||||
window.open("https://portal.iotmanager.org/configs?id=" + res.data.result.insertedId + "&token=" + JWT, "_blank");
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
errors = [{ msg: "ok_success" }];
|
||||
} else if (res.errors) {
|
||||
errors = res.errors;
|
||||
}
|
||||
};
|
||||
|
||||
const getConfigs = async () => {
|
||||
try {
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
let res = await fetch("https://portal.iotmanager.org/api/configurations/get", {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${JWT}`,
|
||||
},
|
||||
mode: "cors",
|
||||
method: "GET",
|
||||
});
|
||||
if (res.ok) {
|
||||
configurations = await res.json();
|
||||
//configurations.push({ topic: { ru: "123" } });
|
||||
console.log("error", configurations);
|
||||
} else {
|
||||
console.log("error", res.statusText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error", e);
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
const res = await portal.getConfigurations(JWT);
|
||||
if (res.ok && res.configurations != null) {
|
||||
configurations = res.configurations;
|
||||
} else {
|
||||
console.log("error", "getConfigurations");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<Range bind:value={widget.status} widget={widget} wsPush={(ws, topic, status) => wsPush(ws, topic, status)} />
|
||||
{/if}
|
||||
{#if widget.widget === "chart"}
|
||||
<Chart bind:value={widget.status} widget={widget} />
|
||||
<Chart widget={widget} />
|
||||
{/if}
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { t, locale, locales } from "../i18n";
|
||||
import { router } from "tinro";
|
||||
import Cookies from "js-cookie";
|
||||
import * as portal from "../api/portal.js";
|
||||
export let show = true;
|
||||
export let serverOnline;
|
||||
|
||||
@@ -12,25 +13,12 @@
|
||||
|
||||
const login = async (user) => {
|
||||
errors = [];
|
||||
try {
|
||||
let res = await fetch("https://portal.iotmanager.org/api/auth/login", {
|
||||
mode: "cors",
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(user),
|
||||
});
|
||||
const content = await res.json();
|
||||
if (res.ok) {
|
||||
errors = [{ msg: "ok_success_login" }];
|
||||
saveToken(content.message);
|
||||
} else {
|
||||
errors = content.message;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
const res = await portal.login(user);
|
||||
if (res.ok && res.data && res.data.message) {
|
||||
errors = [{ msg: "ok_success_login" }];
|
||||
saveToken(res.data.message);
|
||||
} else if (res.data && res.data.message) {
|
||||
errors = res.data.message;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { router } from "tinro";
|
||||
import { t, locale, locales } from "../i18n";
|
||||
import Cookies from "js-cookie";
|
||||
import * as portal from "../api/portal.js";
|
||||
export let show;
|
||||
export let flashProfileJson;
|
||||
export let otaJson;
|
||||
@@ -51,73 +52,33 @@
|
||||
};
|
||||
|
||||
const getUserBuilds = async () => {
|
||||
try {
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
let res = await fetch("https://portal.iotmanager.org/compiler/userorders", {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${JWT}`,
|
||||
},
|
||||
mode: "cors",
|
||||
method: "GET",
|
||||
});
|
||||
if (res.ok) {
|
||||
userBuilds = await res.json();
|
||||
checkStatus(userBuilds);
|
||||
} else {
|
||||
console.log("error", res.statusText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error", e);
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
const delBuild = async (ord) => {
|
||||
try {
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
let res = await fetch("https://portal.iotmanager.org/compiler/delete/builds/" + ord.orderId, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${JWT}`,
|
||||
},
|
||||
mode: "cors",
|
||||
method: "GET",
|
||||
});
|
||||
if (res.ok) {
|
||||
await getUserBuilds();
|
||||
} else {
|
||||
console.log("error", res.statusText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("error", e);
|
||||
}
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
const res = await portal.deleteBuild(JWT, ord.orderId);
|
||||
if (res.ok) await getUserBuilds();
|
||||
else console.log("error", "deleteBuild");
|
||||
};
|
||||
|
||||
const placeOrder = async () => {
|
||||
delete profile["_id"];
|
||||
//добавим в тело имя пользователя
|
||||
profile.username = userdata.username;
|
||||
const JWT = Cookies.get("token_iotm2");
|
||||
try {
|
||||
let res = await fetch("https://portal.iotmanager.org/compiler/order", {
|
||||
mode: "cors",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${JWT}`,
|
||||
},
|
||||
body: JSON.stringify(profile),
|
||||
});
|
||||
const content = await res.json();
|
||||
if (res.ok) {
|
||||
errors = [{ msg: "ok_success" }];
|
||||
await getUserBuilds();
|
||||
console.log(content.message);
|
||||
} else {
|
||||
errors = content.message;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
const res = await portal.placeOrder(JWT, profile);
|
||||
if (res.ok) {
|
||||
errors = [{ msg: "ok_success" }];
|
||||
await getUserBuilds();
|
||||
} else if (res.errors) {
|
||||
errors = res.errors;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user