diff --git a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx index 00b5c997..efab20ab 100644 --- a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx +++ b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx @@ -15,6 +15,7 @@ import { Submission } from '../pages/submissionPage/SubmissionPage.tsx' import { t } from 'i18next' import dayjs from 'dayjs' import { EvenlySpacedRow } from './CustomComponents.tsx' +import { Project } from '../pages/scoresPage/ProjectScoresPage.tsx' interface SubmissionListItemTeacherPageProps { group_name: string @@ -53,6 +54,7 @@ export function SubmissionListItemTeacherPage({ // State for submitted data and score const [submitted, setSubmitted] = useState() const [score, setScore] = useState() + const [assignment, setAssignment] = useState() useEffect(() => { async function fetchData() { try { @@ -107,6 +109,11 @@ export function SubmissionListItemTeacherPage({ setScore(scoreResponse.data[scoreResponse.data.length - 1]) console.log(score?.score) } + + const assignmentResponse = await instance.get( + `/projecten/${assignment_id}/` + ) + setAssignment(assignmentResponse.data) } catch (error) { console.error('Error fetching data:', error) } @@ -168,7 +175,11 @@ export function SubmissionListItemTeacherPage({ , diff --git a/frontend/frontend/src/i18n/en.ts b/frontend/frontend/src/i18n/en.ts index 30ede668..a5e689d0 100644 --- a/frontend/frontend/src/i18n/en.ts +++ b/frontend/frontend/src/i18n/en.ts @@ -139,6 +139,7 @@ const english = { add_course: 'Add course', add_project: 'Add project', no_projects: 'No projects', + upload_project: 'Upload your project files.', may_fail: 'May fail', } diff --git a/frontend/frontend/src/i18n/nl.ts b/frontend/frontend/src/i18n/nl.ts index 8a45475f..e72d9181 100644 --- a/frontend/frontend/src/i18n/nl.ts +++ b/frontend/frontend/src/i18n/nl.ts @@ -139,6 +139,7 @@ const dutch = { add_course: 'Voeg vak toe', add_project: 'Voeg project toe', no_projects: 'Geen projecten', + upload_project: 'Upload je projectbestanden.', may_fail: 'Mag falen', } diff --git a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx index 887b1084..e6bb86b6 100644 --- a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx +++ b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx @@ -105,7 +105,7 @@ export function AddChangeAssignmentPage() { const [assignmentFile, setAssignmentFile] = useState() const [maxScore, SetMaxScore] = useState(20) const [cleared, setCleared] = useState(false) - const [filename, setFilename] = useState('indiening.zip') + const [filename, setFilename] = useState('') const [groupSize, setGroupSize] = useState(1) const [user, setUser] = useState() @@ -191,7 +191,9 @@ export function AddChangeAssignmentPage() { setDescription(assignment.beschrijving) console.log('bestand' + assignment.opgave_bestand) - setFilename(() => assignment.opgave_bestand) + if (assignment.opgave_bestand !== null) { + setFilename(() => assignment.opgave_bestand) + } SetMaxScore(assignment.max_score) console.log('max score' + assignment.max_score) @@ -245,23 +247,25 @@ export function AddChangeAssignmentPage() { }) //get the assignment file - await instance - .get(`/projecten/${assignmentId}/opgave_bestand/`, { - responseType: 'blob', - }) - .then((response) => { - const blob = new Blob([response.data], { - type: response.headers['content-type'], - }) - const file: File = new File([blob], filename, { - type: response.headers['content-type'], + if (filename !== '') { + await instance + .get(`/projecten/${assignmentId}/opgave_bestand/`, { + responseType: 'blob', }) + .then((response) => { + const blob = new Blob([response.data], { + type: response.headers['content-type'], + }) + const file: File = new File([blob], filename, { + type: response.headers['content-type'], + }) - setAssignmentFile(file) - }) - .catch((error) => { - console.error(error) - }) + setAssignmentFile(file) + }) + .catch((error) => { + console.error(error) + }) + } //end loading -> set loading to false setLoading(false) @@ -307,7 +311,11 @@ export function AddChangeAssignmentPage() { if (dueDate === null && extraDueDate === null) { setDeadlineCheck(false) } else if (dueDate !== null && extraDueDate !== null) { - setDeadlineCheck(extraDueDate.diff(dueDate) < 0) + if (dayjs(extraDueDate).isSame(dayjs(dueDate))) { + setDeadlineCheck(true) + } else { + setDeadlineCheck(dayjs(extraDueDate).isBefore(dayjs(dueDate))) + } } else if (dueDate !== null && extraDueDate === null) { setDeadlineCheck(false) } else { @@ -383,81 +391,87 @@ export function AddChangeAssignmentPage() { }) } - // Upload the assignment to the API. patch if it is an edit, post if it is a new assignment. + // Upload the assignment to the API. put if it is an edit, post if it is a new assignment. const uploadAssignment = async () => { - let optionalFile: File | null = null - if (assignmentFile !== undefined) { - optionalFile = assignmentFile - } - const formData = new FormData() - formData.append('titel', title) - formData.append('beschrijving', description) - formData.append('vak', parseInt(courseId as string).toString()) - if (optionalFile) { - formData.append('opgave_bestand', optionalFile) - } - formData.append('zichtbaar', visible.toString()) + try { + const config = { + headers: { + 'Content-Type': 'multipart/form-data', + }, + } + // editing an existing assignment: need to put + if (assignmentId) { + const formData = new FormData() + formData.append('project_id', assignmentId) + if (assignmentFile) { + formData.append('opgave_bestand', assignmentFile) + } - // Add optional fields - if (maxScore !== 20) { - formData.append('max_score', maxScore.toString()) - } - if (dueDate !== null) { - formData.append('deadline', dueDate.format()) - } - if (extraDueDate !== null) { - formData.append('extra_deadline', extraDueDate.format()) - } - formData.append('max_groep_grootte', groupSize.toString()) + formData.append('titel', title) + formData.append('beschrijving', description) + if (courseId) { + formData.append('vak', courseId) + } + if (maxScore !== 20) { + formData.append('max_score', maxScore.toString()) + } + if (dueDate) { + formData.append('deadline', dueDate.format()) + } + if (extraDueDate) { + formData.append('extra_deadline', extraDueDate.format()) + } + formData.append('zichtbaar', visible.toString()) + formData.append('max_groep_grootte', groupSize.toString()) - const config = { - headers: { - 'Content-Type': 'multipart/form-data', - }, - } - if (assignmentId !== undefined) { - formData.append('project_id', assignmentId) - await instance - .patch( - '/projecten/' + parseInt(assignmentId) + '/', + // Send the data to the API + await instance.put( + `/projecten/${assignmentId}/`, formData, config ) - .catch((error) => { - console.error(error) - }) - - //upload the restrictions - handleRestrictionUpload(assignmentId.toString()) - } else { - //if there is no assignmentId, it is a new assignment - let project_id: number = 0 - - await instance - .post('/projecten/', formData, config) - .then((response) => (project_id = response.data.project_id)) - .catch((error) => { - console.error(error) - }) + handleRestrictionUpload(assignmentId.toString()) + } else { + // Creating a new assignment: need to post + const formData = new FormData() + if (assignmentFile) { + formData.append('opgave_bestand', assignmentFile) + } + formData.append('titel', title) + formData.append('beschrijving', description) + if (courseId) { + formData.append('vak', courseId) + } + if (maxScore !== 20) { + formData.append('max_score', maxScore.toString()) + } + if (dueDate) { + formData.append('deadline', dueDate.format()) + } + if (extraDueDate) { + formData.append('extra_deadline', extraDueDate.format()) + } + formData.append('zichtbaar', visible.toString()) + formData.append('max_groep_grootte', groupSize.toString()) - //upload the restrictions - handleRestrictionUpload(project_id.toString()) - } + // Send the data to the API + const project = await instance.post( + '/projecten/', + formData, + config + ) + handleRestrictionUpload(project.data.id) + } - console.info( - 'Form submitted', - title, - description, - dueDate, - restrictions, - visible, - assignmentFile - ) - setSaveConfirmation(false) - if (assignmentId !== undefined) { - navigate('/course/' + courseId + '/assignment/' + assignmentId) - } else { - navigate('/course/' + courseId) + if (assignmentId !== undefined) { + navigate('/course/' + courseId + '/assignment/' + assignmentId) + } else { + navigate('/course/' + courseId) + } + } catch (error) { + console.error(error) + } finally { + setSaveConfirmation(false) } } @@ -1002,7 +1016,7 @@ export function AddChangeAssignmentPage() { title={t('remove')} > {score - ? `${score.score}/${assignment?.max_score} (${(100 * score.score) / Number(assignment?.max_score)}%)` + ? `${score.score}/${assignment?.max_score} (${Math.round((100 * score.score) / Number(assignment?.max_score))}%)` : t('no_score_yet')} ) : ( @@ -1257,7 +1257,9 @@ export function AssignmentPage() { handleFileChange } fileTypes={['*']} - tooltip={t('uploadToolTip')} + tooltip={t( + 'upload_project' + )} /> diff --git a/frontend/frontend/src/pages/subjectsPage/AssignmentListItemSubjectsPage.tsx b/frontend/frontend/src/pages/subjectsPage/AssignmentListItemSubjectsPage.tsx index 5b9013fa..63722a95 100644 --- a/frontend/frontend/src/pages/subjectsPage/AssignmentListItemSubjectsPage.tsx +++ b/frontend/frontend/src/pages/subjectsPage/AssignmentListItemSubjectsPage.tsx @@ -137,7 +137,7 @@ export function AssignmentListItemSubjectsPage({