Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Fixed data tables
Browse files Browse the repository at this point in the history
  • Loading branch information
danielphung01 committed Nov 18, 2021
1 parent 224cdb5 commit 9f6b59e
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 80 deletions.
22 changes: 11 additions & 11 deletions app/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,43 +141,43 @@ app.get('/course/courseNumber/:courseNumber', function(req, res){
});


app.get('/coursesection/:id', function(req, res){
// get course sections from course id
app.get('/coursesection/courseID/:id', function(req, res){
let sql = "SELECT * FROM coursesection WHERE course_ID = ?";
connection.query(sql, [req.params.id], function(err, results){
if (err) throw err;
res.send(results);
});
});

// get instructor using instructor_ID
app.get('/instructor/:id', function(req, res){
let sql = "SELECT * FROM instructor WHERE instructor_ID = ?";
// get course section from section id
app.get('/coursesection/:id', function(req, res){
let sql = "SELECT * FROM coursesection WHERE section_ID = ?";
connection.query(sql, [req.params.id], function(err, results){
if (err) throw err;
res.send(results);
});
});

// get room using room_ID
app.get('/room/:id', function(req, res){
let sql = "SELECT * FROM room WHERE room_ID = ?";
// get instructor using instructor_ID
app.get('/instructor/:id', function(req, res){
let sql = "SELECT * FROM instructor WHERE instructor_ID = ?";
connection.query(sql, [req.params.id], function(err, results){
if (err) throw err;
res.send(results);
});
});

// get coursesection using section_ID
app.get('/coursesection/:id', function(req, res){
let sql = "SELECT * FROM room WHERE section_ID = ?";
// get room using room_ID
app.get('/room/:id', function(req, res){
let sql = "SELECT * FROM room WHERE room_ID = ?";
connection.query(sql, [req.params.id], function(err, results){
if (err) throw err;
res.send(results);
});
});



// SEARCH for sectionName with sectionNumber IN courseSection -> added on page
app.get('/coursesection/name/:id', function(req, res){
let sql = "SELECT * FROM coursesection WHERE sectionNumber = ?";
Expand Down
2 changes: 1 addition & 1 deletion enroll.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

</div>

<body onload="onLoad()">
<body>
<div class= "row1">
<div class="scol">
<h2>Enroll</h2>
Expand Down
3 changes: 2 additions & 1 deletion scripts/drop.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

var student = 1;

document.addEventListener('DOMContentLoaded', function () {
Expand Down Expand Up @@ -31,7 +32,7 @@ async function populateClassSchedule(data) {
.then(response => response.json())
.then((data) => {
cell1.innerHTML = data[0].sectionNumber;
cell2.innerHTML = data[i-1].classSchedule;
cell2.innerHTML = data[0].classSchedule;

courseID = data[0].course_ID;
fetch('http://localhost:3000/courses/' + courseID)
Expand Down
95 changes: 90 additions & 5 deletions scripts/enroll.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,103 @@

function onLoad() {
console.log("onLoad");
var student = 1;


document.addEventListener('DOMContentLoaded', function () {
setTimeout(function(){
showConfirmation();
}, 250);

// get shopping cart and fill shopping cart table
fetch('http://localhost:3000/shoppingcart/students/' + student)
.then(response => response.json())
//.then(data => console.log(data));
.then(data => populateShoppingCart(data));
});

}
async function populateShoppingCart(data) {
var table = document.getElementById("shoppingCart");
console.log(data);

for (var i = 1; i <= data.length; i++) {
// Create and insert new row into table
var row = table.insertRow(i);

// Create and insert new cells into row
var cell0 = row.insertCell(0); // course
var cell1 = row.insertCell(1); // schedule
var cell2 = row.insertCell(2); // room
var cell3 = row.insertCell(3); // instructor
var cell4 = row.insertCell(4); // units
var cell5 = row.insertCell(5); // status
var cell6 = row.insertCell(6); // delete btn


// Insert data into the new cells
var sectionID = data[i-1].section_ID;
await fetch('http://localhost:3000/coursesection/' + sectionID)
.then(response => response.json())
.then((data) => {
cell0.innerHTML = data[0].sectionNumber;
// Get schedule info for current course section
cell1.innerHTML = data[0].classSchedule;

courseID = data[0].course_ID;
fetch('http://localhost:3000/courses/' + courseID)
.then(response => response.json())
.then((data) => {
// Get course info for current course section
cell0.innerHTML = "CS " + data[0].courseNumber + "." + cell0.innerHTML;
// Get credit amount for current course section
cell4.innerHTML = data[0].creditUnit;

});

// Get room number for current course section
roomID = data[0].room_ID;
fetch('http://localhost:3000/room/' + roomID)
.then(response => response.json())
.then((data) => {
cell2.innerHTML = data[0].roomNumber;
});

// Get instructor for current course section
instructorID = data[0].instructor_ID;
fetch('http://localhost:3000/instructor/' + instructorID)
.then(response => response.json())
.then((data) => {
cell3.innerHTML = data[0].firstName + " " + data[0].lastName;
});
});

// TODO needs to be fixed
var maxEnrolledCapacity = data[i-1].maxEnrolledCapacity;
await fetch('http://localhost:3000/countcourseenrollment/' + data[i-1].section_ID)
.then(response => response.json())
.then((data) => {
var numEnrolled = data[0].count;

//console.log("open: " + numEnrolled + "/" + maxEnrolledCapacity);
var status = "";
if (numEnrolled < maxEnrolledCapacity) {
// open
status = "<i class='fas fa-times'>";
} /*else if (numEnrolled == maxEnrolledCapacity && numWaitlisted < maxWaitlistPosition) {
// waitlist
status = "<i class='fas fa-list'>";
} */else {
// closed
//console.log("closed");
status = "<i class='fas fa-check'>";
}
cell5.innerHTML = status;
});

// Delete button
cell6.innerHTML = "<button id='deleteBtn' onclick='deleteThisRow'>Delete</button>";
}
}

function showConfirmation() {
console.log("showConfirmation");
async function showConfirmation() {
var confirmation = confirm("Are you sure you want to enroll in the course(s)?");
if (confirmation) {
// enroll in courses
Expand Down
124 changes: 71 additions & 53 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
var student = 1;

document.addEventListener('DOMContentLoaded', function () {
fetch('http://localhost:3000/courseenrollment/students/' + 1)
document.addEventListener('DOMContentLoaded', async function () {
await fetch('http://localhost:3000/courseenrollment/students/' + student)
.then(response => response.json())
//.then(data => console.log(data));
.then(data => populateClassSchedule(data));

fetch('http://localhost:3000/shoppingcart/students/1')
await fetch('http://localhost:3000/shoppingcart/students/' + student)
.then(response => response.json())
//.then(data => console.log(data));
.then(data => populateShoppingCart(data));
});

async function populateShoppingCart(data) {
var table = document.getElementById("shoppingCart");
console.log(data);

for (var i = 1; i <= data.length; i++) {
// Create and insert new row into table
var row = table.insertRow(i);
Expand All @@ -25,56 +27,70 @@ async function populateShoppingCart(data) {
var cell3 = row.insertCell(3); // instructor
var cell4 = row.insertCell(4); // units
var cell5 = row.insertCell(5); // status
var cell6 = row.insertCell(6); // delete button

var cell6 = row.insertCell(6); // delete btn

/*
cell0.innerHTML = data[i-1].section_ID;
cell1.innerHTML = data[i-1].student_ID;
cell2.innerHTML = data[i-1].unitsEnrolled;
cell3.innerHTML = data[i-1].unitsWaitlisted;
cell4.innerHTML = "";
cell5.innerHTML = "";
cell6.innerHTML = "";
*/
/*
// Insert data into the new cells
cell0.innerHTML = "CS " + data[i-1].course.courseNumber + "-" + data[i].coursesection.sectionNumber; // course
cell1.innerHTML = data[i-1].coursesection.meetingDays + " " + data[i].coursesection.startTime + "-" + data[i].coursesection.endtime; // schedule
cell2.innerHTML = data[i-1].room.roomNumber; // room
cell3.innerHTML = data[i-1].instructor.firstName + " " + instructor.lastName; // instructor
cell4.innerHTML = data[i-1].course.creditUnit; // units
*/

/*
// TODO: run a query to get numEnrolled and numWaitlisted
fetch('http://localhost:3000/courseenrollment')
// TODO: Get number of students enrolled
var numEnrolled = 0;
var sectionID = data[i-1].section_ID;
await fetch('http://localhost:3000/coursesection/' + sectionID)
.then(response => response.json())
.then((data) => {
cell0.innerHTML = data[0].sectionNumber;
// Get schedule info for current course section
cell1.innerHTML = data[0].classSchedule;

// TODO: Get number of students waitlisted
var numWaitlisted = 0;
courseID = data[0].course_ID;
fetch('http://localhost:3000/courses/' + courseID)
.then(response => response.json())
.then((data) => {
// Get course info for current course section
cell0.innerHTML = "CS " + data[0].courseNumber + "." + cell0.innerHTML;
// Get credit amount for current course section
cell4.innerHTML = data[0].creditUnit;
});

// Get room number for current course section
roomID = data[0].room_ID;
fetch('http://localhost:3000/room/' + roomID)
.then(response => response.json())
.then((data) => {
cell2.innerHTML = data[0].roomNumber;
});

// Get instructor for current course section
instructorID = data[0].instructor_ID;
fetch('http://localhost:3000/instructor/' + instructorID)
.then(response => response.json())
.then((data) => {
cell3.innerHTML = data[0].firstName + " " + data[0].lastName;
});
});

// Set status according to number of students
var status = "";
if (numEnrolled < maxEnrolledCapacity) {
// open
status = "<i class='fas fa-check'>";
} else if (numEnrolled == maxEnrolledCapacity && numWaitlisted < maxWaitlistPosition) {
// waitlist
status = "<i class='fas fa-times'>";
} else {
// closed
status = "<i class='fas fa-list'>";
}
*/
// TODO needs to be fixed
var maxEnrolledCapacity = data[i-1].maxEnrolledCapacity;
await fetch('http://localhost:3000/countcourseenrollment/' + data[i-1].section_ID)
.then(response => response.json())
.then((data) => {
var numEnrolled = data[0].count;

/*
cell5.innerHTML = status; // status
//console.log("open: " + numEnrolled + "/" + maxEnrolledCapacity);
var status = "";
if (numEnrolled < maxEnrolledCapacity) {
// open
status = "<i class='fas fa-times'>";
} /*else if (numEnrolled == maxEnrolledCapacity && numWaitlisted < maxWaitlistPosition) {
// waitlist
status = "<i class='fas fa-list'>";
} */else {
// closed
//console.log("closed");
status = "<i class='fas fa-check'>";
}
cell5.innerHTML = status;
});

cell6.innerHTML = "<button id='deleteButton' onclick='deleteThisRow'>Delete</button>";
*/ // delete button
// Delete button
cell6.innerHTML = "<button id='deleteBtn' onclick='deleteThisRow'>Delete</button>";
}
}

Expand All @@ -100,13 +116,16 @@ async function populateClassSchedule(data) {
.then(response => response.json())
.then((data) => {
cell0.innerHTML = data[0].sectionNumber;
cell1.innerHTML = data[i-1].classSchedule;
// Get schedule info for current course section
cell1.innerHTML = data[0].classSchedule;

courseID = data[0].course_ID;
fetch('http://localhost:3000/courses/' + courseID)
.then(response => response.json())
.then((data) => {
// Get course info for current course section
cell0.innerHTML = "CS " + data[0].courseNumber + "." + cell0.innerHTML;
// Get credit amount for current course section
cell4.innerHTML = data[0].creditUnit;
});

Expand All @@ -118,26 +137,25 @@ async function populateClassSchedule(data) {
cell2.innerHTML = data[0].roomNumber;
});

// Get instructor for current course section
instructorID = data[0].instructor_ID;
fetch('http://localhost:3000/instructor/' + instructorID)
.then(response => response.json())
.then((data) => {
cell3.innerHTML = data[0].firstName + " " + data[0].lastName;
console.log("instr" + (i-1));
});
});



// needs to be fixed
// TODO needs to be fixed
var maxEnrolledCapacity = data[i-1].maxEnrolledCapacity;
await fetch('http://localhost:3000/countcourseenrollment/' + data[i-1].section_ID)
.then(response => response.json())
.then((data) => {
//console.log(data[0].count);
var numEnrolled = data[0].count;

console.log("open: " + numEnrolled + "/" + maxEnrolledCapacity);
//console.log("open: " + numEnrolled + "/" + maxEnrolledCapacity);
var status = "";
if (numEnrolled < maxEnrolledCapacity) {
// open
Expand All @@ -147,7 +165,7 @@ async function populateClassSchedule(data) {
status = "<i class='fas fa-list'>";
} */else {
// closed
console.log("closed");
//console.log("closed");
status = "<i class='fas fa-check'>";
}
cell5.innerHTML = status;
Expand Down
Loading

0 comments on commit 9f6b59e

Please sign in to comment.