Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #394 from SELab-2/constraints-switch
Browse files Browse the repository at this point in the history
Add option to disable file constraints
  • Loading branch information
ALBERICLOOS authored May 23, 2024
2 parents 74162b0 + 8fabdf4 commit da10998
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
5 changes: 3 additions & 2 deletions frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
},
"save_button": "Save",
"error_title": "Oops, something went wrong!",
"error_text": "You don't have any courses yet, please create a course first in order to create a project"
"error_text": "You don't have any courses yet, please create a course first in order to create a project",
"enable_constraints": "Enable file constraints"
},
"submission_files": {
"root_switch": {
Expand Down Expand Up @@ -282,4 +283,4 @@
"download": {
"download_all": "Download all submissions"
}
}
}
3 changes: 2 additions & 1 deletion frontend/public/locales/nl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
},
"save_button": "Opslaan",
"error_title": "Oeps, er is iets fout gegaan!",
"error_text": "Je hebt nog geen vakken, maak eerst een vak aan om een project te kunnen maken."
"error_text": "Je hebt nog geen vakken, maak eerst een vak aan om een project te kunnen maken.",
"enable_constraints": "Zet bestandsvoorwaarden aan"
},
"submission_files": {
"root_switch": {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/ProjectStudentComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function ProjectInfo(props: { project: ProjectStudent }): JSX.Element {
</div>
<FieldWithLabel fieldLabel={"> " + t('project.description')}
fieldBody={props.project.description} arrow={false}/>
<div className="field is-horizontal">
{props.project.requiredFiles != null && <div className="field is-horizontal">
<div className="field-label">
<label className="label">{"> " + t('project.submission_files') + ":"}</label>
</div>
Expand All @@ -52,7 +52,7 @@ function ProjectInfo(props: { project: ProjectStudent }): JSX.Element {
/>
</div>
</div>
</div>
</div>}
</div>
)
}
Expand Down
35 changes: 32 additions & 3 deletions frontend/src/components/ProjectTeacherComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,31 @@ export function ProjectTeacherComponent(props: {
document.body.removeChild(a);
}
}

function toggleRequirements(enabled: boolean) {
if (enabled) {
setRequiredFiles({
type: "SUBMISSION",
root_constraint: {
type: "FILE",
file_name: "CHANGE_ME"
}
});
} else {
setRequiredFiles(null);
}
}
async function handleSaveClick() {
let requirements = "";
if (requiredFiles != null) {
requirements = JSON.stringify(requiredFiles);
}
const projectInput: ProjectInput = {
name: projectName,
deadline: deadline,
visible: visible,
archived: archived,
description: description,
requirements: JSON.stringify(requiredFiles),
requirements: requirements,
max_students: max_students == 0 ? 1 : max_students,
dockerfile: dockerString
}
Expand Down Expand Up @@ -395,6 +411,19 @@ export function ProjectTeacherComponent(props: {
</div>
{/* SUBMISSION FIELD */}
<div className="field is-horizontal">
<div className="field-label">
<label className="label">{t('create_project.enable_constraints')}</label>
</div>
<div className="field-body is-fullwidth is-align-content-center">
<Switch
type="checkbox"
onColor="#006edc"
checked={requiredFiles != null}
onChange={(e) => toggleRequirements(e)}
/>
</div>
</div>
{requiredFiles != null && <div className="field is-horizontal">
<div className="field-label">
<label className="label">{t('create_project.submission_files.tag')}</label>
</div>
Expand All @@ -408,7 +437,7 @@ export function ProjectTeacherComponent(props: {
/>
</div>
</div>
</div>
</div>}

{/* VISIBLE FIELD*/}
<div className="field is-horizontal">
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/pages/student/ProjectViewStudent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ export default function ProjectViewStudent(): JSX.Element {
lastSubmission: project_data.submission_student_id === member?.user_id
}
});
let requiredFiles;
if (project_data.project_requirements == "") {
requiredFiles = null;
} else {
requiredFiles = JSON.parse(project_data.project_requirements) as object
}
const project: ProjectStudent = {
projectId: project_data.project_id,
projectName: project_data.project_name,
courseName: project_data.course_name,
deadline: deadline_to_string(project_data.project_deadline),
status: project_status,
description: project_data.project_description,
requiredFiles: JSON.parse(project_data.project_requirements) as object,
requiredFiles: requiredFiles,
group_id: project_data.group_id,
groups_info: project_data.groups_info,
groupMembers: groupMembers,
Expand All @@ -71,4 +77,4 @@ export default function ProjectViewStudent(): JSX.Element {
</div>
</>
)
}
}
9 changes: 7 additions & 2 deletions frontend/src/pages/teacher/ProjectViewTeacher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export default function ProjectViewTeacher() {
if (!projectName){
setProjectName(project_data.project_name)
}

let requiredFiles;
if (project_data.project_requirements == "") {
requiredFiles = null;
} else {
requiredFiles = JSON.parse(project_data.project_requirements) as object
}
const project: ProjectTeacher = {
projectId: project_data.project_id,
projectName: project_data.project_name,
Expand All @@ -38,7 +43,7 @@ export default function ProjectViewTeacher() {
archived: project_data.project_archived,
description: project_data.project_description,
maxGroupMembers: project_data.project_max_students,
requiredFiles: JSON.parse(project_data.project_requirements) as object,
requiredFiles: requiredFiles,
otherFilesAllow: true,
groupProject: project_data.project_max_students > 1,
dockerFile: project_data.project_dockerfile,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/types/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ProjectTeacher = {
visible: boolean,
archived: boolean,
description: string,
requiredFiles: object,
requiredFiles: object | null,
otherFilesAllow: boolean,
groupProject: boolean,
maxGroupMembers: number,
Expand All @@ -36,7 +36,7 @@ export type ProjectStudent = {
deadline: string,
status: ProjectStatus,
description: string,
requiredFiles: object,
requiredFiles: object | null,
group_id: number,
groups_info: GroupInfo[] | undefined,
groupMembers: {
Expand Down

0 comments on commit da10998

Please sign in to comment.