From f8c61cc5d43ec838e35bed41558dab17a14b62f5 Mon Sep 17 00:00:00 2001 From: EwoutV Date: Wed, 3 Apr 2024 00:05:21 +0200 Subject: [PATCH] chore: abstracted the dashboard as example for future views --- frontend/src/components/YearSelector.vue | 11 +- .../src/components/projects/GroupCard.vue | 2 +- .../src/components/projects/ProjectCard.vue | 8 +- .../src/components/projects/ProjectList.vue | 124 +++++++++--------- .../composables/services/assistant.service.ts | 4 +- .../composables/services/students.service.ts | 4 +- .../composables/services/teachers.service.ts | 4 +- frontend/src/store/authentication.store.ts | 5 +- frontend/src/types/users/Student.ts | 2 +- frontend/src/types/users/User.ts | 26 ++++ .../views/courses/roles/StudentCourseView.vue | 11 ++ .../views/courses/roles/TeacherCourseView.vue | 11 ++ .../src/views/dashboard/DashboardView.vue | 122 +---------------- .../dashboard/roles/StudentDashboardView.vue | 74 +++++++++++ frontend/src/views/projects/ProjectView.vue | 12 +- 15 files changed, 217 insertions(+), 203 deletions(-) create mode 100644 frontend/src/views/courses/roles/StudentCourseView.vue create mode 100644 frontend/src/views/courses/roles/TeacherCourseView.vue create mode 100644 frontend/src/views/dashboard/roles/StudentDashboardView.vue diff --git a/frontend/src/components/YearSelector.vue b/frontend/src/components/YearSelector.vue index dd878234..205b15b6 100644 --- a/frontend/src/components/YearSelector.vue +++ b/frontend/src/components/YearSelector.vue @@ -1,12 +1,21 @@ - - - - \ No newline at end of file + + + + + diff --git a/frontend/src/composables/services/assistant.service.ts b/frontend/src/composables/services/assistant.service.ts index a9569f83..aa7e6a3f 100644 --- a/frontend/src/composables/services/assistant.service.ts +++ b/frontend/src/composables/services/assistant.service.ts @@ -75,8 +75,8 @@ export function useAssistant(): AssistantState { await deleteId(endpoint, assistant, Assistant.fromJSON); } - async function initAssistant(assistant: Assistant|null) { - if (assistant !== null) { + async function initAssistant(assistant: Assistant | null): Promise { + if (assistant !== null) { await getCourseByAssistant(assistant.id); assistant.courses = courses.value ?? []; } diff --git a/frontend/src/composables/services/students.service.ts b/frontend/src/composables/services/students.service.ts index 6efe45f1..c3977095 100644 --- a/frontend/src/composables/services/students.service.ts +++ b/frontend/src/composables/services/students.service.ts @@ -93,8 +93,8 @@ export function useStudents(): StudentsState { await deleteId(endpoint, student, Student.fromJSON); } - async function initStudent(student: Student|null) { - if (student !== null) { + async function initStudent(student: Student | null): Promise { + if (student !== null) { await getCoursesByStudent(student.id); student.courses = courses.value ?? []; } diff --git a/frontend/src/composables/services/teachers.service.ts b/frontend/src/composables/services/teachers.service.ts index 90e2e724..22ada208 100644 --- a/frontend/src/composables/services/teachers.service.ts +++ b/frontend/src/composables/services/teachers.service.ts @@ -76,8 +76,8 @@ export function useTeacher(): TeacherState { await deleteId(endpoint, teacher, Teacher.fromJSON); } - async function initTeacher(teacher: Teacher|null) { - if (teacher !== null) { + async function initTeacher(teacher: Teacher | null): Promise { + if (teacher !== null) { await getCoursesByTeacher(teacher.id); teacher.courses = courses.value ?? []; } diff --git a/frontend/src/store/authentication.store.ts b/frontend/src/store/authentication.store.ts index ce8f95ae..ab2b2751 100644 --- a/frontend/src/store/authentication.store.ts +++ b/frontend/src/store/authentication.store.ts @@ -142,7 +142,10 @@ export const useAuthStore = defineStore('auth', () => { }); return { - user, student, teacher, assistant, + user, + student, + teacher, + assistant, view, intent, login, diff --git a/frontend/src/types/users/Student.ts b/frontend/src/types/users/Student.ts index a0a37e37..e0e341ad 100644 --- a/frontend/src/types/users/Student.ts +++ b/frontend/src/types/users/Student.ts @@ -18,7 +18,7 @@ export class Student extends User { public roles: Role[] = [], public courses: Course[] = [], public groups: Group[] = [], - public faculties: Faculty[] = [] + public faculties: Faculty[] = [], ) { super(id, username, email, first_name, last_name, last_enrolled, is_staff, roles, faculties, create_time, last_login); } diff --git a/frontend/src/types/users/User.ts b/frontend/src/types/users/User.ts index daf2c16f..28c1c212 100644 --- a/frontend/src/types/users/User.ts +++ b/frontend/src/types/users/User.ts @@ -17,6 +17,16 @@ export class User { public last_login: Date | null, ) {} + /** + * Get the academic years of the user. + */ + get academic_years(): number[] { + const startYear = this.getAcademicYear(this.create_time); + const endYear = this.getAcademicYear(new Date()); + + return Array.from({ length: endYear - startYear + 1 }, (_, i) => startYear + i); + } + /** * Get the full name of the user. * @@ -26,6 +36,22 @@ export class User { return `${this.first_name} ${this.last_name}`; } + /** + * Get the academic year of a date. + * + * @param date + * @returns number + */ + public getAcademicYear(date: Date = new Date): number { + const year = date.getFullYear(); + + if (date.getMonth() >= 9) { + return year; + } + + return year - 1; + } + /** * Check if the user is a student. * diff --git a/frontend/src/views/courses/roles/StudentCourseView.vue b/frontend/src/views/courses/roles/StudentCourseView.vue new file mode 100644 index 00000000..8af2373f --- /dev/null +++ b/frontend/src/views/courses/roles/StudentCourseView.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/views/courses/roles/TeacherCourseView.vue b/frontend/src/views/courses/roles/TeacherCourseView.vue new file mode 100644 index 00000000..8af2373f --- /dev/null +++ b/frontend/src/views/courses/roles/TeacherCourseView.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/views/dashboard/DashboardView.vue b/frontend/src/views/dashboard/DashboardView.vue index b3d9a11c..acce43d8 100644 --- a/frontend/src/views/dashboard/DashboardView.vue +++ b/frontend/src/views/dashboard/DashboardView.vue @@ -1,134 +1,16 @@ diff --git a/frontend/src/views/dashboard/roles/StudentDashboardView.vue b/frontend/src/views/dashboard/roles/StudentDashboardView.vue new file mode 100644 index 00000000..ec77cd29 --- /dev/null +++ b/frontend/src/views/dashboard/roles/StudentDashboardView.vue @@ -0,0 +1,74 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/views/projects/ProjectView.vue b/frontend/src/views/projects/ProjectView.vue index ec300091..536c984b 100644 --- a/frontend/src/views/projects/ProjectView.vue +++ b/frontend/src/views/projects/ProjectView.vue @@ -7,18 +7,18 @@ import Title from '@/components/layout/Title.vue'; import Skeleton from 'primevue/skeleton'; import GroupCard from '@/components/projects/GroupCard.vue'; import { useGroup } from '@/composables/services/groups.service.ts'; -import { Group } from '@/types/Group.ts'; +import { type Group } from '@/types/Group.ts'; import { useAuthStore } from '@/store/authentication.store.ts'; import { storeToRefs } from 'pinia'; /* Composable injections */ const route = useRoute(); -const { user, student } = storeToRefs(useAuthStore()); +const { student } = storeToRefs(useAuthStore()); const { project, getProjectByID } = useProject(); const { groups, getGroupsByProject, getGroupsByStudent } = useGroup(); /* Component state */ -const group = ref(null); +const group = ref(null); watch( student, @@ -30,12 +30,12 @@ watch( // Check if the student is in a group for the project const projectGroups = groups.value; - await getGroupsByStudent("1"); + await getGroupsByStudent('1'); for (const studentGroup of groups.value ?? []) { const isCommonGroup = projectGroups?.some((projectGroup) => projectGroup.id === studentGroup.id); - if (isCommonGroup) { + if (isCommonGroup === true) { group.value = studentGroup; break; } @@ -44,7 +44,7 @@ watch( }, { immediate: true, - } + }, );