贴吧回复改版

This commit is contained in:
cxt 2016-11-29 09:36:38 +08:00
parent efb0c9917c
commit 3f35b7f806
16 changed files with 243 additions and 114 deletions

View File

@ -14,17 +14,17 @@ class MemosController < ApplicationController
# layout 'base_memos'
def quote
@subject = @memo.subject
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
@content = "#{ll(Setting.default_language, :text_user_wrote, @memo.author)} <br/> &nbsp; "
@content << @memo.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n") + "</blockquote>\n\n<br/>"
@content = "<blockquote style='word-break: break-all;word-wrap: break-word;'>" << @content
#@content = "> #{ll(Setting.default_language, :text_user_wrote, @memo.author)}\n> "
#@content << @memo.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
#@content_html = textilizable(@content)
@temp = Memo.new
@temp.content = @content
# @subject = @memo.subject
# @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
#
# @content = "#{ll(Setting.default_language, :text_user_wrote, @memo.author)} <br/> &nbsp; "
# @content << @memo.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n") + "</blockquote>\n\n<br/>"
# @content = "<blockquote style='word-break: break-all;word-wrap: break-word;'>" << @content
# #@content = "> #{ll(Setting.default_language, :text_user_wrote, @memo.author)}\n> "
# #@content << @memo.content.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
# #@content_html = textilizable(@content)
# @temp = Memo.new
# @temp.content = @content
end
def new
@ -47,6 +47,8 @@ class MemosController < ApplicationController
@quote = params[:quote]
end
#unless params[:quote].nil?
# @quote = params[:quote][:quote]
#end
@ -55,6 +57,10 @@ class MemosController < ApplicationController
@memo.forum_id = params[:forum_id]
@memo.author_id = User.current.id
if params[:memo][:parent_id]
@memo.root_id = (Memo.find params[:memo][:parent_id]).root_id.nil? ? params[:memo][:parent_id].to_i : (Memo.find params[:memo][:parent_id]).root_id
end
@memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
@memo.content = @quote + @memo.content
respond_to do |format|
@ -111,32 +117,37 @@ class MemosController < ApplicationController
@memo = @memo.root # 取出楼主防止输入帖子id让回复作为主贴显示
@memo.update_column(:viewed_count, (@memo.viewed_count.to_i + 1))
page = params[:page]
if params[:r] && page.nil?
offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
page = 1 + offset / pre_count
else
end
@reply_count = @memo.children.count
@reply_pages = Paginator.new @reply_count, pre_count, page
@replies = @memo.children.
includes(:author, :attachments).
reorder("#{Memo.table_name}.created_at DESC").
limit(@reply_pages.per_page).
offset(@reply_pages.offset).
all
# page = params[:page]
# if params[:r] && page.nil?
# offset = @memo.children.where("#{Memo.table_name}.id < ?", params[:r].to_i).count
# page = 1 + offset / pre_count
# else
# end
# @reply_count = @memo.children.count
# @reply_pages = Paginator.new @reply_count, pre_count, page
# @replies = @memo.children.
# includes(:author, :attachments).
# reorder("#{Memo.table_name}.created_at DESC").
# limit(@reply_pages.per_page).
# offset(@reply_pages.offset).
# all
@replies = Memo.where("root_id = #{@memo.id}").reorder("created_at desc")
@reply_count = @replies.count
@replies = get_no_children_comments_all @replies
@limit_count = @replies.count
@page = params[:page] ? params[:page].to_i + 1 : 0
@limit = 10
@replies = @replies[@page * @limit..@page * @limit + 9]
@memo_new = Memo.new
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
# @memo = Memo.find_by_id(params[:id])
# @forum = Forum.find(params[:forum_id])
# @replies = @memo.replies
# @mome_new = Memo.new
respond_to do |format|
format.js
format.html {render :layout=> 'base_forums'}#:layout=> 'base_forums',
format.json { render json: @memo }
format.xml { render xml: @memo }

View File

