Merge branch 'develop' into cxt_course

Conflicts:
	app/controllers/admin_controller.rb
	config/routes.rb
	lib/redmine.rb
cxt_course
cxt 9 years ago
commit 7481d96166

1
.gitignore vendored

@ -30,3 +30,4 @@ vendor/cache
/public/files
/tags
/config/initializers/gitlab_config.rb
1234567

@ -0,0 +1 @@
{"access_token":"bFlabz0uBcoIBfWL7nBJkgpl26aOWDy-dyCOvH_MjUo_hMOOKG83WV1cCL1MG6H-AE-6eMI0iyLoOoAMv9Y3pFFsLYD-GAGr3UH9fT8OqeHMDlFhXyRTvHv9l2QPHGpcARUcCGANEH","expires_in":7200,"got_token_at":1462934760}

@ -1,11 +1,12 @@
source 'https://ruby.taobao.org'
#source 'http://ruby.sdutlinux.org/'
source 'https://rubygems.org/'
### 这里执行bundle config mirror.https://rubygems.org https://gems.ruby-china.org 切换到ruby-china源
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
end
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
gem 'rest-client'
@ -16,8 +17,9 @@ gem 'delayed_job_active_record'#, :group => :production
gem 'daemons'
gem 'grape', '~> 0.9.0'
gem 'grape-entity'
gem 'rack-cors', :require => 'rack/cors'
gem 'seems_rateable', '~> 1.0.13'
gem "rails", "~> 3.2.13"
gem 'rails', '~> 3.2'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem 'coderay', '~> 1.1.0'
@ -40,10 +42,15 @@ gem 'kaminari'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
### profile
#gem 'oneapm_rpm'
group :development do
gem 'grape-swagger'
gem 'better_errors', '~> 1.1.0'
gem 'rack-mini-profiler', '~> 0.9.3'
# gem "query_reviewer"
# gem 'rack-mini-profiler', '~> 0.9.3'
if RUBY_PLATFORM =~ /w32/
gem 'win32console'
end

@ -7,6 +7,16 @@ module Mobile
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'
class API < Grape::API
version 'v1', using: :path
format :json
@ -39,6 +49,15 @@ module Mobile
mount Apis::Upgrade
mount Apis::Homeworks
mount Apis::Comments
mount Apis::Issues
mount Apis::Activities
mount Apis::Whomeworks
mount Apis::Newss
mount Apis::JournalForMessages
mount Apis::Messages
mount Apis::BlogComments
mount Apis::NewComment
mount Apis::Praise
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?

@ -0,0 +1,63 @@
#coding=utf-8
module Mobile
module Apis
class Activities< Grape::API
resources :activities do
desc "get user activities"
params do
requires :page, type: Integer
requires :openid, type: String
end
post do
user = UserWechat.find_by_openid(params[:openid]).user
=begin
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] : 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')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
blog_ids = "("+user.blog.id.to_s+","+((User.watched_by(user.id).count == 0 )? '0' :User.watched_by(user.id).map{|u| u.blog.id}.join(','))+")"
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')
=end
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(','))
user_ids = "(" + user.id.to_s + watched_user_ids + ")"
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
blog_ids = "(" + watched_user_blog_ids + ")"
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')
all_count = activities.count
activities = activities.limit(10).offset(page * 10)
count = activities.count
present :data, activities, with: Mobile::Entities::Activity,user: user
present :all_count, all_count
present :count, count
present :page, page
present :status, 0
end
end
end
end
end

@ -0,0 +1,19 @@
#coding=utf-8
module Mobile
module Apis
class BlogComments< Grape::API
resources :blog_comments do
desc "get special topic"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
blog = BlogComment.find params[:id]
present :data, blog, with: Mobile::Entities::BlogComment,user: user
present :status, 0
end
end
end
end
end

@ -115,7 +115,7 @@ module Mobile
desc '通知评论列表'
params do
requires :token, type: String
#requires :token, type: String
requires :notice_id,type:Integer,desc:'通知id'
optional :page,type:Integer,desc:'页码'
end

@ -0,0 +1,19 @@
#coding=utf-8
module Mobile
module Apis
class Issues< Grape::API
resources :issues do
include IssuesHelper
desc "get special issuse"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
issue = Issue.find params[:id]
present :data, issue, with: Mobile::Entities::Issue,user: user
present :status, 0
end
end
end
end
end

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class JournalForMessages< Grape::API
resources :journal_for_messages do
desc "get special journal"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
jour = JournalsForMessage.find params[:id]
present :data, jour, with: Mobile::Entities::Jours,user: user
present :status, 0
end
end
end
end
end

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class Messages< Grape::API
resources :messages do
desc "get special topic"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
message = Message.find params[:id]
present :data, message, with: Mobile::Entities::Message,user: user
present :status, 0
end
end
end
end
end

