diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index bf402d4a2..720582751 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -30,13 +30,13 @@ class HomeworkCommonController < ApplicationController if @order.blank? @homework_commons = @course.homework_commons.where("name like '%#{@search}%'").order("created_at desc") else - @homework_commons = HomeworkCommon.find_by_sql("SELECT * FROM `homework_commons` hc, `homework_detail_manuals` hdm where hdm.homework_common_id = hc.id and hc.course_id=#{@course.id} and hc.name like '%#{@search}%' and hdm.comment_status='#{@order}';") + @homework_commons = @course.homework_commons.includes(:homework_detail_manual).where("name like '%#{@search}%' and homework_detail_manuals.comment_status = #{@order}") end else if @order.blank? @homework_commons = @course.homework_commons.where("name like '%#{@search}%' and publish_time <= '#{Time.now}'").order("created_at desc") else - @homework_commons = HomeworkCommon.find_by_sql("SELECT * FROM `homework_commons` hc, `homework_detail_manuals` hdm where hdm.homework_common_id = hc.id and hc.course_id=#{@course.id} and hc.name like '%#{@search}%' and hc.publish_time <= #{Time.now} and hdm.comment_status='#{@order}';") + @homework_commons = @course.homework_commons.includes(:homework_detail_manual).where("name like '%#{@search}%' and publish_time <= '#{Time.now}' and homework_detail_manuals.comment_status = #{@order}") end end @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8353edd29..de1573e0c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -328,58 +328,60 @@ module ApplicationHelper status = "" time = "" ho_detail_manual = homework_common.homework_detail_manual - case ho_detail_manual.comment_status - when 0 - status = "挂起" - if homework_common.publish_time && homework_common.publish_time > Time.now - time = time_from_future(homework_common.publish_time).to_s + "后发布" - end - when 1 - status = "提交中" - if homework_common.end_time && homework_common.end_time > Time.now - time = time_from_future(homework_common.end_time).to_s + "后结束" - elsif !homework_common.allow_late && homework_common.anonymous_comment == 0 - if ho_detail_manual.evaluation_start && ho_detail_manual.evaluation_start >= Time.now - status = "匿评中" - time = time_from_future(ho_detail_manual.evaluation_start).to_s + "后开始" + if ho_detail_manual + case ho_detail_manual.comment_status + when 0 + status = "挂起" + if homework_common.publish_time && homework_common.publish_time > Time.now + time = time_from_future(homework_common.publish_time).to_s + "后发布" end - elsif !homework_common.allow_late && homework_common.anonymous_comment == 1 - if homework_common.archive_time && homework_common.archive_time >= Time.now - status = "评阅中" + when 1 + status = "提交中" + if homework_common.end_time && homework_common.end_time > Time.now + time = time_from_future(homework_common.end_time).to_s + "后结束" + elsif !homework_common.allow_late && homework_common.anonymous_comment == 0 + if ho_detail_manual.evaluation_start && ho_detail_manual.evaluation_start >= Time.now + status = "匿评中" + time = time_from_future(ho_detail_manual.evaluation_start).to_s + "后开始" + end + elsif !homework_common.allow_late && homework_common.anonymous_comment == 1 + if homework_common.archive_time && homework_common.archive_time >= Time.now + status = "评阅中" + time = time_from_future(homework_common.archive_time).to_s + "后结束" + end + end + when 2 + status = "补交中" + if homework_common.late_time && homework_common.late_time >= Time.now + time = time_from_future(homework_common.late_time).to_s + "后结束" + elsif homework_common.anonymous_comment == 0 + if ho_detail_manual.evaluation_start && ho_detail_manual.evaluation_start >= Time.now + status = "匿评中" + time = time_from_future(ho_detail_manual.evaluation_start).to_s + "后开始" + end + end + when 3 + status = "匿评中" + if ho_detail_manual.evaluation_end && ho_detail_manual.evaluation_end > Time.now + time = time_from_future(ho_detail_manual.evaluation_end).to_s + "后结束" + elsif homework_common.anonymous_appeal && ho_detail_manual.appeal_time && ho_detail_manual.appeal_time >= Time.now + status = "申诉" + time = time_from_future(ho_detail_manual.appeal_time).to_s + "后开始" + end + when 4 + status = "申诉中" + if ho_detail_manual.appeal_time && ho_detail_manual.appeal_time > Time.now + time = time_from_future(ho_detail_manual.appeal_time).to_s + "后结束" + end + when 5 + status = "评阅中" + if homework_common.archive_time && homework_common.archive_time > Time.now time = time_from_future(homework_common.archive_time).to_s + "后结束" end - end - when 2 - status = "补交中" - if homework_common.late_time && homework_common.late_time >= Time.now - time = time_from_future(homework_common.late_time).to_s + "后结束" - elsif homework_common.anonymous_comment == 0 - if ho_detail_manual.evaluation_start && ho_detail_manual.evaluation_start >= Time.now - status = "匿评中" - time = time_from_future(ho_detail_manual.evaluation_start).to_s + "后开始" - end - end - when 3 - status = "匿评中" - if ho_detail_manual.evaluation_end && ho_detail_manual.evaluation_end > Time.now - time = time_from_future(ho_detail_manual.evaluation_end).to_s + "后结束" - elsif homework_common.anonymous_appeal && ho_detail_manual.appeal_time && ho_detail_manual.appeal_time >= Time.now - status = "申诉" - time = time_from_future(ho_detail_manual.appeal_time).to_s + "后开始" - end - when 4 - status = "申诉中" - if ho_detail_manual.appeal_time && ho_detail_manual.appeal_time > Time.now - time = time_from_future(ho_detail_manual.appeal_time).to_s + "后结束" - end - when 5 - status = "评阅中" - if homework_common.archive_time && homework_common.archive_time > Time.now - time = time_from_future(homework_common.archive_time).to_s + "后结束" - end - when 6 - status = "已结束" - time = format_time homework_common.archive_time + when 6 + status = "已结束" + time = format_time homework_common.archive_time + end end result[:status] = status result[:time] = time diff --git a/app/views/homework_common/_homework_index_list.html.erb b/app/views/homework_common/_homework_index_list.html.erb index eea28fd40..e0e28fa86 100644 --- a/app/views/homework_common/_homework_index_list.html.erb +++ b/app/views/homework_common/_homework_index_list.html.erb @@ -7,7 +7,7 @@ <%= homework_curr_status[:status] %>
- # <%= index + 1 %> + # <%= get_hw_index(homework_common, @is_teacher) %> 创建于<%=time_from_now homework_common.created_at %> <%=homework_common.homework_type_ch %> <% if [1,2,3,4,5,6].include?(homework_common.homework_detail_manual.try(:comment_status)) %> diff --git a/app/views/homework_common/_homework_index_tab.html.erb b/app/views/homework_common/_homework_index_tab.html.erb index b15b21605..5805beace 100644 --- a/app/views/homework_common/_homework_index_tab.html.erb +++ b/app/views/homework_common/_homework_index_tab.html.erb @@ -1,5 +1,7 @@ edu-filter-cir-grey mr5 " data-remote="true">全部 +<% if @is_teacher %> edu-filter-cir-grey mr5" data-remote="true">挂起 +<% end %> edu-filter-cir-grey mr5" data-remote="true">提交中 edu-filter-cir-grey mr5" data-remote="true">补交中 edu-filter-cir-grey mr5" data-remote="true">匿评中