socialforge/app/api/mobile/entities/issue.rb

67 lines
2.3 KiB
Ruby
Raw Normal View History

2016-03-30 17:47:44 +08:00
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)
2016-03-31 20:46:36 +08:00
if f == :created_on
format_time(issue.send(f))
else
issue.send(f)
end
2016-03-30 17:47:44 +08:00
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
2016-04-01 18:23:12 +08:00
when :journals_count
2016-04-01 23:22:39 +08:00
issue.journals.where("notes is not null and notes != ''").count
2016-04-01 21:28:25 +08:00
when :project_name
issue.project.name
2016-04-07 16:40:21 +08:00
when :praise_count
2016-04-01 23:22:39 +08:00
get_activity_praise_num(issue)
2016-04-07 16:40:21 +08:00
when :act_type
'Issue'
when :act_id
issue.id
2016-03-30 17:47:44 +08:00
end
end
end
end
end
expose :subject
expose :description
expose :author, using: Mobile::Entities::User
expose :done_ratio
2016-04-07 16:40:21 +08:00
issue_expose :act_type
issue_expose :act_id
2016-03-31 20:46:36 +08:00
issue_expose :created_on
2016-03-30 17:47:44 +08:00
issue_expose :issue_priority
issue_expose :issue_assigned_to
issue_expose :issue_status
2016-04-01 18:23:12 +08:00
issue_expose :journals_count
2016-04-01 21:28:25 +08:00
issue_expose :project_name
2016-04-07 16:40:21 +08:00
issue_expose :praise_count
2016-03-31 20:46:36 +08:00
expose :issue_journals, using: Mobile::Entities::Journal do |f, opt|
if f.is_a?(::Issue)
2016-04-07 15:09:17 +08:00
f.journals.where("notes is not null and notes != ''").reverse
2016-03-31 20:46:36 +08:00
end
end
2016-04-07 11:16:38 +08:00
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
2016-03-30 17:47:44 +08:00
end
end
end