alarm parameters
This commit is contained in:
parent
4b91a9fd93
commit
371826da09
152
server.js
152
server.js
@ -2127,6 +2127,10 @@ app.post('/update-group', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { groupId, newName } = req.body;
|
const { groupId, newName } = req.body;
|
||||||
|
|
||||||
@ -2162,6 +2166,9 @@ async function getParameters(serial) {
|
|||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 300));
|
||||||
|
|
||||||
|
|
||||||
const requestResponse2 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse2 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
@ -2174,6 +2181,9 @@ async function getParameters(serial) {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 300));
|
||||||
|
|
||||||
|
|
||||||
const requestResponse3 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse3 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2185,6 +2195,9 @@ async function getParameters(serial) {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 300));
|
||||||
|
|
||||||
|
|
||||||
const requestResponse4 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse4 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2196,6 +2209,8 @@ async function getParameters(serial) {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 300));
|
||||||
|
|
||||||
const requestResponse5 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse5 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2219,9 +2234,15 @@ app.post('/main-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { serial } = req.body;
|
const { serial } = req.body;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2234,7 +2255,7 @@ app.post('/main-parameters', async (req, res) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
||||||
|
|
||||||
@ -2249,6 +2270,10 @@ app.put('/main-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
const requestData = req.body;
|
const requestData = req.body;
|
||||||
const { serial } = req.query;
|
const { serial } = req.query;
|
||||||
|
|
||||||
@ -2287,9 +2312,14 @@ app.post('/device-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { serial } = req.body;
|
const { serial } = req.body;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
|
|
||||||
const responseData = await getParameters(serial);
|
const responseData = await getParameters(serial);
|
||||||
@ -2306,9 +2336,15 @@ app.post('/ethernet-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { serial } = req.body;
|
const { serial } = req.body;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2321,7 +2357,7 @@ app.post('/ethernet-parameters', async (req, res) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
||||||
|
|
||||||
@ -2336,6 +2372,10 @@ app.put('/ethernet-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
const requestData = req.body;
|
const requestData = req.body;
|
||||||
const { serial } = req.query;
|
const { serial } = req.query;
|
||||||
|
|
||||||
@ -2387,9 +2427,15 @@ app.post('/wifi-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { serial } = req.body;
|
const { serial } = req.body;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2401,7 +2447,7 @@ app.post('/wifi-parameters', async (req, res) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
||||||
|
|
||||||
@ -2416,6 +2462,10 @@ app.put('/wifi-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
const requestData = req.body;
|
const requestData = req.body;
|
||||||
const { serial } = req.query;
|
const { serial } = req.query;
|
||||||
|
|
||||||
@ -2463,9 +2513,15 @@ app.post('/communication-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { serial } = req.body;
|
const { serial } = req.body;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2477,7 +2533,7 @@ app.post('/communication-parameters', async (req, res) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
||||||
|
|
||||||
@ -2492,6 +2548,10 @@ app.put('/communication-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
|
|
||||||
const requestData = req.body;
|
const requestData = req.body;
|
||||||
const { serial } = req.query;
|
const { serial } = req.query;
|
||||||
@ -2552,9 +2612,15 @@ app.post('/install-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { serial } = req.body;
|
const { serial } = req.body;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2566,7 +2632,7 @@ app.post('/install-parameters', async (req, res) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
||||||
|
|
||||||
@ -2581,9 +2647,16 @@ app.post('/ai-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { serial } = req.body;
|
const { serial } = req.body;
|
||||||
|
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
|
|
||||||
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -2595,7 +2668,7 @@ app.post('/ai-parameters', async (req, res) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 300));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
|
||||||
|
|
||||||
@ -2606,10 +2679,50 @@ app.post('/ai-parameters', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.put('/ai-parameters', async (req, res) => {
|
||||||
|
if (req.session.userId === undefined) {
|
||||||
|
return res.redirect("/signin");
|
||||||
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestData = req.body;
|
||||||
|
const { serial } = req.query;
|
||||||
|
|
||||||
|
const {
|
||||||
|
DSMA
|
||||||
|
} = requestData;
|
||||||
|
|
||||||
|
const requestBody = {
|
||||||
|
"DSM": {
|
||||||
|
"DSMA": DSMA
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/set?serial=${serial}`, {
|
||||||
|
data: JSON.stringify(requestBody),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
res.status(response.status).send(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).send('Произошла ошибка при отправке GET запроса.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.put('/install-parameters', async (req, res) => {
|
app.put('/install-parameters', async (req, res) => {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
|
|
||||||
const requestData = req.body;
|
const requestData = req.body;
|
||||||
const { serial } = req.query;
|
const { serial } = req.query;
|
||||||
@ -2643,6 +2756,10 @@ app.put('/device-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
// Получаем данные из PUT запроса
|
// Получаем данные из PUT запроса
|
||||||
const requestData = req.body;
|
const requestData = req.body;
|
||||||
const { serial } = req.query;
|
const { serial } = req.query;
|
||||||
@ -2719,6 +2836,10 @@ app.put('/camera-parameters', async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
// Получаем данные из PUT запроса
|
// Получаем данные из PUT запроса
|
||||||
const camerasData = req.body;
|
const camerasData = req.body;
|
||||||
const { serial } = req.query;
|
const { serial } = req.query;
|
||||||
@ -2773,6 +2894,10 @@ app.post("/updatedevice", async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
user: DB_User,
|
user: DB_User,
|
||||||
host: DB_Host,
|
host: DB_Host,
|
||||||
@ -2969,6 +3094,10 @@ app.post("/deletedevice", async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.DeleteTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
const id = req.body.id;
|
const id = req.body.id;
|
||||||
|
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
@ -2996,6 +3125,9 @@ app.post("/deleteuser", async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
if (req.session.userId != "admin") {
|
||||||
|
return res.redirect("/signin");
|
||||||
|
}
|
||||||
const id = req.body.id;
|
const id = req.body.id;
|
||||||
|
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
@ -3023,6 +3155,10 @@ app.post("/deletegroup", async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
const id = req.body.id;
|
const id = req.body.id;
|
||||||
|
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
@ -3050,6 +3186,10 @@ app.post("/add-group", async (req, res) => {
|
|||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin");
|
||||||
}
|
}
|
||||||
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
|
if (!userInfo.EditTransport) {
|
||||||
|
return res.redirect("/devices");
|
||||||
|
}
|
||||||
const { name } = req.body;
|
const { name } = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -62,6 +62,44 @@ function fadeOut(element, callback) {
|
|||||||
|
|
||||||
var givenData;
|
var givenData;
|
||||||
|
|
||||||
|
function encodeCHValue(channels) {
|
||||||
|
let CH = 0;
|
||||||
|
for (const channelNumber of channels) {
|
||||||
|
if (channelNumber >= 1 && channelNumber <= 32) {
|
||||||
|
const channelBit = 1 << (channelNumber - 1);
|
||||||
|
CH |= channelBit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CH;
|
||||||
|
}
|
||||||
|
|
||||||
|
let selectedCameras;
|
||||||
|
|
||||||
|
function checkSelectedCameras() {
|
||||||
|
const checkboxes = document.querySelectorAll('.checkbox-input');
|
||||||
|
selectedCameras = [];
|
||||||
|
|
||||||
|
checkboxes.forEach((checkbox) => {
|
||||||
|
if (checkbox.checked) {
|
||||||
|
const cameraNumber = checkbox.id.replace('camera', '');
|
||||||
|
selectedCameras.push(cameraNumber);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeCHValue(CH) {
|
||||||
|
const channels = [];
|
||||||
|
for (let i = 0; i < 32; i++) {
|
||||||
|
const channelBit = (CH >> i) & 1;
|
||||||
|
if (channelBit === 1) {
|
||||||
|
const channelNumber = i + 1;
|
||||||
|
channels.push(channelNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return channels;
|
||||||
|
}
|
||||||
|
|
||||||
for (let radioButton of radioButtons) {
|
for (let radioButton of radioButtons) {
|
||||||
radioButton.addEventListener("change", () => {
|
radioButton.addEventListener("change", () => {
|
||||||
if (radioButton.value === "parameters") {
|
if (radioButton.value === "parameters") {
|
||||||
@ -260,46 +298,6 @@ for (let radioButton of radioButtons) {
|
|||||||
console.log(data.DATA);
|
console.log(data.DATA);
|
||||||
givenData = data.DATA.DSM.DSMA;
|
givenData = data.DATA.DSM.DSMA;
|
||||||
|
|
||||||
console.log(givenData);
|
|
||||||
|
|
||||||
function encodeCHValue(channels) {
|
|
||||||
let CH = 0;
|
|
||||||
for (const channelNumber of channels) {
|
|
||||||
if (channelNumber >= 1 && channelNumber <= 32) {
|
|
||||||
const channelBit = 1 << (channelNumber - 1);
|
|
||||||
CH |= channelBit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return CH;
|
|
||||||
}
|
|
||||||
|
|
||||||
let selectedCameras;
|
|
||||||
|
|
||||||
function checkSelectedCameras() {
|
|
||||||
const checkboxes = document.querySelectorAll('.checkbox-input');
|
|
||||||
selectedCameras = [];
|
|
||||||
|
|
||||||
checkboxes.forEach((checkbox) => {
|
|
||||||
if (checkbox.checked) {
|
|
||||||
const cameraNumber = checkbox.id.replace('camera', '');
|
|
||||||
selectedCameras.push(cameraNumber);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function decodeCHValue(CH) {
|
|
||||||
const channels = [];
|
|
||||||
for (let i = 0; i < 32; i++) {
|
|
||||||
const channelBit = (CH >> i) & 1;
|
|
||||||
if (channelBit === 1) {
|
|
||||||
const channelNumber = i + 1;
|
|
||||||
channels.push(channelNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return channels;
|
|
||||||
}
|
|
||||||
|
|
||||||
var desiredCameras;
|
var desiredCameras;
|
||||||
|
|
||||||
function updateCheckboxes() {
|
function updateCheckboxes() {
|
||||||
@ -338,7 +336,6 @@ for (let radioButton of radioButtons) {
|
|||||||
|
|
||||||
checkSelectedCameras();
|
checkSelectedCameras();
|
||||||
newCH = encodeCHValue(selectedCameras);
|
newCH = encodeCHValue(selectedCameras);
|
||||||
console.log('Выбранные камеры:', newCH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("system-ai").addEventListener("change", function () {
|
document.getElementById("system-ai").addEventListener("change", function () {
|
||||||
@ -349,28 +346,8 @@ for (let radioButton of radioButtons) {
|
|||||||
document.getElementById("checkboxContainer").addEventListener("change", function () {
|
document.getElementById("checkboxContainer").addEventListener("change", function () {
|
||||||
checkSelectedCameras();
|
checkSelectedCameras();
|
||||||
newCH = encodeCHValue(selectedCameras);
|
newCH = encodeCHValue(selectedCameras);
|
||||||
console.log('Выбранные камеры:', newCH);
|
|
||||||
});
|
});
|
||||||
function updateDataInArray(selectedIndex) {
|
|
||||||
const selectedDataRow = data.DATA.DSM.DSMA[selectedIndex];
|
|
||||||
|
|
||||||
selectedDataRow.EN = document.getElementById("system-ai-en1").value;
|
|
||||||
selectedDataRow.AS = document.getElementById("system-ai-as1").value;
|
|
||||||
selectedDataRow.APR.ENSP = document.getElementById("system-ai-ensp1").value;
|
|
||||||
selectedDataRow.FGMS = document.getElementById("system-ai-fgms1").value;
|
|
||||||
selectedDataRow.SGMS = document.getElementById("system-ai-sgms1").value;
|
|
||||||
selectedDataRow.ESST = document.getElementById("system-ai-esst1").value;
|
|
||||||
selectedDataRow.UDT = document.getElementById("system-ai-udt1").value;
|
|
||||||
selectedDataRow.VT = document.getElementById("system-ai-vt1").value;
|
|
||||||
selectedDataRow.SDT = document.getElementById("system-ai-sdt1").value;
|
|
||||||
selectedDataRow.APR.ET = document.getElementById("system-ai-et1").value;
|
|
||||||
selectedDataRow.APR.SS.EN = document.getElementById("system-ai-ss-en1").value;
|
|
||||||
selectedDataRow.APR.AR.D = document.getElementById("system-ai-ar-d1").value;
|
|
||||||
|
|
||||||
selectedDataRow.APR.AR.CH = encodeCHValue(selectedCameras);
|
|
||||||
|
|
||||||
console.log(selectedDataRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateFields(0);
|
updateFields(0);
|
||||||
|
|
||||||
@ -389,3 +366,25 @@ function truncateText(select) {
|
|||||||
option.text = option.text.substring(0, maxLength) + "...";
|
option.text = option.text.substring(0, maxLength) + "...";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateDataInArray() {
|
||||||
|
const selectedIndex = parseInt(document.getElementById("system-ai").value);
|
||||||
|
const selectedDataRow = givenData[selectedIndex];
|
||||||
|
|
||||||
|
selectedDataRow.EN = parseInt(document.getElementById("system-ai-en1").value);
|
||||||
|
selectedDataRow.AS = parseInt(document.getElementById("system-ai-as1").value);
|
||||||
|
selectedDataRow.APR.ENSP = parseInt(document.getElementById("system-ai-ensp1").value);
|
||||||
|
selectedDataRow.FGMS = parseInt(document.getElementById("system-ai-fgms1").value);
|
||||||
|
selectedDataRow.SGMS = parseInt(document.getElementById("system-ai-sgms1").value);
|
||||||
|
selectedDataRow.ESST = parseInt(document.getElementById("system-ai-esst1").value);
|
||||||
|
selectedDataRow.UDT = parseInt(document.getElementById("system-ai-udt1").value);
|
||||||
|
selectedDataRow.VT = parseInt(document.getElementById("system-ai-vt1").value);
|
||||||
|
selectedDataRow.SDT = parseInt(document.getElementById("system-ai-sdt1").value);
|
||||||
|
selectedDataRow.APR.ET = parseInt(document.getElementById("system-ai-et1").value);
|
||||||
|
selectedDataRow.APR.SS.EN = parseInt(document.getElementById("system-ai-ss-en1").value);
|
||||||
|
selectedDataRow.APR.AR.D = parseInt(document.getElementById("system-ai-ar-d1").value);
|
||||||
|
|
||||||
|
selectedDataRow.APR.AR.CH = parseInt(encodeCHValue(selectedCameras));
|
||||||
|
|
||||||
|
givenData[selectedIndex] = selectedDataRow;
|
||||||
|
}
|
||||||
|
@ -131,17 +131,17 @@
|
|||||||
<section class="for-new">
|
<section class="for-new">
|
||||||
|
|
||||||
<section class="stages">
|
<section class="stages">
|
||||||
<input name="newStage" type="radio" value="parameters" id="stage-parameters" checked><label for="stage-parameters">Системные настройки</label>
|
<input autocomplete="off" name="newStage" type="radio" value="parameters" id="stage-parameters" checked><label for="stage-parameters">Системные настройки</label>
|
||||||
<div class="vertical-line" style="background: transparent;"></div>
|
<div class="vertical-line" style="background: transparent;"></div>
|
||||||
<input name="newStage" type="radio" value="ethernet" id="stage-ethernet"><label for="stage-ethernet">Сеть</label>
|
<input autocomplete="off" name="newStage" type="radio" value="ethernet" id="stage-ethernet"><label for="stage-ethernet">Сеть</label>
|
||||||
<div class="vertical-line"></div>
|
<div class="vertical-line"></div>
|
||||||
<input name="newStage" type="radio" value="wifi" id="stage-wifi"><label for="stage-wifi">Wi-Fi</label>
|
<input autocomplete="off" name="newStage" type="radio" value="wifi" id="stage-wifi"><label for="stage-wifi">Wi-Fi</label>
|
||||||
<div class="vertical-line"></div>
|
<div class="vertical-line"></div>
|
||||||
<input name="newStage" type="radio" value="communication" id="stage-communication"><label for="stage-communication">Коммуникации</label>
|
<input autocomplete="off" name="newStage" type="radio" value="communication" id="stage-communication"><label for="stage-communication">Коммуникации</label>
|
||||||
<div class="vertical-line" style="background: transparent;"></div>
|
<div class="vertical-line" style="background: transparent;"></div>
|
||||||
<input name="newStage" type="radio" value="install" id="stage-install"><label for="stage-install">Установка сервера</label>
|
<input autocomplete="off" name="newStage" type="radio" value="install" id="stage-install"><label for="stage-install">Установка сервера</label>
|
||||||
<div class="vertical-line" style="background: transparent;"></div>
|
<div class="vertical-line" style="background: transparent;"></div>
|
||||||
<input name="newStage" type="radio" value="ai" id="stage-ai"><label for="stage-ai">Тревоги</label>
|
<input autocomplete="off" name="newStage" type="radio" value="ai" id="stage-ai"><label for="stage-ai">Тревоги</label>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
<section id="add-new-container" class="add-new">
|
<section id="add-new-container" class="add-new">
|
||||||
@ -476,17 +476,17 @@
|
|||||||
|
|
||||||
<div class="parameters-inputs">
|
<div class="parameters-inputs">
|
||||||
<label for="system-ai">Статус</label>
|
<label for="system-ai">Статус</label>
|
||||||
<select style="width: 100%;" name="AI" id="system-ai">
|
<select autocomplete="off" style="width: 100%;" name="AI" id="system-ai">
|
||||||
<option value="0">0 - Физиологическая усталость</option>
|
<option value="0">Физиологическая усталость</option>
|
||||||
<option value="1">1 - Нет водителя</option>
|
<option value="1">Нет водителя</option>
|
||||||
<option value="2">2 - Говорит по телефону</option>
|
<option value="2">Говорит по телефону</option>
|
||||||
<option value="3">3 - Курение</option>
|
<option value="3">Курение</option>
|
||||||
<option value="4">4 - Отклекся</option>
|
<option value="4">Отвлекся</option>
|
||||||
<option value="5">5 - Предупреждение о покидании полосы движения</option>
|
<option value="5">Предупреждение о покидании полосы движения</option>
|
||||||
<option value="6">6 - Предупреждение о столкновении</option>
|
<option value="6">Предупреждение о столкновении</option>
|
||||||
<option value="9">9 - Расстояние до машины слишком близко</option>
|
<option value="9">Расстояние до машины слишком близко</option>
|
||||||
<option value="10">10 - Зевание</option>
|
<option value="10">Зевание</option>
|
||||||
<option value="11">11 - Столкновение с пешеходом</option>
|
<option value="11">Столкновение с пешеходом</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="parameters-input">
|
<div class="parameters-input">
|
||||||
<label for="system-ai-en1">Статус</label>
|
<label for="system-ai-en1">Статус</label>
|
||||||
@ -565,7 +565,7 @@
|
|||||||
|
|
||||||
<div class="horizontal-line"></div>
|
<div class="horizontal-line"></div>
|
||||||
|
|
||||||
<button onclick="updateDataInArray(0);" type="button">Сохранить</button>
|
<button onclick="sendPutRequest('ai');" type="button">Сохранить</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -1120,6 +1120,54 @@ const requestBody = {
|
|||||||
showMessage("Не удалось обновить данные", false);
|
showMessage("Не удалось обновить данные", false);
|
||||||
console.error('Произошла ошибка при отправке PUT запроса:', error);
|
console.error('Произошла ошибка при отправке PUT запроса:', error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (type === 'ai') {
|
||||||
|
|
||||||
|
const deleteConfirmation = document.getElementById("addInformation");
|
||||||
|
const loader = document.getElementById("loader");
|
||||||
|
const status = document.getElementById("status");
|
||||||
|
const closeButton = document.getElementById("closeButton");
|
||||||
|
const mark = document.getElementById("success-mark");
|
||||||
|
|
||||||
|
loader.style.display = "block";
|
||||||
|
closeButton.style.display = "none";
|
||||||
|
deleteConfirmation.style.display = "flex";
|
||||||
|
mark.style.display = "none";
|
||||||
|
|
||||||
|
updateDataInArray();
|
||||||
|
|
||||||
|
const DSMA = givenData;
|
||||||
|
console.log(DSMA);
|
||||||
|
|
||||||
|
const requestData = {
|
||||||
|
DSMA
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/ai-parameters?serial=${serial}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(requestData),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
var formContainer = $("#form-bg");
|
||||||
|
var form = $("#form");
|
||||||
|
formContainer.removeClass("active");
|
||||||
|
form.removeClass("form-animation");
|
||||||
|
$("body").css("overflow", "auto");
|
||||||
|
showMessage("Данные успешно обновлены", true);
|
||||||
|
console.log('PUT запрос выполнен успешно');
|
||||||
|
} else {
|
||||||
|
showMessage("Не удалось обновить данные", false);
|
||||||
|
console.error('Ошибка при выполнении PUT запроса');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
showMessage("Не удалось обновить данные", false);
|
||||||
|
console.error('Произошла ошибка при отправке PUT запроса:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -1197,7 +1245,7 @@ $(document).ready(function() {
|
|||||||
location.reload();
|
location.reload();
|
||||||
const deleteConfirmation = document.getElementById("addInformation");
|
const deleteConfirmation = document.getElementById("addInformation");
|
||||||
deleteConfirmation.style.display = "none";
|
deleteConfirmation.style.display = "none";
|
||||||
}, 2000);
|
}, 500);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user