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

41 lines
1.3 KiB
Ruby

module Mobile
module Entities
class Attachment < Grape::Entity
include Redmine::I18n
include ActionView::Helpers::NumberHelper
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)
if field == :created_on
format_time(f.send(field))
else
f.send(field)
end
else
case field
when :file_dir
"attachments/download/" << f.send(:id).to_s << '/'
when :attafile_size
(number_to_human_size(f.filesize)).gsub("ytes", "").to_s
when :coursename
f.course.nil? ? "" : f.course.name
end
end
end
end
end
attachment_expose :id
attachment_expose :filename
attachment_expose :description
attachment_expose :downloads
attachment_expose :quotes
attachment_expose :created_on
attachment_expose :file_dir
attachment_expose :attafile_size
attachment_expose :coursename #所属班级名
end
end
end