mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 17:27:55 +08:00
FIX: In long topics, filtering button was not always showing in card
This commit is contained in:
parent
34ee3fb059
commit
e3eaa7fa75
@ -5,14 +5,16 @@ export default ObjectController.extend({
|
|||||||
visible: false,
|
visible: false,
|
||||||
user: null,
|
user: null,
|
||||||
username: null,
|
username: null,
|
||||||
participant: null,
|
|
||||||
avatar: null,
|
avatar: null,
|
||||||
userLoading: null,
|
userLoading: null,
|
||||||
cardTarget: null,
|
cardTarget: null,
|
||||||
post: null,
|
post: null,
|
||||||
|
|
||||||
|
// If inside a topic
|
||||||
|
topicPostCount: null,
|
||||||
|
|
||||||
postStream: Em.computed.alias('controllers.topic.postStream'),
|
postStream: Em.computed.alias('controllers.topic.postStream'),
|
||||||
enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2),
|
enoughPostsForFiltering: Em.computed.gte('topicPostCount', 2),
|
||||||
viewingTopic: Em.computed.match('controllers.application.currentPath', /^topic\./),
|
viewingTopic: Em.computed.match('controllers.application.currentPath', /^topic\./),
|
||||||
viewingAdmin: Em.computed.match('controllers.application.currentPath', /^admin\./),
|
viewingAdmin: Em.computed.match('controllers.application.currentPath', /^admin\./),
|
||||||
showFilter: Em.computed.and('viewingTopic', 'postStream.hasNoFilters', 'enoughPostsForFiltering'),
|
showFilter: Em.computed.and('viewingTopic', 'postStream.hasNoFilters', 'enoughPostsForFiltering'),
|
||||||
@ -28,14 +30,14 @@ export default ObjectController.extend({
|
|||||||
}.property('user.badge_count', 'user.featured_user_badges.@each'),
|
}.property('user.badge_count', 'user.featured_user_badges.@each'),
|
||||||
|
|
||||||
hasCardBadgeImage: function() {
|
hasCardBadgeImage: function() {
|
||||||
var img = this.get('user.card_badge.image');
|
const img = this.get('user.card_badge.image');
|
||||||
return img && img.indexOf('fa-') !== 0;
|
return img && img.indexOf('fa-') !== 0;
|
||||||
}.property('user.card_badge.image'),
|
}.property('user.card_badge.image'),
|
||||||
|
|
||||||
show: function(username, postId, target) {
|
show(username, postId, target) {
|
||||||
// XSS protection (should be encapsulated)
|
// XSS protection (should be encapsulated)
|
||||||
username = username.toString().replace(/[^A-Za-z0-9_]/g, "");
|
username = username.toString().replace(/[^A-Za-z0-9_]/g, "");
|
||||||
var url = "/users/" + username;
|
const url = "/users/" + username;
|
||||||
|
|
||||||
// Don't show on mobile
|
// Don't show on mobile
|
||||||
if (Discourse.Mobile.mobileView) {
|
if (Discourse.Mobile.mobileView) {
|
||||||
@ -43,7 +45,7 @@ export default ObjectController.extend({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUsername = this.get('username'),
|
const currentUsername = this.get('username'),
|
||||||
wasVisible = this.get('visible'),
|
wasVisible = this.get('visible'),
|
||||||
post = this.get('viewingTopic') && postId ? this.get('controllers.topic.postStream').findLoadedPost(postId) : null;
|
post = this.get('viewingTopic') && postId ? this.get('controllers.topic.postStream').findLoadedPost(postId) : null;
|
||||||
|
|
||||||
@ -60,20 +62,21 @@ export default ObjectController.extend({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('participant', null);
|
this.set('topicPostCount', null);
|
||||||
|
|
||||||
// Retrieve their participants info
|
|
||||||
var participants = this.get('controllers.topic.details.participants');
|
|
||||||
if (participants) {
|
|
||||||
this.set('participant', participants.findBy('username', username));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setProperties({ user: null, userLoading: username, cardTarget: target });
|
this.setProperties({ user: null, userLoading: username, cardTarget: target });
|
||||||
|
|
||||||
var self = this;
|
const args = { stats: false };
|
||||||
return Discourse.User.findByUsername(username, { stats: false }).then(function(user) {
|
args.include_post_count_for = this.get('controllers.topic.id');
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
return Discourse.User.findByUsername(username, args).then(function(user) {
|
||||||
|
|
||||||
|
if (user.topic_post_count) {
|
||||||
|
self.set('topicPostCount', user.topic_post_count[args.include_post_count_for]);
|
||||||
|
}
|
||||||
user = Discourse.User.create(user);
|
user = Discourse.User.create(user);
|
||||||
self.setProperties({ user: user, avatar: user, visible: true});
|
self.setProperties({ user, avatar: user, visible: true});
|
||||||
self.appEvents.trigger('usercard:shown');
|
self.appEvents.trigger('usercard:shown');
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
self.close();
|
self.close();
|
||||||
@ -83,19 +86,19 @@ export default ObjectController.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
close: function() {
|
close() {
|
||||||
this.setProperties({ visible: false, cardTarget: null });
|
this.setProperties({ visible: false, cardTarget: null });
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
togglePosts: function(user) {
|
togglePosts(user) {
|
||||||
var postStream = this.get('controllers.topic.postStream');
|
const postStream = this.get('controllers.topic.postStream');
|
||||||
postStream.toggleParticipant(user.get('username'));
|
postStream.toggleParticipant(user.get('username'));
|
||||||
this.close();
|
this.close();
|
||||||
},
|
},
|
||||||
|
|
||||||
cancelFilter: function() {
|
cancelFilter() {
|
||||||
var postStream = this.get('postStream');
|
const postStream = this.get('postStream');
|
||||||
postStream.cancelFilter();
|
postStream.cancelFilter();
|
||||||
postStream.refresh();
|
postStream.refresh();
|
||||||
this.close();
|
this.close();
|
||||||
|
@ -427,14 +427,9 @@ const User = Discourse.Model.extend({
|
|||||||
|
|
||||||
User.reopenClass(Discourse.Singleton, {
|
User.reopenClass(Discourse.Singleton, {
|
||||||
|
|
||||||
/**
|
// Find a `Discourse.User` for a given username.
|
||||||
Find a `Discourse.User` for a given username.
|
|
||||||
|
|
||||||
@method findByUsername
|
|
||||||
@returns {Promise} a promise that resolves to a `Discourse.User`
|
|
||||||
**/
|
|
||||||
findByUsername: function(username, options) {
|
findByUsername: function(username, options) {
|
||||||
var user = Discourse.User.create({username: username});
|
const user = Discourse.User.create({username: username});
|
||||||
return user.findDetails(options);
|
return user.findDetails(options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if showFilter}}
|
{{#if showFilter}}
|
||||||
<li><a class='btn' {{action "togglePosts" user}}>{{fa-icon "filter"}}{{i18n 'topic.filter_to' username=username post_count=participant.post_count}}</a></li>
|
<li><a class='btn' {{action "togglePosts" user}}>{{fa-icon "filter"}}{{i18n 'topic.filter_to' username=username post_count=topicPostCount}}</a></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if hasUserFilters}}
|
{{#if hasUserFilters}}
|
||||||
|
@ -34,6 +34,11 @@ class UsersController < ApplicationController
|
|||||||
if params[:stats].to_s == "false"
|
if params[:stats].to_s == "false"
|
||||||
user_serializer.omit_stats = true
|
user_serializer.omit_stats = true
|
||||||
end
|
end
|
||||||
|
topic_id = params[:include_post_count_for].to_i
|
||||||
|
if topic_id != 0
|
||||||
|
user_serializer.topic_post_count = {topic_id => Post.where(topic_id: topic_id, user_id: @user.id).count }
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
@restrict_fields = guardian.restrict_user_fields?(@user)
|
@restrict_fields = guardian.restrict_user_fields?(@user)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
class UserSerializer < BasicUserSerializer
|
class UserSerializer < BasicUserSerializer
|
||||||
|
|
||||||
attr_accessor :omit_stats
|
attr_accessor :omit_stats,
|
||||||
|
:topic_post_count
|
||||||
|
|
||||||
def self.staff_attributes(*attrs)
|
def self.staff_attributes(*attrs)
|
||||||
attributes(*attrs)
|
attributes(*attrs)
|
||||||
@ -62,7 +63,8 @@ class UserSerializer < BasicUserSerializer
|
|||||||
:has_title_badges,
|
:has_title_badges,
|
||||||
:edit_history_public,
|
:edit_history_public,
|
||||||
:custom_fields,
|
:custom_fields,
|
||||||
:user_fields
|
:user_fields,
|
||||||
|
:topic_post_count
|
||||||
|
|
||||||
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
||||||
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
|
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
|
||||||
@ -293,6 +295,10 @@ class UserSerializer < BasicUserSerializer
|
|||||||
user_fields.present?
|
user_fields.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def include_topic_post_count?
|
||||||
|
topic_post_count.present?
|
||||||
|
end
|
||||||
|
|
||||||
def custom_fields
|
def custom_fields
|
||||||
fields = nil
|
fields = nil
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user