From 2d29751d14eeda99f35ea59e66a4af03e179ca56 Mon Sep 17 00:00:00 2001 From: Ehtesham Date: Mon, 30 May 2016 20:29:44 +0500 Subject: [PATCH] fixing paging footer in topics tab --- .../test/acceptance/tests/lms/test_teams.py | 17 +++++++++++ .../teams/static/teams/js/collections/base.js | 6 +++- .../static/teams/js/collections/my_teams.js | 4 +-- .../teams/js/collections/team_membership.js | 30 ------------------- .../static/teams/js/collections/topic.js | 8 ++--- .../spec/collections/topic_collection_spec.js | 3 +- .../js/spec_helpers/team_spec_helpers.js | 10 ++----- .../teams/static/teams/js/views/teams_tab.js | 6 ++-- 8 files changed, 34 insertions(+), 50 deletions(-) delete mode 100644 lms/djangoapps/teams/static/teams/js/collections/team_membership.js diff --git a/common/test/acceptance/tests/lms/test_teams.py b/common/test/acceptance/tests/lms/test_teams.py index 1d9324a633..5763bb30e4 100644 --- a/common/test/acceptance/tests/lms/test_teams.py +++ b/common/test/acceptance/tests/lms/test_teams.py @@ -521,6 +521,23 @@ class BrowseTopicsTest(TeamsTabBase): self.assertEqual(len(self.topics_page.topic_cards), TOPICS_PER_PAGE) self.assertTrue(self.topics_page.get_pagination_header_text().startswith('Showing 1-12 out of 13 total')) + def test_topic_pagination_one_page(self): + """ + Scenario: Browsing topics when there are fewer topics than the page size i.e. 12 + all topics should show on one page + Given I am enrolled in a course with team configuration and topics + When I visit the Teams page + And I browse topics + And I should see corrected number of topic cards + And I should see the correct page header + And I should not see a pagination footer + """ + self.set_team_configuration({u"max_team_size": 10, u"topics": self.create_topics(10)}) + self.topics_page.visit() + self.assertEqual(len(self.topics_page.topic_cards), 10) + self.assertTrue(self.topics_page.get_pagination_header_text().startswith('Showing 1-10 out of 10 total')) + self.assertFalse(self.topics_page.pagination_controls_visible()) + def test_topic_description_truncation(self): """ Scenario: excessively long topic descriptions should be truncated so diff --git a/lms/djangoapps/teams/static/teams/js/collections/base.js b/lms/djangoapps/teams/static/teams/js/collections/base.js index 5c685e40bf..a5a5e9edfa 100644 --- a/lms/djangoapps/teams/static/teams/js/collections/base.js +++ b/lms/djangoapps/teams/static/teams/js/collections/base.js @@ -6,7 +6,9 @@ constructor: function (models, options) { this.options = options; this.url = options.url; - this.state.perPage = options.per_page; + if (options.perPage) { + this.state.pageSize = options.perPage; + } this.course_id = options.course_id; this.teamEvents = options.teamEvents; @@ -33,6 +35,8 @@ this.isStale = true; }, + // TODO: These changes has been added to backbone.paginator + // remove when backbone.paginator gets a new release sync: function (method, model, options) { // do not send total pages and total records in request if (method === 'read') { diff --git a/lms/djangoapps/teams/static/teams/js/collections/my_teams.js b/lms/djangoapps/teams/static/teams/js/collections/my_teams.js index d9b85d9bb7..84f4136808 100644 --- a/lms/djangoapps/teams/static/teams/js/collections/my_teams.js +++ b/lms/djangoapps/teams/static/teams/js/collections/my_teams.js @@ -8,9 +8,7 @@ }, text_search: function () { return this.searchString || ''; - }, - totalPages: null, - totalRecords: null + } }, constructor: function (teams, options) { diff --git a/lms/djangoapps/teams/static/teams/js/collections/team_membership.js b/lms/djangoapps/teams/static/teams/js/collections/team_membership.js deleted file mode 100644 index f9d5317bc5..0000000000 --- a/lms/djangoapps/teams/static/teams/js/collections/team_membership.js +++ /dev/null @@ -1,30 +0,0 @@ -;(function (define) { - 'use strict'; - define(['teams/js/collections/base', 'teams/js/models/team_membership'], - function(BaseCollection, TeamMembershipModel) { - var TeamMembershipCollection = BaseCollection.extend({ - initialize: function(team_memberships, options) { - this.url = options.url; - var self = this; - BaseCollection.prototype.initialize.call(this, options); - - this.perPage = options.per_page || 10; - this.username = options.username; - - this.server_api = _.extend( - { - expand: 'team,user', - username: this.username, - course_id: function () { return encodeURIComponent(self.course_id); } - }, - BaseCollection.prototype.server_api - ); - delete this.server_api['sort_order']; // Sort order is not specified for the TeamMembership API - delete this.server_api['order_by']; // Order by is not specified for the TeamMembership API - }, - - model: TeamMembershipModel - }); - return TeamMembershipCollection; - }); -}).call(this, define || RequireJS.define); diff --git a/lms/djangoapps/teams/static/teams/js/collections/topic.js b/lms/djangoapps/teams/static/teams/js/collections/topic.js index af4730edcc..25db49747e 100644 --- a/lms/djangoapps/teams/static/teams/js/collections/topic.js +++ b/lms/djangoapps/teams/static/teams/js/collections/topic.js @@ -6,7 +6,6 @@ model: TopicModel, state: { - perPage: null, sortKey: 'name' }, @@ -16,12 +15,13 @@ }, constructor: function(topics, options) { - BaseCollection.prototype.constructor.call(this, topics, options); - - this.state.pageSize = topics.results.length; if (topics.sort_order) { this.state.sortKey = topics.sort_order; } + + options.perPage = topics.results.length; + BaseCollection.prototype.constructor.call(this, topics, options); + this.registerSortableField('name', gettext('name')); // Translators: This refers to the number of teams (a count of how many teams there are) this.registerSortableField('team_count', gettext('team count')); diff --git a/lms/djangoapps/teams/static/teams/js/spec/collections/topic_collection_spec.js b/lms/djangoapps/teams/static/teams/js/spec/collections/topic_collection_spec.js index b14bfb0310..0be46f46cd 100644 --- a/lms/djangoapps/teams/static/teams/js/spec/collections/topic_collection_spec.js +++ b/lms/djangoapps/teams/static/teams/js/spec/collections/topic_collection_spec.js @@ -20,8 +20,9 @@ define(['backbone', 'URI', 'underscore', 'common/js/spec_helpers/ajax_helpers', expect(params[param]).toBe(value); }; - it('sets its perPage based on initial page size', function () { + it('sets its page size based on initial page size', function () { expect(topicCollection.getPageSize()).toBe(5); + expect(topicCollection.getTotalPages()).toBe(2); }); it('sorts by name', function () { diff --git a/lms/djangoapps/teams/static/teams/js/spec_helpers/team_spec_helpers.js b/lms/djangoapps/teams/static/teams/js/spec_helpers/team_spec_helpers.js index eee15b61b5..beb0fa58f2 100644 --- a/lms/djangoapps/teams/static/teams/js/spec_helpers/team_spec_helpers.js +++ b/lms/djangoapps/teams/static/teams/js/spec_helpers/team_spec_helpers.js @@ -2,10 +2,9 @@ define([ 'backbone', 'underscore', 'teams/js/collections/team', - 'teams/js/collections/team_membership', 'teams/js/collections/topic', 'teams/js/models/topic' -], function (Backbone, _, TeamCollection, TeamMembershipCollection, TopicCollection, TopicModel) { +], function (Backbone, _, TeamCollection, TopicCollection, TopicModel) { 'use strict'; var createMockPostResponse, createMockDiscussionResponse, createAnnotatedContentInfo, createMockThreadResponse, createMockTopicData, createMockTopicCollection, createMockTopic, @@ -63,9 +62,7 @@ define([ return new collectionType( createMockTeamsResponse(responseOptions), _.extend({ - state: { - pageSize: 5 - }, + perPage: 5, teamEvents: teamEvents, course_id: testCourseID, parse: true @@ -289,9 +286,6 @@ define([ sort_order: 'name' }, { - state: { - pageSize: 5 - }, teamEvents: teamEvents, course_id: testCourseID, parse: true, 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 17ce0c4475..5c1c7f1c2f 100644 --- a/lms/djangoapps/teams/static/teams/js/views/teams_tab.js +++ b/lms/djangoapps/teams/static/teams/js/views/teams_tab.js @@ -103,7 +103,7 @@ teamEvents: this.teamEvents, course_id: this.context.courseID, username: this.context.userInfo.username, - per_page: 2, + perPage: 2, parse: true, url: this.context.myTeamsUrl } @@ -337,7 +337,7 @@ course_id: view.context.courseID, topic_id: topicID, url: view.context.teamsUrl, - per_page: 10 + perPage: 10 }); view.teamsCollection = collection; collection.getPage(1).then(function () { @@ -346,7 +346,7 @@ collection: collection, breadcrumbs: view.createBreadcrumbs(), showSortControls: true - }); + }); deferred.resolve(teamsView); }); });