From 5578cca1ccfef9476fbecc5d29ddc423f329a64f Mon Sep 17 00:00:00 2001 From: Nathan Sprenkle Date: Wed, 11 Mar 2020 15:05:15 -0400 Subject: [PATCH] Show multiple team memberships in My Team tab (#23324) * Enable pagiation to show all a learner's teams on the "My Teams" tab * Selectively hide/show pagination on the "My Teams" tab * Increase "My Teams" page size to 5 --- .../teams/js/spec/views/my_teams_spec.js | 14 ++++++++++---- .../teams/static/teams/js/views/my_teams.js | 18 ++++++++++++------ .../teams/static/teams/js/views/teams_tab.js | 2 +- lms/djangoapps/teams/views.py | 4 ++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lms/djangoapps/teams/static/teams/js/spec/views/my_teams_spec.js b/lms/djangoapps/teams/static/teams/js/spec/views/my_teams_spec.js index 46780cafa1..5331dbfdb6 100644 --- a/lms/djangoapps/teams/static/teams/js/spec/views/my_teams_spec.js +++ b/lms/djangoapps/teams/static/teams/js/spec/views/my_teams_spec.js @@ -31,10 +31,6 @@ define([ teams = TeamSpecHelpers.createMockTeams({results: teamsData}), myTeamsView = createMyTeamsView(teams); TeamSpecHelpers.verifyCards(myTeamsView, teamsData); - - // Verify that there is no header or footer - expect(myTeamsView.$('.teams-paging-header').text().trim()).toBe(''); - expect(myTeamsView.$('.teams-paging-footer').text().trim()).toBe(''); }); it('shows a message when the user is not a member of any teams', function() { @@ -44,6 +40,16 @@ define([ expect(myTeamsView.$el.text().trim()).toBe('You are not currently a member of any team.'); }); + it('hides pagination when the user is not a member of any teams', function() { + var teams = TeamSpecHelpers.createMockTeams({results: []}), + myTeamsView = createMyTeamsView(teams); + TeamSpecHelpers.verifyCards(myTeamsView, []); + + // Verify that there is no header or footer + expect(myTeamsView.$('.teams-paging-header').text().trim()).toBe(''); + expect(myTeamsView.$('.teams-paging-footer').text().trim()).toBe(''); + }); + it('refreshes a stale membership collection when rendering', function() { var requests = AjaxHelpers.requests(this), teams = TeamSpecHelpers.createMockTeams({ diff --git a/lms/djangoapps/teams/static/teams/js/views/my_teams.js b/lms/djangoapps/teams/static/teams/js/views/my_teams.js index 0ced4b360e..93266b6374 100644 --- a/lms/djangoapps/teams/static/teams/js/views/my_teams.js +++ b/lms/djangoapps/teams/static/teams/js/views/my_teams.js @@ -34,15 +34,21 @@ }, createHeaderView: function() { - // Never show a pagination header for the "My Team" tab - // because there is only ever one team. - return null; + // hide pagination when learner isn't a member of any teams + if (!this.collection.length) { + return null; + } else { + return TeamsView.prototype.createHeaderView.call(this); + } }, createFooterView: function() { - // Never show a pagination footer for the "My Team" tab - // because there is only ever one team. - return null; + // hide pagination when learner isn't a member of any teams + if (!this.collection.length) { + return null; + } else { + return TeamsView.prototype.createFooterView.call(this); + } } }); diff --git a/lms/djangoapps/teams/static/teams/js/views/teams_tab.js b/lms/djangoapps/teams/static/teams/js/views/teams_tab.js index a1a8154924..a199c976f0 100644 --- a/lms/djangoapps/teams/static/teams/js/views/teams_tab.js +++ b/lms/djangoapps/teams/static/teams/js/views/teams_tab.js @@ -107,7 +107,7 @@ teamEvents: this.teamEvents, course_id: this.context.courseID, username: this.context.userInfo.username, - perPage: 2, + perPage: 5, parse: true, url: this.context.myTeamsUrl } diff --git a/lms/djangoapps/teams/views.py b/lms/djangoapps/teams/views.py index 4bc734c6c2..bf808fbcc9 100644 --- a/lms/djangoapps/teams/views.py +++ b/lms/djangoapps/teams/views.py @@ -68,7 +68,7 @@ from .serializers import ( ) from .utils import emit_team_event -TEAM_MEMBERSHIPS_PER_PAGE = 2 +TEAM_MEMBERSHIPS_PER_PAGE = 5 TOPICS_PER_PAGE = 12 MAXIMUM_SEARCH_SIZE = 100000 @@ -165,7 +165,7 @@ class TeamsDashboardView(GenericAPIView): is_user_org_protected = organization_protection_status == OrganizationProtectionStatus.protected filter_query['organization_protected'] = is_user_org_protected - user_teams = CourseTeam.objects.filter(**filter_query) + user_teams = CourseTeam.objects.filter(**filter_query).order_by('-last_activity_at', 'team_size') user_teams_data = self._serialize_and_paginate( MyTeamsPagination, user_teams,