首页动态优化
This commit is contained in:
parent
e85ef7b192
commit
c8cb730397
|
@ -4,45 +4,44 @@ module Mobile
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
def self.course_dynamic_expose(field)
|
def self.course_dynamic_expose(field)
|
||||||
expose field do |c,opt|
|
expose field do |c,opt|
|
||||||
if field == :news_count
|
# if field == :news_count
|
||||||
obj = nil
|
# obj = nil
|
||||||
c[:dynamics].each do |d|
|
# c[:dynamics].each do |d|
|
||||||
if d[:type] == 1
|
# if d[:type] == 1
|
||||||
obj = d[:count]
|
# obj = d[:count]
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
obj
|
# obj
|
||||||
elsif field == :document_count
|
# elsif field == :document_count
|
||||||
obj = nil
|
# obj = nil
|
||||||
c[:dynamics].each do |d|
|
# c[:dynamics].each do |d|
|
||||||
if d[:type] == 3
|
# if d[:type] == 3
|
||||||
obj = d[:count]
|
# obj = d[:count]
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
obj
|
# obj
|
||||||
elsif field == :topic_count
|
# elsif field == :topic_count
|
||||||
obj = nil
|
# obj = nil
|
||||||
c[:dynamics].each do |d|
|
# c[:dynamics].each do |d|
|
||||||
if d[:type] == 2
|
# if d[:type] == 2
|
||||||
obj = d[:count]
|
# obj = d[:count]
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
obj
|
# obj
|
||||||
elsif field == :homework_count
|
# elsif field == :homework_count
|
||||||
obj = nil
|
# obj = nil
|
||||||
c[:dynamics].each do |d|
|
# c[:dynamics].each do |d|
|
||||||
if d[:type] == 4
|
# if d[:type] == 4
|
||||||
obj = d[:count]
|
# obj = d[:count]
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
obj
|
# obj
|
||||||
else
|
# else
|
||||||
c[field] if (c.is_a?(Hash) && c.key?(field))
|
c[field] if (c.is_a?(Hash) && c.key?(field))
|
||||||
end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
course_dynamic_expose :type
|
|
||||||
course_dynamic_expose :course_name
|
course_dynamic_expose :course_name
|
||||||
course_dynamic_expose :course_term
|
course_dynamic_expose :course_term
|
||||||
course_dynamic_expose :course_time
|
course_dynamic_expose :course_time
|
||||||
|
@ -68,52 +67,22 @@ module Mobile
|
||||||
# obj
|
# obj
|
||||||
# end
|
# end
|
||||||
expose :topics,using:Mobile::Entities::Message do |f,opt|
|
expose :topics,using:Mobile::Entities::Message do |f,opt|
|
||||||
obj = nil
|
f[:topics]
|
||||||
f[:dynamics].each do |d|
|
|
||||||
if d[:type] == 2
|
|
||||||
obj = d[:topics]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
obj
|
|
||||||
end
|
end
|
||||||
expose :homeworks,using:Mobile::Entities::Homework do |f,opt|
|
expose :homeworks,using:Mobile::Entities::Homework do |f,opt|
|
||||||
obj = nil
|
f[:homeworks]
|
||||||
f[:dynamics].each do |d|
|
|
||||||
if d[:type] == 4
|
|
||||||
obj = d[:homeworks]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
obj
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expose :news,using:Mobile::Entities::News do |f,opt|
|
expose :news,using:Mobile::Entities::News do |f,opt|
|
||||||
obj = nil
|
f[:news]
|
||||||
f[:dynamics].each do |d|
|
|
||||||
if d[:type] == 1
|
|
||||||
obj = d[:news]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
obj
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expose :better_students,using:Mobile::Entities::User do |f,opt|
|
expose :better_students,using:Mobile::Entities::User do |f,opt|
|
||||||
obj = nil
|
f[:better_students]
|
||||||
f[:dynamics].each do |d|
|
|
||||||
if d[:type] == 6
|
|
||||||
obj = d[:better_students]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
obj
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expose :active_students,using:Mobile::Entities::User do |f,opt|
|
expose :active_students,using:Mobile::Entities::User do |f,opt|
|
||||||
obj = nil
|
f[:active_students]
|
||||||
f[:dynamics].each do |d|
|
|
||||||
if d[:type] == 7
|
|
||||||
obj = d[:active_students]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
obj
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -670,18 +670,25 @@ class CoursesService
|
||||||
membership.each do |mp|
|
membership.each do |mp|
|
||||||
course = mp.course
|
course = mp.course
|
||||||
latest_course_dynamics = []
|
latest_course_dynamics = []
|
||||||
|
notices_count = 0
|
||||||
|
topic_count = 0
|
||||||
|
topics = nil
|
||||||
|
homeworkss = nil
|
||||||
|
notices = nil
|
||||||
|
|
||||||
# 课程通知
|
# 课程通知
|
||||||
latest_news = course.news.page(1).per(2).order("created_on desc")
|
latest_news = course.news.page(1).per(2).order("created_on desc")
|
||||||
unless latest_news.first.nil?
|
unless latest_news.first.nil?
|
||||||
latest_course_dynamics << {:type => 1, :time => latest_news.first.created_on,:count=>course.news.count,
|
notices_count = course.news.count
|
||||||
:news => latest_news.all}
|
notices = latest_news.all
|
||||||
|
latest_course_dynamics << {:time => latest_news.first.created_on }
|
||||||
end
|
end
|
||||||
# 课程讨论区
|
# 课程讨论区
|
||||||
latest_message = course.boards.first.topics.page(1).per(2)
|
latest_message = course.boards.first.topics.page(1).per(2)
|
||||||
unless latest_message.first.nil?
|
unless latest_message.first.nil?
|
||||||
latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
|
topic_count = course.boards.nil? ? 0 : course.boards.first.topics.count
|
||||||
:topics => latest_message.all}
|
topics = latest_message.all
|
||||||
|
latest_course_dynamics << {:time => latest_message.first.created_on}
|
||||||
end
|
end
|
||||||
# 课程资源
|
# 课程资源
|
||||||
# latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
|
# latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
|
||||||
|
@ -693,7 +700,8 @@ class CoursesService
|
||||||
#课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态
|
#课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态
|
||||||
homeworks = course.homework_commons.page(1).per(2).order('created_at desc')
|
homeworks = course.homework_commons.page(1).per(2).order('created_at desc')
|
||||||
unless homeworks.first.nil?
|
unless homeworks.first.nil?
|
||||||
latest_course_dynamics << {:type => 4, :time => homeworks.first.updated_at, :count=>course.homework_commons.count , :homeworks => homeworks}
|
homeworkss = homeworks
|
||||||
|
latest_course_dynamics << {:time => homeworks.first.updated_at}
|
||||||
end
|
end
|
||||||
latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] }
|
latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] }
|
||||||
# 课程学霸 学生总分数排名靠前的5个人
|
# 课程学霸 学生总分数排名靠前的5个人
|
||||||
|
@ -713,10 +721,10 @@ class CoursesService
|
||||||
active_students = User.find_by_sql(sql1)
|
active_students = User.find_by_sql(sql1)
|
||||||
|
|
||||||
if homework_count != 0 && !better_students.empty?
|
if homework_count != 0 && !better_students.empty?
|
||||||
latest_course_dynamics <<{:type=> 6,:time=>"1970-01-01 0:0:0 +0800",:count=> 4,:better_students=> better_students}
|
latest_course_dynamics <<{:time=>"1970-01-01 0:0:0 +0800"}
|
||||||
end
|
end
|
||||||
unless active_students.empty?
|
unless active_students.empty?
|
||||||
latest_course_dynamics <<{:type=> 7,:time=>"1970-01-01 0:0:0 +0800",:count=> 4,:active_students=>active_students}
|
latest_course_dynamics <<{:time=>"1970-01-01 0:0:0 +0800"}
|
||||||
end
|
end
|
||||||
latest_course_dynamic = latest_course_dynamics.first
|
latest_course_dynamic = latest_course_dynamics.first
|
||||||
unless latest_course_dynamic.nil?
|
unless latest_course_dynamic.nil?
|
||||||
|
@ -727,6 +735,14 @@ class CoursesService
|
||||||
:course_img_url => url_to_avatar(course),
|
:course_img_url => url_to_avatar(course),
|
||||||
:course_time => course.time,
|
:course_time => course.time,
|
||||||
:course_term => course.term,
|
:course_term => course.term,
|
||||||
|
:news_count => notices_count,
|
||||||
|
:homework_count => homework_count,
|
||||||
|
:topic_count => topic_count,
|
||||||
|
:news => notices,
|
||||||
|
:homeworks => homeworkss,
|
||||||
|
:topics => topics,
|
||||||
|
:better_students => better_students,
|
||||||
|
:active_students => active_students,
|
||||||
:message => "",
|
:message => "",
|
||||||
:dynamics => latest_course_dynamics,
|
:dynamics => latest_course_dynamics,
|
||||||
:course_student_num=>course ? course.members.count : 0,
|
:course_student_num=>course ? course.members.count : 0,
|
||||||
|
|
Loading…
Reference in New Issue