mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
FIX: group member pages only showing first 50 members alphabetically
This commit is contained in:
parent
e74b9ee5da
commit
8fd69fd3cf
@ -0,0 +1,26 @@
|
|||||||
|
export default Ember.ObjectController.extend({
|
||||||
|
loading: false,
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
loadMore() {
|
||||||
|
if (this.get("loading")) { return; }
|
||||||
|
// we've reached the end
|
||||||
|
if (this.get("members.length") >= this.get("user_count")) { return; }
|
||||||
|
|
||||||
|
this.set("loading", true);
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
Discourse.Group.loadMembers(this.get("name"), this.get("members.length"), this.get("limit")).then(function (result) {
|
||||||
|
self.get("members").addObjects(result.members.map(member => Discourse.User.create(member)));
|
||||||
|
self.setProperties({
|
||||||
|
loading: false,
|
||||||
|
user_count: result.meta.total,
|
||||||
|
limit: result.meta.limit,
|
||||||
|
offset: Math.min(result.meta.offset + result.meta.limit, result.meta.total)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -1,12 +1,4 @@
|
|||||||
/**
|
const Group = Discourse.Model.extend({
|
||||||
The data model for a Group
|
|
||||||
|
|
||||||
@class Group
|
|
||||||
@extends Discourse.Model
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.Group = Discourse.Model.extend({
|
|
||||||
limit: 50,
|
limit: 50,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
user_count: 0,
|
user_count: 0,
|
||||||
@ -26,28 +18,22 @@ Discourse.Group = Discourse.Model.extend({
|
|||||||
if (c > 0) { return c; }
|
if (c > 0) { return c; }
|
||||||
}.property('user_count'),
|
}.property('user_count'),
|
||||||
|
|
||||||
findMembers: function() {
|
findMembers() {
|
||||||
if (Em.isEmpty(this.get('name'))) { return ; }
|
if (Em.isEmpty(this.get('name'))) { return ; }
|
||||||
|
|
||||||
var self = this,
|
const self = this, offset = Math.min(this.get("user_count"), Math.max(this.get("offset"), 0));
|
||||||
offset = Math.min(this.get("user_count"), Math.max(this.get("offset"), 0));
|
|
||||||
|
|
||||||
return Discourse.ajax('/groups/' + this.get('name') + '/members.json', {
|
return Discourse.Group.loadMembers(this.get("name"), offset, this.get("limit")).then(function (result) {
|
||||||
data: {
|
|
||||||
limit: this.get("limit"),
|
|
||||||
offset: offset
|
|
||||||
}
|
|
||||||
}).then(function(result) {
|
|
||||||
self.setProperties({
|
self.setProperties({
|
||||||
user_count: result.meta.total,
|
user_count: result.meta.total,
|
||||||
limit: result.meta.limit,
|
limit: result.meta.limit,
|
||||||
offset: result.meta.offset,
|
offset: result.meta.offset,
|
||||||
members: result.members.map(function(member) { return Discourse.User.create(member); })
|
members: result.members.map(member => Discourse.User.create(member))
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
removeMember: function(member) {
|
removeMember(member) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Discourse.ajax('/admin/groups/' + this.get('id') + '/members.json', {
|
return Discourse.ajax('/admin/groups/' + this.get('id') + '/members.json', {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
@ -58,7 +44,7 @@ Discourse.Group = Discourse.Model.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
addMembers: function(usernames) {
|
addMembers(usernames) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Discourse.ajax('/admin/groups/' + this.get('id') + '/members.json', {
|
return Discourse.ajax('/admin/groups/' + this.get('id') + '/members.json', {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
@ -69,7 +55,7 @@ Discourse.Group = Discourse.Model.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
asJSON: function() {
|
asJSON() {
|
||||||
return {
|
return {
|
||||||
name: this.get('name'),
|
name: this.get('name'),
|
||||||
alias_level: this.get('alias_level'),
|
alias_level: this.get('alias_level'),
|
||||||
@ -79,23 +65,23 @@ Discourse.Group = Discourse.Model.extend({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
create: function(){
|
create() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Discourse.ajax("/admin/groups", { type: "POST", data: this.asJSON() }).then(function(resp) {
|
return Discourse.ajax("/admin/groups", { type: "POST", data: this.asJSON() }).then(function(resp) {
|
||||||
self.set('id', resp.basic_group.id);
|
self.set('id', resp.basic_group.id);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
save: function(){
|
save() {
|
||||||
return Discourse.ajax("/admin/groups/" + this.get('id'), { type: "PUT", data: this.asJSON() });
|
return Discourse.ajax("/admin/groups/" + this.get('id'), { type: "PUT", data: this.asJSON() });
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function(){
|
destroy() {
|
||||||
if (!this.get('id')) { return; }
|
if (!this.get('id')) { return; }
|
||||||
return Discourse.ajax("/admin/groups/" + this.get('id'), { type: "DELETE" });
|
return Discourse.ajax("/admin/groups/" + this.get('id'), { type: "DELETE" });
|
||||||
},
|
},
|
||||||
|
|
||||||
findPosts: function(opts) {
|
findPosts(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
@ -110,22 +96,29 @@ Discourse.Group = Discourse.Model.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.Group.reopenClass({
|
Group.reopenClass({
|
||||||
findAll: function(opts){
|
findAll(opts) {
|
||||||
return Discourse.ajax("/admin/groups.json", { data: opts }).then(function (groups){
|
return Discourse.ajax("/admin/groups.json", { data: opts }).then(function (groups){
|
||||||
return groups.map(function(g) { return Discourse.Group.create(g); });
|
return groups.map(g => Discourse.Group.create(g));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
findGroupCounts: function(name) {
|
findGroupCounts(name) {
|
||||||
return Discourse.ajax("/groups/" + name + "/counts.json").then(function (result) {
|
return Discourse.ajax("/groups/" + name + "/counts.json").then(result => Em.Object.create(result.counts));
|
||||||
return Em.Object.create(result.counts);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
find: function(name) {
|
find(name) {
|
||||||
return Discourse.ajax("/groups/" + name + ".json").then(function (result) {
|
return Discourse.ajax("/groups/" + name + ".json").then(result => Discourse.Group.create(result.basic_group));
|
||||||
return Discourse.Group.create(result.basic_group);
|
},
|
||||||
|
|
||||||
|
loadMembers(name, offset, limit) {
|
||||||
|
return Discourse.ajax('/groups/' + name + '/members.json', {
|
||||||
|
data: {
|
||||||
|
limit: limit || 50,
|
||||||
|
offset: offset || 0
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default Group;
|
@ -1,11 +1,11 @@
|
|||||||
import ShowFooter from "discourse/mixins/show-footer";
|
import ShowFooter from "discourse/mixins/show-footer";
|
||||||
|
|
||||||
export default Discourse.Route.extend(ShowFooter, {
|
export default Discourse.Route.extend(ShowFooter, {
|
||||||
model: function() {
|
model() {
|
||||||
return this.modelFor('group');
|
return this.modelFor('group');
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController(controller, model) {
|
||||||
this.controllerFor('group').set('showing', 'members');
|
this.controllerFor('group').set('showing', 'members');
|
||||||
controller.set("model", model);
|
controller.set("model", model);
|
||||||
model.findMembers();
|
model.findMembers();
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
import LoadMore from "discourse/mixins/load-more";
|
||||||
|
|
||||||
|
export default Discourse.View.extend(Discourse.ScrollTop, LoadMore, {
|
||||||
|
eyelineSelector: '.group-members tr',
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user