Skip to content

Commit

Permalink
Merge branch 'develop' into 148-advanced-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpdev committed May 22, 2024
2 parents 228b980 + a1647d9 commit 1ee2647
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
8 changes: 8 additions & 0 deletions backend/pigeonhole/apps/submissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class SubmissionAdmin(admin.ModelAdmin):
)
}
),
(
'file urls',
{
'fields': (
'file_urls',
)
}
),
)

raw_id_fields = (
Expand Down
38 changes: 34 additions & 4 deletions frontend/app/[locale]/components/EditCourseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {useEffect, useState} from "react";
import {useTranslation} from "react-i18next";
import {getCourse, getImage, postData, updateCourse} from "@lib/api";
import Typography from "@mui/material/Typography";
import {Box, Button, Input, LinearProgress, MenuItem, Select, TextField} from "@mui/material";
import {Box, Button, Input, LinearProgress, MenuItem, Select, TextField, Dialog, DialogActions, DialogTitle} from "@mui/material";
import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
import {DatePicker} from '@mui/x-date-pickers/DatePicker';
Expand All @@ -24,6 +24,8 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {
const [selectedImage, setSelectedImage] = useState<File | null>(null);
const [selectedImageURL, setSelectedImageURL] = useState<string>("");
const [loading, setLoading] = useState(true);
const [openConfirmation, setOpenConfirmation] = useState(false); // State for confirmation dialog


useEffect(() => {
const fetchCourseData = async () => {
Expand Down Expand Up @@ -57,6 +59,15 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {

const handleSubmit = async (event: any) => {
event.preventDefault();
setOpenConfirmation(true); // Open confirmation dialog
};

const handleConfirmationClose = () => {
setOpenConfirmation(false);
};

const handleConfirmationYes = async () => {
setOpenConfirmation(false);
const formData = new FormData();
formData.append('name', name);
formData.append('description', description);
Expand All @@ -66,13 +77,16 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {
fileReader.onload = async function () {
const arrayBuffer = this.result;
if (arrayBuffer !== null) {
formData.append('banner', new Blob([arrayBuffer], {type: 'image/png'}));
formData.append('banner', new Blob([arrayBuffer], { type: 'image/png' }));
await updateCourse(courseId, formData).then((response) => {
window.location.href = `/course/${courseId}/`;
});
}
await updateCourse(courseId, formData);
window.location.href = `/course/${courseId}/`;
}
if (selectedImage) fileReader.readAsArrayBuffer(selectedImage);
};


const handleImageUpload = (event: any) => {
const imageFile = event.target.files[0];
setSelectedImage(imageFile);
Expand Down Expand Up @@ -253,6 +267,22 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {
{t("cancel")}
</Button>
</Box>
<Dialog
open={openConfirmation}
onClose={handleConfirmationClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">{t("Are you sure you want to submit this course?")}</DialogTitle>
<DialogActions>
<Button onClick={handleConfirmationClose} color="primary">
{t("cancel")}
</Button>
<Button onClick={handleConfirmationYes} color="primary" autoFocus>
{t("edit course")}
</Button>
</DialogActions>
</Dialog>
</Box>
);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"role": "Role",
"save changes": "Save changes",
"save course": "Save course",
"edit course": "Edit course",
"save": "Save",
"save_changes": "Save Changes",
"score_required": "Score is required",
Expand Down
1 change: 1 addition & 0 deletions frontend/locales/nl/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"role": "Rol",
"save changes": "Wijzigingen opslaan",
"save course": "Cursus opslaan",
"edit course": "Cursus bewerken",
"save": "Opslaan",
"save_changes": "Wijzigingen Opslaan",
"score_required": "Score is verplicht",
Expand Down
20 changes: 11 additions & 9 deletions scripts/mockdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def run():
description=lorem_ipsum,
course_id=course_5,
deadline='2021-12-12 12:12:14',
file_structure='+src/*.py,+extra/verslag.pdf',
visible=True,
number_of_groups=1,
group_size=8
Expand Down Expand Up @@ -305,7 +306,8 @@ def run():
deadline='2021-12-12 12:12:14',
visible=True,
number_of_groups=10,
group_size=2
group_size=2,
file_structure='+extra/verslag.pdf,+src/*.py'
)

# Create groups
Expand Down Expand Up @@ -400,55 +402,55 @@ def run():
Submissions.objects.get_or_create(
group_id=group_1,
submission_nr=1,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:12'
)

Submissions.objects.get_or_create(
group_id=group_1,
submission_nr=2,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:13'
)

Submissions.objects.get_or_create(
group_id=group_1,
submission_nr=3,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:15'
)

Submissions.objects.get_or_create(
group_id=group_1,
submission_nr=4,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:16'
)

Submissions.objects.get_or_create(
group_id=group_2,
submission_nr=1,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:12'
)

Submissions.objects.get_or_create(
group_id=group_3,
submission_nr=1,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:13'
)

Submissions.objects.get_or_create(
group_id=group_4,
submission_nr=1,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:15'
)

Submissions.objects.get_or_create(
group_id=group_5,
submission_nr=1,
file_urls=lorem_ipsum_file,
file_urls='src/main.py, extra/verslag.pdf',
timestamp='2021-12-12 12:12:16'
)

0 comments on commit 1ee2647

Please sign in to comment.