-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearch.html
282 lines (254 loc) · 9.55 KB
/
Search.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
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/Project/Students/Search/search.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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,[email protected],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">
<title>Masai Connect</title>
</head>
<body>
<div id="main">
<div id="left">
<div>
<div>
<img src="/Project/Images/Logo.png" id="logo" alt="Masai Connect">
</div>
<div><span class="material-symbols-outlined">
grid_view
</span><p><a href="/Dashboard.html">Dashboard</a></p></div>
<div id="search"> <span class="material-symbols-outlined">
person_search
</span><p><a href="#">Search</a></p></div>
<div><span class="material-symbols-outlined">
groups
</span><p><a href="" id="must">Groups</a></p></div>
<div><span class="material-symbols-outlined">
task_alt
</span><p><a href="/Tasks.html">Tasks</a></p></div>
<div id="task123"><span class="material-symbols-outlined">
chat
</span><p><a href="/Discussion.html">Discussion</a></p></div>
<div><span class="material-symbols-outlined">
account_circle
</span><p><a href="/Account.html">Account</a></p></div>
</div>
<div>
<div><span class="material-symbols-outlined">
logout
</span><p><a href="" id="LogoutBtn">Logout</a></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>
<p>Search</p>
</div>
<div>
<input type="text" placeholder="Search Student" id="searched">
<button id="se">SEARCH</button>
</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">STUDENT CODE</th>
<th class="same">STATUS</th>
</tr>
</thead>
<tbody id="body">
<!-- Append Each Row Here -->
</tbody>
</table>
<div id="f"></div>
</div>
</div>
</div>
</body>
</html>
<script>
let visible = true;
let slidebtn = document.getElementById("slide");
let slide = document.getElementById("left");
slidebtn.addEventListener("click", function () {
if (visible == true) {
slide.style.display = 'none'
visible = false;
right.style.width = '100%';
}
else if (visible == false) {
slide.style.display = 'flex'
visible = true;
right.style.width = '86%';
}
})
// const url = new URL('https://64b63253df0839c97e151a61.mockapi.io/Students');
// 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)
let f=document.getElementById("f");
let id=localStorage.getItem("userid");
let a=localStorage.getItem("current");
console.log(a);
let search=document.getElementById("searched");
let select=document.getElementById("se");
select.addEventListener("click", function () {
console.log(select.value, search.value);
let url = new URL(`https://64b63253df0839c97e151a61.mockapi.io/Students/`);
url.searchParams.append('name', search.value);
fetch(url)
.then((res) => {
return res.json();
})
.then(function (data) {
if(search.value!=""){
console.log(data);
display(data);
}
})
})
let cont = document.getElementById("body");
function display(data) {
f.innerHTML="";
cont.innerHTML = "";
// <!-- <thead>
// <tr>
// <th class="same">ID</th>
// <th class="same">Name</th>
// <th class="same">Email</th>
// <th class="same">Student Code</th>
// </tr>
// </thead>
// let thead=document.createElement("thead");
// let trow=document.createElement("tr");
// let tr1=document.createElement("th");
// let tr2=document.createElement("th");
// let tr3=document.createElement("th");
// let tr4=document.createElement("th");
// tr1.innerText="ID";
// tr2.innerText="NAME";
// tr3.innerText="E-MAIL"
// tr4.innerText="STUDENT CODE"
// trow.append(tr1,tr2,tr3,tr4);
// thead.append(trow);
// cont.append(thead)
if(data.length==0){
let h2=document.createElement("h1");
h2.style.color="red";
h2.innerText="No Data Found!"
h2.style.textAlign="center";
h2.style.padding="20px";
f.append(h2);
}else{
data.forEach(function (item,ind) {
if(ind<8){
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;
name.style.textTransform="capitalize";
let email = document.createElement("td");
email.innerText = item.email;
let studentcode = document.createElement("td");
studentcode.innerText = item.student_code;
let status = document.createElement("td");
if (item.active==true){
status.style.color = "green";
status.innerText = "ACTIVE";
}
else {
status.style.color = "red";
status.innerText ="INACTIVE";
}
row.append(id, name, email, studentcode,status);
cont.append(row);}
})}
}
let must=document.getElementById("must");
if(a=="Students"){
must.href="/StudentGroup.html";
}else{
must.href="/Manager-Group.html";
}
let LogoutBtn = document.getElementById("LogoutBtn");
LogoutBtn.addEventListener("click", async function (event) {
console.log("hiiii");
event.preventDefault();
let status = false;
try {
let res = await fetch(`https://64b63253df0839c97e151a61.mockapi.io/api/admin/${a}/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ active: status }),
});
window.location.href = "/index.html";
} catch (error) {
console.log(error);
}
});
// Dark Mode
if (localStorage.getItem("darkmode") === null) {
localStorage.setItem("darkmode", "false");
}
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();
</script>