@ -155,6 +155,8 @@ class UsersController < ApplicationController
@comment = Comment.find params[:comment].to_i
when 'Journal','is_project_issue'
@comment = Journal.find params[:comment].to_i
when 'Memo'
@comment = Memo.find params[:comment].to_i
end
@user_activity_id = params[:user_activity_id]
@parent_id = params[:parent_id] if params[:parent_id]
@ -299,6 +301,15 @@ class UsersController < ApplicationController
@root.update_column('updated_at', Time.now)
@count = @root.journals_for_messages.count
@comments = @root.journals_for_messages.reorder("created_on desc").limit(3)
when 'Memo'
@root = reply.root
comment = Memo.new
comment.author = User.current
comment.forum = reply.forum
comment.content = params[:reply_message]
comment.subject = "#{@root.subject}"
comment.root_id = reply.root_id
reply.children << comment
end
update_course_activity(@root.class.to_s,@root.id)
update_user_activity(@root.class.to_s,@root.id)

View File

@ -3422,6 +3422,8 @@ def get_reply_by_type type, reply_id
reply = Journal.find reply_id
when 'Syllabus'
reply = JournalsForMessage.find reply_id
when 'Memo'
reply = Memo.find reply_id
end
reply
end

View File

@ -79,7 +79,8 @@ class Memo < ActiveRecord::Base
"lock",
"sticky",
"parent_id",
"replies_count"
"replies_count",
"root_id"
after_create :add_author_as_watcher, :reset_counters!, :send_mail, :send_message,:create_memo_ealasticsearch_index
after_update :update_memo_ealasticsearch_index
@ -126,6 +127,18 @@ class Memo < ActiveRecord::Base
Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added')
end
def creator_user
self.author
end
def created_time
self.created_on
end
def content_detail
self.content
end
# 公共贴吧消息记录
# 原则贴吧创始人发帖人wanglingchun特殊用户
def send_message

View File

@ -18,7 +18,8 @@
</div>
<div class="postDetailReply fr">
<a href="<%= forum_memo_path(topic.forum, topic)%>" class="postReplyIcon mr5" target="_blank"></a>
<%= link_to (topic.replies_count), forum_memo_path(topic.forum, topic),:target =>'_blank',:class=>'linkGrey2' %>
<% replies_count = Memo.where("root_id = #{topic.id}").count %>
<%= link_to (replies_count), forum_memo_path(topic.forum, topic),:target =>'_blank',:class=>'linkGrey2' %>
<a href="javascript:void(0);" class="linkGrey2 disablePostLikeIcon ml10" style="cursor: default" title="点赞人数" > <%= get_praise_num(topic)%></a>
</div>

View File

@ -7,13 +7,10 @@
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','application','prettify', 'nyan', :media => 'all' %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','application','prettify', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application', 'jquery.colorbox-min') %>
<%= import_ke(enable_at: false, prettify: true, init_activity: false) %>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>

View File