@ -0,0 +1,105 @@
#coding=utf-8
module Mobile
module Apis
class NewComment< Grape::API
include ApplicationHelper
include ApiHelper
resources :new_comment do
desc "add a new comment"
params do
requires :type, type: String
requires :content, type: String
requires :openid, type: String
end
post ':id' do
type = params[:type]
result = 1
current_user = UserWechat.find_by_openid(params[:openid]).user
if params[:content]!="" && current_user
case type
when "HomeworkCommon"
homework_common = HomeworkCommon.find(params[:id])
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
if (feedback.errors.empty?)
homework_common.update_column(:updated_at, Time.now)
result = 2
end
when "News"
news = News.find(params[:id])
comment = Comment.new
comment.comments = params[:content]
comment.author = current_user
if news.comments << comment
result = 2
end
when "Message"
message = Message.find(params[:id])
board = Board.find(message.board_id)
topic = message.root
reply = Message.new
reply.author = current_user
reply.board = board
reply.content = params[:content]
reply.parent_id = params[:id]
reply.subject = "RE: #{topic.subject}"
if topic.children << reply
result = 2
end
when "JournalsForMessage"
jour = JournalsForMessage.find params[:id]
parent_id = params[:id]
author_id = current_user.id
reply_user_id = jour.user_id
reply_id = params[:id]
content = params[:content]
options = {:user_id => author_id,
:status => true,
:m_parent_id => parent_id,
:m_reply_id => reply_id,
:reply_id => reply_user_id,
:notes => content,
:is_readed => false}
jfm = jour.user.add_jour(nil, nil, nil, options)
if jfm.errors.empty?
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
result = 2
end
when 'Issue'
issue = Issue.find params[:id]
is_jour = Journal.new
is_jour.user_id = current_user.id
is_jour.notes = params[:content]
is_jour.journalized = issue
if is_jour.save
result = 2
end
when 'BlogComment'
blog = BlogComment.find(params[:id]).root
blogComment = BlogComment.new
blogComment.author = current_user
blogComment.blog = blog.blog
blogComment.content = params[:content]
blogComment.title = "RE: #{blog.title}"
if blog.children << blogComment
result = 2
end
end
if result == 2
update_course_activity_api(type,params[:id])
update_user_activity_api(type,params[:id])
update_org_activity_api(type,params[:id])
update_forge_activity_api(type,params[:id])
update_principal_activity_api(type,params[:id])
end
else
result = 3
end
present :result, result
present :status, 0
end
end
end
end
end

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class Newss< Grape::API
resources :newss do
desc "get special news"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
news = News.find params[:id]
present :data, news, with: Mobile::Entities::News,user: user
present :status, 0
end
end
end
end
end

@ -0,0 +1,41 @@
#coding=utf-8
module Mobile
module Apis
class Praise< Grape::API
include ApiHelper
resources :praise do
desc "praise an activity"
params do
requires :type, type: String
requires :openid, type: String
end
post ':id' do
obj_id = params[:id]
obj_type = params[:type]
user = UserWechat.find_by_openid(params[:openid]).user
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first
if pts.blank?
praise_or_cancel(obj_type,obj_id,user,1)
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
num = get_activity_praise_num(obj) if !obj.blank?
else
pts.destroy if !pts.blank?
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
ptc = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
ptc.praise_minus(1) if !ptc.blank?
if ptc.praise_num == 0
ptc.delete
end
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
num = !obj.blank? ? get_activity_praise_num(obj) : 0
end
present :data, num
present :status, 0
end
end
end
end
end

@ -0,0 +1,18 @@
#coding=utf-8
module Mobile
module Apis
class Whomeworks< Grape::API
resources :whomeworks do
desc "get one homework"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
homework = HomeworkCommon.find params[:id]
present :data, homework, with: Mobile::Entities::Whomework,user: user
present :status, 0
end
end
end
end
end

