From db4004455730b8ecbfb62163d720f0d445b39174 Mon Sep 17 00:00:00 2001 From: MohammadQ Date: Sun, 23 Jul 2023 12:35:53 -0400 Subject: [PATCH 1/4] Deleted old get marks csv button --- .../AggregatedGradesTable.jsx | 2 - .../GetMarksCsvButton.jsx | 69 ------------------- 2 files changed, 71 deletions(-) delete mode 100644 frontend/src/components/General/AggregatedGradesTable/GetMarksCsvButton.jsx diff --git a/frontend/src/components/General/AggregatedGradesTable/AggregatedGradesTable.jsx b/frontend/src/components/General/AggregatedGradesTable/AggregatedGradesTable.jsx index 2a7dca3e..475704e3 100644 --- a/frontend/src/components/General/AggregatedGradesTable/AggregatedGradesTable.jsx +++ b/frontend/src/components/General/AggregatedGradesTable/AggregatedGradesTable.jsx @@ -26,7 +26,6 @@ import { visuallyHidden } from '@mui/utils'; import FeatherIcon from 'feather-icons-react'; import CustomCheckbox from '../../FlexyMainComponents/forms/custom-elements/CustomCheckbox'; import CustomSwitch from '../../FlexyMainComponents/forms/custom-elements/CustomSwitch'; -import GetMarksCsvButton from './GetMarksCsvButton'; import TableSearchbar from './TableSearchbar'; function descendingComparator(a, b, orderBy) { @@ -219,7 +218,6 @@ const AggregatedGradesTable = ({ headCells, rows, tableWidth, courseId }) => { - { - /** - * Source: https://youtu.be/JPxzeG4N5nQ?t=660 - * Takes in a csv string and downloads it on the browsers - * @param text a string of characters in csv format - */ - const downloadCSV = (text) => { - const blob = new Blob([text], { type: 'application/csv' }); - const url = URL.createObjectURL(blob); - - const a = document.createElement('a'); - a.download = `course_${courseId}_marks.csv`; - a.href = url; - a.style.display = 'none'; - - document.body.append(a); - - a.click(); - a.remove(); - URL.revokeObjectURL(url); - }; - - const handleClick = () => { - StaffApi.getAllMarks(courseId) - .then((markRes) => { - StaffApi.all_tasks(courseId) - .then((taskRes) => { - const taskNames = taskRes.data.task.map((taskObj) => taskObj.task); - let csvHeader = 'username'; - for (const name of taskNames) { - csvHeader += `,${name}`; - } - const csvRows = Object.keys(markRes.data.marks).map((studentName) => { - // - let row = `${studentName}`; - - for (const taskName of Object.keys(markRes.data.marks[studentName])) { - const taskMark = markRes.data.marks[studentName][taskName]; - row += `,${taskMark.mark}/${taskMark.out_of}`; - } - - return row; - }); - let csvText = `${csvHeader}`; - for (const rowText of csvRows) { - csvText += `\n${rowText}`; - } - - downloadCSV(csvText); - }) - .catch((error) => toast.error('Unknown error', { theme: 'colored' })); - }) - .catch((error) => toast.error('Unknown error', { theme: 'colored' })); - }; - - return ( - - ); -}; - -export default getMarksCsvButton; From ce3520b660f4e6c23da136f2d7b3b0608647a051 Mon Sep 17 00:00:00 2001 From: MohammadQ Date: Sun, 23 Jul 2023 12:40:08 -0400 Subject: [PATCH 2/4] Created api call function for get marks csv endpoint --- frontend/src/api/instructor_api.js | 103 ++++++++++++++++++----------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/frontend/src/api/instructor_api.js b/frontend/src/api/instructor_api.js index fc50a59b..a7ceb1e0 100644 --- a/frontend/src/api/instructor_api.js +++ b/frontend/src/api/instructor_api.js @@ -1,4 +1,13 @@ import axios from 'axios'; +import http from './client'; + +let get_marks_csv = async (course_id, task) => { + try { + return await http.get(`/instructor/course/${course_id}/mark/all_csv?task=${task}`); + } catch (err) { + return err.response; + } +}; let all_tasks = async (course_id) => { let token = sessionStorage.getItem('token'); @@ -17,7 +26,6 @@ let all_tasks = async (course_id) => { } }; - let impersonate = async (course_id, username) => { let token = sessionStorage.getItem('token'); @@ -128,54 +136,69 @@ let submitMark = async (courseId, task, criteria, username, mark) => { // } // }; - let allGroups = async (course_id, task) => { - let token = sessionStorage.getItem("token") + let token = sessionStorage.getItem('token'); - let config = { - headers: { Authorization: `Bearer ${token}` } - }; + let config = { + headers: { Authorization: `Bearer ${token}` } + }; - try { - return await axios.get(process.env.REACT_APP_API_URL + "/instructor/course/" + course_id + "/group/all?task=" + task, config); - } catch (err) { - return err.response; - } -} + try { + return await axios.get( + process.env.REACT_APP_API_URL + + '/instructor/course/' + + course_id + + '/group/all?task=' + + task, + config + ); + } catch (err) { + return err.response; + } +}; let taskGroups = async (course_id, task) => { - /** - * Gets all groups for a particular task within a course. - */ - let token = sessionStorage.getItem("token"); - - let config = { - headers: { Authorization: `Bearer ${token}` } - }; + /** + * Gets all groups for a particular task within a course. + */ + let token = sessionStorage.getItem('token'); - try { - return await axios.get(process.env.REACT_APP_API_URL + "/instructor/course/" + course_id + "/group/all?task=" + task, config); - } catch (err) { - return err.response; - } -} + let config = { + headers: { Authorization: `Bearer ${token}` } + }; + try { + return await axios.get( + process.env.REACT_APP_API_URL + + '/instructor/course/' + + course_id + + '/group/all?task=' + + task, + config + ); + } catch (err) { + return err.response; + } +}; let InstructorApi = { - //Course related - all_tasks, - // Task related - impersonate, - taskGroups, - // - // // Group related - // check_group, - allGroups, - // - // // Interview related - // all_interviews, - // schedule_interview, - // delete_interview, + //Course related + all_tasks, + // Task related + impersonate, + taskGroups, + // + // // Group related + // check_group, + allGroups, + // + // // Interview related + // all_interviews, + // schedule_interview, + // delete_interview, + + // Mark related + get_marks_csv }; export default InstructorApi; From db53312c9e362e8c47bd1fa5f2061ba394e75473 Mon Sep 17 00:00:00 2001 From: MohammadQ Date: Sun, 23 Jul 2023 12:40:35 -0400 Subject: [PATCH 3/4] Created button that retrieves marks for a task in CSV format --- .../Module/Mark/GetMarkCSVButton.jsx | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 frontend/src/components/Module/Mark/GetMarkCSVButton.jsx diff --git a/frontend/src/components/Module/Mark/GetMarkCSVButton.jsx b/frontend/src/components/Module/Mark/GetMarkCSVButton.jsx new file mode 100644 index 00000000..0ddeacbf --- /dev/null +++ b/frontend/src/components/Module/Mark/GetMarkCSVButton.jsx @@ -0,0 +1,42 @@ +import { Button } from '@mui/material'; +import InstructorApi from '../../../api/instructor_api'; + +/** + * 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 ( + + ); +}; + +export default GetMarkCSVButton; From c5cd8ead6d336b0b9d8fb5abfe5a96a915e4e319 Mon Sep 17 00:00:00 2001 From: MohammadQ Date: Sun, 23 Jul 2023 12:43:17 -0400 Subject: [PATCH 4/4] added icon to button --- .../src/components/Module/Mark/GetMarkCSVButton.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/Module/Mark/GetMarkCSVButton.jsx b/frontend/src/components/Module/Mark/GetMarkCSVButton.jsx index 0ddeacbf..518f9920 100644 --- a/frontend/src/components/Module/Mark/GetMarkCSVButton.jsx +++ b/frontend/src/components/Module/Mark/GetMarkCSVButton.jsx @@ -1,5 +1,6 @@ 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 @@ -33,8 +34,13 @@ const GetMarkCSVButton = ({ task, course_id }) => { }; return ( - ); };