修改时间格式解析

dev_repository_hjq
z9hang 11 years ago
parent 103a411b40
commit 3018ee206c

@ -1,6 +1,7 @@
module Mobile module Mobile
module Entities module Entities
class Course < Grape::Entity class Course < Grape::Entity
include Redmine::I18n
def self.course_expose(field) def self.course_expose(field)
expose field do |f,opt| expose field do |f,opt|
c = nil c = nil
@ -12,6 +13,8 @@ module Mobile
if field == :img_url if field == :img_url
f[field] if f.is_a?(Hash) && f.key?(field) f[field] if f.is_a?(Hash) && f.key?(field)
#f.img_url if f.respond_to?(:img_url) #f.img_url if f.respond_to?(:img_url)
elsif field == :created_at || field == :updated_at
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field))
else else
(c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field)) (c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field))
end end

@ -6,7 +6,11 @@ module Mobile
def self.homework_jours_expose(field) def self.homework_jours_expose(field)
expose field do |f,opt| expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field) if f.is_a?(Hash) && f.key?(field)
f[field] if field == :created_at
format_time(f[field])
else
f[field]
end
elsif f.is_a?(::SeemsRateableRates) elsif f.is_a?(::SeemsRateableRates)
end end

@ -1,6 +1,7 @@
module Mobile module Mobile
module Entities module Entities
class News < Grape::Entity class News < Grape::Entity
include Redmine::I18n
def self.news_expose(field) def self.news_expose(field)
expose field do |f,opt| expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field) if f.is_a?(Hash) && f.key?(field)
@ -9,13 +10,18 @@ module Mobile
n = f[:news] n = f[:news]
comments = f[:comments] comments = f[:comments]
if n.is_a?(::News) if n.is_a?(::News)
n.send(field) if n.respond_to?(field) if field == :created_on
format_time(n.send(field)) if n.respond_to?(field)
else
n.send(field) if n.respond_to?(field)
end
end end
end end
end end
end end
news_expose :id
#新闻标题 #新闻标题
news_expose :title news_expose :title

@ -117,7 +117,7 @@ class CoursesService
scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user) scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user)
news = [] news = []
scope.each do |n| scope.each do |n|
news << {:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count}
end end
news news
end end

Loading…
Cancel
Save