devices deletion and fix bugs

This commit is contained in:
Ivan 2023-09-22 22:47:53 +03:00
parent 2a227043eb
commit c6b92f06e0
Signed by untrusted user who does not match committer: ppechenkoo
GPG Key ID: 0C191B86D9582583
7 changed files with 95 additions and 6 deletions

View File

@ -2592,6 +2592,33 @@ app.post("/deletedriver", async (req, res) => {
} }
}); });
app.post("/deletedevice", async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
const id = req.body.id;
const pool = new Pool({
user: DB_User,
host: DB_Host,
database: DB_Name,
password: DB_Password,
port: DB_Port,
});
const client = await pool.connect();
try {
// Выполняем запрос и получаем результат
const query = "DELETE FROM registrars WHERE id = $1;";
const devicedata = await client.query(query, [id]);
// Формирование и отправка ответа
res.send("Data deleted successfully");
} finally {
client.release();
}
});
app.post("/deleteuser", async (req, res) => { app.post("/deleteuser", async (req, res) => {
if (req.session.userId === undefined) { if (req.session.userId === undefined) {
return res.redirect("/signin"); return res.redirect("/signin");

View File

@ -83,6 +83,7 @@ const createTable = () => {
trashButton.setAttribute("class", "trash"); trashButton.setAttribute("class", "trash");
trashButton.value = `delete-device-${device.id}`; trashButton.value = `delete-device-${device.id}`;
trashButton.id = `delete-device-${device.id}`; trashButton.id = `delete-device-${device.id}`;
trashButton.setAttribute("onclick", `deleteDevice(${device.id})`);
trashCell.appendChild(trashButton); trashCell.appendChild(trashButton);
} }
if (EditTransport) { if (EditTransport) {

View File

@ -684,6 +684,7 @@ header img {
border: 2px solid rgba(245, 245, 250, 1); border: 2px solid rgba(245, 245, 250, 1);
border-radius: 30px; border-radius: 30px;
overflow: hidden; overflow: hidden;
overflow-x: auto;
position: relative; position: relative;
} }

View File

@ -175,7 +175,7 @@
<h1>Удаление водителя </h1> <br> <h1>Удаление водителя </h1> <br>
<span>Вы уверены что хотите удалить <span id="driverDeleteInfo"></span>?</span> <span>Вы уверены что хотите удалить <span id="driverDeleteInfo"></span>?</span>
<div class="buttons"> <div class="buttons">
<button id="deleteCancel" onclick="closeDeletion();" style="display: inline-block; background-color: white; color: rgba(0, 0, 0, 0.7); margin-right: 5px;" type="button" onclick="deleteDriver()">Отменить</button> <button id="deleteCancel" onclick="closeDeletion();" style="display: inline-block; background-color: white; color: rgba(0, 0, 0, 0.7); margin-right: 5px;" type="button">Отменить</button>
<button id="deleteDriver" style="display: inline-block;" type="button">Подтвердить</button> <button id="deleteDriver" style="display: inline-block;" type="button">Подтвердить</button>
</div> </div>
</div> </div>

View File

@ -126,7 +126,7 @@
<th>Номер телефона</th> <th>Номер телефона</th>
<th>Почта</th> <th>Почта</th>
<th>Карта водителя</th> <th>Карта водителя</th>
<th><button id="delete-device-all" value="delete-device-all" class="trash"></button></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@ -130,9 +130,7 @@
<th>Статус</th> <th>Статус</th>
<th>Номер SIM-карты</th> <th>Номер SIM-карты</th>
<th>IP-адрес</th> <th>IP-адрес</th>
<th>{{#if DeleteTransport}} <th></th>
<button id="delete-device-all" value="delete-device-all" class="trash"></button>
{{/if}}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -657,6 +655,18 @@
</section> </section>
</section> </section>
<section style="display: none;" class="dberror" id="deleteConfirmation">
<div class="erorr-container">
<img src="../img/warning.svg"> <br>
<h1>Удаление устройства </h1> <br>
<span>Вы уверены что хотите удалить <span id="deviceDeleteInfo"></span>?</span>
<div class="buttons">
<button id="deleteCancel" onclick="closeDeletion();" style="display: inline-block; background-color: white; color: rgba(0, 0, 0, 0.7); margin-right: 5px;" type="button">Отменить</button>
<button id="deleteDevice" style="display: inline-block;" type="button" onclick="deleteDevice()">Подтвердить</button>
</div>
</div>
</section>
<script> <script>
const devices = [ const devices = [
{{#each Registrars}} {{#each Registrars}}
@ -1054,6 +1064,56 @@
</script> </script>
<script>
function deleteDevice(id) {
var deleteConfirmation = $("#deleteConfirmation");
$.ajax({
url: "/devicedata",
method: "POST",
contentType: "application/json",
data: JSON.stringify({ id: id }),
success: function(response) {
// Установка значений полей формы
$("#deviceDeleteInfo").html(response.serial);
document.getElementById('deleteDevice').setAttribute("onclick", `confirmDelete(${response.id})`);
document.getElementById('deleteConfirmation').style.display = "flex";
$("body").css("overflow", "hidden");
},
error: function() {
// Обработка ошибки при запросе к серверу
alert("Произошла ошибка при запросе к серверу.");
}
});
}
function closeDeletion() {
document.getElementById('deleteConfirmation').style.display = "none";
}
function confirmDelete(id) {
$.ajax({
url: "/deletedevice",
method: "POST",
contentType: "application/json",
data: JSON.stringify({ id: id }),
success: function(response) {
location.reload();
},
error: function() {
// Обработка ошибки при запросе к серверу
alert("Произошла ошибка при запросе к серверу.");
}
});
}
</script>
<script> <script>
// Скрытие/Показ дополнительных меню аккаунта // Скрытие/Показ дополнительных меню аккаунта
const accountMain = document.getElementById('account-main'); const accountMain = document.getElementById('account-main');

View File

@ -122,7 +122,7 @@
<th>Серийный номер</th> <th>Серийный номер</th>
<th>Время</th> <th>Время</th>
<th>Местоположение</th> <th>Местоположение</th>
<th><button id="share-device-all" value="share-device-all" class="share" onclick="location.href = '/reports/346';"></button></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>