socialforge/app/helpers/homework_common_helper.rb

98 lines
3.4 KiB
Ruby

# encoding: utf-8
module HomeworkCommonHelper
#获取匿评相关连接代码
def homework_anonymous_comment homework
if homework.homework_type == 1 && homework.homework_detail_manual #匿评作业
if homework.student_works.count >= 2 #作业份数大于2
case homework.homework_detail_manual.comment_status
when 1
link = link_to '启动匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit'
when 2
link = link_to '关闭匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit'
when 3
link = "<span class='fr pr_join_span mr10' title='匿评结束'>匿评结束</span>".html_safe
end
else
link = "<span class='fr mr10 pr_join_span ' title='学生提交作业数大于2时才可以启动匿评'>启动匿评</span>".html_safe
end
else
link = "<span class='fr mr10 pr_join_span ' title='未开启匿评作业不可以启动匿评'>启动匿评</span>".html_safe
end
link
end
def student_new_homework homework
work = cur_user_works_for_homework homework
if work.nil?
link_to l(:label_commit_homework), new_student_work_path(:homework => homework.id),:class => 'fr mr10 work_edit'
else
if homework.homework_type == 2 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前
"<span class='fr mr10 pr_join_span ' title='已开启匿评不能修改作品'>#{l(:label_edit_homework)}</span>".html_safe
else
link_to l(:label_edit_homework), edit_student_work_path(work.id),:class => 'fr mr10 work_edit'
end
end
end
def student_anonymous_comment homework
if homework.homework_type == 1 && homework.homework_detail_manual
case homework.homework_detail_manual.comment_status
when 1
"<span class='fr mr10 pr_join_span '>未开启匿评</span>".html_safe
when 2
"<span class='fr mr10 pr_join_span '>正在匿评中</span>".html_safe
when 3
"<span class='fr mr10 pr_join_span '>匿评已结束</span>".html_safe
end
elsif homework.homework_type == 0
"<span class='fr mr10 pr_join_span '>未启用匿评</span>".html_safe
elsif homework.homework_type == 2
"<span class='fr mr10 pr_join_span '>编程作业</span>".html_safe
end
end
#获取当前用户在指定作业下提交的作业的集合
def cur_user_works_for_homework homework
homework.student_works.where("user_id = ?",User.current).first
end
#迟交扣分下拉框
def late_penalty_option
type = []
for i in (1..5)
option = []
option << i
option << i
type << option
end
type
end
#教辅评分比例下拉框
def ta_proportion_option
type = []
i = 10
while i <= 100
option = []
option << i.to_s + "%"
option << i.to_f / 100
type << option
i += 10
end
type
end
#缺评扣分
def absence_penalty_option
type = []
i = 1
while i <= 5
option = []
option << i
option << i
type << option
i += 1
end
type
end
end