From e5ea2187a17ca0c13ec613cfb5b6db00d7f4ccf7 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Tue, 10 May 2022 13:47:18 -0700 Subject: [PATCH 1/3] Sort facility user viewset to prevent errors in pagination. --- kolibri/core/auth/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kolibri/core/auth/api.py b/kolibri/core/auth/api.py index 1b14162e923..3d49cfc8fbc 100644 --- a/kolibri/core/auth/api.py +++ b/kolibri/core/auth/api.py @@ -298,6 +298,8 @@ class FacilityUserViewSet(ValuesViewset): DjangoFilterBackend, filters.SearchFilter, ) + order_by_field = "username" + queryset = FacilityUser.objects.all() serializer_class = FacilityUserSerializer filter_class = FacilityUserFilter @@ -338,6 +340,7 @@ def consolidate(self, items, queryset): roles.append(role) item["roles"] = roles output.append(item) + output = sorted(output, key=lambda x: x[self.order_by_field]) return output def set_password_if_needed(self, instance, serializer): From 60f98f984533c0a230349d0b57475c97fda3ddd6 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Tue, 10 May 2022 13:47:52 -0700 Subject: [PATCH 2/3] Clean up pagination implementation. --- .../src/modules/userManagement/handlers.js | 9 +- .../PaginatedListContainerWithBackend.vue | 157 +++--------------- .../assets/src/views/UserPage/index.vue | 95 ++++++++++- 3 files changed, 118 insertions(+), 143 deletions(-) diff --git a/kolibri/plugins/facility/assets/src/modules/userManagement/handlers.js b/kolibri/plugins/facility/assets/src/modules/userManagement/handlers.js index 9aed40c4940..393de407cf8 100644 --- a/kolibri/plugins/facility/assets/src/modules/userManagement/handlers.js +++ b/kolibri/plugins/facility/assets/src/modules/userManagement/handlers.js @@ -1,3 +1,4 @@ +import pickBy from 'lodash/pickBy'; import { FacilityUserResource } from 'kolibri.resources'; import samePageCheckGenerator from 'kolibri.utils.samePageCheckGenerator'; import { _userState } from '../mappers'; @@ -6,7 +7,13 @@ export function showUserPage(store, toRoute) { store.dispatch('preparePage'); const facilityId = toRoute.params.facility_id || store.getters.activeFacilityId; return FacilityUserResource.fetchCollection({ - getParams: { member_of: facilityId, page_size: 30 }, + getParams: pickBy({ + member_of: facilityId, + page: toRoute.query.page || 1, + page_size: toRoute.query.page_size || 30, + search: toRoute.query.search && toRoute.query.search.trim(), + user_type: toRoute.query.user_type, + }), force: true, }).only( samePageCheckGenerator(store), diff --git a/kolibri/plugins/facility/assets/src/views/PaginatedListContainerWithBackend.vue b/kolibri/plugins/facility/assets/src/views/PaginatedListContainerWithBackend.vue index 610fe36750c..ea2ea1e08f7 100644 --- a/kolibri/plugins/facility/assets/src/views/PaginatedListContainerWithBackend.vue +++ b/kolibri/plugins/facility/assets/src/views/PaginatedListContainerWithBackend.vue @@ -9,32 +9,29 @@ :layout12="{ span: 5, alignment: 'right' }" class="text-filter" > - +
- +