Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch score in backend when edited in the frontend and i18n for page #355

Merged
merged 9 commits into from
May 20, 2024
1 change: 0 additions & 1 deletion backend/project/endpoints/submissions/submission_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def patch(self, submission_id:int) -> dict[str, any]:

# Save the submission
session.commit()

data["message"] = f"Submission (submission_id={submission_id}) patched"
data["url"] = urljoin(f"{BASE_URL}/", str(submission.submission_id))
data["data"] = submission_response(submission, API_HOST)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataGrid, GridColDef, GridRenderCellParams } from "@mui/x-data-grid";
import {DataGrid, GridColDef, GridRenderCellParams} from "@mui/x-data-grid";
import { Box, IconButton } from "@mui/material";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import { green, red } from "@mui/material/colors";
Expand Down Expand Up @@ -27,9 +27,28 @@ const fetchSubmissionsFromUser = async (submission_id: string) => {
});
};

const editGrade = (submission: Submission, oldSubmission: Submission) => {
const submission_id = submission.submission_id;
const newGrade = submission.grading;

if (newGrade < 0 || newGrade > 20) {
return oldSubmission;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this get caught anywhere so people know that the submission wasn't changed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What he said

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

const formData = new FormData();
formData.append('grading', newGrade.toString());

authenticatedFetch(`${APIURL}/submissions/${submission_id}`, {
method: "PATCH",
body: formData
})

return submission
};

const columns: GridColDef<Submission>[] = [
{ field: "submission_id", headerName: "Submission ID", flex: 0.4 },
{ field: "display_name", headerName: "Student", width: 160, flex: 0.4 },
{ field: "submission_id", headerName: "Submission ID", flex: 0.4, editable: false },
{ field: "display_name", headerName: "Student", width: 160, flex: 0.4, editable: false },
{
field: "grading",
headerName: "Grading",
Expand All @@ -39,6 +58,7 @@ const columns: GridColDef<Submission>[] = [
{
field: "submission_status",
headerName: "Status",
editable: false,
renderCell: (params: GridRenderCellParams<Submission>) => (
<>
{params.row.submission_status === "SUCCESS" ? (
Expand All @@ -63,7 +83,7 @@ const columns: GridColDef<Submission>[] = [
];

/**
* @returns the datagrid for displaying submissiosn
* @returns the datagrid for displaying submissions
*/
export default function ProjectSubmissionsOverviewDatagrid({
submissions,
Expand All @@ -78,6 +98,9 @@ export default function ProjectSubmissionsOverviewDatagrid({
columns={columns}
pageSizeOptions={[20]}
disableRowSelectionOnClick
processRowUpdate={(updatedRow, oldRow) =>
editGrade(updatedRow, oldRow)
}
/>
</Box>
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface Submission {
submission_time: string;
submission_status: string;
uid: string;
grading: number;
}