@ -0,0 +1,146 @@
# encoding: utf-8
module Mobile
module Entities
class Activity <Grape::Entity
include ApplicationHelper
include ApiHelper
def self.act_expose(f)
expose f do |ac,opt|
if ac.is_a?(Hash) && ac.key?(f)
ac[f]
elsif ac.is_a?(::UserActivity)
if ac.respond_to?(f)
ac.send(f)
else
case f
when :user_act
if ac.act_type == "ProjectCreateInfo"
ac unless ac.nil?
else
ac.act unless ac.nil? || ac.act.nil?
end
when :reply_count
if ac.act_type == "HomeworkCommon"
ac.nil? || ac.act.nil? ? 0 : ac.act.journals_for_messages.count
elsif ac.act_type == "News"
ac.nil? || ac.act.nil? ? 0 : ac.act.comments.count
elsif ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage"
ac.nil? || ac.act.nil? ? 0 : ac.act.children.count
elsif ac.act_type == "Issue"
ac.nil? || ac.act.nil? ? 0 : ac.act.journals.where("notes is not null and notes != ''").count
end
when :subject
if ac.act_type == "HomeworkCommon"
ac.act.name unless ac.nil? || ac.act.nil?
elsif ac.act_type == "News" || ac.act_type == "BlogComment"
ac.act.title unless ac.nil? || ac.act.nil?
elsif ac.act_type == "Message" || ac.act_type == "Issue"
ac.act.subject unless ac.nil? || ac.act.nil?
elsif ac.act_type == "JournalsForMessage"
ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil?
end
when :description
if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News"
ac.act.description unless ac.nil? || ac.act.nil?
elsif ac.act_type == "Message" || ac.act_type == "BlogComment"
ac.act.content unless ac.nil? || ac.act.nil?
elsif ac.act_type == "JournalsForMessage"
ac.act.notes unless ac.nil? || ac.act.nil?
end
when :latest_update
time_from_now ac.updated_at unless ac.nil?
when :praise_count
if ac.act_type == "HomeworkCommon" || ac.act_type == "News" || ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage" || ac.act_type == "Issue"
ac.nil? || ac.act.nil? ? 0 : get_activity_praise_num(ac.act)
end
#when :homework_common_detail_manual
# if ac.act_type == "HomeworkCommon"
# ac.act.homework_detail_manual unless ac.nil? || ac.act.nil? || ac.act.homework_detail_manual.nil?
# end
when :course_project_name
if ac.container_type == "Course"
name = (get_course(ac.container_id)).name
name
elsif ac.container_type == "Project"
name = (get_project(ac.container_id)).name
name
elsif ac.container_type == "Blog"
"发表博客"
end
when :activity_type_name
if ac.container_type == "Course"
case ac.act_type
when "HomeworkCommon"
"课程作业"
when "News"
"课程通知"
when "Message"
"课程问答区"
when "Poll"
"课程问卷"
when "Course"
"课程"
end
elsif ac.container_type == "Project"
case ac.act_type
when "Issue"
"项目缺陷"
when "Message"
"项目讨论区"
when "ProjectCreateInfo"
"项目"
end
end
end
end
end
end
end
expose :act_type #缺陷/作业/讨论区/留言等类型
expose :act_id
expose :container_type #课程/项目/博客/个人
expose :author, using: Mobile::Entities::User do |a, opt| #用户信息
if a.is_a? ::UserActivity
if a.act_type == "ProjectCreateInfo"
get_user(get_project(a.act_id).user_id)
elsif !a.act.nil?
if a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment'
a.act.author
elsif a.act_type == 'HomeworkCommon' || a.act_type == 'Poll' || a.act_type == 'JournalsForMessage'
a.act.user
elsif a.act_type == 'Course'
a.act.teacher
end
end
end
end
expose :homework_common_detail , using: Mobile::Entities::Whomework do |a, opt| #作业相关信息
if a.act_type == "HomeworkCommon"
a.act
end
end
expose :issue_detail, using: Mobile::Entities::Issue do |a, opt| #缺陷信息
if a.act_type == "Issue"
a.act
end
end
act_expose :reply_count #回复数
act_expose :praise_count #点赞数
#act_expose :user_act #某个动态
act_expose :subject #标题
act_expose :description #描述
act_expose :latest_update #最新更新时间
act_expose :course_project_name #课程/项目名字
act_expose :activity_type_name #课程问答区/项目缺陷等
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
if instance.act_type == "HomeworkCommon" || instance.act_type == "News" || instance.act_type == "Message" || instance.act_type == "BlogComment" || instance.act_type == "JournalsForMessage" || instance.act_type == "Issue"
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end
end

