作业列表增加序号和翻页、按创建时间倒排

This commit is contained in:
cxt 2016-05-19 13:50:45 +08:00
parent 31d94dc052
commit 0f2f4717b6
5 changed files with 27 additions and 4 deletions

View File

@ -20,15 +20,16 @@ class HomeworkCommonController < ApplicationController
@page = params[:page] ? params[:page].to_i + 1 : 0
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
if @is_teacher
@homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10)
#@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10)
@homework_commons = @course.homework_commons.order("created_at desc")
else
@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10)
#@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10)
@homework_commons = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc")
end
@is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher))
@is_new = params[:is_new]
@homeworks = paginateHelper @homework_commons,10
#设置at已读
@homeworks.each do |homework|
homework.journals_for_messages.each do |j|

View File

@ -3248,3 +3248,14 @@ def strip_html(text,len=0,endss="...")
end
return ss
end
def get_hw_index(hw,is_teacher)
if is_teacher
homeworks = hw.course.homework_commons.order("created_at asc")
else
homeworks = hw.course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc")
end
hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty?
index = hw_ids.index(hw.id)
return index
end

View File

@ -73,6 +73,12 @@
<% end%>
<%= render :partial => 'users/user_homework_list', :locals => {:homework_commons => @homeworks,:page => 0,:is_in_course => 1,:course_id => @course.id} %>
<div style="width:210px; text-align:center; margin:0 auto;">
<ul class="wlist" style=" border:none; display:inline-block; float:none; margin-top:10px;">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
</ul>
<div class="cl"></div>
</div>
</div>
<div class="cl"></div>

View File

@ -11,7 +11,12 @@
<%= link_to homework_common.course.name, course_path(homework_common.course_id), :class => "newsBlue ml15"%>
</div>
<span class="homepagePostTitle hidden fl m_w505">
<%= link_to homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
<% if is_in_course == 1%>
<% index = get_hw_index(homework_common, is_teacher) %>
<%= link_to "<span class='fontBlue2'>作业#{index+1}</span>".html_safe+homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
<% else %>
<%= link_to homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
<% end %>
</span>
<% if homework_common.homework_detail_manual%>

View File

@ -31,7 +31,7 @@
<% if homework_commons.count == 10%>
<% if is_in_course == 1%>
<!-- 在课程内 -->
<%= link_to "点击展开更多",homework_common_index_path(:course => course_id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%>
<%#= link_to "点击展开更多",homework_common_index_path(:course => course_id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%>
<% else%>
<!-- 在个人主页 -->
<%= link_to "点击展开更多",student_homeworks_user_path(User.current.id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%>