实训作业列表优化

dev_ec
cxt 6 years ago
parent 4f1fcaa16d
commit cb03317076

@ -30,9 +30,9 @@ class HomeworkCommonController < ApplicationController
@homework_type = params[:homework_type].to_i @homework_type = params[:homework_type].to_i
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
if @search 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 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 end
if @is_teacher if @is_teacher
@homework_commons = @homework_commons @homework_commons = @homework_commons
@ -72,6 +72,9 @@ class HomeworkCommonController < ApplicationController
@is_new = params[:is_new] @is_new = params[:is_new]
@homeworks = paginateHelper @homework_commons,15 @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已读 #设置at已读
=begin =begin
ids = @homeworks.inject([]) do |ids, homework| ids = @homeworks.inject([]) do |ids, homework|

@ -1317,11 +1317,11 @@ module ApplicationHelper
def had_commit_studentwork_count homework_common def had_commit_studentwork_count homework_common
member = homework_common.course.members.where(:user_id => User.current.id).first member = homework_common.course.members.where(:user_id => User.current.id).first
student_works = homework_common.student_works 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) 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) student_works = student_works.where(:user_id => group_students)
end end
student_works.where("work_status !=?", 0).count student_works.where("work_status !=?", 0).size
end end
# 实训作业的有效作品数 # 实训作业的有效作品数
@ -1357,11 +1357,11 @@ module ApplicationHelper
def had_uncommit_studentwork_count homework_common def had_uncommit_studentwork_count homework_common
member = homework_common.course.members.where(:user_id => User.current.id).first member = homework_common.course.members.where(:user_id => User.current.id).first
student_works = homework_common.student_works 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) 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) student_works = student_works.where(:user_id => group_students)
end end
student_works.where("work_status =?", 0).count student_works.where("work_status =?", 0).size
end 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 #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 member = homework_common.course.members.where(:user_id => User.current.id).first
student_works = homework_common.student_works 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) 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) student_works = student_works.where(:user_id => group_students)
end end
has_comment = StudentWorksScore.where(:student_work_id => student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).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.count student_count = student_works.size
return student_count - has_comment return student_count - has_comment
end end

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

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

@ -13,9 +13,9 @@
</li> </li>
<% unless course_board.children.empty? %> <% unless course_board.children.empty? %>
<ul> <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"> <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> <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 %> <% if count > 0 %>
<span class="fr mr30 courseNewNum"><%= count %></span> <span class="fr mr30 courseNewNum"><%= count %></span>

@ -17,9 +17,9 @@
</a> </a>
</li> </li>
<% end %> <% end %>
<% @course.course_groups.each do |group| %> <% @course.course_groups.includes(:members).each do |group| %>
<li id="course_group_<%=group.id %>" class="clearfix"> <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> <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 %> <% if count > 0 %>
<span class="fl ml10 color-grey-9 font-12 groupNum"><%= count %></span> <span class="fl ml10 color-grey-9 font-12 groupNum"><%= count %></span>

Loading…
Cancel
Save