@ -0,0 +1,77 @@
<% @replies.each do |reply| %>
<script type="text/javascript">
$(function(){
$("#activity_description_<%= reply.id %> p,#activity_description_<%= reply.id %> span,#activity_description_<%= reply.id %> em").each(function(){
var postContent = $(this).html();
postContent = postContent.replace(/&nbsp;/g," ");
postContent= postContent.replace(/ {2}/g,"&nbsp; ");
postContent=postContent.replace(/&nbsp; &nbsp;/g,"&nbsp;&nbsp;&nbsp;");
postContent=postContent.replace(/&nbsp; /g,"&nbsp;&nbsp; ");
postContent = postContent.replace(/<script>*/g, "<script>");
postContent = postContent.replace(/<html>*/g, "<html>");
$(this).html(postContent);
});
autoUrl('activity_description_<%= reply.id %>');
description_show_hide(<%= reply.id %>);
});
$(".homepagePostReplyDes").mouseover(function(){
$(this).find("a[id*='delete_memo_reply']").show();
}).mouseout(function(){
$(this).find("a[id*='delete_memo_reply']").hide();
});
</script>
<div class="homepagePostReplyContainer" >
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %>
</div>
<div class="homepagePostReplyDes" onmouseover="$('#delete_reply_<%=reply.id %>').show();" onmouseout="$('#delete_reply_<%=reply.id %>').hide();">
<div class="homepagePostReplyPublisher">
<%= render :partial => 'users/message_contents', :locals => {:comment => reply, :type => 'Memo', :user_activity_id => @memo.id}%>
</div>
<div class="homepagePostReplyContent break_word" style="margin-bottom:15px;" id="activity_description_<%= reply.id %>">
<p><%= reply.content.gsub(/script/, "script&nbsp").html_safe %></p>
</div>
<div class="orig_reply mb10 mt-10">
<div class="reply">
<span class="reply-right">
<span id="reply_praise_count_<%= reply.id %>">
<%= render :partial => "praise_tread/praise", :locals => {:activity => reply, :user_activity_id => reply.id, :type => "reply"} %>
</span>
<span style="position: relative" class="fr mr20">
<%= link_to(
l(:button_reply),
{:action => 'quote', :id => reply},
:remote => true,
:method => 'get',
:title => l(:button_reply)) %>
<span id="reply_iconup_<%= reply.id %>" class="reply_iconup02" style="display: none"> ︿</span>
</span>
<%= link_to(
l(:button_delete),
forum_memo_path(@memo.forum, reply),
:method => :delete,
:id => "delete_reply_#{reply.id}",
:class => 'fr mr20 undis',
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) if @memo.author.id == User.current.id || User.current.admin? %>
</span>
<div class="cl"></div>
</div>
</div>
<p id="reply_message_<%= reply.id%>"></p>
</div>
<div class="cl"></div>
</div>
<% end %>
<% if @limit_count > @page * @limit + 10 %>
<div id="more_memo_replies">
<div class="detail_cont_hide clearfix">
<span class="orig_icon" >&darr; </span>
<span class="orig_icon" style="display:none;" > &uarr;</span>
<%= link_to '点击展开更多回复', forum_memo_path(@memo.forum_id, @memo, :page => @page),:remote=>true %>
</div>
</div>
<% end %>

View File

@ -0,0 +1,31 @@
<div class="ReplyToMessageContainer borderBottomNone" id="reply_to_message_<%= reply.id%>">
<div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= reply.id%>">
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
</div>
<div class="ReplyToMessageInputContainer mb10">
<% if User.current.logged? %>
<div nhname='new_message_<%= reply.id%>'>
<%= form_for('memo',:url=>forum_memos_path,:method => "post") do |f|%>
<%= f.hidden_field :subject, :required => true, value: reply.subject %>
<%= f.hidden_field :forum_id, :required => true, value: reply.forum_id %>
<%= f.hidden_field :parent_id, :required => true, value: reply.id %>
<%= hidden_field_tag :quote,"",:required => false,:style => 'display:none' %>
<div nhname='toolbar_container_<%= reply.id%>'></div>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea_<%= reply.id%>' name="memo[content]"></textarea>
<a id="new_message_submit_btn_<%= reply.id%>" href="javascript:void(0)" onclick="this.style.display='none'" class="blue_n_btn fr" style="display:none;margin-top:6px;">发送</a>
<div class="cl"></div>
<p nhname='contentmsg_<%= reply.id%>'></p>
<% end%>
</div>
<% else %>
<%= render :partial => "users/show_unlogged" %>
<% end %>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
<script>
$(function(){
sd_create_editor_from_data(<%= reply.id%>,null,"100%", "<%=reply.class.to_s%>");
});
</script>

View File

@ -1,5 +1,5 @@
//ckeditor.setData("<%= raw escape_javascript(@content) %>");
$('#message_quote').html("<%= raw escape_javascript(@temp.content.html_safe) %>");
$('#quote').val("<%= raw escape_javascript(@content) %>");
showAndScrollTo("new_memo", "cke_editor01");
$("img").removeAttr("align");
if($("#reply_message_<%= @memo.id%>").length > 0) {
$("#reply_message_<%= @memo.id%>").replaceWith("<%= escape_javascript(render :partial => 'memos/reply_message', :locals => {:reply => @memo}) %>");
}else if($("#reply_to_message_<%= @memo.id%>").length >0) {
$("#reply_to_message_<%= @memo.id%>").replaceWith("<p id='reply_message_<%= @memo.id%>'></p>");
}

View File

