forked from DeerCo/IBS
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from DakshChan/feature/DEV-012-aggregatedGrades
[IBS-12] Add 3 extra features to Aggregated Grades Table
- Loading branch information
Showing
7 changed files
with
225 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const client = require("../../../setup/db"); | ||
const helpers = require("../../../utilities/helpers"); | ||
|
||
router.get("/", (req, res) => { | ||
console.log(`[+] RESPONSE Locals: ${res.locals["course_id"]}`); | ||
if (res.locals["course_id"] === "") { | ||
res.status(400).json({ message: "The course id is missing or invalid." }); | ||
} | ||
let sqlCourse = "SELECT * FROM course WHERE course_id = ($1)"; | ||
client.query(sqlCourse, [res.locals["course_id"]], (err, pgRes) => { | ||
if (err) { | ||
res.status(404).json({ message: "Unknown error." }); | ||
} else if (pgRes.rowCount === 1) { | ||
res | ||
.status(200) | ||
.json({ | ||
message: "Course details are returned.", | ||
course: pgRes.rows[0], | ||
}); | ||
} else { | ||
res.status(400).json({ message: "The course id is invalid." }); | ||
} | ||
}); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
frontend/src/components/General/AggregatedGradesTable/TableSearchbar.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Autocomplete, IconButton, InputAdornment, Stack, TextField } from '@mui/material'; | ||
|
||
const TableSearchbar = (props) => { | ||
const { originalRows, setCurrRows, placeholder, width } = props; | ||
|
||
return ( | ||
<> | ||
<Autocomplete | ||
freeSolo | ||
id="table-searchbar" | ||
options={originalRows.map((option) => option.student)} | ||
onChange={(event, newValue, reason) => { | ||
setCurrRows((prevState) => { | ||
// We use original rows because prevState could've been changed from previous | ||
// autocomplete | ||
const newState = []; | ||
if (Array.isArray(originalRows)) { | ||
for (const studentObj of originalRows) { | ||
if (studentObj.student === newValue) { | ||
newState.push(studentObj); | ||
} | ||
} | ||
} | ||
console.log(newState); | ||
return newState; | ||
}); | ||
if (reason === 'clear') { | ||
setCurrRows(originalRows); | ||
} | ||
}} | ||
renderInput={(params) => ( | ||
<TextField | ||
{...params} | ||
size="small" | ||
placeholder={placeholder} | ||
aria-label="Search Input" | ||
/> | ||
)} | ||
sx={{ | ||
width: width | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
TableSearchbar.propTypes = { | ||
// Original rows which is fetched from backend (displays all possible rows) | ||
originalRows: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
// setCurrRows useState callback function to set rows to be displayed on table | ||
setCurrRows: PropTypes.func.isRequired, | ||
// Placeholder text for the searchbar | ||
placeholder: PropTypes.string.isRequired, | ||
// Width of searchbar. Either string like '100%' or a numeric integer value. | ||
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired | ||
}; | ||
|
||
export default TableSearchbar; |
Oops, something went wrong.