@ -0,0 +1,65 @@
module Mobile
module Entities
class BlogComment < Grape::Entity
include ApplicationHelper
include ApiHelper
def self.blog_comment_expose(f)
expose f do |u,opt|
if u.is_a?(Hash) && u.key?(f)
u[f]
elsif u.is_a?(::BlogComment)
if u.respond_to?(f)
if f == :created_at
format_time( u.send(f))
else
u.send(f)
end
else
case f
when :praise_count
get_activity_praise_num(u)
when :lasted_comment
time_from_now(u.created_at)
when :act_type
'BlogComment'
when :act_id
u.id
when :comment_count
u.children.count
end
end
end
end
end
expose :user, using: Mobile::Entities::User do |c, opt|
if c.is_a?(::BlogComment)
c.author
end
end
blog_comment_expose :act_type
blog_comment_expose :act_id
blog_comment_expose :blog_id
blog_comment_expose :title
blog_comment_expose :content
blog_comment_expose :comment_count
blog_comment_expose :created_at
blog_comment_expose :lasted_comment
blog_comment_expose :id
blog_comment_expose :praise_count
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
if c.is_a? (::BlogComment)
c.children.reverse
end
end
expose :has_praise, if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

@ -9,7 +9,7 @@ module Mobile
elsif f.is_a?(::Comment)
if f.respond_to?(field)
if field == :created_on
format_time(f.send(field))
time_from_now(f.send(field))
else
f.send(field)
end

@ -0,0 +1,67 @@
module Mobile
module Entities
class Issue <Grape::Entity
include ApiHelper
include Redmine::I18n
def self.issue_expose(f)
expose f do |issue, opt|
if issue.is_a?(Hash) && issue.key?(f)
issue[f]
elsif issue.is_a?(::Issue)
if issue.respond_to?(f)
if f == :created_on
format_time(issue.send(f))
else
issue.send(f)
end
else
case f
when :issue_priority
get_issue_priority_api issue.priority_id
when :issue_assigned_to
(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
when :project_name
issue.project.name
when :praise_count
get_activity_praise_num(issue)
when :act_type
'Issue'
when :act_id
issue.id
end
end
end
end
end
expose :subject
expose :description
expose :author, using: Mobile::Entities::User
expose :done_ratio
issue_expose :act_type
issue_expose :act_id
issue_expose :created_on
issue_expose :issue_priority
issue_expose :issue_assigned_to
issue_expose :issue_status
issue_expose :journals_count
issue_expose :project_name
issue_expose :praise_count
expose :issue_journals, using: Mobile::Entities::Journal do |f, opt|
if f.is_a?(::Issue)
f.journals.where("notes is not null and notes != ''").reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

@ -0,0 +1,44 @@
module Mobile
module Entities
class Journal <Grape::Entity
include Redmine::I18n
=begin
include Redmine::I18n
include ApplicationHelper
include ApiHelper
include IssuesHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
=end
def self.journal_expose(f)
expose f do |journal, opt|
if journal.is_a?(Hash) && journal.key?(f)
journal[f]
elsif journal.is_a?(::Journal)
if journal.respond_to?(f)
if f == :created_on
time_from_now(journal.send(f))
else
journal.send(f)
end
else
case f
when :detail_journal
if journal.details.any?
details_to_strings(journal.details)
end
end
end
end
end
end
expose :notes
journal_expose :created_on
expose :user,using: Mobile::Entities::User do |f, opt|
f.user
end
#journal_expose :detail_journal
end
end
end

@ -3,7 +3,6 @@ module Mobile
#普通留言
class Jours < Grape::Entity
include Redmine::I18n
include WordsHelper
def self.jours_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
@ -15,13 +14,24 @@ module Mobile
f.send(field)
end
else
case f
when :course_name
f[:jour_type] == "Course" ? f.course.name : ""
case field
when :lasted_comment
time_from_now f.created_on
when :reply_count
f.children.count
when :praise_count
get_activity_praise_num(f)
when :act_type
'JournalsForMessage'
when :act_id
f.id
end
end
end
end
jours_expose :act_type
jours_expose :act_id
jours_expose :id
jours_expose :jour_type
jours_expose :jour_id
@ -29,9 +39,12 @@ module Mobile
f.user
end
jours_expose :created_on
jours_expose :lasted_comment
jours_expose :notes
jours_expose :m_reply_id
jours_expose :m_parent_id
jours_expose :reply_count
jours_expose :praise_count
expose :course,using:Mobile::Entities::Course do |f,opt|
if f.is_a?(::JournalsForMessage) && f[:jour_type] == "Course"
f.course
@ -42,9 +55,16 @@ module Mobile
end
expose :child_reply,using: Mobile::Entities::Jours do |f, opt|
if f.is_a?(::JournalsForMessage)
fetch_user_leaveWord_reply(f)
f.children.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

@ -15,10 +15,22 @@ module Mobile
u.send(f)
end
else
# case f
# when :xx
# #
# end
case f
when :course_project_name
if u.board.project_id == -1
u.course.name
else
u.project.name
end
when :lasted_comment
time_from_now u.created_on
when :praise_count
get_activity_praise_num(u)
when :act_type
'Message'
when :act_id
u.id
end
end
end
@ -30,17 +42,29 @@ module Mobile
c.author
end
end
message_expose :act_type
message_expose :act_id
message_expose :course_project_name
message_expose :board_id
message_expose :subject
message_expose :content
message_expose :replies_count
message_expose :praise_count
message_expose :created_on
message_expose :id
message_expose :lasted_comment
expose :message_children,using:Mobile::Entities::Message do |c,opt|
if c.is_a? (::Message)
c.children
c.children.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

@ -2,15 +2,29 @@ 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)
f[field]
elsif f.is_a?(::News)
if field == :created_on
format_time(f.send(field)) if f.respond_to?(field)
if f.respond_to?(field)
if field == :created_on
format_time(f.send(field))
else
f.send(field)
end
else
f.send(field) if f.respond_to?(field)
case field
when :course_name
get_course(f.course_id).name unless f.course_id == nil
when :praise_count
get_activity_praise_num(f)
when :act_type
'News'
when :act_id
f.id
end
end
elsif f.is_a?(Hash) && !f.key?(field)
n = f[:news]
@ -40,6 +54,8 @@ module Mobile
end
obj
end
news_expose :act_type
news_expose :act_id
#作者id
news_expose :author_id
#作者名
@ -52,16 +68,24 @@ module Mobile
news_expose :created_on
#评论数量
news_expose :comments_count
news_expose :praise_count
#课程名字
news_expose :course_name
#评论
expose :comments, using: Mobile::Entities::Comment do |f, opt|
if f.is_a?(Hash) && f.key?(:comments)
f[:comments]
elsif f.is_a?(::News) && f.respond_to?(:comments)
f.send(:comments)
f.comments.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

