Commit 9e7c93d9 by Peter Fogg

Merge pull request #9504 from edx/peter-fogg/sort-team-page

Allow sorting of teams in a topic
parents 1e430a76 2c774fd2
...@@ -20,6 +20,25 @@ TEAMS_HEADER_CSS = '.teams-header' ...@@ -20,6 +20,25 @@ TEAMS_HEADER_CSS = '.teams-header'
CREATE_TEAM_LINK_CSS = '.create-team' CREATE_TEAM_LINK_CSS = '.create-team'
class TeamCardsMixin(object):
"""Provides common operations on the team card component."""
@property
def team_cards(self):
"""Get all the team cards on the page."""
return self.q(css='.team-card')
@property
def team_names(self):
"""Return the names of each team on the page."""
return self.q(css='h3.card-title').map(lambda e: e.text).results
@property
def team_descriptions(self):
"""Return the names of each team on the page."""
return self.q(css='p.card-description').map(lambda e: e.text).results
class TeamsPage(CoursePage): class TeamsPage(CoursePage):
""" """
Teams page/tab. Teams page/tab.
...@@ -84,7 +103,7 @@ class TeamsPage(CoursePage): ...@@ -84,7 +103,7 @@ class TeamsPage(CoursePage):
self.q(css='a.nav-item').filter(text=topic)[0].click() self.q(css='a.nav-item').filter(text=topic)[0].click()
class MyTeamsPage(CoursePage, PaginatedUIMixin): class MyTeamsPage(CoursePage, PaginatedUIMixin, TeamCardsMixin):
""" """
The 'My Teams' tab of the Teams page. The 'My Teams' tab of the Teams page.
""" """
...@@ -98,11 +117,6 @@ class MyTeamsPage(CoursePage, PaginatedUIMixin): ...@@ -98,11 +117,6 @@ class MyTeamsPage(CoursePage, PaginatedUIMixin):
return False return False
return 'is-active' in button_classes[0] return 'is-active' in button_classes[0]
@property
def team_cards(self):
"""Get all the team cards on the page."""
return self.q(css='.team-card')
class BrowseTopicsPage(CoursePage, PaginatedUIMixin): class BrowseTopicsPage(CoursePage, PaginatedUIMixin):
""" """
...@@ -145,7 +159,7 @@ class BrowseTopicsPage(CoursePage, PaginatedUIMixin): ...@@ -145,7 +159,7 @@ class BrowseTopicsPage(CoursePage, PaginatedUIMixin):
self.wait_for_ajax() self.wait_for_ajax()
class BrowseTeamsPage(CoursePage, PaginatedUIMixin): class BrowseTeamsPage(CoursePage, PaginatedUIMixin, TeamCardsMixin):
""" """
The paginated UI for browsing teams within a Topic on the Teams The paginated UI for browsing teams within a Topic on the Teams
page. page.
...@@ -179,9 +193,13 @@ class BrowseTeamsPage(CoursePage, PaginatedUIMixin): ...@@ -179,9 +193,13 @@ class BrowseTeamsPage(CoursePage, PaginatedUIMixin):
return self.q(css=TEAMS_HEADER_CSS + ' .page-description')[0].text return self.q(css=TEAMS_HEADER_CSS + ' .page-description')[0].text
@property @property
def team_cards(self): def sort_order(self):
"""Get all the team cards on the page.""" """Return the current sort order on the page."""
return self.q(css='.team-card') return self.q(
css='#paging-header-select option'
).filter(
lambda e: e.is_selected()
).results[0].text.strip()
def click_create_team_link(self): def click_create_team_link(self):
""" Click on create team link.""" """ Click on create team link."""
...@@ -204,6 +222,13 @@ class BrowseTeamsPage(CoursePage, PaginatedUIMixin): ...@@ -204,6 +222,13 @@ class BrowseTeamsPage(CoursePage, PaginatedUIMixin):
query.first.click() query.first.click()
self.wait_for_ajax() self.wait_for_ajax()
def sort_teams_by(self, sort_order):
"""Sort the list of teams by the given `sort_order`."""
self.q(
css='#paging-header-select option[value={sort_order}]'.format(sort_order=sort_order)
).click()
self.wait_for_ajax()
class CreateOrEditTeamPage(CoursePage, FieldsMixin): class CreateOrEditTeamPage(CoursePage, FieldsMixin):
""" """
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
define(['teams/js/collections/base', 'teams/js/models/team', 'gettext'], define(['teams/js/collections/base', 'teams/js/models/team', 'gettext'],
function(BaseCollection, TeamModel, gettext) { function(BaseCollection, TeamModel, gettext) {
var TeamCollection = BaseCollection.extend({ var TeamCollection = BaseCollection.extend({
sortField: 'last_activity_at',
initialize: function(teams, options) { initialize: function(teams, options) {
var self = this; var self = this;
BaseCollection.prototype.initialize.call(this, options); BaseCollection.prototype.initialize.call(this, options);
...@@ -12,14 +14,14 @@ ...@@ -12,14 +14,14 @@
topic_id: this.topic_id = options.topic_id, topic_id: this.topic_id = options.topic_id,
expand: 'user', expand: 'user',
course_id: function () { return encodeURIComponent(self.course_id); }, course_id: function () { return encodeURIComponent(self.course_id); },
order_by: function () { return 'name'; } // TODO surface sort order in UI order_by: function () { return this.sortField; }
}, },
BaseCollection.prototype.server_api BaseCollection.prototype.server_api
); );
delete this.server_api.sort_order; // Sort order is not specified for the Team API delete this.server_api.sort_order; // Sort order is not specified for the Team API
this.registerSortableField('name', gettext('name')); this.registerSortableField('last_activity_at', gettext('last activity'));
this.registerSortableField('open_slots', gettext('open_slots')); this.registerSortableField('open_slots', gettext('open slots'));
}, },
model: TeamModel model: TeamModel
......
...@@ -10,10 +10,6 @@ ...@@ -10,10 +10,6 @@
var TeamsView = PaginatedView.extend({ var TeamsView = PaginatedView.extend({
type: 'teams', type: 'teams',
events: {
'click button.action': '' // entry point for team creation
},
srInfo: { srInfo: {
id: "heading-browse-teams", id: "heading-browse-teams",
text: gettext('All teams') text: gettext('All teams')
......
;(function (define) { ;(function (define) {
'use strict'; 'use strict';
define([
define(['backbone', 'gettext', 'teams/js/views/teams', 'backbone',
'text!teams/templates/team-actions.underscore'], 'gettext',
function (Backbone, gettext, TeamsView, teamActionsTemplate) { 'teams/js/views/teams',
'common/js/components/views/paging_header',
'text!teams/templates/team-actions.underscore'
], function (Backbone, gettext, TeamsView, PagingHeader, teamActionsTemplate) {
var TopicTeamsView = TeamsView.extend({ var TopicTeamsView = TeamsView.extend({
events: { events: {
'click a.browse-teams': 'browseTeams', 'click a.browse-teams': 'browseTeams',
...@@ -54,6 +57,14 @@ ...@@ -54,6 +57,14 @@
showCreateTeamForm: function (event) { showCreateTeamForm: function (event) {
event.preventDefault(); event.preventDefault();
Backbone.history.navigate('topics/' + this.teamParams.topicID + '/create-team', {trigger: true}); Backbone.history.navigate('topics/' + this.teamParams.topicID + '/create-team', {trigger: true});
},
createHeaderView: function () {
return new PagingHeader({
collection: this.options.collection,
srInfo: this.srInfo,
showSortControls: true
});
} }
}); });
......
...@@ -164,6 +164,7 @@ ...@@ -164,6 +164,7 @@
label { // override label { // override
color: inherit; color: inherit;
font-size: inherit; font-size: inherit;
cursor: auto;
} }
.listing-sort-select { .listing-sort-select {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment