Skip to content

Commit

Permalink
Merge https://github.com/SELab-2/UGent-3 into frontend/header-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vucis committed May 23, 2024
2 parents ef68caf + 37606d4 commit 1ba16a6
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 96 deletions.
4 changes: 3 additions & 1 deletion backend/project/endpoints/projects/endpoint_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
help='Projects visibility for students',
location="form"
)
parser.add_argument("archived", type=bool, help='Projects', location="form")
parser.add_argument("archived", type=str, help='Projects', location="form")
parser.add_argument(
"regex_expressions",
type=str,
Expand Down Expand Up @@ -61,6 +61,8 @@ def parse_project_params():
)
)
result_dict[key] = new_deadlines
elif "archived" == key:
result_dict[key] = value == "true"
else:
result_dict[key] = value

Expand Down
4 changes: 2 additions & 2 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ psycopg2-binary
docker
pytest~=8.0.1
SQLAlchemy~=2.0.27
requests>=2.31.0
requests<=2.31.0
waitress
flask_swagger_ui
flask_executor
flask_executor
4 changes: 0 additions & 4 deletions documentation/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ const config: Config = {
{
docs: {
sidebarPath: './sidebars.ts',
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/SELab-2/UGent-3',
},
theme: {
customCss: './src/css/custom.css',
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/en/projectformTranslation.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"runnerComponent": {
"testWarning": "No appropriate test file found, can't upload project",
"clearSelected": "Clear Selection",
"tooltipRunner": "If you're having trouble figuring out the runner please refer to the docs",
"tooltipRunner": "If you're having trouble figuring out the runner please refer to the ",
"userDocs": "runner user docs"
},
"dragAndDrop": {
Expand Down
8 changes: 5 additions & 3 deletions frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"cancel": "Cancel",
"create": "Create",
"activeCourses": "Active Courses",
"archivedCourses":"Archived Courses"
"archivedCourses":"Archived Courses"
},
"courseForm": {
"courseName": "Course Name",
Expand All @@ -72,7 +72,9 @@
"running": "Running",
"submitTime": "Time submitted",
"status": "Status"
}
},
"projectOverview": "Overview",
"archive": "Archive"
},
"time": {
"yearsAgo": "years ago",
Expand Down Expand Up @@ -149,4 +151,4 @@
"no_projects": "There are no projects here.",
"new_project": "New Project"
}
}
}
4 changes: 3 additions & 1 deletion frontend/public/locales/nl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
"running": "Aan het uitvoeren",
"submitTime": "Indientijd",
"status": "Status"
}
},
"projectOverview": "Overzicht",
"archive": "Archiveer"
},
"time": {
"yearsAgo": "jaren geleden",
Expand Down
70 changes: 48 additions & 22 deletions frontend/src/components/Courses/AllCoursesTeacher.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import { Button, Dialog, DialogActions, DialogTitle, FormControl, FormHelperText, Grid, Input, InputLabel } from "@mui/material";
import {
Button,
Dialog,
DialogActions,
DialogTitle,
FormControl,
FormHelperText,
Grid,
Input,
InputLabel,
} from "@mui/material";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { SideScrollableCourses } from "./CourseUtilComponents";
import {Course, callToApiToCreateCourse, ProjectDetail} from "./CourseUtils";
import { Course, callToApiToCreateCourse, ProjectDetail } from "./CourseUtils";
import { Title } from "../Header/Title";
import { useLoaderData } from "react-router-dom";
import { Me } from "../../types/me";

/**
* @returns A jsx component representing all courses for a teacher
*/
export function AllCoursesTeacher(): JSX.Element {
const [open, setOpen] = useState(false);
const loader = useLoaderData() as {
const { courses, projects, me } = useLoaderData() as {
courses: Course[];
me: Me;
projects: { [courseId: string]: ProjectDetail[] };
};
const courses = loader.courses;
const projects = loader.projects;

const [courseName, setCourseName] = useState('');
const [error, setError] = useState('');
const [courseName, setCourseName] = useState("");
const [error, setError] = useState("");

const navigate = useNavigate();

const { t } = useTranslation('translation', { keyPrefix: 'allCoursesTeacher' });
const { t } = useTranslation("translation", {
keyPrefix: "allCoursesTeacher",
});

const handleClickOpen = () => {
setOpen(true);
Expand All @@ -36,14 +48,14 @@ export function AllCoursesTeacher(): JSX.Element {

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setCourseName(event.target.value);
setError(''); // Clearing error message when user starts typing
setError(""); // Clearing error message when user starts typing
};

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault(); // Prevents the default form submission behaviour

if (!courseName.trim()) {
setError(t('emptyCourseNameError'));
setError(t("emptyCourseNameError"));
return;
}

Expand All @@ -52,33 +64,47 @@ export function AllCoursesTeacher(): JSX.Element {
};
return (
<>
<Title title={t('title')}></Title>
<Grid container direction={'column'} style={{marginTop: '1rem', width:'100vw', height: '80vh'}}>
<SideScrollableCourses courses={courses} projects={projects}></SideScrollableCourses>
<Title title={t("title")}></Title>
<Grid
container
direction={"column"}
style={{ marginTop: "1rem", width: "100vw", height: "80vh" }}
>
<SideScrollableCourses
courses={courses}
projects={projects}
></SideScrollableCourses>
<Dialog open={open} onClose={handleClose}>
<DialogTitle>{t('courseForm')}</DialogTitle>
<DialogTitle>{t("courseForm")}</DialogTitle>
<form style={{ margin: "2rem" }} onSubmit={handleSubmit}>
<FormControl>
<InputLabel htmlFor="course-name">{t('courseName')}</InputLabel>
<InputLabel htmlFor="course-name">{t("courseName")}</InputLabel>
<Input
id="course-name"
value={courseName}
onChange={handleInputChange}
error={!!error}
aria-describedby="my-helper-text"
/>
{error && <FormHelperText id="my-helper-text">{error}</FormHelperText>}
{error && (
<FormHelperText id="my-helper-text">{error}</FormHelperText>
)}
</FormControl>
<DialogActions>
<Button onClick={handleClose}>{t('cancel')}</Button>
<Button type="submit">{t('submit')}</Button>
<Button onClick={handleClose}>{t("cancel")}</Button>
<Button type="submit">{t("submit")}</Button>
</DialogActions>
</form>
</Dialog>
<Grid item style={{position: "absolute", left: "2rem", bottom: "5rem"}}>
<Button onClick={handleClickOpen} >{t('create')}</Button>
</Grid>
{me && me.role === "TEACHER" && (
<Grid
item
style={{ position: "absolute", left: "2rem", bottom: "5rem" }}
>
<Button onClick={handleClickOpen}>{t("create")}</Button>
</Grid>
)}
</Grid>
</>
);
}
}
4 changes: 3 additions & 1 deletion frontend/src/components/Courses/CourseUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NavigateFunction, Params } from "react-router-dom";
import { authenticatedFetch } from "../../utils/authenticated-fetch";
import { Me } from "../../types/me";
import { fetchMe } from "../../utils/fetches/FetchMe";

export interface Course {
course_id: string;
Expand Down Expand Up @@ -125,11 +126,12 @@ export const dataLoaderCourses = async () => {

const courses = await fetchData(`courses`);
const projects = await fetchProjectsCourse(courses);
const me = await fetchMe();
for( const c of courses){
const teacher = await fetchData(`users/${c.teacher}`)
c.teacher = teacher.display_name
}
return {courses, projects}
return {courses, projects, me}
};

/**
Expand Down
43 changes: 43 additions & 0 deletions frontend/src/components/DeadlineView/DeadlineGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow} from "@mui/material";
import {Deadline} from "../../types/deadline.ts";
import {useTranslation} from "react-i18next";

interface Props {
deadlines: Deadline[];
minWidth: number
}

/**
* @returns grid that displays deadlines in a grid
*/
export default function DeadlineGrid({deadlines, minWidth}: Props) {

const { t } = useTranslation('translation', { keyPrefix: 'projectForm' });

return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: minWidth }}>
<TableHead>
<TableRow>
<TableCell sx={{ fontWeight: 'bold' }}>{t("deadline")}</TableCell>
<TableCell sx={{ fontWeight: 'bold' }} align="right">{t("description")}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{deadlines.length === 0 ? ( // Check if deadlines is empty
<TableRow>
<TableCell colSpan={2} align="center">{t("noDeadlinesPlaceholder")}</TableCell>
</TableRow>
) : (
deadlines.map((deadline, index) => (
<TableRow key={index} sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>
<TableCell component="th" scope="row">{deadline.deadline}</TableCell>
<TableCell align="right">{deadline.description}</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</TableContainer>
)
}
28 changes: 3 additions & 25 deletions frontend/src/components/ProjectForm/ProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import AdvancedRegex from "./AdvancedRegex.tsx";
import RunnerSelecter from "./RunnerSelecter.tsx";
import { authenticatedFetch } from "../../utils/authenticated-fetch.ts";
import i18next from "i18next";
import DeadlineGrid from "../DeadlineView/DeadlineGrid.tsx";

interface Course {
course_id: string;
Expand Down Expand Up @@ -332,30 +333,7 @@ export default function ProjectForm() {
deadlines={[]}
onChange={(deadlines: Deadline[]) => handleDeadlineChange(deadlines)}
editable={true} />
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }}>
<TableHead>
<TableRow>
<TableCell sx={{ fontWeight: 'bold' }}>{t("deadline")}</TableCell>
<TableCell sx={{ fontWeight: 'bold' }} align="right">{t("description")}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{deadlines.length === 0 ? ( // Check if deadlines is empty
<TableRow>
<TableCell colSpan={2} align="center">{t("noDeadlinesPlaceholder")}</TableCell>
</TableRow>
) : (
deadlines.map((deadline, index) => (
<TableRow key={index} sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>
<TableCell component="th" scope="row">{deadline.deadline}</TableCell>
<TableCell align="right">{deadline.description}</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</TableContainer>
<DeadlineGrid deadlines={deadlines} minWidth={650} />
</Grid>
<Grid item>
<Stack direction="row" style={{display: "flex", alignItems:"center"}}>
Expand All @@ -372,7 +350,7 @@ export default function ProjectForm() {
<Grid item>
<Stack direction="row" style={{display: "flex", alignItems:"center", paddingBottom: "40px"}}>
<FolderDragDrop onFileDrop={file => handleFileUpload2(file)} regexRequirements={[]} />
<Tooltip style={{ height: "40%" }} title={<Typography variant="h6">{t("fileInfo")}: <Link to="/">{t("userDocs")}</Link></Typography>}>
<Tooltip style={{ height: "40%" }} title={<Typography variant="h6">{t("fileInfo")}: <Link to="/user-guide">{t("userDocs")}</Link></Typography>}>
<IconButton>
<InfoOutlined/>
</IconButton>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ProjectForm/RunnerSelecter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function RunnerSelecter({ handleSubmit, runner, containsDocker, c
<MenuItem value={t("clearSelected")}>{t("clearSelected")}</MenuItem>
</Select>
</FormControl>
<Tooltip title={<Typography variant="h6">{t("tooltipRunner")}: <Link to="/">{t("userDocs")}</Link></Typography>}>
<Tooltip title={<Typography variant="h6">{t("tooltipRunner")} <Link to="/user-guide/docs/category/evaluators">{t("userDocs")}</Link></Typography>}>
<IconButton>
<InfoOutlined/>
</IconButton>
Expand Down
Loading

0 comments on commit 1ba16a6

Please sign in to comment.