mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 19:30:23 -06:00
Merge pull request #2617 from techAPJ/patch-2
FEATURE: dynamically load more invites
This commit is contained in:
commit
06c681b0de
@ -10,6 +10,8 @@ export default Ember.ObjectController.extend({
|
|||||||
user: null,
|
user: null,
|
||||||
model: null,
|
model: null,
|
||||||
totalInvites: null,
|
totalInvites: null,
|
||||||
|
canLoadMore: true,
|
||||||
|
invitesLoading: false,
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
this._super();
|
this._super();
|
||||||
@ -30,13 +32,6 @@ export default Ember.ObjectController.extend({
|
|||||||
});
|
});
|
||||||
}, 250).observes('searchTerm'),
|
}, 250).observes('searchTerm'),
|
||||||
|
|
||||||
/**
|
|
||||||
The maximum amount of invites that will be displayed in the view
|
|
||||||
|
|
||||||
@property maxInvites
|
|
||||||
**/
|
|
||||||
maxInvites: Discourse.computed.setting('invites_shown'),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Can the currently logged in user invite users to the site
|
Can the currently logged in user invite users to the site
|
||||||
|
|
||||||
@ -64,15 +59,6 @@ export default Ember.ObjectController.extend({
|
|||||||
return this.get('totalInvites') > 9;
|
return this.get('totalInvites') > 9;
|
||||||
}.property('totalInvites'),
|
}.property('totalInvites'),
|
||||||
|
|
||||||
/**
|
|
||||||
Were the results limited by our `maxInvites`
|
|
||||||
|
|
||||||
@property truncated
|
|
||||||
**/
|
|
||||||
truncated: function() {
|
|
||||||
return this.get('invites.length') === Discourse.SiteSettings.invites_shown;
|
|
||||||
}.property('invites.length'),
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,6 +70,22 @@ export default Ember.ObjectController.extend({
|
|||||||
rescind: function(invite) {
|
rescind: function(invite) {
|
||||||
invite.rescind();
|
invite.rescind();
|
||||||
return false;
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
loadMore: function() {
|
||||||
|
var self = this;
|
||||||
|
var model = self.get('model');
|
||||||
|
|
||||||
|
if(self.get('canLoadMore')) {
|
||||||
|
self.set('invitesLoading', true);
|
||||||
|
Discourse.Invite.findInvitedBy(self.get('user'), self.get('searchTerm'), model.invites.length).then(function(invite_model) {
|
||||||
|
self.set('invitesLoading', false);
|
||||||
|
model.invites.pushObjects(invite_model.invites);
|
||||||
|
if(invite_model.invites.length === 0 || invite_model.invites.length < Discourse.SiteSettings.invites_per_page) {
|
||||||
|
self.set('canLoadMore', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +29,12 @@ Discourse.Invite.reopenClass({
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
findInvitedBy: function(user, filter) {
|
findInvitedBy: function(user, filter, offset) {
|
||||||
if (!user) { return Em.RSVP.resolve(); }
|
if (!user) { return Em.RSVP.resolve(); }
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
if (!Em.isNone(filter)) { data.filter = filter; }
|
if (!Em.isNone(filter)) { data.filter = filter; }
|
||||||
|
data.offset = offset || 0;
|
||||||
|
|
||||||
return Discourse.ajax("/users/" + user.get('username_lower') + "/invited.json", {data: data}).then(function (result) {
|
return Discourse.ajax("/users/" + user.get('username_lower') + "/invited.json", {data: data}).then(function (result) {
|
||||||
result.invites = result.invites.map(function (i) {
|
result.invites = result.invites.map(function (i) {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if model.invites}}
|
{{#if model.invites}}
|
||||||
<table class='table'>
|
<table class='table invite-list'>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{i18n user.invited.user}}</th>
|
<th>{{i18n user.invited.user}}</th>
|
||||||
<th>{{i18n user.invited.redeemed_at}}</th>
|
<th>{{i18n user.invited.redeemed_at}}</th>
|
||||||
@ -62,9 +62,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</table>
|
</table>
|
||||||
|
{{#if invitesLoading}}
|
||||||
{{#if truncated}}
|
<div class='spinner'>{{i18n loading}}</div>
|
||||||
<p>{{i18n user.invited.truncated count=maxInvites}}</p>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
export default Ember.View.extend({
|
export default Ember.View.extend(Discourse.LoadMore, {
|
||||||
|
classNames: ['paginated-topics-list'],
|
||||||
|
eyelineSelector: '.paginated-topics-list .invite-list tr',
|
||||||
templateName: 'user/invited'
|
templateName: 'user/invited'
|
||||||
});
|
});
|
||||||
|
@ -94,11 +94,12 @@ class UsersController < ApplicationController
|
|||||||
|
|
||||||
def invited
|
def invited
|
||||||
inviter = fetch_user_from_params
|
inviter = fetch_user_from_params
|
||||||
|
offset = params[:offset].to_i || 0
|
||||||
|
|
||||||
invites = if guardian.can_see_invite_details?(inviter)
|
invites = if guardian.can_see_invite_details?(inviter)
|
||||||
Invite.find_all_invites_from(inviter)
|
Invite.find_all_invites_from(inviter, offset)
|
||||||
else
|
else
|
||||||
Invite.find_redeemed_invites_from(inviter)
|
Invite.find_redeemed_invites_from(inviter, offset)
|
||||||
end
|
end
|
||||||
|
|
||||||
invites = invites.filter_by(params[:filter])
|
invites = invites.filter_by(params[:filter])
|
||||||
|
@ -126,18 +126,19 @@ class Invite < ActiveRecord::Base
|
|||||||
group_ids
|
group_ids
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_all_invites_from(inviter)
|
def self.find_all_invites_from(inviter, offset=0)
|
||||||
Invite.where(invited_by_id: inviter.id)
|
Invite.where(invited_by_id: inviter.id)
|
||||||
.includes(:user => :user_stat)
|
.includes(:user => :user_stat)
|
||||||
.order('CASE WHEN invites.user_id IS NOT NULL THEN 0 ELSE 1 END',
|
.order('CASE WHEN invites.user_id IS NOT NULL THEN 0 ELSE 1 END',
|
||||||
'user_stats.time_read DESC',
|
'user_stats.time_read DESC',
|
||||||
'invites.redeemed_at DESC')
|
'invites.redeemed_at DESC')
|
||||||
.limit(SiteSetting.invites_shown)
|
.limit(SiteSetting.invites_per_page)
|
||||||
|
.offset(offset)
|
||||||
.references('user_stats')
|
.references('user_stats')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_redeemed_invites_from(inviter)
|
def self.find_redeemed_invites_from(inviter, offset=0)
|
||||||
find_all_invites_from(inviter).where('invites.user_id IS NOT NULL')
|
find_all_invites_from(inviter, offset).where('invites.user_id IS NOT NULL')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.filter_by(email_or_username)
|
def self.filter_by(email_or_username)
|
||||||
|
@ -951,7 +951,7 @@ en:
|
|||||||
|
|
||||||
enable_names: "Allow showing user full names. Disable to hide full names."
|
enable_names: "Allow showing user full names. Disable to hide full names."
|
||||||
display_name_on_posts: "Show a user's full name on their posts in addition to their @username."
|
display_name_on_posts: "Show a user's full name on their posts in addition to their @username."
|
||||||
invites_shown: "Maximum invites shown on the user page."
|
invites_per_page: "Default invites shown on the user page."
|
||||||
short_progress_text_threshold: "After the number of posts in a topic goes above this number, the progress bar will only show the current post number. If you change the progress bar's width, you may need to change this value."
|
short_progress_text_threshold: "After the number of posts in a topic goes above this number, the progress bar will only show the current post number. If you change the progress bar's width, you may need to change this value."
|
||||||
default_code_lang: "Default programming language syntax highlighting applied to GitHub code blocks (lang-auto, ruby, python etc.)"
|
default_code_lang: "Default programming language syntax highlighting applied to GitHub code blocks (lang-auto, ruby, python etc.)"
|
||||||
warn_reviving_old_topic_age: "When someone starts replying to a topic where the last reply is older than this many days, a warning will be displayed. Disable by setting to 0."
|
warn_reviving_old_topic_age: "When someone starts replying to a topic where the last reply is older than this many days, a warning will be displayed. Disable by setting to 0."
|
||||||
|
@ -257,9 +257,9 @@ users:
|
|||||||
default: true
|
default: true
|
||||||
invite_expiry_days: 30
|
invite_expiry_days: 30
|
||||||
invite_passthrough_hours: 0
|
invite_passthrough_hours: 0
|
||||||
invites_shown:
|
invites_per_page:
|
||||||
client: true
|
client: true
|
||||||
default: 30
|
default: 40
|
||||||
delete_user_max_post_age:
|
delete_user_max_post_age:
|
||||||
client: true
|
client: true
|
||||||
default: 60
|
default: 60
|
||||||
|
Loading…
Reference in New Issue
Block a user