From 3018ee206c80b88b85fa8bfbc28fd1740009cd09 Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 10 Feb 2015 10:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/course.rb | 3 +++ app/api/mobile/entities/homework_jours.rb | 6 +++++- app/api/mobile/entities/news.rb | 10 ++++++++-- app/services/courses_service.rb | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index ec00579ce..977c32c48 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -1,6 +1,7 @@ module Mobile module Entities class Course < Grape::Entity + include Redmine::I18n def self.course_expose(field) expose field do |f,opt| c = nil @@ -12,6 +13,8 @@ module Mobile if field == :img_url f[field] if f.is_a?(Hash) && f.key?(field) #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 (c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field)) end diff --git a/app/api/mobile/entities/homework_jours.rb b/app/api/mobile/entities/homework_jours.rb index 63c6997fd..0b9defe67 100644 --- a/app/api/mobile/entities/homework_jours.rb +++ b/app/api/mobile/entities/homework_jours.rb @@ -6,7 +6,11 @@ module Mobile def self.homework_jours_expose(field) expose field do |f,opt| 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) end diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index 406db59e4..f189771e3 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -1,6 +1,7 @@ module Mobile module Entities class News < Grape::Entity + include Redmine::I18n def self.news_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) @@ -9,13 +10,18 @@ module Mobile n = f[:news] comments = f[:comments] 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 - + news_expose :id #新闻标题 news_expose :title diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f4201774a..7ed8fe65a 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -117,7 +117,7 @@ class CoursesService scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user) news = [] 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 news end