From cdb77828497c06c5dd9e927330c42ec6c83c8052 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Fri, 22 Jul 2016 15:37:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=99=A4=E4=BA=86issue=20=E5=92=8Cnews?= =?UTF-8?q?=E9=83=BD=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BA=8C=E7=BA=A7=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/whomeworks.rb | 10 +- app/api/mobile/entities/blog_comment.rb | 7 +- app/api/mobile/entities/issue.rb | 10 +- app/api/mobile/entities/jours.rb | 95 ++++++++++++++++++- app/api/mobile/entities/message.rb | 76 ++++++++++++++- app/api/mobile/entities/news.rb | 4 +- app/api/mobile/entities/whomework.rb | 17 +++- app/controllers/courses_controller.rb | 7 +- public/assets/wechat/blog_detail.html | 33 +------ public/assets/wechat/course_notice.html | 4 +- public/assets/wechat/homework_detail.html | 51 ++++++++-- public/assets/wechat/issue_detail.html | 4 +- public/assets/wechat/jour_message_detail.html | 48 ++++++++-- public/assets/wechat/project_discussion.html | 47 ++++++++- .../wechat/templates/comment_reply.html | 13 +++ public/javascripts/wechat/controllers/blog.js | 8 +- .../wechat/controllers/discussion.js | 28 +++++- .../wechat/controllers/homework.js | 29 +++++- .../wechat/controllers/journals.js | 29 +++++- .../wechat/directives/comment_reply.js | 9 ++ public/javascripts/wechat/others/factory.js | 31 +++++- 21 files changed, 471 insertions(+), 89 deletions(-) create mode 100644 public/assets/wechat/templates/comment_reply.html create mode 100644 public/javascripts/wechat/directives/comment_reply.js diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb index db1e7e269..9d03eed9f 100644 --- a/app/api/mobile/apis/whomeworks.rb +++ b/app/api/mobile/apis/whomeworks.rb @@ -13,8 +13,14 @@ module Mobile #0一级回复的更多 1 二级回复的更多 type = params[:type] || 0 page = params[:page] || 0 - homework = HomeworkCommon.find params[:id] - present :data, homework, with: Mobile::Entities::Whomework,user: user,type: type,page: page + + if type == 0 + homework = HomeworkCommon.find params[:id] + present :data, homework, with: Mobile::Entities::Whomework,user: user,type: type,page: page,comment_type: "homework" + else + jour = JournalsForMessage.find params[:id] + present :data, jour, with: Mobile::Entities::Jours,user: user,type: type,page: page,comment_type: "homework" + end present :type, type present :page, page present :status, 0 diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb index 3f58e901f..726949bb5 100644 --- a/app/api/mobile/entities/blog_comment.rb +++ b/app/api/mobile/entities/blog_comment.rb @@ -51,9 +51,8 @@ module Mobile blog_comment_expose :id blog_comment_expose :locked blog_comment_expose :praise_count - expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt| + expose :all_children, using:Mobile::Entities::BlogComment do |c,opt| if c.is_a? (::BlogComment) - ##自己的父回复为空 才有子回复 if !opt[:children] if c.parent.nil? && opt[:type] == 0 opt[:children] = true @@ -86,7 +85,7 @@ module Mobile #取二级回复的底楼层 parents_reply = [] parents_reply = get_reply_parents_no_root(parents_reply, c) - if parents_reply.count > 0 && !opt[:bottom] + if parents_reply.count > 0 && parents_reply.count != 2 && !opt[:bottom] if opt[:type] == 1 # opt[:bottom] = true # parents_reply[opt[:page]..opt[:page]] @@ -105,7 +104,7 @@ module Mobile #取二级回复的顶楼层 parents_reply = [] parents_reply = get_reply_parents_no_root(parents_reply, c) - if parents_reply.count > 0 && !opt[:top] + if parents_reply.count >= 2 && !opt[:top] if opt[:type] == 1 opt[:bottom] = true tStart = (opt[:page]-1)*5+2 diff --git a/app/api/mobile/entities/issue.rb b/app/api/mobile/entities/issue.rb index b99ea03a5..dc4fd0567 100644 --- a/app/api/mobile/entities/issue.rb +++ b/app/api/mobile/entities/issue.rb @@ -22,10 +22,10 @@ module Mobile (get_user(issue.assigned_to_id)).login when :issue_status IssueStatus.find(issue.status_id).name - when :journals_count - # issue.journals.where("notes is not null and notes != ''").count - all_comments = [] - get_all_children(all_comments, f).count + when :comment_count + issue.journals.where("notes is not null and notes != ''").count + # all_comments = [] + # get_all_children(all_comments, f).count when :project_name issue.project.name when :praise_count @@ -49,7 +49,7 @@ module Mobile issue_expose :issue_priority issue_expose :issue_assigned_to issue_expose :issue_status - issue_expose :journals_count + issue_expose :comment_count issue_expose :project_name issue_expose :praise_count expose :issue_journals, using: Mobile::Entities::Journal do |f, opt| diff --git a/app/api/mobile/entities/jours.rb b/app/api/mobile/entities/jours.rb index f98d7a9ed..0e4c699c2 100644 --- a/app/api/mobile/entities/jours.rb +++ b/app/api/mobile/entities/jours.rb @@ -17,7 +17,7 @@ module Mobile case field when :lasted_comment time_from_now f.created_on - when :reply_count + when :comment_count # f.children.count all_comments = [] get_all_children(all_comments, f).count @@ -27,6 +27,8 @@ module Mobile 'JournalsForMessage' when :act_id f.id + when :content + f.notes end end end @@ -42,10 +44,10 @@ module Mobile end jours_expose :created_on jours_expose :lasted_comment - jours_expose :notes + jours_expose :content jours_expose :m_reply_id jours_expose :m_parent_id - jours_expose :reply_count + jours_expose :comment_count jours_expose :praise_count expose :course,using:Mobile::Entities::Course do |f,opt| if f.is_a?(::JournalsForMessage) && f[:jour_type] == "Course" @@ -55,9 +57,20 @@ module Mobile expose :reply_user,using: Mobile::Entities::User do |f, opt| f.at_user end - expose :child_reply,using: Mobile::Entities::Jours do |f, opt| + expose :all_children,using: Mobile::Entities::Jours do |f, opt| if f.is_a?(::JournalsForMessage) - f.children.reverse + # f.children.reverse + if !opt[:children] && opt[:comment_type].nil? + if f.parent.nil? && opt[:type] == 0 + opt[:children] = true + all_comments = [] + tStart = opt[:page]*5 + tEnd = (opt[:page]+1)*5 - 1 + + all_comments = get_all_children(all_comments, f)[tStart..tEnd] + all_comments + end + end end end expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| @@ -67,6 +80,78 @@ module Mobile has_praise = obj.empty? ? false : true has_praise end + + expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| + parents_reply = [] + + if options[:comment_type].nil? + parents_reply = get_reply_parents_no_root(parents_reply, instance) + elsif options[:comment_type] == "homework" + parents_reply = get_reply_parents(parents_reply, instance) + end + parents_reply.count + end + + expose :parents_reply_bottom, using:Mobile::Entities::Jours do |f,opt| + if f.is_a? (::JournalsForMessage) + #取二级回复的底楼层 + parents_reply = [] + if opt[:comment_type].nil? + parents_reply = get_reply_parents_no_root(parents_reply, f) + elsif opt[:comment_type] == "homework" + parents_reply = get_reply_parents(parents_reply, f) + end + if parents_reply.count > 0 && parents_reply.count != 2 && !opt[:bottom] + if opt[:type] == 1 + # opt[:bottom] = true + # parents_reply[opt[:page]..opt[:page]] + else + opt[:bottom] = true + parents_reply[0..0] + end + else + [] + end + end + end + + expose :parents_reply_top, using:Mobile::Entities::Jours do |f,opt| + if f.is_a? (::JournalsForMessage) + #取二级回复的顶楼层 + parents_reply = [] + + if opt[:comment_type].nil? + parents_reply = get_reply_parents_no_root(parents_reply, f) + elsif opt[:comment_type] == "homework" + parents_reply = get_reply_parents(parents_reply, f) + end + if parents_reply.count >= 2 && !opt[:top] + if opt[:type] == 1 + opt[:bottom] = true + tStart = (opt[:page]-1)*5+2 + tEnd = (opt[:page])*5+2 - 1 + + if tEnd >= parents_reply.count - 1 + tEnd = parents_reply.count - 2 + end + + if tStart <= parents_reply.count - 2 + parents_reply = parents_reply.reverse[tStart..tEnd] + parents_reply.reverse + else + [] + end + else + opt[:top] = true + parents_reply = parents_reply.reverse[0..1] + parents_reply.reverse + end + else + [] + end + end + end + end end end diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index d58192378..c2744f63a 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -30,7 +30,7 @@ module Mobile 'Message' when :act_id u.id - when :replies_count + when :comment_count all_comments = [] get_all_children(all_comments, u).count end @@ -51,15 +51,26 @@ module Mobile message_expose :board_id message_expose :subject message_expose :content - message_expose :replies_count + message_expose :comment_count message_expose :praise_count message_expose :created_on message_expose :locked message_expose :id message_expose :lasted_comment - expose :message_children,using:Mobile::Entities::Message do |c,opt| + expose :all_children,using:Mobile::Entities::Message do |c,opt| if c.is_a? (::Message) - c.children.reverse + # c.children.reverse + if !opt[:children] + if c.parent.nil? && opt[:type] == 0 + opt[:children] = true + all_comments = [] + tStart = opt[:page]*5 + tEnd = (opt[:page]+1)*5 - 1 + + all_comments = get_all_children(all_comments, c)[tStart..tEnd] + all_comments + end + end end end expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| @@ -69,6 +80,63 @@ module Mobile has_praise = obj.empty? ? false : true has_praise end + + expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| + parents_reply = [] + parents_reply = get_reply_parents_no_root(parents_reply, instance) + parents_reply.count + end + + expose :parents_reply_bottom, using:Mobile::Entities::Message do |c,opt| + if c.is_a? (::Message) + #取二级回复的底楼层 + parents_reply = [] + parents_reply = get_reply_parents_no_root(parents_reply, c) + if parents_reply.count > 0 && parents_reply.count != 2 && !opt[:bottom] + if opt[:type] == 1 + # opt[:bottom] = true + # parents_reply[opt[:page]..opt[:page]] + else + opt[:bottom] = true + parents_reply[0..0] + end + else + [] + end + end + end + + expose :parents_reply_top, using:Mobile::Entities::Message do |c,opt| + if c.is_a? (::Message) + #取二级回复的顶楼层 + parents_reply = [] + parents_reply = get_reply_parents_no_root(parents_reply, c) + if parents_reply.count >= 2 && !opt[:top] + if opt[:type] == 1 + opt[:bottom] = true + tStart = (opt[:page]-1)*5+2 + tEnd = (opt[:page])*5+2 - 1 + + if tEnd >= parents_reply.count - 1 + tEnd = parents_reply.count - 2 + end + + if tStart <= parents_reply.count - 2 + parents_reply = parents_reply.reverse[tStart..tEnd] + parents_reply.reverse + else + [] + end + else + opt[:top] = true + parents_reply = parents_reply.reverse[0..1] + parents_reply.reverse + end + else + [] + end + end + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index ff1452b1c..d69232c44 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -24,7 +24,7 @@ module Mobile 'News' when :act_id f.id - when :comments_count + when :comment_count all_comments = [] get_all_children(all_comments, f).count end @@ -70,7 +70,7 @@ module Mobile #发布时间 news_expose :created_on #评论数量 - news_expose :comments_count + news_expose :comment_count news_expose :praise_count #课程名字 news_expose :course_name diff --git a/app/api/mobile/entities/whomework.rb b/app/api/mobile/entities/whomework.rb index 8985f3d60..7178ff67d 100644 --- a/app/api/mobile/entities/whomework.rb +++ b/app/api/mobile/entities/whomework.rb @@ -26,7 +26,7 @@ module Mobile wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1) when :praise_count get_activity_praise_num(wh) - when :whomework_journal_count + when :comment_count wh.journals_for_messages.count when :course_name wh.course.name @@ -58,6 +58,7 @@ module Mobile expose :anonymous_comment expose :quotes expose :is_open + expose :id whomework_expose :act_type whomework_expose :act_id whomework_expose :course_name @@ -66,11 +67,19 @@ module Mobile whomework_expose :evaluation_start whomework_expose :evaluation_end whomework_expose :praise_count - whomework_expose :whomework_journal_count - expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt| + whomework_expose :comment_count + expose :all_children, using: Mobile::Entities::Jours do |f, opt| #f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages) if f.is_a?(::HomeworkCommon) - f.journals_for_messages.reverse + # f.journals_for_messages.reverse + if !opt[:children] && opt[:type] == 0 + opt[:children] = true + tStart = opt[:page]*5 + tEnd = (opt[:page]+1)*5 - 1 + + all_comments = f.journals_for_messages.reorder("created_on desc") + all_comments[tStart..tEnd] + end end end expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 665273ae0..28366b109 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -634,8 +634,11 @@ class CoursesController < ApplicationController end if @course #发送微信消息 - ss = SyllabusesService.new - ss.send_wechat_create_class_notice User.current,@course + count = ShieldWechatMessage.where("container_type='User' and container_id=#{User.current.id} and shield_type='Course' and shield_id=#{@course.id}").count + if count == 0 + ss = SyllabusesService.new + ss.send_wechat_create_class_notice User.current,@course + end respond_to do |format| flash[:notice] = l(:notice_successful_create) format.html {redirect_to course_url(@course)} diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index d18575b94..075c752ef 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -31,8 +31,8 @@