冲突解决
This commit is contained in:
commit
4902361b3f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -40,7 +40,7 @@ module Mobile
|
|||
issue_expose :journals_count
|
||||
expose :issue_journals, using: Mobile::Entities::Journal do |f, opt|
|
||||
if f.is_a?(::Issue)
|
||||
f.journals
|
||||
f.journals.where("notes != null")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Journal <Grape::Entity
|
||||
=begin
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
include IssuesHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
#include Erubis::ERB::Util
|
||||
include ActionView::Helpers::UrlHelper
|
||||
=end
|
||||
def self.journal_expose(f)
|
||||
expose f do |journal, opt|
|
||||
if journal.is_a?(Hash) && journal.key?(f)
|
||||
|
@ -21,7 +24,7 @@ module Entities
|
|||
case f
|
||||
when :detail_journal
|
||||
if journal.details.any?
|
||||
jdetails_to_strings(journal.details)
|
||||
details_to_strings(journal.details)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -31,7 +34,7 @@ module Entities
|
|||
|
||||
expose :notes
|
||||
journal_expose :created_on
|
||||
journal_expose :detail_journal
|
||||
#journal_expose :detail_journal
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#评论
|
||||
|
|
|
@ -212,13 +212,65 @@
|
|||
</div>
|
||||
<! } !>
|
||||
<! } !>
|
||||
<div class="more-events mt10" onclick="loadMore()">更多</div>
|
||||
<! if ((count + page * 10) < all_count) {!>
|
||||
<div id="more_activities" class="more-events mt10" onclick="loadDataFromServer(8686, <!= page+1 !>);">更多</div>
|
||||
<! } !>
|
||||
</script>
|
||||
|
||||
<script src="/javascripts/jquery-1.3.2.js"></script>
|
||||
<script src="/javascripts/baiduTemplate.js"></script>
|
||||
<script src="/javascripts/wechat/wechat_dev.js"></script>
|
||||
<script src="/javascripts/wechat/homework_detail.js"></script>
|
||||
<script src="/javascripts/wechat/auth.js"></script>
|
||||
<script type="text/javascript">
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_DELIMITER='!>';
|
||||
|
||||
var apiUrl = '/api/v1/';
|
||||
var loadDataFromServer = function(id, page){
|
||||
//getOpenId(function(openid){
|
||||
$.ajax({
|
||||
url: apiUrl + 'activities/' + id +"?page=" + parseInt(page),
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
setTemplate(data.data, data.all_count, data.count, data.page);
|
||||
},
|
||||
error: function(xhr,status,err){
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
//})
|
||||
|
||||
};
|
||||
var setTemplate = function(data, all_count, count, page){
|
||||
console.log(data);
|
||||
var html=bt('t:result-list',{activities: data, all_count: all_count, count: count, page: page});
|
||||
if (page == 0) {
|
||||
$('#container').prepend(html);
|
||||
} else {
|
||||
$("#more_activities").remove();
|
||||
$('#container').append(html);
|
||||
}
|
||||
descToggle();
|
||||
};
|
||||
//内容全部显示与部分隐藏
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -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 + ")");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
});
|
|
@ -2,59 +2,5 @@
|
|||
* Created by root on 3/25/16.
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
|
||||
var bt=baidu.template;
|
||||
bt.LEFT_DELIMITER='<!';
|
||||
bt.RIGHT_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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue