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

Commit

Permalink
fixing search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanvpham committed Nov 18, 2021
1 parent 9303d59 commit ba29aa8
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 36 deletions.
48 changes: 43 additions & 5 deletions app/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,24 @@ app.delete('/courseenrollment/:section_ID/:student_ID', function(req, res){

// SELECT - based off course name AND/OR course number (search for classes)
// SEARCH for courseID with courseName IN course-> SEARCH for sectionName with courseID IN courseSection -> added on page
app.get('/course/:courseName', function(req, res){
app.get('/course/courseName/:courseName', function(req, res){
let sql = "SELECT * FROM course WHERE courseName = ?";
connection.query(sql, [decodeURI(req.params.courseName)], function(err, results){
if (err) throw err;
res.send(results);
});
});

// SEARCH for sectionName with sectionNumber IN courseSection -> added on page
app.get('/course/courseNumber/:courseNumber', function(req, res){
let sql = "SELECT * FROM course WHERE courseNumber = ?";
connection.query(sql, [decodeURI(req.params.courseNumber)], function(err, results){
if (err) throw err;
res.send(results);
});
});


app.get('/coursesection/:id', function(req, res){
let sql = "SELECT * FROM coursesection WHERE course_ID = ?";
connection.query(sql, [req.params.id], function(err, results){
Expand All @@ -139,6 +149,26 @@ app.get('/coursesection/:id', function(req, res){
});
});

// 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 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 All @@ -148,21 +178,29 @@ app.get('/coursesection/name/:id', function(req, res){
});
});

let data = {
section_ID: 1,
student_ID: 1,
unitsEnrolled: 2,
unitsWaitlisted: 2
}

// INSERT - courses into shopping cart, adding from search results (based on student id) - not working
app.post("create/shoppingcart/:section_ID/:student_ID/:unitsEnrolled/:unitsWaitlisted", (req, res) =>{
app.post('post/shoppingcart', (req, res) =>{
let sql = "INSERT INTO shoppingcart VALUES (?, ?, ?, ?)";
connection.query(sql, [req.params.section_ID, req.params.student_ID, req.params.unitsEnrolled, req.params.unitsWaitlisted],function(err, results){
console.log(req.body.section_ID)
connection.query(sql, [data.section_ID, data.student_ID, data.unitsEnrolled, data.unitsWaitlisted],function(err, results){
if (err) throw err;
res.send(results);
});
})


// INSERT - courses into course enrollment (based on student id) - not working
app.post("create/courseenrollment/:section_ID/:student_ID/:grade", (req, res) =>{
app.post('/courseenrollment', (req, res) =>{
const {section_ID, student_ID, grade} = req.body;
let sql = "INSERT INTO courseenrollment VALUES (?, ?, ?)";
connection.query(sql, [req.body.section_ID, req.body.student_ID, req.body.grade],function(err, results){
connection.query(sql, [section_ID, student_ID, grade],function(err, results){
if (err) throw err;
res.send(results);
});
Expand Down
2 changes: 1 addition & 1 deletion app/tempCodeRunnerFile.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
req.params.section_ID
create/shoppingcart
5 changes: 3 additions & 2 deletions courseEnrollmentDatabaseQuery.sql
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ INSERT INTO course VALUES
(3, 3560, 'Object-Oriented Design and Programming', 3);

INSERT INTO coursesection VALUES
(1, 1, 1, 1, 1300, 'MWF 11:00AM - 12:15PM', 30, 20),
(2, 2, 1, 2, 3010, 'TTh 9:00AM - 11:15AM', 30, 20);
(1, 1, 1, 1, 1, 'MWF 11:00AM - 12:15PM', 30, 20),
(2, 2, 1, 2, 1, 'TTh 9:00AM - 11:15AM', 30, 20),
(3, 2, 2, 2, 2, 'TTh 4:00PM - 5:15PM', 30, 20);

INSERT INTO courseenrollment VALUES
(1, 1, 'A-'),
Expand Down
10 changes: 5 additions & 5 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function populateShoppingCart(data) {
*/
/*
// Insert data into the new cells
cell0.innerHTML = "CS " + data[i].course.courseNumber + "-" + data[i].coursesection.sectionNumber; // course
cell1.innerHTML = data[i].coursesection.meetingDays + " " + data[i].coursesection.startTime + "-" + data[i].coursesection.endtime; // schedule
cell2.innerHTML = data[i].room.roomNumber; // room
cell3.innerHTML = data[i].instructor.firstName + " " + instructor.lastName; // instructor
cell4.innerHTML = data[i].course.creditUnit; // units
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
*/

/*
Expand Down
98 changes: 84 additions & 14 deletions scripts/search.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,96 @@

function searchButtonPressed() {

/*
// temporary toggle search results visibility
var searchResults = document.getElementById("searchResults");
if (searchResults.classList.contains("hidden")) {
searchResults.classList.remove("hidden");
} else {
searchResults.classList.add("hidden");
}
*/

// Show search results section
// Unhide search results section
searchResults.classList.remove("hidden");

var table = document.getElementById("resultList");

/*
// Clear search results
for (var i = table.rows.length - 1; i > 0; i--) {
table.deleteRow(i);
}

var courseNumber = document.getElementById("courseNumberSearch").value;
var courseName = document.getElementById("courseNameSearch").value;

// Populate search results table
if (courseNumber.length > 0) {
// search by course number
fetch('http://localhost:3000/course/courseNumber/' + courseNumber)
.then(response => response.json())
//.then(data => console.log(data));
.then(data => getCourseSections(data));

} else if (courseName.length > 0) {
// search by course name
fetch('http://localhost:3000/course/courseName/' + courseName)
.then(response => response.json())
//.then(data => console.log(data));
.then(data => getCourseSections(data));
}
}

function getCourseSections(data) {
// Set course name
var courseFullName = document.getElementById("courseFullName");
courseFullName.value = data[0].courseNumber + " - " + data[0].courseName;

// Get course sections
var courseID = data[0].course_ID;
fetch('http://localhost:3000/coursesection/' + courseID)
.then(response => response.json())
//.then(data => console.log(data));
.then(data => populateSearchResults(data));
}

function populateSearchResults(data) {


// Fill search results
for (var i = 1; i <= data.length; i++) {

// Get instructor for current course section
var instructorID = data[i-1].instructor_ID;
var instructorFirstName;
var instructorLastName;

fetch('http://localhost:3000/instructor/' + instructorID)
.then(response => response.json())
.then((data) => {
instructorFirstName = data[0].firstName;
instructorLastName = data[0].lastName;
});

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

var row = table.insertRow(i);

// Create and insert new cells into row
var cell0 = row.insertCell(0); // section
var cell1 = row.insertCell(1); // schedule
var cell2 = row.insertCell(2); // room
var cell3 = row.insertCell(3); // instructor
var cell4 = row.insertCell(4); // status
var cell5 = row.insertCell(5); // select button

// Insert data into the new cells
cell0.innerHTML = data[i-1].sectionNumber;
cell1.innerHTML = data[i-1].classSchedule;
cell2.innerHTML = roomNumber;
cell3.innerHTML = instructorFirstName + " " + instructorLastName;
cell4.innerHTML = "";
cell5.innerHTML = "<button id='selectBtn' onclick='addToShoppingCart(" + + ")'>Select</button>";
}


/*
// Add and fill 5 random rows
for (var i = 0; i < Math.random()*10; i++) {
var row = table.insertRow(table.rows.length);
Expand All @@ -45,4 +111,8 @@ function searchButtonPressed() {
cell6.innerHTML = "NEW CELL6";
}
*/
}

function addToShoppingCart() {

}
16 changes: 7 additions & 9 deletions search.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ <h2>Search Classes</h2>

<div class= "row1">
<div class="scol">
<h2>Subject</h2>
<h2>Course Number</h2>
</div>
<input class="textbox" type="text">
<input id='courseNumberSearch' class="textbox" type="text">
</div>

<div class= "row1">
<div class="scol">
<h2>Course Number</h2>
<h2 >Course Name</h2>
</div>
<input class="textbox" type="text">
<input id='courseNameSearch' class="textbox" type="text">
</div>

<div id="searchResults" class="hidden">

<hr>
<br>

<h3 id="courseName">CS 1300 - Discrete Structures</h3>
<h3 id="courseFullName"></h3>

<div position='absolute' bottom='0px'>
<div class ="subrow">
Expand All @@ -68,7 +68,7 @@ <h3 id="courseName">CS 1300 - Discrete Structures</h3>
<th id="selectCol"></th>
</tr>

<!--sample table row-->
<!-- sample table rows
<tr>
<td>01</td>
<td>MWF 4:00PM - 4:50PM</td>
Expand All @@ -77,7 +77,6 @@ <h3 id="courseName">CS 1300 - Discrete Structures</h3>
<td id='openStatus'>✓</td>
<td id="selectCol"><button id="selectBtn">Select</button></td>
</tr>
<!--sample table row-->
<tr>
<td>02</td>
<td>TTh 12:00PM - 1:50PM</td>
Expand All @@ -86,7 +85,6 @@ <h3 id="courseName">CS 1300 - Discrete Structures</h3>
<td id='closedStatus'>■</td>
<td><button id="selectBtn">Select</button></td>
</tr>
<!--sample table row-->
<tr>
<td>03</td>
<td>MW 10:00AM - 11:50AM</td>
Expand All @@ -95,7 +93,6 @@ <h3 id="courseName">CS 1300 - Discrete Structures</h3>
<td id='waitlistStatus'>▲</td>
<td><button id="selectBtn">Select</button></td>
</tr>
<!--sample table row-->
<tr>
<td>04</td>
<td>TuTh 10:00AM - 11:50AM</td>
Expand All @@ -104,6 +101,7 @@ <h3 id="courseName">CS 1300 - Discrete Structures</h3>
<td id='openStatus'>✓</td>
<td><button id="selectBtn">Select</button></td>
</tr>
-->
</table>
</div>

Expand Down

0 comments on commit ba29aa8

Please sign in to comment.