Skip to content

Commit

Permalink
Merge pull request #324 from SELab-2/last_last_bugs
Browse files Browse the repository at this point in the history
procenten afgerond + opgavebestanden verwijderbaar gemaakt
  • Loading branch information
Bendemeurichy authored May 23, 2024
2 parents 9b00687 + 441553d commit b815edc
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,6 +54,7 @@ export function SubmissionListItemTeacherPage({
// State for submitted data and score
const [submitted, setSubmitted] = useState<Submission>()
const [score, setScore] = useState<Score>()
const [assignment, setAssignment] = useState<Project>()
useEffect(() => {
async function fetchData() {
try {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -168,7 +175,11 @@ export function SubmissionListItemTeacherPage({
<ListItemText
primary={
score
? `${Number(score.score)}` + '/20'
? `${Number(score.score)}` +
'/' +
(assignment
? assignment.max_score
: '20')
: t('no_score_yet')
}
/>,
Expand Down
1 change: 1 addition & 0 deletions frontend/frontend/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
1 change: 1 addition & 0 deletions frontend/frontend/src/i18n/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function AddChangeAssignmentPage() {
const [assignmentFile, setAssignmentFile] = useState<File>()
const [maxScore, SetMaxScore] = useState<number>(20)
const [cleared, setCleared] = useState<boolean>(false)
const [filename, setFilename] = useState<string>('indiening.zip')
const [filename, setFilename] = useState<string>('')
const [groupSize, setGroupSize] = useState<number>(1)

const [user, setUser] = useState<User>()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -1002,7 +1016,7 @@ export function AddChangeAssignmentPage() {
title={t('remove')}
>
<IconButton
color={'warning'}
color={'error'}
onClick={
openDeleteConfirmation
}
Expand Down
6 changes: 4 additions & 2 deletions frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
</Typography>
) : (
Expand Down Expand Up @@ -1257,7 +1257,9 @@ export function AssignmentPage() {
handleFileChange
}
fileTypes={['*']}
tooltip={t('uploadToolTip')}
tooltip={t(
'upload_project'
)}
/>
</Grid>
<Grid item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function AssignmentListItemSubjectsPage({
<ListItemText
primary={
score
? `${score.score}/${maxScore} (${(100 * score.score) / maxScore}%)`
? `${score.score}/${maxScore} (${Math.round((100 * score.score) / maxScore)}%)`
: t('no_score_yet')
}
/>
Expand Down

0 comments on commit b815edc

Please sign in to comment.