diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 5b03010d..e404c5ee 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -30,9 +30,9 @@ class HomeworkCommonController < ApplicationController @homework_type = params[:homework_type].to_i @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) if @search - @homework_commons = @course.homework_commons.where(:homework_type => @homework_type).where("homework_commons.name like '%#{@search}%'").includes(:homework_detail_manual, :homework_group_settings, :student_works) + @homework_commons = @course.homework_commons.where(:homework_type => @homework_type).where("homework_commons.name like '%#{@search}%'") else - @homework_commons = @course.homework_commons.where(:homework_type => @homework_type).includes(:homework_detail_manual, :homework_group_settings, :student_works) + @homework_commons = @course.homework_commons.where(:homework_type => @homework_type) end if @is_teacher @homework_commons = @homework_commons @@ -72,6 +72,9 @@ class HomeworkCommonController < ApplicationController @is_new = params[:is_new] @homeworks = paginateHelper @homework_commons,15 + + @homeworks = @homework_type == 4 ? @homeworks.includes(:homework_detail_manual, :homework_group_settings, [homework_commons_shixuns: :shixun]) : + @homeworks.includes(:homework_detail_manual, :homework_group_settings) #设置at已读 =begin ids = @homeworks.inject([]) do |ids, homework| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ade22d4e..4261a406 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1317,11 +1317,11 @@ module ApplicationHelper def had_commit_studentwork_count homework_common member = homework_common.course.members.where(:user_id => User.current.id).first student_works = homework_common.student_works - if member.present? && member.teacher_course_groups.count > 0 + if member.present? && member.teacher_course_groups.size > 0 group_students = homework_common.course.members.where(:course_group_id => member.teacher_course_groups.pluck(:course_group_id)).map(&:user_id) student_works = student_works.where(:user_id => group_students) end - student_works.where("work_status !=?", 0).count + student_works.where("work_status !=?", 0).size end # 实训作业的有效作品数 @@ -1357,11 +1357,11 @@ module ApplicationHelper def had_uncommit_studentwork_count homework_common member = homework_common.course.members.where(:user_id => User.current.id).first student_works = homework_common.student_works - if member.present? && member.teacher_course_groups.count > 0 + if member.present? && member.teacher_course_groups.size > 0 group_students = homework_common.course.members.where(:course_group_id => member.teacher_course_groups.pluck(:course_group_id)).map(&:user_id) student_works = student_works.where(:user_id => group_students) end - student_works.where("work_status =?", 0).count + student_works.where("work_status =?", 0).size end # 未评阅 @@ -1369,12 +1369,12 @@ module ApplicationHelper #count = StudentWorksScore.find_by_sql("SELECT count(distinct student_work_id) as count FROM student_works_scores sws, student_works sw, homework_commons hc where hc.id =#{homework_common.id} and sw.homework_common_id=hc.id and sw.is_delete = 0 and sws.student_work_id = sw.id and sws.user_id=#{User.current.id};").first.try(:count).to_i member = homework_common.course.members.where(:user_id => User.current.id).first student_works = homework_common.student_works - if member.present? && member.teacher_course_groups.count > 0 + if member.present? && member.teacher_course_groups.size > 0 group_students = homework_common.course.members.where(:course_group_id => member.teacher_course_groups.pluck(:course_group_id)).map(&:user_id) student_works = student_works.where(:user_id => group_students) end - has_comment = StudentWorksScore.where(:student_work_id => student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).count - student_count = student_works.count + has_comment = StudentWorksScore.where(:student_work_id => student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).size + student_count = student_works.size return student_count - has_comment end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index abe09e08..af466de3 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -150,7 +150,7 @@ class HomeworkCommon < ActiveRecord::Base # 作业的实训 def shixun - Shixun.find(self.homework_commons_shixuns.try(:shixun_id)) + homework_commons_shixuns.shixun end # 作业实训过关的数目 diff --git a/app/views/homework_common/_homework_index_list.html.erb b/app/views/homework_common/_homework_index_list.html.erb index 865f7adf..884fd0b9 100644 --- a/app/views/homework_common/_homework_index_list.html.erb +++ b/app/views/homework_common/_homework_index_list.html.erb @@ -61,22 +61,22 @@ <% end %> <% end %> <%# elsif homework_common.homework_type != 4 %> - <% else %> - <% if had_commit_studentwork_count(homework_common) > 0 %> - - <%= link_to had_commit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> - 已交 - + <%# else %> + <%# if had_commit_studentwork_count(homework_common) > 0 %> + + <%#= link_to had_commit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> + + <%# if homework_common.homework_type == 4 %> <%# end %> - - <%= link_to had_uncommit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> - 未交 - - <% end %> + + <%#= link_to had_uncommit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> + + + <%# end %> <%# elsif homework_common.homework_type == 4 && homework_common.homework_commons_shixuns.shixun %> <%# had_passed_count = had_passed_changllenge_count(homework_common.homework_commons_shixuns.shixun, User.current) %> <%# challenge_count = homework_common.homework_commons_shixuns.shixun.challenges.count %> @@ -129,7 +129,7 @@ <%= link_to "创建项目", new_project_path(:host=>Setting.host_name, :course_id => homework_common.course_id), :class => 'white-btn orange-btn fr mr10 mt8', :target => "_blank" %> <% end %> <% elsif homework_common.homework_type == 4 && homework_common.homework_commons_shixuns.shixun %> - <%= link_to "实训详情", shixun_path(Shixun.find(homework_common.homework_commons_shixuns.shixun_id)), :target => "_blank", :class => 'white-btn orange-btn fr mr10 mt8' %> + <%= link_to "实训详情", shixun_path(homework_common.homework_commons_shixuns.shixun.try(:identifier)), :target => "_blank", :class => 'white-btn orange-btn fr mr10 mt8' %> <% end %> <% if @is_teacher %> @@ -148,7 +148,7 @@
  • <%= link_to '立即发布', publish_notice_homework_common_path(homework_common), :remote => true %>
  • - <% elsif (homework_common.homework_detail_manual.try(:comment_status) == 1 || homework_common.homework_detail_manual.try(:comment_status) == 2) && homework_common.end_time > Time.now %> + <% elsif (homework_common.homework_detail_manual.try(:comment_status) == 1 || homework_common.homework_detail_manual.try(:comment_status) == 2) && homework_common.end_time && homework_common.end_time > Time.now %>
  • <%= link_to '立即截止', end_notice_homework_common_path(homework_common), :remote => true %>
  • diff --git a/app/views/layouts/_board_children_list.html.erb b/app/views/layouts/_board_children_list.html.erb index 779b900a..3871098e 100644 --- a/app/views/layouts/_board_children_list.html.erb +++ b/app/views/layouts/_board_children_list.html.erb @@ -13,9 +13,9 @@ <% unless course_board.children.empty? %>