forked from JayachandranRamu/Connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdmin-employee.html
270 lines (249 loc) · 9.46 KB
/
Admin-employee.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="/Project/Admin/employee.css">
</head>
<body>
<div id="main">
<div id="left">
<div>
<div>
<img src="/Project/Images/Logo.png" id="logo" alt="Masai Connect">
</div>
<div id="dashboard">
<span class="material-symbols-outlined">
grid_view
</span>
<p>Dashboard</p>
</div>
<div id="search">
<span class="material-symbols-outlined">
person_search
</span>
<p>Search</p>
</div>
<div id="students">
<span class="material-symbols-outlined">
groups
</span>
<p>Students</p>
</div>
<div id="employee">
<span class="material-symbols-outlined">
person
</span>
<p>Employee</p>
</div>
</div>
<div>
<div></div>
<div id="logout">
<span class="material-symbols-outlined">
logout
</span>
<p>Logout</p>
</div>
</div>
</div>
<div id="right">
<div id="r1">
<div>
<span class="material-symbols-outlined" id="slide" class="icon">
keyboard_double_arrow_right
</span>
</div>
<div>
<img src="/Project/Images/dark theme icon/moon.png" alt="" id="darkmode_btn" class="icon">
<img src="/Project/Images/man.png" alt="" id="profile">
</div>
</div>
<div>
<h3>Employee List</h3>
</div>
<div id="table">
<table>
<thead>
<tr>
<th class="same">ID</th>
<th class="same">NAME</th>
<th class="same">EMAIL</th>
<th class="same">PASSWORD</th>
<th class="delete">DELETE</th>
</tr>
</thead>
<tbody id="body">
<!-- Append Each Row Here -->
</tbody>
</table>
</div>
<div id="pagination_wrapper">
</div>
</div>
</div>
</body>
<script>
const url = new URL('https://64b63253df0839c97e151a61.mockapi.io/api/admin/users');
url.searchParams.append('page', 1);
url.searchParams.append('limit', 10);
function fetchData(url) {
fetch(url)
.then((res) => {
return res.json();
})
.then(function (data) {
display(data);
})
}
fetchData(url)
function enableDarkMode() {
document.body.classList.add("dark-mode");
const darkButton = document.getElementById("darkmode_btn");
const slideBtn = document.getElementById("slide");
darkButton.src = "/Project/Images/dark theme icon/sun.png";
slideBtn.style.color = "white";
}
function disableDarkMode() {
document.body.classList.remove("dark-mode");
const darkButton = document.getElementById("darkmode_btn");
const slideBtn = document.getElementById("slide");
darkButton.src = "/Project/Images/dark theme icon/moon.png";
slideBtn.style.color = "black";
}
function toggleDarkMode() {
if (localStorage.getItem("darkmode")==="true") {
enableDarkMode();
} else {
disableDarkMode();
}
}
document.getElementById("darkmode_btn").addEventListener("click", function(){
if (localStorage.getItem("darkmode")==="false"){
localStorage.setItem("darkmode","true")
enableDarkMode();
} else if (localStorage.getItem("darkmode")==="true"){
localStorage.setItem("darkmode","false")
disableDarkMode();
}
toggleDarkMode();
});
toggleDarkMode();
const url1 = new URL('https://64b63253df0839c97e151a61.mockapi.io/api/admin/users');
function fetchData1() {
fetch("https://64b63253df0839c97e151a61.mockapi.io/api/admin/users")
.then((res) => {
return res.json();
})
.then(function (data) {
let total_page = Math.ceil(data.length / 8);
if (total_page > 1){
button_create(total_page);
}
})
}
fetchData1()
let cont = document.getElementById("body");
function display(data) {
cont.innerHTML = "";
data.forEach(function (item) {
let row = document.createElement("tr");
row.className = "row";
let id = document.createElement("td");
id.innerText = item.id;
let name = document.createElement("td");
name.innerText = item.name;
let email = document.createElement("td");
email.innerText = item.email;
let Password = document.createElement("td");
Password.innerText = item.password;
let Delete = document.createElement("td");
Delete.innerText = "Delete"
Delete.className = "delete";
Delete.setAttribute("data-id", item.id);
Delete.addEventListener("click", function (e) {
e.preventDefault()
let itemID = Delete.getAttribute("data-id");
fetch(`https://64b63253df0839c97e151a61.mockapi.io/api/admin/users/${itemID}`, {
method: "DELETE",
headers: {
"Content-type": "application/json"
}
})
.then(res => res.json())
.then(data => {
fetchData(url)
})
.catch(err => { console.log(err) });
})
row.append(id, name, email, Password, Delete);
cont.append(row);
})
}
let visible = true;
let left = document.getElementById("left");
let right = document.getElementById("right");
let status = document.getElementById("status");
document.getElementById("slide").addEventListener("click", function () {
if (visible == true) {
left.style.display = "none";
right.style.width = "100%";
visible = false;
}
else {
left.style.display = "flex";
right.style.width = "80%";
visible = true;
}
})
let pagination = document.getElementById("pagination_wrapper")
function button_create(total_page) {
pagination.innerHTML = "";
for (let i = 1; i <= total_page; i++) {
let button = document.createElement("button");
button.innerText = i;
button.setAttribute("page_no", i);
button.classList.add("pagination-button");
pagination.append(button);
button.addEventListener("click", function (e) {
if (e.target.classList.contains("pagination-button")) {
let pageno = e.target.getAttribute("page_no");
let url = new URL('https://64b63253df0839c97e151a61.mockapi.io/api/admin/users');
url.searchParams.append('page', pageno);
url.searchParams.append('limit', 8);
fetchData(url);
const buttons = document.querySelectorAll(".pagination-button");
buttons.forEach((btn) => {
if (btn === e.target) {
btn.style.backgroundColor = "green";
} else {
btn.style.backgroundColor = "";
}
});
}
});
}
}
document.getElementById("dashboard").addEventListener("click", function () {
window.location.href = "/Admin-admin.html";
})
document.getElementById("search").addEventListener("click", function () {
window.location.href = "/Admin-search.html";
})
document.getElementById("students").addEventListener("click", function () {
window.location.href = "/Admin-student.html";
})
document.getElementById("employee").addEventListener("click", function () {
window.location.href = "/Admin-student.html";
})
document.getElementById("logout").addEventListener("click",function(){
window.location.href = "/index.html"
})
</script>