From a5289610a32d67c6e3d89e90f8060ab684f7c7a8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 30 Sep 2017 19:23:38 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=9E=E8=AE=ADTPI=E7=9A=84=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 12 +- app/controllers/users_controller.rb | 19 ++ app/helpers/application_helper.rb | 2 + app/models/discuss.rb | 8 + app/views/games/_game_show.html.erb | 2 +- .../games/_shixun_comment_block.html.erb | 78 ++++--- app/views/games/_shixun_comment_list.html.erb | 206 ++++++++++++++---- app/views/users/_reply_to.html.erb | 10 +- app/views/users/reply_detail.js.erb | 12 + public/javascripts/create_kindeditor.js | 135 ++++++++++++ 10 files changed, 397 insertions(+), 87 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 170349350..b619cf52b 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -735,13 +735,13 @@ class ShixunsController < ApplicationController end def shixun_discuss - @discusses = @shixun.discusses.where(:parent_id => nil).reorder("created_at desc") + @discusses = @shixun.discusses.reorder("created_at desc") @discusses_count = @discusses.count - @limit = 15 - @is_remote = true - @discusses_pages = Paginator.new @discusses_count, @limit, params['page'] || 1 - @offset ||= @discusses_pages.offset - @discusses = paginateHelper @discusses, @limit + #@limit = 15 + #@is_remote = true + #@discusses_pages = Paginator.new @discusses_count, @limit, params['page'] || 1 + # @offset ||= @discusses_pages.offset + #@discusses = paginateHelper @discusses, @limit #@game_challenge = params[:challenge_id].blank? ? Challenge.find(@discusses.challenge_id) : Challenge.find(params[:challenge_id]) @game_challenge = Challenge.find(params[:challenge_id].to_i) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1f545fd9e..2a73e648e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -326,6 +326,11 @@ class UsersController < ApplicationController @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] @type = 'Memo' + when 'Challenge' + @reply = Discuss.find params[:reply_id] + @user_activity_id = params[:user_activity_id] + @activity_id = params[:activity_id] + @type = 'Challenge' end respond_to do |format| format.js @@ -452,6 +457,20 @@ class UsersController < ApplicationController comment.subject = "#{@root.subject}" comment.root_id = reply.root_id reply.children << comment + when 'Challenge' + @game_challenge = Challenge.where(:id => reply.challenge_id).first + @root = reply.root + comment = Discuss.new + comment.user_id = User.current.id + comment.content = params[:reply_message] + comment.root_id = reply.root_id + comment.challenge_id = reply.challenge_id + comment.dis_type = "Shixun" + comment.dis_id = @game_challenge.shixun.try(:id) + comment.praise_count = 0 + reply.children << comment + @discusses = @game_challenge.shixun.discusses.reorder("created_at desc") + @discusses_count = @discusses.count end update_course_activity(@root.class.to_s,@root.id) update_user_activity(@root.class.to_s,@root.id) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1d2d2cb00..06d62c7ab 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4483,6 +4483,8 @@ def get_reply_by_type type, reply_id reply = JournalsForMessage.find reply_id when 'Memo' reply = Memo.find reply_id + when 'Challenge' + reply = Discuss.find reply_id end reply end diff --git a/app/models/discuss.rb b/app/models/discuss.rb index effd1cb26..af5f96601 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -7,4 +7,12 @@ class Discuss < ActiveRecord::Base acts_as_tree :foreign_key => 'parent_id' belongs_to :dis, :polymorphic => true validates_presence_of :dis, :user, :content + + def creator_user + User.find(self.user_id) + end + + def content_detail + self.content + end end diff --git a/app/views/games/_game_show.html.erb b/app/views/games/_game_show.html.erb index c30f163b9..561093ecb 100644 --- a/app/views/games/_game_show.html.erb +++ b/app/views/games/_game_show.html.erb @@ -82,7 +82,7 @@
diff --git a/app/views/users/reply_detail.js.erb b/app/views/users/reply_detail.js.erb index e3b21a71d..3924a200e 100644 --- a/app/views/users/reply_detail.js.erb +++ b/app/views/users/reply_detail.js.erb @@ -54,5 +54,17 @@ $("#activity_post_reply_<%= @user_activity_id%>").html("<%= escape_javascript(re $("#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) %>"; +<% elsif @type == 'Challenge' %> + $(".-tab-nav li").removeClass("tab_hover"); + $('#tab_nav_4').addClass("tab_hover"); + $(".tab-info").hide(); + $('#tab_con_4').show().html("<%= j(render :partial => "games/shixun_comment_list") %>"); + <% if @discusses_count > 0 %> + $("#discusses_count").html("<%= @discusses_count %>"); + <% end %> +<% end %> +<% if @discusses_count > 0 %> +$("#discusses_count").html("<%= @discusses_count %>"); + //window.location.href = "<%#= myshixun_game_path(@challenge.current_user_game, :myshixun_id => @challenge.current_user_game.try(:myshixun)) %>"; <% end %> sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity"); \ No newline at end of file diff --git a/public/javascripts/create_kindeditor.js b/public/javascripts/create_kindeditor.js index bf11fcac1..d5ca03e56 100644 --- a/public/javascripts/create_kindeditor.js +++ b/public/javascripts/create_kindeditor.js @@ -92,6 +92,96 @@ function sd_create_editor(params){ return editor; } +function sd_create_shixun_editor(params){ + // var minHeight; //最小高度 + var paramsHeight = params.height; //设定的高度 + var id = arguments[1] ? arguments[1] : undefined; + var type = arguments[2] ? arguments[2] : ''; + var paramsWidth = params.width == undefined ? "100%" : params.width; + + var editor = params.kindutil.create(params.textarea, { + resizeType : 1,minWidth:"1px",width:"94%", + height:"33px",// == undefined ? "30px":paramsHeight+"px", + minHeight:"33px",// == undefined ? "30px":paramsHeight+"px", + width:params.width, + /* + items:['emoticons','fontname', + 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|', + 'formatblock', 'fontsize', '|','indent', 'outdent', + '|','imagedirectupload','more'],*/ + items : ['imagedirectupload'], + afterChange:function(){//按键事件 + var edit = this.edit; + var body = edit.doc.body; + //edit.iframe.height(paramsHeight); + //this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : (params.kindutil.GECKO ? body.offsetHeight+26:body.offsetHeight+7)) , 15)); + }, + afterBlur:function(){ + //params.toolbar_container.hide(); + params.textarea.blur(); + sd_check_editor_form_field({content:this,contentmsg:params.contentmsg,textarea:params.textarea}); + if(this.isEmpty()) { + this.edit.html("我要回复"); + } + //params.toolbar_container.hide(); + $('#reply_image_' + id).addClass('imageFuzzy'); + if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(this.edit.html())){ + params.submit_btn.hide(); + params.toolbar_container.hide(); + this.resize("100%", "30px"); + }else if(this.edit.html().trim() != ""){ + params.submit_btn.show(); + params.toolbar_container.show(); + } + //params.submit_btn.css("display","none"); + $("#dis_reply_id").val(""); + }, + afterFocus: function(){ + var edit = this.edit; + var body = edit.doc.body; + if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(edit.html())){ + edit.html(""); + } + params.submit_btn.show(); + params.contentmsg.hide(); + params.toolbar_container.show(); + // params.toolbar_container.show(); + $('#reply_image_' + id).removeClass('imageFuzzy'); + //edit.iframe.width(paramsWidth); + console.log(this); + this.resize("100%", "150px"); + this.resize(paramsWidth, "150px"); + //params.submit_btn.show(); + }, + + afterCreate:function(){ + //params.submit_btn.hide(); + var toolbar = $("div[class='ke-toolbar']",params.div_form); + toolbar.css('display','inline'); + toolbar.css('padding',0); + $(".ke-outline>.ke-toolbar-icon",toolbar).append('表情'); + params.toolbar_container.append(toolbar); + params.toolbar_container.hide(); + params.submit_btn.hide(); + //init + var edit = this.edit; + var body = edit.doc.body; + edit.iframe[0].scroll = 'no'; + body.style.overflowY = 'hidden'; + //reset height + paramsHeight = paramsHeight == undefined ? params.kindutil.removeUnit(this.height) : paramsHeight; + edit.iframe.height(paramsHeight); + edit.html("我要回复"); + this.resize(null,paramsHeight);// Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight)+ paramsHeight , paramsHeight) + // params.toolbar_container.hide(); + if(typeof enableAt === 'function'){ + enableAt(this, id, type); + } + } + }).loadPlugin('paste'); + return editor; +} + function sd_check_editor_form_field(params){ var result=true; if(params.content!=undefined){ @@ -183,6 +273,51 @@ function sd_create_editor_from_data(id){ }); }); + div_form = $("div[nhname='new_message_" + id + "']"); + $(".ke-edit", div_form).css("height","33px"); + $(".ke-edit-iframe",div_form).css("height","33px"); +} + + +//第二个参数是高度,可以传,可以不传 +function sd_create_editor_from_shixun_data(id){ + var height = arguments[1] ? arguments[1] : undefined; + var width = arguments[2] ? arguments[2] : undefined; + var type = arguments[3] ? arguments[3] : undefined; + KindEditor.ready(function (K) { + $("div[nhname='new_message_" + id + "']").each(function () { + var params = {}; + params.kindutil = K; + params.div_form = $(this); + params.form = $("form", params.div_form); + if (params.form == undefined || params.form.length == 0) { + return; + } + params.textarea = $("textarea[nhname='new_message_textarea_" + id + "']", params.div_form); + params.contentmsg = $("span[nhname='contentmsg_" + id + "']", params.div_form); + params.toolbar_container = $("div[nhname='toolbar_container_" + id + "']", params.div_form); + params.cancel_btn = $("#new_message_cancel_btn_" + id); + params.submit_btn = $("#new_message_submit_btn_" + id); + params.height = height; + params.width = width; + if (params.textarea.data('init') == undefined) { + params.editor = sd_create_shixun_editor(params,id, type); + sd_create_form(params); + params.cancel_btn.click(function () { + sd_reset_editor_form(params); + }); + params.submit_btn.click(function () { + params.form.submit(); + }); + params.textarea.focus(function (){ + params.editor.focus(); + }); + params.textarea.data('init', 1); + $(this).show(); + } + }); + }); + div_form = $("div[nhname='new_message_" + id + "']"); $(".ke-edit", div_form).css("height","33px"); $(".ke-edit-iframe",div_form).css("height","33px"); From 7dcc150a25bd800fe6b28ca2cee620aa3c47c486 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 30 Sep 2017 19:49:53 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=B4=B4=E5=90=A7=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forums_controller.rb | 18 +++++++++--------- app/helpers/application_helper.rb | 2 +- app/views/forums/index.html.erb | 6 ++++++ app/views/layouts/_logined_header.html.erb | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 337f951aa..4cd1b26c7 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -137,17 +137,17 @@ class ForumsController < ApplicationController @order_str = "reorder_time=desc" end =end - @memo = Memo.new(:forum => @forum) + #@memo = Memo.new(:forum => @forum) @memos = Memo.where("parent_id is null") @topic_count = @memos.count - @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] - @memos = @memos.includes(:last_reply). - limit(@topic_pages.per_page). - offset(@topic_pages.offset). - reorder(order). - preload(:author, {:last_reply => :author}). - all - @forums = Forum.find_by_sql("SELECT *,topic_count + memo_count tm FROM `forums` order by tm desc;") + + @limit = 20 + @is_remote = true + @topic_pages = Paginator.new @topic_count, @limit, params['page'] || 1 + @memos = @memos.includes(:last_reply).reorder(order) + @memos = paginateHelper @memos, @limit + + #@forums = Forum.find_by_sql("SELECT *,topic_count + memo_count tm FROM `forums` order by tm desc;") @my_forums_count = Memo.where("author_id =? and parent_id is null", User.current.id).count @my_memos_count = Memo.where("author_id =? and parent_id is not null", User.current.id).count @errors = params[:errors] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 06d62c7ab..6ec99bdba 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2032,7 +2032,7 @@ module ApplicationHelper elsif @organization title << (@organization.name.nil? ? "创新源于实践" : @organization.name) elsif @forum || params[:controller] == "forums" - title << "问吧" + title << "论坛" elsif @my_syllabuses title << "我的课堂" elsif @user diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index eee792a77..7583463ce 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -86,6 +86,12 @@ + + + + + + <% if false %> <%= content_for(:header_tags) do %> <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 2085a3c5d..6a638ac62 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -18,7 +18,7 @@
- <%= link_to dis.user.show_name, user_path(dis.user), :class => "fl link-color-grey mr20" ,:style => "display: block" %> - <%= time_from_now dis.created_at %> - <% if dis.try(:challenge_id).present? %> - [第<%= Challenge.find(dis.try(:challenge_id)).try(:position) %>关] - <% end %> - +
+ <% no_children_comments.each do |comment| %>
+ <% unless comment.nil? %>
+
+
+
+ <%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 50, :height => 50, :alt => "用户头像"), user_url_in_org(comment.creator_user), :target => '_blank' %>
+
+
+
+
+ <% if !comment.parent.nil? %>
+ <% parents_rely = [] %>
+ <% parents_rely = get_reply_parents parents_rely, comment %>
+ <% length = parents_rely.length %>
+
+ <% if length <= 5 %>
+ <%=render :partial => 'student_work/homework_reply', :locals => {:comment => comment.parent, :parent_id => comment.id, :user_activity_id => @game_challenge.id, :type => @game_challenge.class.to_s} %>
+ <% else %>
+
+
+
+
+
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[length - 1], :type => @game_challenge.class.to_s, :user_activity_id => @game_challenge.id, :parent_id => comment.id} %>
+
+
+
+ <%= link_to '点击展开隐藏楼层', show_all_replies_users_path(:comment => comment, :type => comment.class, :user_activity_id => @game_challenge.id, :parent_id => comment.id),:remote=>true, :class => '' %>
+
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[3], :type => @game_challenge.class.to_s, :user_activity_id => @game_challenge.id, :parent_id => comment.id} %>
+
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[2], :type => @game_challenge.class.to_s, :user_activity_id => @game_challenge.id, :parent_id => comment.id} %>
+
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[1], :type => @game_challenge.class.to_s, :user_activity_id => @game_challenge.id, :parent_id => comment.id} %>
+
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[0], :type => @game_challenge.class.to_s, :user_activity_id => @game_challenge.id, :parent_id => comment.id} %>
+
+ <% end %>
+
+ <% end %>
+
+
+ <%= comment.content.html_safe %>
+
+
+
+
+
+
+
+
+
+
+
+ <%= link_to comment.creator_user.show_real_name, user_url_in_org(comment.creator_user), :class => "content-username hide fl" %>
+ <%= time_from_now(comment.respond_to?(:created_on) ? comment.created_on : comment.created_at) %>
+
+
+
+
+
+ <% end %>
+ <% end %>
+
+
+ <% if comment.creator_user == User.current || User.current.admin? || User.current.manager_of_shixun?(comment.dis_id) %> + 删除 + <% end %> + | + <%= link_to( + '回复'.html_safe, + {:controller => 'users' ,:action => 'reply_to',:reply_id => comment.id, :type => @game_challenge.class.to_s, :user_activity_id => @game_challenge.id}, + :remote => true, + :method => 'get', + :title => l(:button_reply),:class => "color-grey") %> + | + + <%=render :partial=> "praise_tread/edu_praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + +
+