diff --git a/backend/api/views/assistant_view.py b/backend/api/views/assistant_view.py index d02ca681..8148c710 100644 --- a/backend/api/views/assistant_view.py +++ b/backend/api/views/assistant_view.py @@ -39,24 +39,18 @@ def create(self, request: Request, *args, **kwargs) -> Response: def search(self, request: Request) -> Response: # Extract filter params search = request.query_params.get("search", "") - roles = request.query_params.getlist("roles[]") faculties = request.query_params.getlist("faculties[]") - # Make sure that if roles are passed, assistant is a selected role - if roles and "assistant" not in roles: - queryset = [] - - else: - # Filter the queryset based on the search term - queryset = Assistant.objects.annotate( - full_name=Concat('first_name', Value(' '), 'last_name') - ).filter( - full_name__icontains=search - ) - - # Filter the queryset based on selected faculties - if faculties: - queryset = queryset.filter(faculties__id__in=faculties) + # Filter the queryset based on the search term + queryset = Assistant.objects.annotate( + full_name=Concat('first_name', Value(' '), 'last_name') + ).filter( + full_name__icontains=search + ) + + # Filter the queryset based on selected faculties + if faculties: + queryset = queryset.filter(faculties__id__in=faculties) # Serialize the resulting queryset serializer = self.serializer_class(self.paginate_queryset(queryset), many=True, context={ diff --git a/backend/api/views/teacher_view.py b/backend/api/views/teacher_view.py index 7e09df9f..2aff9fcb 100644 --- a/backend/api/views/teacher_view.py +++ b/backend/api/views/teacher_view.py @@ -39,24 +39,18 @@ def create(self, request: Request, *args, **kwargs) -> Response: def search(self, request: Request) -> Response: # Extract filter params search = request.query_params.get("search", "") - roles = request.query_params.getlist("roles[]") faculties = request.query_params.getlist("faculties[]") - # Make sure that if roles are passed, teacher is a selected role - if roles and "teacher" not in roles: - queryset = [] - - else: - # Filter the queryset based on the search term - queryset = Teacher.objects.annotate( - full_name=Concat('first_name', Value(' '), 'last_name') - ).filter( - full_name__icontains=search - ) + # Filter the queryset based on the search term + queryset = Teacher.objects.annotate( + full_name=Concat('first_name', Value(' '), 'last_name') + ).filter( + full_name__icontains=search + ) - # Filter the queryset based on selected faculties - if faculties: - queryset = queryset.filter(faculties__id__in=faculties) + # Filter the queryset based on selected faculties + if faculties: + queryset = queryset.filter(faculties__id__in=faculties) # Serialize the resulting queryset serializer = self.serializer_class(self.paginate_queryset(queryset), many=True, context={ diff --git a/frontend/src/components/teachers_assistants/TeacherAssistantSearch.vue b/frontend/src/components/teachers_assistants/TeacherAssistantSearch.vue index daad52e3..0178db79 100644 --- a/frontend/src/components/teachers_assistants/TeacherAssistantSearch.vue +++ b/frontend/src/components/teachers_assistants/TeacherAssistantSearch.vue @@ -47,8 +47,20 @@ const filteredUsers = ref(null); * Fetch the users based on the filter. */ async function fetchUsers(): Promise { - await searchTeachers(filter.value, page.value, pageSize.value); - await searchAssistants(filter.value, page.value, pageSize.value); + if (filter.value.roles.length === 0) { + // No roles selected, so all users should be fetched + await searchTeachers(filter.value, page.value, pageSize.value); + await searchAssistants(filter.value, page.value, pageSize.value); + } else { + // Depending on the roles, fetch the users + if (filter.value.roles.includes('teacher')) { + await searchTeachers(filter.value, page.value, pageSize.value); + } + + if (filter.value.roles.includes('assistant')) { + await searchAssistants(filter.value, page.value, pageSize.value); + } + } // Set the filtered users filteredUsers.value = [...(teacherPagination.value?.results ?? []), ...(assistantPagination.value?.results ?? [])]; diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 4853a2df..cf7b5921 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -25,6 +25,5 @@ app.use(ConfirmationService); app.directive('ripple', Ripple); app.directive('tooltip', Tooltip); - /* Mount the application */ app.mount('#app'); diff --git a/frontend/src/views/courses/roles/TeacherCourseView.vue b/frontend/src/views/courses/roles/TeacherCourseView.vue index 25bd58fc..826978c0 100644 --- a/frontend/src/views/courses/roles/TeacherCourseView.vue +++ b/frontend/src/views/courses/roles/TeacherCourseView.vue @@ -116,9 +116,9 @@ const handleClone = async (): Promise => {
{{ t('views.courses.teachers_and_assistants.title') }} -
+
-
+