博客动态回复二级回复修改

This commit is contained in:
yuanke 2016-07-20 10:09:27 +08:00
parent ea88c92d31
commit 1ce7b22c0e
5 changed files with 90 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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(){
}

View File

@ -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();
}