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 #257 from SELab-2/group-join
Browse files Browse the repository at this point in the history
Group join
  • Loading branch information
cstefc authored May 20, 2024
2 parents e24dd07 + 0458100 commit 77c313e
Show file tree
Hide file tree
Showing 10 changed files with 408 additions and 261 deletions.
217 changes: 100 additions & 117 deletions frontend/package-lock.json

Large diffs are not rendered by default.

383 changes: 249 additions & 134 deletions frontend/src/components/ProjectStudentComponent.tsx

Large diffs are not rendered by default.

55 changes: 51 additions & 4 deletions frontend/src/dataloaders/ProjectsStudentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,52 @@ export interface memberInfo {
id: number;
}

export interface GroupInfo {
id: number,
member_count: number,
visible_id: number
}

export async function getGroupInfo(project_id: number): Promise<GroupInfo[] | undefined> {
const groups = await apiFetch<GroupInfo[]>(`/projects/${project_id}/groups`)
if (!groups.ok) {
return undefined
}
return groups.content
}

export async function loadGroupMembers(project_id: number) {
const groupIdData = await apiFetch<{ id: number }>(`/projects/${project_id}/group`)
if (!groupIdData.ok) {
return undefined;
}
const groupId: number = groupIdData.content.id;

const submissionData = await apiFetch<Backend_submission>(`/groups/${groupId}/submission`)
let submission: string = "";
let lastSubmissionId = -1;
if (submissionData.ok) {
submission = submissionData.content.filename.split('/').reverse()[0]
lastSubmissionId = submissionData.content.student_id;
}

const groupMembersIdData = await apiFetch<[{ id: number }]>(`/groups/${groupId}/members`);
if (!groupMembersIdData.ok) {
return undefined
}
const groupMembersId = groupMembersIdData.content
const groupMembers = await Promise.all(groupMembersId.map(async (id_object) => {
const user = await apiFetch<Backend_user>(`/users/${id_object.id}`);

return {
name: user.content.name,
email: user.content.email,
lastSubmission: user.content.id == lastSubmissionId
}
}))
return {members: groupMembers, id: groupId, submission: submission}
}

export default async function projectsStudentLoader(): Promise<projectsStudentLoaderObject> {
const projects: CompleteProjectStudent[] = await LoadProjectsForStudent();
return {projects};
Expand All @@ -53,7 +99,7 @@ export async function LoadProjectsForStudent(filter_on_current: boolean = false,

const apiGroups = project_ids.map(async project_id => {
const apiGroupData = await apiFetch<Backend_group>(`/projects/${project_id}/group`);
if (apiGroupData.ok && apiGroupData.content){
if (apiGroupData.ok && apiGroupData.content) {
return mapGroup(apiGroupData.content)
}
return undefined;
Expand Down Expand Up @@ -105,7 +151,8 @@ export async function LoadProjectsForStudent(filter_on_current: boolean = false,

const allGroupMembers: (groupInfo | undefined)[] = await Promise.all(groupMembersPromises);
const groupMembers = allGroupMembers.filter(gm => gm !== undefined) as groupInfo[]
return projects.map((project) => {
return await Promise.all(projects.map(async (project) => {
const groupInfo = await getGroupInfo(project.project_id)
const group = groupMembers.find(group => group.project_id === project.project_id) as groupInfo;
const group_id = group ? group.group_id : -1
const submission = submissions.find(submission => submission.submission_group_id === group?.group_id);
Expand All @@ -117,11 +164,11 @@ export async function LoadProjectsForStudent(filter_on_current: boolean = false,
...project,
...course,
group_id: group_id,
groups_info: groupInfo,
submission_state: submission?.submission_state ?? SUBMISSION_STATE.Pending,
submission_file: submission?.submission_filename.split('/').reverse()[0] ?? "",
submission_student_id: submission?.submission_student_id,
group_members: groupMembers.find(group => group.project_id == project.project_id)?.users ?? [],

}
})
}))
}
2 changes: 1 addition & 1 deletion frontend/src/pages/student/ProjectViewStudent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default function ProjectViewStudent(): JSX.Element {
lastSubmission: project_data.submission_student_id === member?.user_id
}
});

const project: ProjectStudent = {
projectId: project_data.project_id,
projectName: project_data.project_name,
Expand All @@ -51,6 +50,7 @@ export default function ProjectViewStudent(): JSX.Element {
description: project_data.project_description,
requiredFiles: JSON.parse(project_data.project_requirements) as object,
group_id: project_data.group_id,
groups_info: project_data.groups_info,
groupMembers: groupMembers,
maxGroupMembers: project_data.project_max_students,
submission: project_data.submission_file
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Course} from "../utils/ApiInterfaces.ts";
import {GroupInfo} from "../dataloaders/ProjectsStudentLoader.ts";

export type ValuePiece = Date | null; // nodig voor de deadline
export type Value = ValuePiece | [ValuePiece, ValuePiece]; // nodig voor de deadline
Expand Down Expand Up @@ -32,6 +33,7 @@ export type ProjectStudent = {
description: string,
requiredFiles: object,
group_id: number,
groups_info: GroupInfo[] | undefined,
groupMembers: {
name: string,
email: string,
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/utils/ApiInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {GroupInfo} from "../dataloaders/ProjectsStudentLoader.ts";

export interface Course {
course_id: number,
course_name: string,
Expand Down Expand Up @@ -43,6 +45,7 @@ export interface CompleteProject extends Project, Course {

export interface CompleteProjectStudent extends CompleteProject {
group_id: number,
groups_info: GroupInfo[] | undefined,
submission_state: SUBMISSION_STATE,
submission_student_id: number | undefined,
group_members: User[],
Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/api/Course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export async function course_create_project(courseId: number, projectInput: Proj
if (projectData.ok) {
return mapProject(projectData.content);
}else{
// TODO: error handling
throw projectData.status_code
}
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/api/Groups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApiFetch from "../ApiFetch.ts";

export function joinGroup(groupId: number): void {
void ApiFetch(`/groups/${groupId}/join`,
export async function joinGroup(groupId: number): Promise<void> {
await ApiFetch(`/groups/${groupId}/join`,
{method: 'POST', headers: {'Content-Type': 'application/json'}});
}

Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/api/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export async function project_create_group(project_id: number): Promise<Group> {
if (groupData.ok) {
return mapGroup(groupData.content);
}
// TODO: error handling
throw groupData.status_code
}

Expand Down
1 change: 0 additions & 1 deletion frontend/src/utils/api/Teacher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export async function createCourse(name: string): Promise<Course> {
if (courseData.ok){
return mapCourse(courseData.content);
}else{
// TODO: error handling
throw courseData.status_code
}
}

0 comments on commit 77c313e

Please sign in to comment.