Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-rahul-1 committed Apr 7, 2024
2 parents ad4f636 + b04fe3d commit 1c6e25c
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 12 deletions.
3 changes: 2 additions & 1 deletion app/faculty.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def get_student_details():
def get_student_user_ids():
subject = request.args.get('subject')
cursor.execute("SELECT studentId FROM student WHERE subject = %s", (subject,))
user_ids = [result['studentId'] for result in cursor.fetchall()]
results = cursor.fetchall()
user_ids = [result['studentId'] for result in results]
return jsonify(user_ids)


Expand Down
2 changes: 1 addition & 1 deletion app/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_student_attendance():
userID = request.args.get('userID')
subject = request.args.get('subject')
db.reconnect() # Retrieve subject from query parameter
cursor.execute("SELECT subject, status, date FROM attendance WHERE studentId = %s AND subject = %s",
cursor.execute("SELECT subject, status, date FROM attendance WHERE studentId = %s AND subject = %s order by date",
(userID, subject))
attendance = cursor.fetchall()
return jsonify(attendance)
Expand Down
154 changes: 144 additions & 10 deletions static/Scripts/faculty.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ document.addEventListener('DOMContentLoaded', function () {
});
}


function fetchSubjectButtons() {
fetch('/getFacultySubjects?userID=' + userID) // Replace with your actual endpoint to fetch faculty subjects
.then(response => {
Expand All @@ -52,6 +53,10 @@ document.addEventListener('DOMContentLoaded', function () {
if (defaulter.style.display === "block") {
fetchDefaulters(subject.subject);
}
let att = document.querySelector(".attendance-page");
if (att.style.display === "block") {
fetchAttendance(subject.subject);
}
});
nav.appendChild(button);
});
Expand Down Expand Up @@ -188,6 +193,7 @@ document.addEventListener('DOMContentLoaded', function () {
document.querySelector(".leave").classList.remove("active");
document.querySelector(".defaulter_button").classList.remove("active")
document.querySelector(".logout").classList.remove("active");
document.querySelector(".show_attendance").classList.remove("active");
let leaveSection = document.querySelector(".leave-section");
if (leaveSection.style.display === "block") {
leaveSection.style.display = "none";
Expand All @@ -202,6 +208,10 @@ document.addEventListener('DOMContentLoaded', function () {
if (defaulter.style.display === "block") {
defaulter.style.display = "none";
}
let att = document.querySelector(".attendance-page");
if (att.style.display === "block") {
att.style.display = "none";
}
document.getElementById("subject-0").click();
}

Expand All @@ -210,6 +220,7 @@ document.addEventListener('DOMContentLoaded', function () {
document.querySelector(".mark").classList.remove("active");
document.querySelector(".leave").classList.add("active");
document.querySelector(".defaulter_button").classList.remove("active")
document.querySelector(".show_attendance").classList.remove("active");
document.querySelector(".logout").classList.remove("active");
let attendanceSection = document.querySelector(".attendance-section");
if (attendanceSection.style.display === "block") {
Expand All @@ -225,6 +236,10 @@ document.addEventListener('DOMContentLoaded', function () {
if (defaulter.style.display === "block") {
defaulter.style.display = "none";
}
let att = document.querySelector(".attendance-page");
if (att.style.display === "block") {
att.style.display = "none";
}
fetchLeaveApplication();
}

Expand Down Expand Up @@ -316,11 +331,12 @@ document.addEventListener('DOMContentLoaded', function () {
});

// Close the dropdown if the user clicks outside of it
function defaulters(subject) {
function defaulters() {

document.querySelector(".mark").classList.remove("active");
document.querySelector(".leave").classList.remove("active");
document.querySelector(".defaulter_button").classList.add("active")
document.querySelector(".show_attendance").classList.remove("active");
document.querySelector(".logout").classList.remove("active");
let attendanceSection = document.querySelector(".attendance-section");
if (attendanceSection.style.display === "block") {
Expand All @@ -336,6 +352,10 @@ document.addEventListener('DOMContentLoaded', function () {
if (defaulter.style.display === "none") {
defaulter.style.display = "block";
}
let att = document.querySelector(".attendance-page");
if (att.style.display === "block") {
att.style.display = "none";
}
document.getElementById("subject-0").click();
}

Expand Down Expand Up @@ -393,7 +413,7 @@ document.addEventListener('DOMContentLoaded', function () {
})
.then(attendance => {
console.log(attendance)
if (attendance.length == 0) {
if (attendance.length === 0) {
console.log('table is empty')
document.querySelector(".emptyTable").style.display = "block";
document.querySelector("#defaulters_table").style.display = "none"
Expand Down Expand Up @@ -426,21 +446,135 @@ document.addEventListener('DOMContentLoaded', function () {
document.getElementById('subjectNav').style.display = "";
markAttendance();
});
document.querySelector('.leave').addEventListener('click', function (e) {
document.querySelector('.leave').addEventListener('click', function () {
document.getElementById('subjectNav').style.display = "none";
leaveApplication();
});
document.querySelector('.defaulter_button').addEventListener('click', function () {
document.getElementById('subjectNav').style.display = "";
defaulters();
});
});
/*
document.querySelector('.mark').addEventListener('click', function () {

document.getElementsByClassName("attendance-section").style.display = "none";
document.getElementsByClassName("nextBtn").style.display = "visible";
document.getElementsByClassName("backBtn").style.display = "visible";
function fetchStudentIDs(subject) {
fetch('/getStudentUserIDs?subject=' + subject) // Replace with your actual endpoint to fetch student IDs based on the subject
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Failed to fetch student IDs');
}
})
.then(studentIDs => {
// Select the dropdown menu element
const dropdown = document.getElementById('studentDropdown');

// Clear previous options
dropdown.innerHTML = '';

// Add a default option
const defaultOption = document.createElement('option');
defaultOption.text = 'Select Student ID';
defaultOption.value = '';
dropdown.add(defaultOption);

// Add each student ID as an option in the dropdown menu
studentIDs.forEach(id => {
const option = document.createElement('option');
option.text = id;
option.value = id;
dropdown.add(option);
});
})
.catch(error => {
console.error('Error:', error);
});
}

function fetchAttendance(subject) {
fetchStudentIDs(subject)
document.getElementById('attendance-button').addEventListener('click', function () {
const userID = document.getElementById('studentDropdown').value;
fetch(`/getStudentDetails?userID=${userID}`)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Failed to fetch student details');
}
})
.then(student => {
const studentDetailsDiv = document.getElementById('student-details');
studentDetailsDiv.innerHTML = `
<p><strong>Name:</strong> ${student.studentName}</p>
<p><strong>ID:</strong> ${student.studentId}</p>
<p><strong>Email:</strong> ${student.email}</p>
`;
fetch(`/getStudentAttendance?userID=${userID}&subject=${selected_subject}`)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Failed to fetch student attendance');
}
})
.then(attendance => {
const tableBody = document.getElementById('attendance-data');
tableBody.innerHTML = ''; // Clear previous data

attendance.forEach(record => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${record.subject}</td>
<td>${record.status}</td>
<td>${record.date.substring(0, 16)}</td>
`;
tableBody.appendChild(row);
});
})
.catch(error => {
console.error('Error:', error);
});
})
.catch(error => {
console.error('Error:', error);
});


});
}


function show_attendance() {

});*/
document.querySelector(".mark").classList.remove("active");
document.querySelector(".leave").classList.remove("active");
document.querySelector(".defaulter_button").classList.remove("active")
document.querySelector(".show_attendance").classList.add("active");
document.querySelector(".logout").classList.remove("active");
let attendanceSection = document.querySelector(".attendance-section");
if (attendanceSection.style.display === "block") {
attendanceSection.style.display = "none";
document.querySelector(".nextBtn").style.display = "none";
document.querySelector(".backBtn").style.display = "none";
}
let leaveSection = document.querySelector(".leave-section");
if (leaveSection.style.display === "block") {
leaveSection.style.display = "none";
}
let defaulter = document.querySelector(".defaulters");
if (defaulter.style.display === "block") {
defaulter.style.display = "none";
}
let att = document.querySelector(".attendance-page");
if (att.style.display === "none") {
att.style.display = "block";
}
document.getElementById("subject-0").click();
}

document.querySelector('.show_attendance').addEventListener('click', function () {
document.getElementById('subjectNav').style.display = "";
show_attendance();
});
})
;
28 changes: 28 additions & 0 deletions templates/faculty.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ <h3 id="facultyName">NAME</h3>
<span class="item">Defaulter list</span>
</a>
</li>
<li>
<a class="show_attendance">
<span class="icon"><i class="fas fa-user-friends"></i></span>
<span class="item">Check Attendance</span>
</a>
</li>
<li>
<a class="logout" href="/">
<span class="icon"><i class="fa fa-sign-out"></i></span>
Expand Down Expand Up @@ -158,6 +164,28 @@ <h3 style="color: #ffd76a;margin-bottom: 9px;">Leave Application Details</h3>
<p class="selectSub">Please select a subject</p>
<p class="emptyTable" style="display: none;">There are no defaulters.</p>
</section>
<section class="attendance-page" style="display: none;">
<label for="studentDropdown">Roll No. </label><select id="studentDropdown">
<!-- Options will be dynamically inserted here -->
</select>
<button id="attendance-button">Show Attendance</button><br>
<h3>Student Details</h3>
<div id="student-details">
<!-- Student details will be dynamically inserted here -->
</div>
<table id="attendance-table">
<thead>
<tr>
<th>Subject</th>
<th>Status</th>
<th>Date</th>
</tr>
</thead>
<tbody id="attendance-data">
<!-- Attendance data will be dynamically inserted here -->
</tbody>
</table>
</section>
<footer>
YEAR 2024-25
</footer>
Expand Down

0 comments on commit 1c6e25c

Please sign in to comment.