mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Make embedded comments look nicer
This commit is contained in:
parent
fd36fa1c2f
commit
1ffcf39448
10 changed files with 69 additions and 22 deletions
|
@ -23,6 +23,7 @@ article.post {
|
|||
color: #4a6b82;
|
||||
font-size: 13px;
|
||||
margin: 0;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,11 +37,27 @@ article.post {
|
|||
}
|
||||
}
|
||||
|
||||
.post-replies {
|
||||
background-color: #eee;
|
||||
padding: 5px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.in-reply-to {
|
||||
font-size: 13px;
|
||||
margin-top: 4px;
|
||||
display: inline-block;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.replies {
|
||||
font-size: 15px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
header {
|
||||
padding: 10px 10px 20px 10px;
|
||||
|
||||
font-size: 18px;
|
||||
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ class EmbedController < ApplicationController
|
|||
|
||||
layout 'embed'
|
||||
|
||||
def best
|
||||
def comments
|
||||
embed_url = params.require(:embed_url)
|
||||
topic_id = TopicEmbed.topic_id_for_embed(embed_url)
|
||||
|
||||
if topic_id
|
||||
@topic_view = TopicView.new(topic_id, current_user, {best: 5})
|
||||
@topic_view = TopicView.new(topic_id, current_user, limit: SiteSetting.embed_post_limit, exclude_first: true)
|
||||
@second_post_url = "#{@topic_view.topic.url}/2" if @topic_view
|
||||
else
|
||||
Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url)
|
||||
|
|
|
@ -218,6 +218,13 @@ class Post < ActiveRecord::Base
|
|||
(quote_count == 0) && (reply_to_post_number.present?)
|
||||
end
|
||||
|
||||
def reply_to_post
|
||||
return if reply_to_post_number.blank?
|
||||
@reply_to_post ||= Post.where("topic_id = :topic_id AND post_number = :post_number",
|
||||
topic_id: topic_id,
|
||||
post_number: reply_to_post_number).first
|
||||
end
|
||||
|
||||
def reply_notification_target
|
||||
return if reply_to_post_number.blank?
|
||||
Post.where("topic_id = :topic_id AND post_number = :post_number AND user_id <> :user_id",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<header>
|
||||
<%- if @topic_view.posts.present? %>
|
||||
<%= link_to(I18n.t('embed.title'), @second_post_url, class: 'button', target: '_blank') %>
|
||||
<%= link_to(I18n.t('embed.continue'), @second_post_url, class: 'button', target: '_blank') %>
|
||||
<span class='replies'><%= I18n.t('embed.replies', count: @topic_view.topic.posts_count) %></span>
|
||||
|
||||
<%- else %>
|
||||
<%= link_to(I18n.t('embed.start_discussion'), @topic_view.topic.url, class: 'button', target: '_blank') %>
|
||||
<%- end if %>
|
||||
|
@ -12,17 +14,29 @@
|
|||
<%- @topic_view.posts.each do |post| %>
|
||||
<article class='post'>
|
||||
<%= link_to post.created_at.strftime("%e %b %Y"), post.url, class: 'post-date', target: "_blank" %>
|
||||
<%- if post.reply_to_post.present? %>
|
||||
<%= link_to I18n.t('embed.in_reply_to', username: post.reply_to_post.username), post.reply_to_post.url, class: 'in-reply-to', target: "_blank" %>
|
||||
<%- end %>
|
||||
|
||||
<div class='author'>
|
||||
<img src='<%= post.user.small_avatar_url %>'>
|
||||
<h3><%= post.user.username %></h3>
|
||||
<h3 class='username'><%= post.user.username %></h3>
|
||||
</div>
|
||||
<div class='cooked'><%= raw post.cooked %></div>
|
||||
<div class='cooked'>
|
||||
<%= raw post.cooked %>
|
||||
|
||||
<%- if post.reply_count > 0 %>
|
||||
<%= link_to I18n.t('embed.replies', count: post.reply_count), post.url, class: 'post-replies', target: "_blank" %>
|
||||
<%- end %>
|
||||
</div>
|
||||
|
||||
<div style='clear: both'></div>
|
||||
</article>
|
||||
<%- end %>
|
||||
|
||||
<footer>
|
||||
<%= link_to(I18n.t('embed.continue'), @second_post_url, class: 'button', target: '_blank') %>
|
||||
<span class='replies'><%= I18n.t('embed.replies', count: @topic_view.topic.posts_count) %></span>
|
||||
<%= link_to(image_tag(SiteSetting.logo_url, class: 'logo'), Discourse.base_url, target: '_blank') %>
|
||||
</footer>
|
||||
|
|
@ -30,12 +30,15 @@ en:
|
|||
too_many_replies: "Sorry you can't reply any more times in that topic."
|
||||
|
||||
embed:
|
||||
title: "Discussion Highlights"
|
||||
start_discussion: "Begin the Discussion"
|
||||
continue: "Continue the Discussion"
|
||||
loading: "Loading Discussion..."
|
||||
permalink: "Permalink"
|
||||
imported_from: "Imported from: %{link}"
|
||||
in_reply_to: "in reply to %{username}"
|
||||
replies:
|
||||
one: "1 reply"
|
||||
other: "%{count} replies"
|
||||
|
||||
too_many_mentions:
|
||||
zero: "Sorry, you can't mention other users."
|
||||
|
@ -773,6 +776,7 @@ en:
|
|||
feed_polling_enabled: "Whether to import a RSS/ATOM feed as posts"
|
||||
feed_polling_url: "URL of RSS/ATOM feed to import"
|
||||
embed_by_username: "Discourse username of the user who creates the topics"
|
||||
embed_post_limit: "Maximum number of posts to embed"
|
||||
|
||||
notification_types:
|
||||
mentioned: "%{display_username} mentioned you in %{link}"
|
||||
|
|
|
@ -242,7 +242,7 @@ Discourse::Application.routes.draw do
|
|||
get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
|
||||
get 'embed/best' => 'embed#best'
|
||||
get 'embed/comments' => 'embed#comments'
|
||||
|
||||
# Topic routes
|
||||
get "t/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/}
|
||||
|
|
|
@ -356,6 +356,7 @@ embedding:
|
|||
feed_polling_enabled: false
|
||||
feed_polling_url: ''
|
||||
embed_by_username: ''
|
||||
embed_post_limit: 100
|
||||
|
||||
uncategorized:
|
||||
tos_url:
|
||||
|
|
|
@ -37,7 +37,7 @@ class TopicView
|
|||
def canonical_path
|
||||
path = @topic.relative_url
|
||||
path << if @post_number
|
||||
page = ((@post_number.to_i - 1) / SiteSetting.posts_per_page) + 1
|
||||
page = ((@post_number.to_i - 1) / @limit) + 1
|
||||
(page > 1) ? "?page=#{page}" : ""
|
||||
else
|
||||
(@page && @page.to_i > 1) ? "?page=#{@page}" : ""
|
||||
|
@ -130,8 +130,12 @@ class TopicView
|
|||
|
||||
def filter_posts_paged(page)
|
||||
page = [page, 1].max
|
||||
min = SiteSetting.posts_per_page * (page - 1)
|
||||
max = (min + SiteSetting.posts_per_page) - 1
|
||||
min = @limit * (page - 1)
|
||||
|
||||
# Sometimes we don't care about the OP, for example when embedding comments
|
||||
min = 1 if min == 0 && @exclude_first
|
||||
|
||||
max = (min + @limit) - 1
|
||||
|
||||
filter_posts_in_range(min, max)
|
||||
end
|
||||
|
@ -317,12 +321,12 @@ class TopicView
|
|||
return nil if closest_index.nil?
|
||||
|
||||
# Make sure to get at least one post before, even with rounding
|
||||
posts_before = (SiteSetting.posts_per_page.to_f / 4).floor
|
||||
posts_before = (@limit.to_f / 4).floor
|
||||
posts_before = 1 if posts_before.zero?
|
||||
|
||||
min_idx = closest_index - posts_before
|
||||
min_idx = 0 if min_idx < 0
|
||||
max_idx = min_idx + (SiteSetting.posts_per_page - 1)
|
||||
max_idx = min_idx + (@limit - 1)
|
||||
|
||||
# Get a full page even if at the end
|
||||
ensure_full_page(min_idx, max_idx)
|
||||
|
@ -331,7 +335,7 @@ class TopicView
|
|||
def ensure_full_page(min, max)
|
||||
upper_limit = (filtered_post_ids.length - 1)
|
||||
if max >= upper_limit
|
||||
return (upper_limit - SiteSetting.posts_per_page) + 1, upper_limit
|
||||
return (upper_limit - @limit) + 1, upper_limit
|
||||
else
|
||||
return min, max
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
var comments = document.getElementById('discourse-comments'),
|
||||
iframe = document.createElement('iframe');
|
||||
iframe.src = discourseUrl + "embed/best?embed_url=" + encodeURIComponent(discourseEmbedUrl);
|
||||
iframe.src = discourseUrl + "embed/comments?embed_url=" + encodeURIComponent(discourseEmbedUrl);
|
||||
iframe.id = 'discourse-embed-frame';
|
||||
iframe.width = "100%";
|
||||
iframe.frameBorder = "0";
|
||||
|
|
|
@ -6,13 +6,13 @@ describe EmbedController do
|
|||
let(:embed_url) { "http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html" }
|
||||
|
||||
it "is 404 without an embed_url" do
|
||||
get :best
|
||||
get :comments
|
||||
response.should_not be_success
|
||||
end
|
||||
|
||||
it "raises an error with a missing host" do
|
||||
SiteSetting.stubs(:embeddable_host).returns(nil)
|
||||
get :best, embed_url: embed_url
|
||||
get :comments, embed_url: embed_url
|
||||
response.should_not be_success
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,7 @@ describe EmbedController do
|
|||
end
|
||||
|
||||
it "raises an error with no referer" do
|
||||
get :best, embed_url: embed_url
|
||||
get :comments, embed_url: embed_url
|
||||
response.should_not be_success
|
||||
end
|
||||
|
||||
|
@ -42,13 +42,13 @@ describe EmbedController do
|
|||
retriever = mock
|
||||
TopicRetriever.expects(:new).returns(retriever)
|
||||
retriever.expects(:retrieve)
|
||||
get :best, embed_url: embed_url
|
||||
get :comments, embed_url: embed_url
|
||||
end
|
||||
|
||||
it "creates a topic view when a topic_id is found" do
|
||||
TopicEmbed.expects(:topic_id_for_embed).returns(123)
|
||||
TopicView.expects(:new).with(123, nil, {best: 5})
|
||||
get :best, embed_url: embed_url
|
||||
TopicView.expects(:new).with(123, nil, {limit: 100, exclude_first: true})
|
||||
get :comments, embed_url: embed_url
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue