From b1c5e4c5a5575bdb4f2b37a498ee811448a0652d Mon Sep 17 00:00:00 2001 From: neroduckale Date: Wed, 3 Jan 2024 16:21:15 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20=D0=B0?= =?UTF-8?q?=D0=B4=D0=BC=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nrdkwebsite/Pages/users.cshtml | 30 ++++++++++++---- nrdkwebsite/wwwroot/js/site.js | 65 +++++++++++++++++++++------------- 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/nrdkwebsite/Pages/users.cshtml b/nrdkwebsite/Pages/users.cshtml index 5c27c68..6435bed 100644 --- a/nrdkwebsite/Pages/users.cshtml +++ b/nrdkwebsite/Pages/users.cshtml @@ -3,21 +3,37 @@ -Всего в таблице записей:
- +
АйдиНикнеймМасть
Loading...Loading...Loading...
Loading...Loading...Loading...
+
\ No newline at end of file diff --git a/nrdkwebsite/wwwroot/js/site.js b/nrdkwebsite/wwwroot/js/site.js index 28a7d95..df8d396 100644 --- a/nrdkwebsite/wwwroot/js/site.js +++ b/nrdkwebsite/wwwroot/js/site.js @@ -1,5 +1,5 @@ -console.log("Start!") -alert("startaed!") +const loading = document.getElementById("loading"); +let loadingLive = true async function getUsers() { // отправляет запрос и получаем ответ const response = await fetch("/api/users", { @@ -10,29 +10,46 @@ async function getUsers() { if (response.ok === true) { // получаем данные const users = await response.json(); - const table = document.querySelector("#users"); - const count = document.querySelector("#count") - count.outerHTML = "1"; - document.querySelector("#loading").destroy(); + const table = document.getElementById("users"); + if (loadingLive) { + loading.remove(); + loadingLive = false + } + users.forEach(user => table.append(create(user))); + return users; } } -// Получение одного пользователя -async function getUser(id) { - const response = await fetch(`/api/users/${id}`, { - method: "GET", - headers: { "Accept": "application/json" } - }); - if (response.ok === true) { - const user = await response.json(); - document.getElementById("userId").value = user.id; - document.getElementById("userName").value = user.nickname; - document.getElementById("userMast").value = user.mast; - } - else { - // если произошла ошибка, получаем сообщение об ошибке - const error = await response.json(); - console.log(error.message); // и выводим его на консоль - } + +function create(user) { + let tr = document.createElement("tr"); + let tdName = document.createElement("td"); + let tdMast = document.createElement("td"); + let tdId = document.createElement("td"); + let tdBut = document.createElement("td"); + let ButtDel = document.createElement("button"); + let ButtEdit = document.createElement("button"); + tdId.append(user.id); + tdName.append(user.nickname); + tdMast.append(user.mast); + ButtDel.append("УДАЛИТЬ"); + ButtEdit.append("ИЗМЕНИТЬ"); + tdBut.append(ButtDel, ButtEdit); + tdBut.id = "ADMINBUT" + user.id; + tdBut.className = "ADMINBUT" + tdBut.style.display = "none"; + tr.append(tdId, tdName, tdMast, tdBut); + return tr; } // Добавление пользователя -await getUsers(); \ No newline at end of file +console.log(getUsers()); +console.log("loaded!"); + + +function admin() { + document.body.style.background = "black"; + document.getElementById("admin").remove(); + let adminbuttons = document.getElementsByClassName("ADMINBUT"); + for (let item of adminbuttons) { + item.style.display = "inline"; + } +} \ No newline at end of file