From 7cc969753efb4f05686f121948245781599f3c89 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 16:16:48 +0200 Subject: [PATCH 1/4] procenten afgerond + opgavebestanden verwijderbaar gemaakt --- .../components/SubmissionListItemTeacherPage.tsx | 13 ++++++++++++- .../AddChangeAssignmentPage.tsx | 6 +++++- .../src/pages/assignmentPage/AssignmentPage.tsx | 2 +- .../subjectsPage/AssignmentListItemSubjectsPage.tsx | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) 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/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx index 887b1084..c944799d 100644 --- a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx +++ b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx @@ -386,10 +386,14 @@ export function AddChangeAssignmentPage() { // Upload the assignment to the API. patch if it is an edit, post if it is a new assignment. const uploadAssignment = async () => { let optionalFile: File | null = null + const formData = new FormData() + if (assignmentFile !== undefined) { optionalFile = assignmentFile + } else { + formData.append('opgave_bestand', '') } - const formData = new FormData() + formData.append('titel', title) formData.append('beschrijving', description) formData.append('vak', parseInt(courseId as string).toString()) diff --git a/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx b/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx index 4866d22c..6492d938 100644 --- a/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx +++ b/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx @@ -1039,7 +1039,7 @@ export function AssignmentPage() { color={'text.primary'} > {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')} ) : ( 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({ From 4a7599138f88c33b157f2483c106eac74eb1b6f9 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 16:44:45 +0200 Subject: [PATCH 2/4] tooltip veranderd + kleur vuilbak --- frontend/frontend/src/i18n/en.ts | 1 + frontend/frontend/src/i18n/nl.ts | 1 + .../AddChangeAssignmentPage.tsx | 10 +++++++--- .../src/pages/assignmentPage/AssignmentPage.tsx | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/frontend/src/i18n/en.ts b/frontend/frontend/src/i18n/en.ts index c817851a..84fa821c 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.', } export default english diff --git a/frontend/frontend/src/i18n/nl.ts b/frontend/frontend/src/i18n/nl.ts index 8091d071..bdf23e68 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.', } export default dutch diff --git a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx index c944799d..bc9ea9f7 100644 --- a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx +++ b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx @@ -385,20 +385,23 @@ export function AddChangeAssignmentPage() { // Upload the assignment to the API. patch if it is an edit, post if it is a new assignment. const uploadAssignment = async () => { - let optionalFile: File | null = null + let optionalFile: File | null const formData = new FormData() if (assignmentFile !== undefined) { optionalFile = assignmentFile } else { - formData.append('opgave_bestand', '') + optionalFile = null } formData.append('titel', title) formData.append('beschrijving', description) formData.append('vak', parseInt(courseId as string).toString()) if (optionalFile) { + console.log('optional file' + optionalFile.name) formData.append('opgave_bestand', optionalFile) + } else { + formData.append('opgave_bestand', '') } formData.append('zichtbaar', visible.toString()) @@ -421,6 +424,7 @@ export function AddChangeAssignmentPage() { } if (assignmentId !== undefined) { formData.append('project_id', assignmentId) + console.log('file', formData.get('opgave_bestand')) await instance .patch( '/projecten/' + parseInt(assignmentId) + '/', @@ -1006,7 +1010,7 @@ export function AddChangeAssignmentPage() { title={t('remove')} > From 37d95290b9ddf2cc531a4df5ed51f61d27aa031d Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 17:46:14 +0200 Subject: [PATCH 3/4] veranderingen opgave_bestand --- .../AddChangeAssignmentPage.tsx | 193 +++++++++--------- 1 file changed, 99 insertions(+), 94 deletions(-) diff --git a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx index bc9ea9f7..6b44a9b1 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,89 +391,86 @@ 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 - const formData = new FormData() - - if (assignmentFile !== undefined) { - optionalFile = assignmentFile - } else { - optionalFile = null - } - - formData.append('titel', title) - formData.append('beschrijving', description) - formData.append('vak', parseInt(courseId as string).toString()) - if (optionalFile) { - console.log('optional file' + optionalFile.name) - formData.append('opgave_bestand', optionalFile) - } else { - formData.append('opgave_bestand', '') - } - formData.append('zichtbaar', visible.toString()) - - // 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()) + 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) + } + 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) - console.log('file', formData.get('opgave_bestand')) - 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) } } From 441553d065e87e2c2357988aab275b6d2fb3c636 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 18:14:41 +0200 Subject: [PATCH 4/4] veranderingen opgave_bestand --- .../pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx index 6b44a9b1..e6bb86b6 100644 --- a/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx +++ b/frontend/frontend/src/pages/addChangeAssignmentPage/AddChangeAssignmentPage.tsx @@ -406,6 +406,7 @@ export function AddChangeAssignmentPage() { if (assignmentFile) { formData.append('opgave_bestand', assignmentFile) } + formData.append('titel', title) formData.append('beschrijving', description) if (courseId) {