From 1ce7b22c0eaa78316b62f66c3dd865ac9860d1ac Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Wed, 20 Jul 2016 10:09:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E5=8A=A8=E6=80=81=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E4=BA=8C=E7=BA=A7=E5=9B=9E=E5=A4=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/api.rb | 38 +++++++------- app/api/mobile/apis/blog_comments.rb | 7 ++- app/api/mobile/entities/blog_comment.rb | 49 ++++++++++++++++++- public/javascripts/wechat/controllers/blog.js | 14 +++++- public/javascripts/wechat/others/factory.js | 10 ++-- 5 files changed, 90 insertions(+), 28 deletions(-) diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index 5a0345207..9b4bdb5d6 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -1,25 +1,25 @@ #coding=utf-8 module Mobile - # require_relative 'middleware/error_handler' - # require_relative 'apis/auth' - # require_relative 'apis/users' - # require_relative 'apis/courses' - # require_relative 'apis/watches' - # require_relative 'apis/upgrade' - # require_relative 'apis/homeworks' - # require_relative 'apis/comments' - # require_relative 'apis/issues' - # require_relative 'apis/activities' - # require_relative 'apis/whomeworks' - # require_relative 'apis/newss' - # require_relative 'apis/journal_for_messages' - # require_relative 'apis/messages' - # require_relative 'apis/blog_comments' - # require_relative 'apis/new_comment' - # require_relative 'apis/praise' - # require_relative 'apis/resources' - # require_relative 'apis/syllabuses' + require_relative 'middleware/error_handler' + require_relative 'apis/auth' + require_relative 'apis/users' + require_relative 'apis/courses' + require_relative 'apis/watches' + require_relative 'apis/upgrade' + require_relative 'apis/homeworks' + require_relative 'apis/comments' + require_relative 'apis/issues' + require_relative 'apis/activities' + require_relative 'apis/whomeworks' + require_relative 'apis/newss' + require_relative 'apis/journal_for_messages' + require_relative 'apis/messages' + require_relative 'apis/blog_comments' + require_relative 'apis/new_comment' + require_relative 'apis/praise' + require_relative 'apis/resources' + require_relative 'apis/syllabuses' class API < Grape::API version 'v1', using: :path diff --git a/app/api/mobile/apis/blog_comments.rb b/app/api/mobile/apis/blog_comments.rb index bb5758e71..5b970e0ba 100644 --- a/app/api/mobile/apis/blog_comments.rb +++ b/app/api/mobile/apis/blog_comments.rb @@ -8,8 +8,13 @@ module Mobile desc "get special topic" get ':id' do user = current_user + + #0一级回复的更多 1 二级回复的更多 + type = params[:type] || 0 + page = params[:page] || 0 + blog = BlogComment.find params[:id] - present :data, blog, with: Mobile::Entities::BlogComment,user: user + present :data, blog, with: Mobile::Entities::BlogComment,user: user,type: type,page: page present :status, 0 end end diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb index a61864900..cd7902097 100644 --- a/app/api/mobile/entities/blog_comment.rb +++ b/app/api/mobile/entities/blog_comment.rb @@ -53,7 +53,18 @@ module Mobile blog_comment_expose :praise_count expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt| if c.is_a? (::BlogComment) - 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| @@ -63,6 +74,42 @@ module Mobile has_praise = obj.empty? ? false : true has_praise end + + expose :parents_reply_bottom, using:Mobile::Entities::BlogComment do |c,opt| + if c.is_a? (::BlogComment) + #取二级回复的底楼层 + if (opt[:type] == 1 && !opt[:bottom]) + opt[:bottom] = true + parents_reply = [] + parents_reply = c.parent.nil? ? [] : parents_reply << c.parent #get_reply_parents_no_root(parents_reply, c)[0] + parents_reply + end + end + end + + expose :parents_reply_top, using:Mobile::Entities::BlogComment do |c,opt| + if c.is_a? (::BlogComment) + #取二级回复的顶楼层 + if (opt[:type] == 1 && !opt[:top]) + opt[:top] = true + + parents_reply = [] + parents_reply = get_reply_parents_no_root(parents_reply, c) + + tStart = opt[:page]*2 + tEnd = (opt[:page]+1)*2 - 1 + + parents_reply = parents_reply.reverse[tStart,tEnd] + parents_reply + end + end + 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 end end end \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/blog.js b/public/javascripts/wechat/controllers/blog.js index 4c2403944..48bd2863a 100644 --- a/public/javascripts/wechat/controllers/blog.js +++ b/public/javascripts/wechat/controllers/blog.js @@ -7,8 +7,18 @@ app.controller('BlogController', scope: $scope, type: 'blog_comments', replyType: 'BlogComment', - loadCallback: function(data){ - $scope.blog = data.data; + loadCallback: function(data,replytype,page){ + console.log(data.data); + + if (replytype == 0 && page == 0 ) { + $scope.blog = data.data; + } + else{ + + + + + } }, replyCallback: function(){ } diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index 2b0d4f994..3e5b4c4f3 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -158,19 +158,19 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms', function($http, au var init = function(args){ args.scope.formData = {comment: ''}; - var loadData = function(id){ - loadCommonData(id, args.type).then(function successCallback(response) { - args.loadCallback(response.data); + var loadData = function(id,replytype,page){ + loadCommonData(id, args.type,replytype,page).then(function successCallback(response) { + args.loadCallback(response.data,replytype,page); }, function errorCallback(response) { }); }; - loadData(args.id); + loadData(args.id,0,0); args.scope.addReply = function(data){ console.log(data.comment); addCommonReply(args.id, args.replyType, data, function(){ args.scope.formData = {comment: ''}; - loadData(args.id); + loadData(args.id,0,0); if(typeof args.replyCallback === 'function'){ args.replyCallback(); }