2015-01-22 09:30:29 +08:00
|
|
|
module Mobile
|
|
|
|
module Entities
|
|
|
|
class Attachment < Grape::Entity
|
2015-06-19 15:05:25 +08:00
|
|
|
include Redmine::I18n
|
2015-01-22 09:30:29 +08:00
|
|
|
def self.attachment_expose(field)
|
|
|
|
expose field do |f,opt|
|
|
|
|
if f.is_a?(Hash) && f.key?(field)
|
|
|
|
f[field]
|
|
|
|
elsif f.is_a?(::Attachment)
|
|
|
|
if f.respond_to?(field)
|
2015-06-19 15:05:25 +08:00
|
|
|
if field == :created_on
|
|
|
|
format_time(f.send(field))
|
|
|
|
else
|
|
|
|
f.send(field)
|
|
|
|
end
|
2015-01-22 09:30:29 +08:00
|
|
|
else
|
2015-07-03 15:32:57 +08:00
|
|
|
case field
|
|
|
|
when :file_dir
|
|
|
|
"attachments/download/" << f.send(:id).to_s << '/'
|
|
|
|
end
|
2015-01-22 09:30:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-04-29 17:46:39 +08:00
|
|
|
attachment_expose :id
|
2015-01-22 09:30:29 +08:00
|
|
|
attachment_expose :filename
|
|
|
|
attachment_expose :description
|
2015-04-29 17:46:39 +08:00
|
|
|
attachment_expose :downloads
|
|
|
|
attachment_expose :quotes
|
2015-06-19 15:05:25 +08:00
|
|
|
attachment_expose :created_on
|
2015-07-03 15:32:57 +08:00
|
|
|
attachment_expose :file_dir
|
2015-01-22 09:30:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|