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
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion frontend/public/locales/en/submissionOverview.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"submissionOverview": {
"submissionOverviewHeader": "Project status overview",
"downloadButton": "DOWNLOAD ALL PROJECTS"
"downloadButton": "DOWNLOAD ALL PROJECTS",
"scoreError": "Grade must be between 0 and 20",
"submissionID": "Submission ID",
"student": "Student",
"grading": "Grading",
"status": "Status",
"download": "Download"
}
}
12 changes: 12 additions & 0 deletions frontend/public/locales/nl/submissionOverview.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"submissionOverview": {
"submissionOverviewHeader": "Project status overzicht",
"downloadButton": "DOWNLOAD ALLE PROJECTEN",
"scoreError": "Score moeten tussen 0 en 20 liggen",
"submissionID": "Indiening ID",
"student": "Student",
"grading": "Score",
"status": "Status",
"download": "Download"
}
}
6 changes: 0 additions & 6 deletions frontend/public/locales/nl/submissionsOverview.json

This file was deleted.

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, 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 All @@ -7,6 +7,8 @@ import DownloadIcon from "@mui/icons-material/Download";
import download from "downloadjs";
import { authenticatedFetch } from "../../utils/authenticated-fetch";
import { Submission } from "../../types/submission";
import {useTranslation} from "react-i18next";
import {TFunction} from "i18next";

const APIURL = import.meta.env.VITE_APP_API_HOST;

Expand All @@ -27,57 +29,88 @@ const fetchSubmissionsFromUser = async (submission_id: string) => {
});
};

const columns: GridColDef<Submission>[] = [
{ field: "submission_id", headerName: "Submission ID", flex: 0.4 },
{ field: "display_name", headerName: "Student", width: 160, flex: 0.4 },
{
field: "grading",
headerName: "Grading",
editable: true,
flex: 0.2,
},
{
field: "submission_status",
headerName: "Status",
renderCell: (params: GridRenderCellParams<Submission>) => (
<>
{params.row.submission_status === "SUCCESS" ? (
<CheckCircleIcon sx={{ color: green[500] }} />
) : (
<CancelIcon sx={{ color: red[500] }} />
)}
</>
),
},
{
field: "submission_path",
headerName: "Download",
renderCell: (params: GridRenderCellParams<Submission>) => (
<IconButton
onClick={() => fetchSubmissionsFromUser(params.row.submission_id)}
>
<DownloadIcon />
</IconButton>
),
},
];
const editGrade = (submission: Submission, oldSubmission: Submission, errorMessage: string) => {
const submission_id = submission.submission_id;
const newGrade = submission.grading;

if (newGrade < 0 || newGrade > 20) {
alert(errorMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

No using alert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do i need to use then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 getTranslatedRows = (t: TFunction<string, string>) => {
return [
{ field: "submission_id", headerName: t("submissionID"), flex: 0.4, editable: false },
{ field: "display_name", headerName: t("student"), width: 160, flex: 0.4, editable: false },
{
field: "grading",
headerName: t("grading"),
editable: true,
flex: 0.2,
},
{
field: "submission_status",
headerName: t("status"),
editable: false,
renderCell: (params: GridRenderCellParams<Submission>) => (
<>
{params.row.submission_status === "SUCCESS" ? (
<CheckCircleIcon sx={{ color: green[500] }} />
) : (
<CancelIcon sx={{ color: red[500] }} />
)}
</>
),
},
{
field: "submission_path",
headerName: t("download"),
renderCell: (params: GridRenderCellParams<Submission>) => (
<IconButton
onClick={() => fetchSubmissionsFromUser(params.row.submission_id)}
>
<DownloadIcon />
</IconButton>
),
},
];
}

/**
* @returns the datagrid for displaying submissiosn
* @returns the datagrid for displaying submissions
*/
export default function ProjectSubmissionsOverviewDatagrid({
submissions,
}: {
submissions: Submission[];
}) {

const { t } = useTranslation('submissionOverview', { keyPrefix: 'submissionOverview' });

const errorMsg = t("scoreError");

return (
<Box my={4}>
<DataGrid
getRowId={getRowId}
rows={submissions}
columns={columns}
columns={getTranslatedRows(t)}
pageSizeOptions={[20]}
disableRowSelectionOnClick
processRowUpdate={(updatedRow, oldRow) =>
editGrade(updatedRow, oldRow, errorMsg)
}
/>
</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;
}