@ -32,14 +32,14 @@ module Mobile
end
end
student_work_expose :student_id
student_work_expose :id
student_work_expose :id
student_work_expose :name
student_work_expose :description
student_work_expose :final_score
student_work_expose :teacher_score
student_work_expose :student_score
student_work_expose :teacher_asistant_score
student_work_expose :created_at
student_work_expose :description
student_work_expose :final_score
student_work_expose :teacher_score
student_work_expose :student_score
student_work_expose :teacher_asistant_score
student_work_expose :created_at
end
end
end

@ -13,7 +13,7 @@ module Mobile
else
case f
when :img_url
url_to_avatar(u)
"/images/#{url_to_avatar(u)}"
when :gender
u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender
when :work_unit
@ -24,6 +24,8 @@ module Mobile
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction
when :student_num
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id
when :realname
u.nil? ? "" : get_user_realname(u)
end
end
end
@ -37,7 +39,7 @@ module Mobile
#昵称
expose :nickname
#真名
expose :realname
user_expose :realname
#性别
user_expose :gender
#我的二维码

@ -0,0 +1,85 @@
# encoding: utf-8
module Mobile
module Entities
class Whomework <Grape::Entity
include ApiHelper
include ApplicationHelper
include Redmine::I18n
def self.whomework_expose(f)
expose f do |wh, opt|
if wh.is_a?(Hash) && wh.key?(f)
wh[f]
elsif wh.is_a?(::HomeworkCommon)
if wh.respond_to?(f)
if f == :created_at
format_time(wh.send(f))
else
wh.send(f)
end
else
case f
when :absence_penalty
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
when :evaluation_start
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
when :evaluation_end
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
wh.journals_for_messages.count
when :course_name
wh.course.name
when :act_type
'HomeworkCommon'
when :act_id
wh.id
end
end
end
end
end
expose :author, using: Mobile::Entities::User do |w, opt|
if w.is_a?(::HomeworkCommon)
w.user
end
end
expose :current_user, using: Mobile::Entities::User do |w, opt|
current_user
end
expose :name
expose :description
expose :publish_time
expose :end_time
expose :homework_type
expose :late_penalty
expose :course_id
expose :anonymous_comment
expose :quotes
expose :is_open
whomework_expose :act_type
whomework_expose :act_id
whomework_expose :course_name
whomework_expose :created_at
whomework_expose :absence_penalty
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|
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
if f.is_a?(::HomeworkCommon)
f.journals_for_messages.reverse
end
end
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
has_praise = false
current_user = options[:user]
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
has_praise = obj.empty? ? false : true
has_praise
end
end
end
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save