+
Ошибка
+ Не удалось получить данные из БД + +
diff --git a/server.js b/server.js index 4640135..71231eb 100644 --- a/server.js +++ b/server.js @@ -878,7 +878,7 @@ async function reports(req, res) { } const query = ` - SELECT a.evtuuid, a.id, a.cmdno, a.time, a.serial, a.st, r.plate, g.latitude, g.longitude + SELECT a.evtuuid, a.id, a.cmdno, a.time, a.serial, a.st, r.plate, g.latitude, g.longitude, r.number FROM ( SELECT DISTINCT ON (evtuuid) evtuuid, id, cmdno, time, serial, st FROM alarms @@ -1016,6 +1016,7 @@ async function reports(req, res) { id: alarm.id, cmdno: alarm.cmdno, time: formatDate(alarm.time), + number: alarm.number, serial: alarm.serial, st: alarm.st, type: type, @@ -1879,7 +1880,193 @@ async function devices(req, res) { } } +app.get('/devices/device/system/:serial', 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 serial = req.params.serial; + let templateData = { + SERVER_IP: process.env.SERVER_IP, + Organisation: userInfo.Organisation, + User: userInfo.User, + UserInfo: userInfo.Users, + isAdmin: req.session.userId === 'admin', + ifDBError: false, + Serial: serial, + EditTransport: false, + DeleteTransport: false, + Update: false, + }; + + try { + const pool = new Pool({ + user: DB_User, + host: DB_Host, + database: DB_Name, + password: DB_Password, + port: DB_Port, + }); + const client = await pool.connect(); + + const source = fs.readFileSync("static/templates/devices/system.html", "utf8"); + const template = handlebars.compile(source); + const resultT = template(templateData); + res.send(resultT); + + client.release(); + } catch (error) { + console.error(error); + templateData.ifDBError = true; + + const source = fs.readFileSync( + "static/templates/devices/system.html", + "utf8" + ); + const template = handlebars.compile(source); + const resultT = template(templateData); + res.send(resultT); + } +}); + +app.get('/devices/device/:serial', 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 serial = req.params.serial; + + let templateData = { + SERVER_IP: process.env.SERVER_IP, + Organisation: userInfo.Organisation, + User: userInfo.User, + UserInfo: userInfo.Users, + isAdmin: req.session.userId === 'admin', + ifDBError: false, + Serial: serial, + EditTransport: false, + DeleteTransport: false, + Update: false, + GroupsList: [], + + Number: "", + Plate: "", + PlateColor: "", + Channels: "", + Protocol: "", + Ip: "", + Group: "", + Port: "", + Sim: "", + Imei: "", + Imsi: "", + Module: "", + Type: "", + Factory: "", + Capacity: "", + Engine: "", + Stanina: "", + Fuel: "", + Certificate: "", + Category: "", + Expire: "", + Consumption: "", + Region: "", + City: "", + Name: "", + Password: "", + Batch: "", + Release: "", + Installer: "", + Installation: "", + Description: "", + }; + + try { + const pool = new Pool({ + user: DB_User, + host: DB_Host, + database: DB_Name, + password: DB_Password, + port: DB_Port, + }); + const client = await pool.connect(); + + const query = "SELECT * FROM registrars WHERE serial = $1"; + const result = await client.query(query, [serial]); + + const groupsQuery = "SELECT id, name FROM groups"; + const groupsResult = await client.query(groupsQuery); + + templateData.GroupsList = groupsResult.rows.map(row => ({ + id: row.id, + name: row.name, + })); + + // Предполагается, что результат запроса содержит одну строку данных. + if (result.rows.length === 1) { + const rowData = result.rows[0]; + + // Заполнение данных из результата SQL запроса в объект templateData. + templateData.Number = rowData.number; + templateData.Plate = rowData.plate; + templateData.PlateColor = rowData.plate_color; + templateData.Channels = rowData.channels; + templateData.Protocol = rowData.protocol; + templateData.Ip = rowData.ip; + templateData.Group = rowData.group; + templateData.Port = rowData.port; + templateData.Sim = rowData.sim; + templateData.Imei = rowData.imei; + templateData.Imsi = rowData.imsi; + templateData.Module = rowData.module; + templateData.Type = rowData.auto; + templateData.Factory = rowData.factory; + templateData.Capacity = rowData.capacity; + templateData.Engine = rowData.engine; + templateData.Stanina = rowData.stanina; + templateData.Fuel = rowData.fuel; + templateData.Certificate = rowData.certificate; + templateData.Category = rowData.category; + templateData.Expire = rowData.certificate_exp; + templateData.Consumption = rowData.consumption; + templateData.Region = rowData.region; + templateData.City = rowData.city; + templateData.Name = rowData.name; + templateData.Password = rowData.password; + templateData.Batch = rowData.batch; + templateData.Release = rowData.release; + templateData.Installer = rowData.installer; + templateData.Installation = rowData.installation; + templateData.Description = rowData.description; + } + + const source = fs.readFileSync("static/templates/devices/device.html", "utf8"); + const template = handlebars.compile(source); + const resultT = template(templateData); + res.send(resultT); + + client.release(); + } catch (error) { + console.error(error); + templateData.ifDBError = true; + + const source = fs.readFileSync( + "static/templates/devices/device.html", + "utf8" + ); + const template = handlebars.compile(source); + const resultT = template(templateData); + res.send(resultT); + } +}); async function groups(req, res) { if (req.session.userId === undefined) { @@ -1971,7 +2158,7 @@ async function getParameters(serial) { }, data: JSON.stringify({ "FIELDS": [ - "DOSD" + "EOSD" ] }), }); @@ -2024,11 +2211,78 @@ async function getParameters(serial) { await new Promise(resolve => setTimeout(resolve, 300)); const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`); - // console.log(getResponse.data); return getResponse.data; } +app.post('/main-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + try { + const { serial } = req.body; + + const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, { + headers: { + 'Content-Type': 'application/json', + }, + data: JSON.stringify({ + "FIELDS": [ + "RIP", + "VS" + ] + }), + }); + + await new Promise(resolve => setTimeout(resolve, 300)); + + const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`); + + res.json(getResponse.data); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +app.put('/main-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + const requestData = req.body; + const { serial } = req.query; + + const { + NUMBER, + PLATE, + VIN + } = requestData; + + const requestBody = { + "RIP": { + "BN": NUMBER, + "BID": PLATE + }, + "VS": { + "VIN": VIN + } + }; + + + + 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.post('/device-parameters', async (req, res) => { if (req.session.userId === undefined) { return res.redirect("/signin"); @@ -2037,7 +2291,7 @@ app.post('/device-parameters', async (req, res) => { const { serial } = req.body; - // Используем асинхронный цикл для выполнения GET-запросов по очереди + const responseData = await getParameters(serial); @@ -2048,6 +2302,314 @@ app.post('/device-parameters', async (req, res) => { } }); +app.post('/ethernet-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + try { + const { serial } = req.body; + + const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, { + headers: { + 'Content-Type': 'application/json', + }, + data: JSON.stringify({ + "FIELDS": [ + "ETHERNET", + "KEYS" + ] + }), + }); + + await new Promise(resolve => setTimeout(resolve, 300)); + + const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`); + + res.json(getResponse.data); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +app.put('/ethernet-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + const requestData = req.body; + const { serial } = req.query; + + const { + IPMODE, + IPADDR, + SUBMASK, + GATEWAY, + DNSMODE, + PDNS, + ADNS, + MAC + } = requestData; + + + const requestBody = { + "ETHERNET": { + "IPMODE": IPMODE, + "PIP": { + "IPADDR": IPADDR, + "SUBMASK": SUBMASK, + "GATEWAY": GATEWAY, + }, + "DNSMODE": DNSMODE, + "DNS": { + "PDNS": PDNS, + "ADNS": ADNS + } + }, + "KEYS": { + "MAC": MAC + } + }; + + 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.post('/wifi-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + try { + const { serial } = req.body; + + const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, { + headers: { + 'Content-Type': 'application/json', + }, + data: JSON.stringify({ + "FIELDS": [ + "WIFI" + ] + }), + }); + + await new Promise(resolve => setTimeout(resolve, 300)); + + const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`); + + res.json(getResponse.data); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +app.put('/wifi-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + const requestData = req.body; + const { serial } = req.query; + + const { + WIFI, + ESSID, + ECRYPTTYPE, + PWD, + IPMODE, + IPADDR, + SUBMASK, + GATEWAY + } = requestData; + + + const requestBody = { + "WIFI": { + "ENABLE": WIFI, + "ESSID": ESSID, + "ECRYPTTYPE": ECRYPTTYPE, + "IPMODE": IPMODE, + "PWD": PWD, + "PIP": { + "IPADDR": IPADDR, + "SUBMASK": SUBMASK, + "GATEWAY": GATEWAY, + } + } + }; + + 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.post('/communication-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + try { + const { serial } = req.body; + + const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, { + headers: { + 'Content-Type': 'application/json', + }, + data: JSON.stringify({ + "FIELDS": [ + "M3G" + ] + }), + }); + + await new Promise(resolve => setTimeout(resolve, 300)); + + const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`); + + res.json(getResponse.data); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +app.put('/communication-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + + const requestData = req.body; + const { serial } = req.query; + + const { + NM1, + APN1, + UN1, + PW1, + NM2, + APN2, + UN2, + PW2, + AT, + TN1, + TN2, + TN3 + } = requestData; + + + const requestBody = { + "M3G": { + "M3M": { + "AT": AT, + "TN1":TN1, + "TN2":TN2, + "TN3":TN3 + }, + "MP": { + "NM": NM1, + "APN": APN1, + "UN": UN1, + "PW": PW1 + }, + "M4G": { + "NM": NM2, + "APN": APN2, + "UN": UN2, + "PW": PW2 + }, + } + }; + + 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.post('/install-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + try { + const { serial } = req.body; + + const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, { + headers: { + 'Content-Type': 'application/json', + }, + data: JSON.stringify({ + "FIELDS": [ + "MCMS" + ] + }), + }); + + await new Promise(resolve => setTimeout(resolve, 300)); + + const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`); + + res.json(getResponse.data); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +app.put('/install-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + + const requestData = req.body; + const { serial } = req.query; + + const { + SP + } = requestData; + + + const requestBody = { + "MCMS": { + "SP": SP + } + }; + + + 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('/device-parameters', async (req, res) => { if (req.session.userId === undefined) { return res.redirect("/signin"); @@ -2069,9 +2631,11 @@ app.put('/device-parameters', async (req, res) => { TE, VE, SE, - GE + GE, + DE } = requestData; + // Создаем JSON для GET запроса const requestBody = { "TIMEP": { @@ -2087,16 +2651,26 @@ app.put('/device-parameters', async (req, res) => { "SUBSTRNET": { "SM": parseInt(SUBSTREAMMODE, 10) || 1 }, - "DOSD": { - "NE": parseInt(NE, 10) || 1, - "TE": parseInt(TE, 10) || 1, - "VE": parseInt(VE, 10) || 0, - "SE": parseInt(SE, 10) || 0, - "GE": parseInt(GE, 10) || 0 - } + "EOSD": [ + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + { "GE": GE, "NE": NE, "SE": SE, "TE": TE, "VE": VE, "DE": DE }, + ] }; - // Отправляем GET запрос с JSON BODY try { const response = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/set?serial=${serial}`, { @@ -2183,6 +2757,7 @@ app.post("/updatedevice", async (req, res) => { serialNumber, deviceNumber, plateNumber, + vinNumber, channelsAmount, plateColor, IPAddress, @@ -2249,8 +2824,9 @@ app.post("/updatedevice", async (req, res) => { installer = $28, installation = $29, description = $30, - number = $31 - WHERE serial = $32 + number = $31, + vin = $32 + WHERE serial = $33 RETURNING *; `; @@ -2286,6 +2862,7 @@ app.post("/updatedevice", async (req, res) => { equipmentInstalled, equipmentDescription, deviceNumber, + vinNumber, serialNumber, ]; diff --git a/static/scripts/parameters-form.js b/static/scripts/parameters-form.js new file mode 100644 index 0000000..5a22474 --- /dev/null +++ b/static/scripts/parameters-form.js @@ -0,0 +1,253 @@ + + +const container = document.getElementById("new-parameters"); +const content1 = document.getElementById("parameters"); +const content2 = document.getElementById("ethernet"); +const content3 = document.getElementById("wifi"); +const content4 = document.getElementById("communication"); +const content5 = document.getElementById("install"); +const content6 = document.getElementById("cameras");; +const radioButtons = document.querySelectorAll( + 'input[type="radio"][name="newStage"]' +); +const duration = 100; + +let activeContent = content1; + +function switchContent(newContent) { + fadeOut(activeContent, () => { + fadeIn(newContent); + activeContent = newContent; + }); +} + +function fadeIn(element) { + element.style.opacity = 0; + element.style.display = "block"; + let start = performance.now(); + + function animate(time) { + let timeFraction = (time - start) / duration; + if (timeFraction > 1) { + element.style.opacity = 1; + } else { + element.style.opacity = timeFraction; + requestAnimationFrame(animate); + } + } + + requestAnimationFrame(animate); +} + +function fadeOut(element, callback) { + element.style.opacity = 1; + let start = performance.now(); + + function animate(time) { + let timeFraction = (time - start) / duration; + if (timeFraction > 1) { + element.style.opacity = 0; + element.style.display = "none"; + if (callback) { + callback(); + } + } else { + element.style.opacity = 1 - timeFraction; + requestAnimationFrame(animate); + } + } + + requestAnimationFrame(animate); +} + + +for (let radioButton of radioButtons) { + radioButton.addEventListener("change", () => { + if (radioButton.value === "parameters") { + switchContent(content1); + document.getElementById('parameters-bg').style.display = 'flex'; + + fetch('/device-parameters', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(requestBody) + }) + .then(response => response.json()) + .then(data => { + + document.getElementById('parameters-bg').style.display = 'none'; + + camerasData = data; + + console.log(data.DATA); + + document.getElementById('system-date').value = data.DATA.TIMEP.DATEM; + document.getElementById('system-time').value = data.DATA.TIMEP.TIMEM; + document.getElementById('system-language').value = data.DATA.GSP.LANT; + document.getElementById('system-timezone').value = data.DATA.TIMEP.TIMEZ; + document.getElementById('system-geo').value = data.DATA.GSP.GM; + document.getElementById('system-stream').value = data.DATA.SUBSTRNET.SM; + document.getElementById('NE').checked = data.DATA.EOSD[0].NE === 1; + document.getElementById('TE').checked = data.DATA.EOSD[0].TE === 1; + document.getElementById('VE').checked = data.DATA.EOSD[0].VE === 1; + document.getElementById('SE').checked = data.DATA.EOSD[0].SE === 1; + document.getElementById('GE').checked = data.DATA.EOSD[0].GE === 1; + document.getElementById('DE').checked = data.DATA.EOSD[0].DE === 1; + + $("select").trigger("input"); + }) + .catch(error => console.error('Ошибка:', error)); + } else if (radioButton.value === "ethernet") { + switchContent(content2); + + document.getElementById('parameters-bg').style.display = 'flex'; + + fetch('/ethernet-parameters', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(requestBody) + }) + .then(response => response.json()) + .then(data => { + + document.getElementById('parameters-bg').style.display = 'none'; + + camerasData = data; + + console.log(data.DATA); + + document.getElementById('system-ipmode').value = data.DATA.ETHERNET.IPMODE; + document.getElementById('system-ipaddr').value = data.DATA.ETHERNET.PIP.IPADDR; + document.getElementById('system-submask').value = data.DATA.ETHERNET.PIP.SUBMASK; + document.getElementById('system-gateway').value = data.DATA.ETHERNET.PIP.GATEWAY; + document.getElementById('system-dnsmode').value = data.DATA.ETHERNET.DNSMODE; + document.getElementById('system-pdns').value = data.DATA.ETHERNET.DNS.PDNS; + document.getElementById('system-adns').value = data.DATA.ETHERNET.DNS.ADNS; + document.getElementById('system-mac').value = data.DATA.KEYS.MAC; + + $("select").trigger("input"); + + }) + .catch(error => console.error('Ошибка:', error)); + } else if (radioButton.value === "wifi") { + switchContent(content3); + + document.getElementById('parameters-bg').style.display = 'flex'; + + fetch('/wifi-parameters', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(requestBody) + }) + .then(response => response.json()) + .then(data => { + + document.getElementById('parameters-bg').style.display = 'none'; + + camerasData = data; + + console.log(data.DATA); + + document.getElementById('system-wifi').value = data.DATA.WIFI.ENABLE; + document.getElementById('system-wifi-essid').value = data.DATA.WIFI.ESSID; + document.getElementById('system-wifi-ecrypttype').value = data.DATA.WIFI.ECRYPTTYPE; + document.getElementById('system-wifi-pwd').value = data.DATA.WIFI.PWD; + document.getElementById('system-wifi-ipmode').value = data.DATA.WIFI.IPMODE; + document.getElementById('system-wifi-ipaddr').value = data.DATA.WIFI.PIP.IPADDR; + document.getElementById('system-wifi-submask').value = data.DATA.WIFI.PIP.SUBMASK; + document.getElementById('system-wifi-gateway').value = data.DATA.WIFI.PIP.GATEWAY; + + $("select").trigger("input"); + + }) + .catch(error => console.error('Ошибка:', error)); + } else if (radioButton.value === "communication") { + switchContent(content4); + + document.getElementById('parameters-bg').style.display = 'flex'; + + fetch('/communication-parameters', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(requestBody) + }) + .then(response => response.json()) + .then(data => { + + document.getElementById('parameters-bg').style.display = 'none'; + + camerasData = data; + + console.log(data.DATA); + + document.getElementById('system-nm1').value = data.DATA.M3G.MP.NM; + document.getElementById('system-apn1').value = data.DATA.M3G.MP.APN; + document.getElementById('system-un1').value = data.DATA.M3G.MP.UN; + document.getElementById('system-pw1').value = data.DATA.M3G.MP.PW; + + document.getElementById('system-nm2').value = data.DATA.M3G.M4G.NM; + document.getElementById('system-apn2').value = data.DATA.M3G.M4G.APN; + document.getElementById('system-un2').value = data.DATA.M3G.M4G.UN; + document.getElementById('system-pw2').value = data.DATA.M3G.M4G.PW; + + document.getElementById('system-at').value = data.DATA.M3G.M3M.AT; + document.getElementById('system-tn1').value = data.DATA.M3G.M3M.TN1; + document.getElementById('system-tn2').value = data.DATA.M3G.M3M.TN2; + document.getElementById('system-tn3').value = data.DATA.M3G.M3M.TN3; + + $("select").trigger("input"); + + }) + .catch(error => console.error('Ошибка:', error)); + } else if (radioButton.value === "install") { + switchContent(content5); + + document.getElementById('parameters-bg').style.display = 'flex'; + + fetch('/install-parameters', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(requestBody) + }) + .then(response => response.json()) + .then(data => { + + document.getElementById('parameters-bg').style.display = 'none'; + + camerasData = data; + + console.log(data.DATA); + + clearServerContainer(); + + data.DATA.MCMS.SP.forEach((data) => { + addServer(data); + }); + + $("select").trigger("input"); + + }) + .catch(error => console.error('Ошибка:', error)); + } else if (radioButton.value === "cameras") { + switchContent(content6); + } + }); +} + +function truncateText(select) { + var maxLength = 30; + var option = select.options[select.selectedIndex]; + if (option.text.length > maxLength) { + option.text = option.text.substring(0, maxLength) + "..."; + } +} diff --git a/static/scripts/table-reports.js b/static/scripts/table-reports.js index 18699b1..31ed24d 100644 --- a/static/scripts/table-reports.js +++ b/static/scripts/table-reports.js @@ -30,7 +30,7 @@ const createTable = () => { reportID.textContent = device.id; row.appendChild(reportID); const plate = document.createElement("td"); - plate.textContent = device.plate; + plate.textContent = device.number; row.appendChild(plate); const numberTS = document.createElement("td"); numberTS.textContent = device.serial; @@ -77,7 +77,6 @@ const createPagination = () => { const pageLink = document.createElement("a"); pageLink.href = "#"; if (i === currentPage) { - document.querySelector("#device-all").checked = false; pageLink.classList.add("active"); } pageLink.textContent = i; diff --git a/static/scripts/table.js b/static/scripts/table.js index c0d7614..9a2e6cd 100644 --- a/static/scripts/table.js +++ b/static/scripts/table.js @@ -27,9 +27,6 @@ const createTable = () => { const number = document.createElement("td"); number.textContent = device.number; row.appendChild(number); - const plate = document.createElement("td"); - plate.textContent = device.plate; - row.appendChild(plate); const serial = document.createElement("td"); serial.textContent = device.serial; row.appendChild(serial); @@ -72,7 +69,8 @@ const createTable = () => { if (EditTransport) { const optionsButton = document.createElement("button"); optionsButton.setAttribute("class", "options"); - optionsButton.setAttribute("onclick", `openForm("${device.id}")`); + // optionsButton.setAttribute("onclick", `openForm("${device.id}")`); + optionsButton.setAttribute("onclick", `location.href = "/devices/device/${device.serial}"`); optionsButton.value = `options-device-${device.id}`; optionsButton.id = `options-device-${device.id}`; trashCell.appendChild(optionsButton); @@ -103,7 +101,7 @@ const createPagination = () => { const pageLink = document.createElement("a"); pageLink.href = "#"; if (i === currentPage) { - document.querySelector("#device-all").checked = false; + // document.querySelector("#device-all").checked = false; pageLink.classList.add("active"); } pageLink.textContent = i; diff --git a/static/styles/main.css b/static/styles/main.css index 1908465..97285df 100644 --- a/static/styles/main.css +++ b/static/styles/main.css @@ -1130,6 +1130,7 @@ tr:nth-child(even) { height: 90%; border: 2px solid #f5f5fa; border-radius: 20px 0px 0px 20px; + padding-bottom: 25px; } .for-new input[type="radio"] { @@ -1190,6 +1191,7 @@ tr:nth-child(even) { border: 2px solid #f5f5fa; border-left: 0; border-radius: 0px 20px 20px 0px; + padding-bottom: 25px; } .new-parameters { diff --git a/static/templates/devices/device.html b/static/templates/devices/device.html new file mode 100644 index 0000000..78d6954 --- /dev/null +++ b/static/templates/devices/device.html @@ -0,0 +1,685 @@ + + +
+ + + +diff --git a/static/templates/devices/system.html b/static/templates/devices/system.html new file mode 100644 index 0000000..421a74d --- /dev/null +++ b/static/templates/devices/system.html @@ -0,0 +1,1119 @@ + + +
+ + + +
+ + +
+