From 45ecfd257a530c54203aeda3d6f2cb466a4a4509 Mon Sep 17 00:00:00 2001 From: Bram Meir Date: Sat, 30 Mar 2024 17:31:03 +0100 Subject: [PATCH 01/14] chore: display dashboard data depending on role --- .../composables/services/courses.service.ts | 6 ++++ frontend/src/config/endpoints.ts | 1 + .../src/views/dashboard/DashboardView.vue | 28 +++++++++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/frontend/src/composables/services/courses.service.ts b/frontend/src/composables/services/courses.service.ts index 78c80705..d4246b74 100644 --- a/frontend/src/composables/services/courses.service.ts +++ b/frontend/src/composables/services/courses.service.ts @@ -22,6 +22,11 @@ export function useCourses() { await getList(endpoint, courses, Course.fromJSON); } + async function getCoursesByTeacher(teacher_id: string) { + const endpoint = endpoints.courses.byTeacher.replace('{teacher_id}', teacher_id); + await getList(endpoint, courses, Course.fromJSON); + } + async function createCourse(course_data: Course) { const endpoint = endpoints.courses.index; await create(endpoint, @@ -50,6 +55,7 @@ export function useCourses() { getCourseByID, getCourses, getCoursesByStudent, + getCoursesByTeacher, createCourse, cloneCourse, diff --git a/frontend/src/config/endpoints.ts b/frontend/src/config/endpoints.ts index f7f26cf1..ada05de3 100644 --- a/frontend/src/config/endpoints.ts +++ b/frontend/src/config/endpoints.ts @@ -13,6 +13,7 @@ export const endpoints = { index: '/api/courses/', retrieve: '/api/courses/{id}/', byStudent: '/api/students/{student_id}/courses/', + byTeacher: '/api/teachers/{teacher_id}/courses/', clone: '/api/courses/{course_id}/clone/' }, students: { diff --git a/frontend/src/views/dashboard/DashboardView.vue b/frontend/src/views/dashboard/DashboardView.vue index 6640a0fe..4a61a10f 100644 --- a/frontend/src/views/dashboard/DashboardView.vue +++ b/frontend/src/views/dashboard/DashboardView.vue @@ -7,13 +7,14 @@ import BaseLayout from '@/components/layout/BaseLayout.vue'; import Title from '@/components/layout/Title.vue'; import {useI18n} from 'vue-i18n'; import {PrimeIcons} from 'primevue/api'; -import {onMounted} from 'vue'; +import {onMounted, watch} from 'vue'; import {useCourses} from '@/composables/services/courses.service.ts'; import {ref} from 'vue'; import {Project} from "@/types/Projects.ts"; import {useProject} from "@/composables/services/project.service.ts"; import ProjectCard from "@/components/projects/ProjectCard.vue"; import {useAuthStore} from '@/store/authentication.store.ts'; +import {storeToRefs} from 'pinia'; /* Composable injections */ const {t} = useI18n(); @@ -22,13 +23,28 @@ const {t} = useI18n(); const allProjects = ref([]); /* Service injection */ -const { user } = useAuthStore(); +const { user } = useAuthStore(); +const { view }= storeToRefs(useAuthStore()); const { projects, getProjectsByCourse } = useProject(); -const { courses, getCoursesByStudent } = useCourses(); +const { courses, getCoursesByStudent, getCoursesByTeacher } = useCourses(); -onMounted(async () => { +onMounted(() => { + fetchDashboardData(); +}); + +watch(view, () => { + fetchDashboardData(); +}); + +/* Fetch the data for the dashboard */ +async function fetchDashboardData() { if (user !== null) { - await getCoursesByStudent(user.id); + // Get the courses, depending on the user's role + if (view.value === 'teacher') { + await getCoursesByTeacher(user.id); + } else { + await getCoursesByStudent(user.id); + } for (const course of courses.value ?? []) { await getProjectsByCourse(course.id); @@ -40,7 +56,7 @@ onMounted(async () => { allProjects.value.concat(projects.value ?? []); } } -}); +} From c340d566c4224441ec578d3f93c0223b615ab837 Mon Sep 17 00:00:00 2001 From: Bram Meir Date: Sat, 30 Mar 2024 18:27:23 +0100 Subject: [PATCH 02/14] chore: correct projects + assistant view --- .../composables/services/courses.service.ts | 6 ++++++ frontend/src/config/endpoints.ts | 1 + frontend/src/views/dashboard/DashboardView.vue | 18 +++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/frontend/src/composables/services/courses.service.ts b/frontend/src/composables/services/courses.service.ts index d4246b74..157fea9b 100644 --- a/frontend/src/composables/services/courses.service.ts +++ b/frontend/src/composables/services/courses.service.ts @@ -27,6 +27,11 @@ export function useCourses() { await getList(endpoint, courses, Course.fromJSON); } + async function getCourseByAssistant(assistant_id: string) { + const endpoint = endpoints.courses.byAssistant.replace('{assistant_id}', assistant_id); + await getList(endpoint, courses, Course.fromJSON); + } + async function createCourse(course_data: Course) { const endpoint = endpoints.courses.index; await create(endpoint, @@ -56,6 +61,7 @@ export function useCourses() { getCourses, getCoursesByStudent, getCoursesByTeacher, + getCourseByAssistant, createCourse, cloneCourse, diff --git a/frontend/src/config/endpoints.ts b/frontend/src/config/endpoints.ts index ada05de3..0c1b77c9 100644 --- a/frontend/src/config/endpoints.ts +++ b/frontend/src/config/endpoints.ts @@ -14,6 +14,7 @@ export const endpoints = { retrieve: '/api/courses/{id}/', byStudent: '/api/students/{student_id}/courses/', byTeacher: '/api/teachers/{teacher_id}/courses/', + byAssistant: '/api/assistants/{assistant_id}/courses/', clone: '/api/courses/{course_id}/clone/' }, students: { diff --git a/frontend/src/views/dashboard/DashboardView.vue b/frontend/src/views/dashboard/DashboardView.vue index 4a61a10f..b81fed62 100644 --- a/frontend/src/views/dashboard/DashboardView.vue +++ b/frontend/src/views/dashboard/DashboardView.vue @@ -7,9 +7,8 @@ import BaseLayout from '@/components/layout/BaseLayout.vue'; import Title from '@/components/layout/Title.vue'; import {useI18n} from 'vue-i18n'; import {PrimeIcons} from 'primevue/api'; -import {onMounted, watch} from 'vue'; +import { ref, onMounted, watch } from 'vue'; import {useCourses} from '@/composables/services/courses.service.ts'; -import {ref} from 'vue'; import {Project} from "@/types/Projects.ts"; import {useProject} from "@/composables/services/project.service.ts"; import ProjectCard from "@/components/projects/ProjectCard.vue"; @@ -23,10 +22,10 @@ const {t} = useI18n(); const allProjects = ref([]); /* Service injection */ -const { user } = useAuthStore(); -const { view }= storeToRefs(useAuthStore()); +const { user } = useAuthStore(); +const { view } = storeToRefs(useAuthStore()); const { projects, getProjectsByCourse } = useProject(); -const { courses, getCoursesByStudent, getCoursesByTeacher } = useCourses(); +const { courses, getCoursesByStudent, getCoursesByTeacher, getCourseByAssistant } = useCourses(); onMounted(() => { fetchDashboardData(); @@ -42,10 +41,15 @@ async function fetchDashboardData() { // Get the courses, depending on the user's role if (view.value === 'teacher') { await getCoursesByTeacher(user.id); - } else { + } else if (view.value === 'student') { await getCoursesByStudent(user.id); + } else { + await getCourseByAssistant(user.id); } + // Clear the projects, so that the projects from another role are not displayed + allProjects.value = []; + for (const course of courses.value ?? []) { await getProjectsByCourse(course.id); @@ -53,7 +57,7 @@ async function fetchDashboardData() { project.course = course; }); - allProjects.value.concat(projects.value ?? []); + allProjects.value = allProjects.value.concat(projects.value ?? []); } } } From 3441b6669ee6569af2c9107502406f916bfeb019 Mon Sep 17 00:00:00 2001 From: Bram Meir Date: Sat, 30 Mar 2024 19:11:53 +0100 Subject: [PATCH 03/14] chore: plus button based on role --- frontend/src/assets/lang/en.json | 8 ++++++++ frontend/src/views/dashboard/DashboardView.vue | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/frontend/src/assets/lang/en.json b/frontend/src/assets/lang/en.json index 0ddf5c85..64e5acc4 100644 --- a/frontend/src/assets/lang/en.json +++ b/frontend/src/assets/lang/en.json @@ -3,6 +3,7 @@ "header": { "logo": "Ghent University logo", "login": "login", + "view": "View as {0}", "navigation": { "dashboard": "Dashboard", "calendar": "Calendar", @@ -64,6 +65,13 @@ "open": "details" } }, + "types": { + "roles": { + "student": "Student", + "assistant": "Assistant", + "teacher": "Teacher" + } + }, "toasts": { "messages": { "unknown": "An unknown error has occurred." diff --git a/frontend/src/views/dashboard/DashboardView.vue b/frontend/src/views/dashboard/DashboardView.vue index b81fed62..4c910a60 100644 --- a/frontend/src/views/dashboard/DashboardView.vue +++ b/frontend/src/views/dashboard/DashboardView.vue @@ -36,7 +36,7 @@ watch(view, () => { }); /* Fetch the data for the dashboard */ -async function fetchDashboardData() { +const fetchDashboardData = async () => { if (user !== null) { // Get the courses, depending on the user's role if (view.value === 'teacher') { @@ -74,7 +74,10 @@ async function fetchDashboardData() {