实训作业列表优化

dev_ec
cxt 6 years ago
parent 4f1fcaa16d
commit cb03317076

@ -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|

@ -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

@ -150,7 +150,7 @@ class HomeworkCommon < ActiveRecord::Base
# 作业的实训
def shixun
Shixun.find(self.homework_commons_shixuns.try(:shixun_id))
homework_commons_shixuns.shixun
end
# 作业实训过关的数目

@ -61,22 +61,22 @@
<% end %>
<% end %>
<%# elsif homework_common.homework_type != 4 %>
<% else %>
<% if had_commit_studentwork_count(homework_common) > 0 %>
<span class="ml50 fl">
<%= link_to had_commit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %>
已交
</span>
<%# else %>
<%# if had_commit_studentwork_count(homework_common) > 0 %>
<!-- <span class="ml50 fl">-->
<%#= link_to had_commit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %>
<!-- 已交-->
<!-- </span>-->
<%# if homework_common.homework_type == 4 %>
<!--<span class="ml50">-->
<!--<a href="javascript:void(0);" class="color-orange03 mr5" style="cursor: default"><%#= homework_common.pass_game_count %></a>通关-->
<!--</span>-->
<%# end %>
<span class="ml50 fl">
<%= link_to had_uncommit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %>
未交
</span>
<% end %>
<!-- <span class="ml50 fl">-->
<%#= link_to had_uncommit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %>
<!-- 未交-->
<!-- </span>-->
<%# 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 @@
<li>
<%= link_to '立即发布', publish_notice_homework_common_path(homework_common), :remote => true %>
</li>
<% 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 %>
<li>
<%= link_to '立即截止', end_notice_homework_common_path(homework_common), :remote => true %>
</li>

@ -13,9 +13,9 @@
</li>
<% unless course_board.children.empty? %>
<ul>
<% course_board.children.reorder("position asc").each do |board| %>
<% course_board.children.includes(:messages).reorder("position asc").each do |board| %>
<li id="board_children_<%= board.id %>" class="clearfix">
<% count = board ? board.messages.count : 0 %>
<% count = board ? board.messages.size : 0 %>
<a href="<%= course_boards_path(@course, :board_id => board.id) %>" class="fl"><span class="fl ml38 devide_class task-hide" data-tip-down="<%=board.name %>"><%=board.name %></span>
<% if count > 0 %>
<span class="fr mr30 courseNewNum"><%= count %></span>

@ -17,9 +17,9 @@
</a>
</li>
<% end %>
<% @course.course_groups.each do |group| %>
<% @course.course_groups.includes(:members).each do |group| %>
<li id="course_group_<%=group.id %>" class="clearfix">
<% count = group.members.count %>
<% count = group.members.size %>
<a href="<%= students_course_path(@course, :group_id => group.id) %>" class="fl"><span class="fl ml38 devide_class task-hide" data-tip-down="<%=group.name %>"><%=group.name %></span>
<% if count > 0 %>
<span class="fl ml10 color-grey-9 font-12 groupNum"><%= count %></span>

Loading…
Cancel
Save