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 #31 from DakshChan/feature/IBS-20-getMarksCSV
[IBS-20] get marks csv button
- Loading branch information
Showing
4 changed files
with
111 additions
and
111 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
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
69 changes: 0 additions & 69 deletions
69
frontend/src/components/General/AggregatedGradesTable/GetMarksCsvButton.jsx
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
import { Button } from '@mui/material'; | ||
import InstructorApi from '../../../api/instructor_api'; | ||
import FileDownloadIcon from '@mui/icons-material/FileDownload'; | ||
|
||
/** | ||
* Triggers a download of a CSV file containing marks for a given task within | ||
* a given course | ||
* @param task the task for which marks to fetch | ||
* @param course_id the id of the course to which the task belongs to | ||
* @returns {JSX.Element} | ||
* @constructor | ||
*/ | ||
const GetMarkCSVButton = ({ task, course_id }) => { | ||
const downloadCSV = (text) => { | ||
const blob = new Blob([text], { type: 'application/csv' }); | ||
const url = URL.createObjectURL(blob); | ||
|
||
const a = document.createElement('a'); | ||
a.download = `course_${course_id}_marks.csv`; | ||
a.href = url; | ||
a.style.display = 'none'; | ||
|
||
document.body.append(a); | ||
|
||
a.click(); | ||
a.remove(); | ||
URL.revokeObjectURL(url); | ||
}; | ||
|
||
const handleExport = () => { | ||
InstructorApi.get_marks_csv(course_id, task) | ||
.then((res) => res.data) | ||
.then((data) => downloadCSV(data)); | ||
}; | ||
|
||
return ( | ||
<Button | ||
startIcon={<FileDownloadIcon />} | ||
variant="contained" | ||
size="small" | ||
onClick={handleExport} | ||
> | ||
Export Marks | ||
</Button> | ||
); | ||
}; | ||
|
||
export default GetMarkCSVButton; |