-
Notifications
You must be signed in to change notification settings - Fork 0
/
attendance-list.html
183 lines (177 loc) · 5.71 KB
/
attendance-list.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<script src="script.js" defer></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<title>Attendance</title>
<style>
.container{
padding: 20px;
height: 80vh;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
#subjectCodeInput, button {
margin-top: 20px;
padding: 10px;
font-size: 16px;
}
button {
cursor: pointer;
}
#submitBtn {
background-color: #0056b3;
color: white;
border: none;
}
#refreshBtn {
background-color: black;
color: white;
border: none;
}
</style>
</head>
<body>
<!-- Navbar -->
<nav class="navbar">
<div class="logo"><a href="index.html">FaceSnap</a></div>
<div class="navbar-links">
<a href="index.html">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
<a href="login.html">Account</a>
<a href="/Teacher-info.html">Teacher Info</a>
<a href="/FaceSnap/subject.html">Manage Subject</a>
<a href="/FaceSnap/attendance-list.html">Attendance List</a>
</div>
<div id="mobile-toggle" class="icon">☰</div>
</nav>
<div class="container">
<h1>Attendance</h1>
<label for="subjectCodeInput">Enter Subject Code:</label>
<input type="text" id="subjectCodeInput" placeholder="Enter subject code" />
<button id="submitBtn" onclick="getAttendanceBySubjectCode()">Submit</button>
<button id="refreshBtn" onclick="window.location.reload()">Refresh</button>
<table>
<thead>
<tr>
<th>ID</th>
<th>Student ID</th>
<th>Subject Code</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody id="attendanceTableBody"></tbody>
</table>
</div>
<!-- Footer -->
<footer class="footer">
<div class="footer-left">
<a href="https://www.linkedin.com/in/shubham-choudhary-shubh/" class="social-icon"><i class="fab fa-linkedin-in"></i></a>
<a href="https://github.com/ShubhamChoudharyShubh" class="social-icon"><i class="fab fa-github"></i></a>
<a href="https://www.instagram.com/shubhamchoudharyshubh/" class="social-icon"><i class="fab fa-instagram"></i></a>
<a href="https://www.linkedin.com/in/shubham-choudhary-shubh/" class="social-icon"><i class="fab fa-facebook"></i></a>
</div>
<div class="footer-right">
<p class="f-para">Copyright © 2024, FaceSnap.in all rights reserved</p>
</div>
</footer>
<script>
document.addEventListener("DOMContentLoaded", () => {
getAttendance(); // Fetch all attendance on page load
});
async function getAttendance() {
let data;
console.log("function is called");
try {
fetch("http://192.168.158.246:5000/attendance", {
method: "POST",
headers: {
"Content-Type": "application/json",
}, // Ensure the server requires a body, otherwise remove this line
body: JSON.stringify({}), // Remove if no body is required
})
.then((response) => {
return response.json();
})
.then((response) => {
data = response;
console.log(data);
populateAttendanceTable(data);
console.log(response);
})
.catch((error) => {
console.error("Error:", error);
});
} catch (error) {
console.error("Error fetching attendance:", error);
// You can display an error message to the user here
}
}
async function getAttendanceBySubjectCode() {
const subjectCode = document.getElementById("subjectCodeInput").value;
if (!subjectCode) {
alert("Please enter a subject code.");
return; // Prevent unnecessary fetch if no code entered
}
try {
const response = await fetch(
"http://192.168.158.246:5000/attendance_by_subject_code",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ subject_code: subjectCode }),
}
)
.then((response) => {
if (!response.ok) {
const errorMessage = `Network response was not ok (status: ${response.status})`;
throw new Error(errorMessage);
}
return response.json();
})
.then((response) => {
populateAttendanceTable(response);
});
} catch (error) {
console.error("Error fetching attendance by subject code:", error);
// You can display an error message to the user here
}
}
function populateAttendanceTable(data) {
const tbody = document.getElementById("attendanceTableBody");
tbody.innerHTML = ""; // Clear any existing rows
data.forEach((record) => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${record.id}</td>
<td>${record.student_id}</td>
<td>${record.subject_code}</td>
<td>${record.date}</td>
<td>${record.status}</td>
`;
tbody.appendChild(row);
});
}
</script>
</body>
</html>