mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Allow truncated group posts to be expanded
This commit is contained in:
parent
32756060bb
commit
287cb4bfc5
@ -0,0 +1,19 @@
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
tagName: '',
|
||||
|
||||
actions: {
|
||||
expandItem() {
|
||||
const item = this.get('item');
|
||||
const topicId = item.get('topic_id');
|
||||
const postNumber = item.get('post_number');
|
||||
|
||||
return ajax(`/posts/by_number/${topicId}/${postNumber}.json`).then(result => {
|
||||
item.set('truncated', false);
|
||||
item.set('excerpt', result.cooked);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,22 +1,8 @@
|
||||
import { propertyEqual } from 'discourse/lib/computed';
|
||||
import { actionDescription } from "discourse/components/small-action";
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNameBindings: [":item", "item.hidden", "item.deleted:deleted", "moderatorAction"],
|
||||
moderatorAction: propertyEqual("item.post_type", "site.post_types.moderator_action"),
|
||||
actionDescription: actionDescription("item.action_code", "item.created_at", "item.username"),
|
||||
|
||||
actions: {
|
||||
expandItem() {
|
||||
const item = this.get('item');
|
||||
const topicId = item.get('topic_id');
|
||||
const postNumber = item.get('post_number');
|
||||
|
||||
return ajax(`/posts/by_number/${topicId}/${postNumber}.json`).then(result => {
|
||||
item.set('truncated', false);
|
||||
item.set('excerpt', result.cooked);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,5 @@
|
||||
{{#if item.truncated}}
|
||||
<a class="expand-item" href {{action "expandItem"}} title={{i18n "post.expand_collapse"}}>
|
||||
{{fa-icon "chevron-down"}}
|
||||
</a>
|
||||
{{/if}}
|
@ -2,6 +2,7 @@
|
||||
<div class='clearfix info'>
|
||||
<a href="{{unbound post.user.userUrl}}" data-user-card="{{unbound post.user.username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar post.user imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
|
||||
<span class='time'>{{format-date post.created_at leaveAgo="true"}}</span>
|
||||
{{expand-post item=post}}
|
||||
<span class="title">
|
||||
<a href={{post.url}}>{{{post.topic.fancyTitle}}}</a>
|
||||
</span>
|
||||
@ -13,6 +14,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<p class='excerpt'>
|
||||
{{{unbound post.excerpt}}}
|
||||
{{{post.excerpt}}}
|
||||
</p>
|
||||
</div>
|
||||
|
@ -1,11 +1,7 @@
|
||||
<div class='clearfix info'>
|
||||
<a href={{item.userUrl}} data-user-card={{item.username}} class='avatar-link'><div class='avatar-wrapper'>{{avatar item imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
|
||||
<span class='time'>{{format-date item.created_at}}</span>
|
||||
{{#if item.truncated}}
|
||||
<a class="expand-item" href {{action "expandItem"}} title={{i18n "post.expand_collapse"}}>
|
||||
{{fa-icon "chevron-down"}}
|
||||
</a>
|
||||
{{/if}}
|
||||
{{expand-post item=item}}
|
||||
{{topic-status topic=item disableActions=true}}
|
||||
<span class="title">
|
||||
<a href={{item.postUrl}}>{{{item.title}}}</a>
|
||||
|
@ -1,4 +1,7 @@
|
||||
require_relative 'post_item_excerpt'
|
||||
|
||||
class AdminUserActionSerializer < ApplicationSerializer
|
||||
include PostItemExcerpt
|
||||
|
||||
attributes(
|
||||
:id,
|
||||
@ -13,7 +16,6 @@ class AdminUserActionSerializer < ApplicationSerializer
|
||||
:title,
|
||||
:category_id,
|
||||
:truncated,
|
||||
:excerpt,
|
||||
:hidden,
|
||||
:moderator_action,
|
||||
:deleted,
|
||||
@ -23,18 +25,10 @@ class AdminUserActionSerializer < ApplicationSerializer
|
||||
:action_type
|
||||
)
|
||||
|
||||
def truncated
|
||||
true
|
||||
end
|
||||
|
||||
def post_id
|
||||
object.id
|
||||
end
|
||||
|
||||
def include_truncated?
|
||||
object.excerpt != object.cooked
|
||||
end
|
||||
|
||||
def deleted
|
||||
deleted_at.present?
|
||||
end
|
||||
|
@ -1,10 +1,15 @@
|
||||
require_relative 'post_item_excerpt'
|
||||
|
||||
class GroupPostSerializer < ApplicationSerializer
|
||||
include PostItemExcerpt
|
||||
|
||||
attributes :id,
|
||||
:excerpt,
|
||||
:created_at,
|
||||
:title,
|
||||
:url,
|
||||
:category
|
||||
:category,
|
||||
:post_number,
|
||||
:topic_id
|
||||
|
||||
has_one :user, serializer: GroupPostUserSerializer, embed: :object
|
||||
has_one :topic, serializer: BasicTopicSerializer, embed: :object
|
||||
|
25
app/serializers/post_item_excerpt.rb
Normal file
25
app/serializers/post_item_excerpt.rb
Normal file
@ -0,0 +1,25 @@
|
||||
module PostItemExcerpt
|
||||
|
||||
def self.included(base)
|
||||
base.attributes(:excerpt, :truncated)
|
||||
end
|
||||
|
||||
def cooked
|
||||
@cooked ||= object.cooked || PrettyText.cook(object.raw)
|
||||
end
|
||||
|
||||
def excerpt
|
||||
return nil unless cooked
|
||||
@excerpt ||= PrettyText.excerpt(cooked, 300, keep_emoji_images: true)
|
||||
end
|
||||
|
||||
def truncated
|
||||
true
|
||||
end
|
||||
|
||||
def include_truncated?
|
||||
cooked.length > 300
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,9 +1,10 @@
|
||||
require_relative 'post_item_excerpt'
|
||||
|
||||
class UserActionSerializer < ApplicationSerializer
|
||||
include PostItemExcerpt
|
||||
|
||||
attributes :action_type,
|
||||
:created_at,
|
||||
:excerpt,
|
||||
:truncated,
|
||||
:avatar_template,
|
||||
:acting_avatar_template,
|
||||
:slug,
|
||||
@ -30,22 +31,6 @@ class UserActionSerializer < ApplicationSerializer
|
||||
:closed,
|
||||
:archived
|
||||
|
||||
def cooked
|
||||
@cooked ||= object.cooked || PrettyText.cook(object.raw)
|
||||
end
|
||||
|
||||
def excerpt
|
||||
return nil unless cooked
|
||||
@excerpt ||= PrettyText.excerpt(cooked, 300, keep_emoji_images: true)
|
||||
end
|
||||
|
||||
def truncated
|
||||
true
|
||||
end
|
||||
|
||||
def include_truncated?
|
||||
cooked.length > 300
|
||||
end
|
||||
|
||||
def avatar_template
|
||||
User.avatar_template(object.username, object.uploaded_avatar_id)
|
||||
|
Loading…
Reference in New Issue
Block a user