FIX: Members should be ordered by username.

This commit is contained in:
Guo Xiang Tan 2016-12-08 14:26:50 +08:00
parent ae047c39a4
commit b9b4b0c175
5 changed files with 19 additions and 19 deletions

View File

@ -4,21 +4,21 @@ import { bufferedRender } from 'discourse-common/lib/buffered-render';
export default Ember.Component.extend(bufferedRender({
tagName: 'th',
classNames: ['sortable'],
rerenderTriggers: ['order', 'asc'],
rerenderTriggers: ['order', 'desc'],
buildBuffer(buffer) {
buffer.push(I18n.t(this.get('i18nKey')));
if (this.get('field') === this.get('order')) {
buffer.push(iconHTML(this.get('asc') ? 'chevron-up' : 'chevron-down'));
buffer.push(iconHTML(this.get('desc') ? 'chevron-down' : 'chevron-up'));
}
},
click() {
if (this.get('order') === this.field) {
this.set('asc', this.get('asc') ? null : true);
this.set('desc', this.get('desc') ? null : true);
} else {
this.setProperties({ order: this.field, asc: null });
this.setProperties({ order: this.field, desc: null });
}
}
}));

View File

@ -3,18 +3,18 @@ import Group from 'discourse/models/group';
import { observes } from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend({
queryParams: ['order', 'asc'],
order: 'last_posted_at',
asc: null,
queryParams: ['order', 'desc'],
order: '',
desc: null,
loading: false,
limit: null,
offset: null,
isOwner: Ember.computed.alias('model.is_group_owner'),
@observes('order', 'asc')
@observes('order', 'desc')
refreshMembers() {
this.get('model') &&
this.get('model').findMembers({ order: this.get('order'), asc: this.get('asc') });
this.get('model').findMembers({ order: this.get('order'), desc: this.get('desc') });
},
actions: {
@ -39,7 +39,7 @@ export default Ember.Controller.extend({
this.get("model.name"),
this.get("model.members.length"),
this.get("limit"),
{ order: this.get('order'), asc: this.get('asc') }
{ order: this.get('order'), desc: this.get('desc') }
).then(result => {
this.get("model.members").addObjects(result.members.map(member => Discourse.User.create(member)));
this.setProperties({

View File

@ -9,9 +9,9 @@
{{#load-more selector=".group-members tr" action="loadMore"}}
<table class='group-members'>
<thead>
<th></th>
{{group-index-toggle order=order asc=asc field='last_posted_at' i18nKey='last_post'}}
{{group-index-toggle order=order asc=asc field='last_seen_at' i18nKey='last_seen'}}
{{group-index-toggle order=order desc=desc field='username_lower' i18nKey='username'}}
{{group-index-toggle order=order desc=desc field='last_posted_at' i18nKey='last_post'}}
{{group-index-toggle order=order desc=desc field='last_seen_at' i18nKey='last_seen'}}
<th></th>
</thead>

View File

@ -74,24 +74,24 @@ class GroupsController < ApplicationController
limit = (params[:limit] || 20).to_i
offset = params[:offset].to_i
dir = (params[:desc] && !params[:desc].blank?) ? 'DESC' : 'ASC'
order = {}
if params[:order] && %w{last_posted_at last_seen_at}.include?(params[:order])
order.merge!({ params[:order] => params[:asc].blank? ? 'ASC' : 'DESC' })
order.merge!(params[:order] => dir)
end
total = group.users.count
members = group.users
.order('NOT group_users.owner')
.order(order)
.order(:username_lower)
.order(:username_lower => dir)
.limit(limit)
.offset(offset)
owners = group.users
.order(order)
.order(:username_lower)
.order(:username_lower => dir)
.where('group_users.owner')
render json: {

View File

@ -110,7 +110,7 @@ describe "Groups" do
let(:group) { Fabricate(:group, users: [user1, user2]) }
it "should allow members to be sorted by" do
xhr :get, "/groups/#{group.name}/members", order: 'last_seen_at', asc: true
xhr :get, "/groups/#{group.name}/members", order: 'last_seen_at', desc: true
expect(response).to be_success
@ -126,7 +126,7 @@ describe "Groups" do
expect(members.map { |m| m["id"] }).to eq([user2.id, user1.id])
xhr :get, "/groups/#{group.name}/members", order: 'last_posted_at', asc: true
xhr :get, "/groups/#{group.name}/members", order: 'last_posted_at', desc: true
expect(response).to be_success