From b3b0488bf5188ea2c4083afcc18c97e79a64737c Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 1 Apr 2016 20:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=82=B9=E5=87=BB=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/activities.rb | 14 ++++- app/api/mobile/apis/new_comment.rb | 2 +- app/api/mobile/entities/message.rb | 3 ++ app/api/mobile/entities/news.rb | 6 ++- public/assets/wechat/activities.html | 56 +++++++++++++++++++- public/javascripts/wechat/homework-detail.js | 10 ++-- public/javascripts/wechat/wechat-dev.js | 56 +------------------- 7 files changed, 81 insertions(+), 66 deletions(-) diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb index 41069b4bf..9329ea860 100644 --- a/app/api/mobile/apis/activities.rb +++ b/app/api/mobile/apis/activities.rb @@ -6,12 +6,16 @@ module Mobile resources :activities do desc "get user activities" + + params do + requires :page, type: Integer + end get ':id' do #uw = UserWechat.find params[:openid] user = User.find params[:id] shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id) shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id) - page = params[:page] ? params[:page].to_i + 1 : 0 + page = params[:page] ? params[:page] : 0 user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll','Course')" @@ -22,8 +26,14 @@ module Mobile activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(50).offset(page * 10) + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc') + all_count = activities.count + activities = activities.limit(10).offset(page * 10) + count = activities.count present :data, activities, with: Mobile::Entities::Activity + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end end diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 63775c12d..753299956 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -12,7 +12,7 @@ module Mobile requires :type, type: String requires :content, type: String end - get ':id' do + post ':id' do type = params[:type] result = 1 current_user = User.find 8686 diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index 3d7fb7bbe..d182e5965 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -24,6 +24,8 @@ module Mobile end when :lasted_comment time_from_now u.created_on + when :message_praise_count + get_activity_praise_num(u) end end end @@ -41,6 +43,7 @@ module Mobile message_expose :subject message_expose :content message_expose :replies_count + message_expose :message_praise_count message_expose :created_on message_expose :id message_expose :lasted_comment diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index bf084c2f4..d1ec9c5c3 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -2,6 +2,7 @@ module Mobile module Entities class News < Grape::Entity include Redmine::I18n + include ApiHelper def self.news_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -16,7 +17,9 @@ module Mobile else case field when :course_name - Course.find(f.course_id).name unless f.course_id == nil + get_course(f.course_id).name unless f.course_id == nil + when :news_praise_count + get_activity_praise_num(f) end end elsif f.is_a?(Hash) && !f.key?(field) @@ -59,6 +62,7 @@ module Mobile news_expose :created_on #评论数量 news_expose :comments_count + news_expose :news_praise_count #课程名字 news_expose :course_name #评论 diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index c1467bc52..066a28f25 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -211,13 +211,65 @@ -
更多
+ +
更多
+ - + \ No newline at end of file diff --git a/public/javascripts/wechat/homework-detail.js b/public/javascripts/wechat/homework-detail.js index e4e3a9758..1c223bfc2 100644 --- a/public/javascripts/wechat/homework-detail.js +++ b/public/javascripts/wechat/homework-detail.js @@ -64,14 +64,14 @@ $(document).ready(function(){ //获取并传送回复用户数据 var userInfo = { - "replyType" : "homework_assignment", - "replyContent" : postInput + "type" : "HomeworkCommon", + "content" : postInput }; $.ajax({ type: "POST", //提交方式 dataType: "json", //类型 - url: "前台地址/后台方法", //提交的页面,方法名 + url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名 data: userInfo, //参数,如果没有,可以为null success: function (data) { //如果执行成功,那么执行此方法 alert(data.d); //用data.d来获取后台传过来的json语句,或者是单纯的语句 @@ -82,14 +82,14 @@ $(document).ready(function(){ }); } - } + }; //点赞效果 var praiseClick = function(){ var praiseNum = $(".post-interactive-praise").text().match(/\d+/g); praiseNum++; $(".praise-num").text("(" + praiseNum + ")"); - } + }; }); \ No newline at end of file diff --git a/public/javascripts/wechat/wechat-dev.js b/public/javascripts/wechat/wechat-dev.js index eacbf8559..c921ed64d 100644 --- a/public/javascripts/wechat/wechat-dev.js +++ b/public/javascripts/wechat/wechat-dev.js @@ -2,59 +2,5 @@ * Created by root on 3/25/16. */ $(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_DELIMITER=''; - - - var apiUrl = '/api/v1/'; - - var setTemplate = function(data){ - console.log(data); - var html=bt('t:result-list',{activities: data}); - $('#container').prepend(html); - descToggle(); - $('.post-reply-submit').click(function(){ - replyInsert(); - }); - }; - - var loadDataFromServer = function(id){ - //getOpenId(function(openid){ - $.ajax({ - url: apiUrl + 'activities/' + id, - dataType: 'json', - success: function(data){ - setTemplate(data.data); - }, - error: function(xhr,status,err){ - console.log(err); - } - }); - //}) - - - }; - - loadDataFromServer(1); - - //内容全部显示与部分隐藏 - var descToggle = function(){ - $(".post-all-content").each(function(){ - var postHeight = $(this).height(); - if (postHeight > 90){ - $(this).parent().next().css("display","block"); - $(this).parent().next().toggle(function(){ - $(this).text("点击隐藏"); - $(this).prev().css("height",postHeight); - },function(){ - $(this).text("点击展开"); - $(this).prev().css("height",90); - }); - } - }); - } - - + loadDataFromServer(8686, 0); });