@ -4,22 +4,6 @@
<% end %>
<script>
function expand_reply(container,btnid){
var target = $(container).children();
var btn = $(btnid);
if(btn.data('init')=='0'){
btn.data('init',1);
btn.html('收起回复');
target.show();
}else{
btn.data('init',0);
btn.html('展开更多');
target.hide();
target.eq(0).show();
target.eq(1).show();
target.eq(2).show();
}
}
$(function() {
sd_create_editor_from_data(<%= @memo.id%>,null,"100%", "<%=@memo.class.to_s%>");
});
@ -82,46 +66,8 @@
<div class="homepagePostReplyBannerCount">回复(<%=@reply_count %></div>
<div class="homepagePostReplyBannerTime"></div>
</div>
<div class="" id="reply_div_<%= @memo.id %>">
<% @replies.each_with_index do |reply,i| %>
<div class="homepagePostReplyContainer" >
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %>
</div>
<div class="homepagePostReplyDes">
<div class="homepagePostReplyPublisher"><a href="<%=user_path(reply.author)%>" class="newsBlue mr10 f14"><%= reply.author.show_name%></a><%= format_date(reply.created_at) %></div>
<div class="homepagePostReplyContent break_word" style="margin-bottom:25px;" id="activity_description_<%= reply.id %>"><p><%= reply.content.gsub(/script/, "script&nbsp").html_safe %></p>
<% if @memo.author.id == User.current.id || User.current.admin? %>
<%= link_to "删除", forum_memo_path(@memo.forum, reply), :class => "fr undis", :method => "delete", :confirm => l(:text_are_you_sure), :id => "delete_memo_reply_#{reply.id}" %>
<% end %>
</div>
</div>
<script type="text/javascript">
$(function(){
$("#activity_description_<%= reply.id %> p,#activity_description_<%= reply.id %> span,#activity_description_<%= reply.id %> em").each(function(){
var postContent = $(this).html();
postContent = postContent.replace(/&nbsp;/g," ");
postContent= postContent.replace(/ {2}/g,"&nbsp; ");
postContent=postContent.replace(/&nbsp; &nbsp;/g,"&nbsp;&nbsp;&nbsp;");
postContent=postContent.replace(/&nbsp; /g,"&nbsp;&nbsp; ");
postContent = postContent.gsub(/<script>*/, "<script>");
postContent = postContent.gsub(/<html>*/, "<html>");
$(this).html(postContent);
});
autoUrl('activity_description_<%= reply.id %>');
description_show_hide(<%= reply.id %>);
});
$(".homepagePostReplyDes").mouseover(function(){
$(this).find("a[id*='delete_memo_reply']").show();
}).mouseout(function(){
$(this).find("a[id*='delete_memo_reply']").hide();
});
</script>
<div class="cl"></div>
</div>
<% end %>
<div class="" id="reply_div_<%= @memo.id %>">
<%= render :partial => 'memos/memo_all_replies' %>
</div>
<div class="cl"></div>
<div class="homepagePostReplyContainer borderBottomNone minHeight48">

View File

@ -0,0 +1 @@
$("#more_memo_replies").replaceWith("<%= escape_javascript(render :partial => 'memos/memo_all_replies')%>");

View File

@ -1,13 +1,13 @@
<% if @obj_type == 'Memo'%>
$('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}
)%>');
<% elsif @activity %>
<% if @activity %>
<% if @type.to_s == 'activity' %>
$('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>');
<% else @type.to_s == 'reply' %>
$('#reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>');
<% end %>
<% elsif @obj_type == 'Memo'%>
$('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}
)%>');
<% else %>
$('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}

View File

@ -43,6 +43,8 @@ $("#activity_post_reply_<%= @user_activity_id%>").html("<%= escape_javascript(re
window.location.href = "<%=org_document_comment_path(:id => @root.id, :organization_id => @root.organization.id) %>";
<% end %>
<% elsif @type == 'Syllabus' %>
$("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'syllabuses/syllabus_post_reply', :locals => {:activity => @root, :user_activity_id => @user_activity_id}) %>");
$("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'syllabuses/syllabus_post_reply', :locals => {:activity => @root, :user_activity_id => @user_activity_id}) %>");
<% elsif @type == 'Memo' %>
window.location.href = "<%=forum_memo_path(@root.forum_id, @root) %>";
<% end %>
sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity");

View File

@ -5,7 +5,7 @@
$('#comment_reply_<%=@comment.id %>').html("<%= escape_javascript(render :partial => 'projects/journal_comment_reply', :locals => {:comment => @comment.parent, :user_activity_id => @user_activity_id, :parent_id => @parent_id})%>");
<% elsif params[:type] == 'is_project_issue' %>
$('#comment_reply_<%=@comment.id %>').html("<%= escape_javascript(render :partial => 'projects/project_issue_comments_reply', :locals => {:comment => @comment.parent, :user_activity_id => @user_activity_id, :parent_id => @parent_id})%>");
<% elsif (@comment.class.to_s == 'Message' || @comment.class.to_s == 'BlogComment' || @comment.class.to_s == 'OrgDocumentComment') %>
<% elsif (@comment.class.to_s == 'Message' || @comment.class.to_s == 'BlogComment' || @comment.class.to_s == 'OrgDocumentComment' || @comment.class.to_s == 'Memo') %>
$('#comment_reply_<%=@comment.id %>').html("<%= escape_javascript(render :partial => 'users/journal_comment_reply', :locals => {:comment => @comment.parent, :type => params[:type], :user_activity_id => @user_activity_id, :parent_id => @parent_id})%>");
<% else %>
$('#comment_reply_<%=@comment.id %>').html("<%= escape_javascript(render :partial => 'users/comment_reply', :locals => {:comment => @comment.parent, :type => params[:type], :user_activity_id => @user_activity_id, :parent_id => @parent_id})%>");

View File

@ -0,0 +1,26 @@
class AddRootIdToMemos < ActiveRecord::Migration
def change
add_column :memos, :root_id, :integer
add_index :memos, :root_id
def get_base_parent comment
comm = comment
while comm.parent
comm = comm.parent
end
comm
end
count = Memo.all.count / 30 + 2
transaction do
for i in 1 ... count do i
Memo.page(i).per(30).each do |memo|
unless memo.parent.nil?
parent = get_base_parent memo
memo.update_column('root_id', parent.id)
end
end
end
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20161125024643) do
ActiveRecord::Schema.define(:version => 20161128072528) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -325,16 +325,14 @@ ActiveRecord::Schema.define(:version => 20161125024643) do
add_index "changeset_parents", ["parent_id"], :name => "changeset_parents_parent_ids"
create_table "changesets", :force => true do |t|
t.integer "repository_id", :null => false
t.string "revision", :null => false
t.integer "repository_id", :null => false
t.string "revision", :null => false
t.string "committer"
t.datetime "committed_on", :null => false
t.datetime "committed_on", :null => false
t.text "comments"
t.date "commit_date"
t.string "scmid"
t.integer "user_id"
t.integer "project_id"
t.integer "type", :default => 0
end
add_index "changesets", ["committed_on"], :name => "index_changesets_on_committed_on"
@ -518,6 +516,20 @@ ActiveRecord::Schema.define(:version => 20161125024643) do
t.integer "container_id", :default => 0
end
create_table "course_class_post", :id => false, :force => true do |t|
t.integer "班级id", :default => 0, :null => false
t.string "班级名"
t.integer "帖子id", :default => 0, :null => false
t.integer "主贴id"
t.string "帖子标题", :default => "", :null => false
t.text "帖子内容"
t.integer "帖子用户id"
t.integer "帖子回复数", :default => 0, :null => false
t.integer "最后回帖id"
t.datetime "发帖时间", :null => false
t.datetime "帖子更新时间", :null => false
end
create_table "course_contributor_scores", :force => true do |t|
t.integer "course_id"
t.integer "user_id"
@ -996,10 +1008,6 @@ ActiveRecord::Schema.define(:version => 20161125024643) do
t.datetime "updated_at", :null => false
end
create_table "innodb_monitor", :id => false, :force => true do |t|
t.integer "a"
end
create_table "invite_lists", :force => true do |t|
t.integer "project_id"
t.integer "user_id"
@ -1211,8 +1219,11 @@ ActiveRecord::Schema.define(:version => 20161125024643) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "viewed_count", :default => 0
t.integer "root_id"
end
add_index "memos", ["root_id"], :name => "index_memos_on_root_id"
create_table "message_alls", :force => true do |t|
t.integer "user_id"
t.integer "message_id"