mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
init project
This commit is contained in:
2
app/helpers/admin_helper.rb
Normal file
2
app/helpers/admin_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module AdminHelper
|
||||
end
|
||||
23
app/helpers/admins/mirror_repositories_helper.rb
Normal file
23
app/helpers/admins/mirror_repositories_helper.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
module Admins::MirrorRepositoriesHelper
|
||||
def mirror_type_tag(mirror)
|
||||
case mirror.main_type
|
||||
when '1' then '<i class="fa fa-star text-success font-16" aria-hidden="true" data-toggle="tooltip" data-title="主类别"></i>'.html_safe
|
||||
when '0' then '<i class="fa fa-star text-secondary font-16" aria-hidden="true" data-toggle="tooltip" data-title="子类别"></i>'.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def mirror_status_tag(mirror)
|
||||
case mirror.status
|
||||
when 0
|
||||
'<i class="fa fa-check-circle text-secondary font-16" data-toggle="tooltip" data-title="未发布"></i>'.html_safe
|
||||
when 1
|
||||
'<i class="fa fa-check-circle text-success font-16" data-toggle="tooltip" data-title="已发布"></i>'.html_safe
|
||||
when 2, 3
|
||||
'<i class="fa fa-exclamation-circle text-danger font-16" data-toggle="tooltip" data-title="被修改"></i>'.html_safe
|
||||
when 4
|
||||
'<i class="fa fa-times-circle text-danger font-18" data-toggle="tooltip" data-title="被删除"></i>'.html_safe
|
||||
when 5
|
||||
'<i class="fa fa-exclamation-circle text-warning font-16" data-toggle="tooltip" data-title="子节点异常"></i>'.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
22
app/helpers/admins/subjects_helper.rb
Normal file
22
app/helpers/admins/subjects_helper.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module Admins::SubjectsHelper
|
||||
def display_subject_status(subject)
|
||||
style =
|
||||
case subject.public
|
||||
when 0 then 'text-secondary'
|
||||
when 1 then 'text-warning'
|
||||
when 2 then 'text-success'
|
||||
end
|
||||
|
||||
status =
|
||||
if subject.public == 2
|
||||
"publiced"
|
||||
elsif subject.public == 1
|
||||
"pending"
|
||||
elsif subject.status == 2
|
||||
"processed"
|
||||
else
|
||||
"editing"
|
||||
end
|
||||
raw content_tag(:span, t("subject.public.#{status}"), class: style)
|
||||
end
|
||||
end
|
||||
431
app/helpers/application_helper.rb
Normal file
431
app/helpers/application_helper.rb
Normal file
@@ -0,0 +1,431 @@
|
||||
# 所有的方法请按首字母的顺序依次列出
|
||||
module ApplicationHelper
|
||||
include Educoder::I18n
|
||||
include GitHelper
|
||||
|
||||
ONE_MINUTE = 60 * 1000
|
||||
ONE_HOUR = 60 * ONE_MINUTE
|
||||
ONE_DAY = 24 * ONE_HOUR
|
||||
ONE_MONTH = 30 * ONE_DAY
|
||||
|
||||
ONE_YEAR = 12 * ONE_MONTH
|
||||
|
||||
# 全局参数配置
|
||||
def edu_setting name
|
||||
EduSetting.get(name)
|
||||
end
|
||||
|
||||
# xss共计问题
|
||||
def content_safe content
|
||||
tags = %w(
|
||||
a abbr b bdo blockquote br caption cite code col colgroup dd del dfn dl
|
||||
dt em figcaption figure h1 h2 h3 h4 h5 h6 hgroup i img ins kbd li mark
|
||||
ol p pre q rp rt ruby s samp small strike strong sub sup table tbody td
|
||||
tfoot th thead time tr u ul var wbr div span
|
||||
)
|
||||
attributes = %w(href src width height alt cite datetime title class name xml:lang abbr style)
|
||||
sanitize content, tags: tags, attributes: attributes
|
||||
end
|
||||
|
||||
def graduation_navigation graduation
|
||||
graduation.class.to_s == "GraduationTopic" ? "毕设选题" : "毕设任务"
|
||||
end
|
||||
|
||||
def graduation_navigation_id course
|
||||
course.course_modules.find_by(module_type: "graduation").try(:id)
|
||||
end
|
||||
|
||||
# 是否关注
|
||||
# from_user_id为被关注的用户
|
||||
def follow?(from_user_id, user_id)
|
||||
Watcher.where(watchable_type: 'Principal', watchable_id: from_user_id, user_id: user_id).exists?
|
||||
end
|
||||
|
||||
# git用户
|
||||
# git用户命名规则:login+"@educoder.net"
|
||||
def git_username(email)
|
||||
User.find_by_mail(email) || User.find_by_login(email.split("@").first)
|
||||
end
|
||||
|
||||
# 不同的类型扩展不同的目录
|
||||
def relative_path
|
||||
"avatars"
|
||||
end
|
||||
|
||||
def storage_path
|
||||
File.join(Rails.root, "public", "images", relative_path)
|
||||
end
|
||||
|
||||
# 推荐实训
|
||||
def recommend_shixun(shixun)
|
||||
tag_repertoire_id = shixun.tag_repertoires.first.present? ? shixun.tag_repertoires.first.try(:id) : 0
|
||||
shixun_id = ShixunTagRepertoire.where("tag_repertoire_id = #{tag_repertoire_id} and
|
||||
shixun_id != #{shixun.id}").pluck(:shixun_id)
|
||||
|
||||
shixun_id = shixun_id.blank? ? -1 : shixun_id.join(",")
|
||||
Shixun.select([:id, :name, :user_id, :challenges_count, :myshixuns_count, :trainee, :identifier]).where("id
|
||||
in(#{shixun_id})").unhidden.publiced.order("homepage_show asc, myshixuns_count desc").limit(3)
|
||||
|
||||
end
|
||||
|
||||
# shixun开启挑战对应的行为名及url
|
||||
def task_operation_url current_myshixun, shixun
|
||||
if current_myshixun.blank?
|
||||
name = shixun.status == 0 ? "模拟实战" : "开启挑战"
|
||||
url = "/shixuns/#{shixun.identifier}/shixun_exec"
|
||||
else
|
||||
identifier = current_myshixun.current_task(current_myshixun.games).try(:identifier)
|
||||
if current_myshixun.status == 1
|
||||
name = "查看实战"
|
||||
else
|
||||
name = "继续挑战"
|
||||
end
|
||||
url = identifier
|
||||
end
|
||||
[name, url]
|
||||
end
|
||||
|
||||
# 获取当前时间
|
||||
def time_from_now(time)
|
||||
if String === time
|
||||
time = Time.parse(time)
|
||||
end
|
||||
|
||||
lastUpdateTime = time.to_i*1000
|
||||
|
||||
currentTime = Time.now.to_i*1000
|
||||
timePassed = currentTime - lastUpdateTime
|
||||
timeIntoFormat = 0
|
||||
updateAtValue = ""
|
||||
if timePassed < 0
|
||||
updateAtValue = "刚刚"
|
||||
elsif timePassed < ONE_MINUTE
|
||||
updateAtValue = "1分钟前"
|
||||
elsif timePassed < ONE_HOUR
|
||||
timeIntoFormat = timePassed / ONE_MINUTE
|
||||
updateAtValue = timeIntoFormat.to_s + "分钟前"
|
||||
elsif (timePassed < ONE_DAY)
|
||||
timeIntoFormat = timePassed / ONE_HOUR
|
||||
updateAtValue = timeIntoFormat.to_s + "小时前"
|
||||
elsif (timePassed < ONE_MONTH)
|
||||
timeIntoFormat = timePassed / ONE_DAY
|
||||
updateAtValue = timeIntoFormat.to_s + "天前"
|
||||
elsif (timePassed < ONE_YEAR)
|
||||
timeIntoFormat = timePassed / ONE_MONTH
|
||||
updateAtValue = timeIntoFormat.to_s + "个月前"
|
||||
else
|
||||
timeIntoFormat = timePassed / ONE_YEAR
|
||||
updateAtValue = timeIntoFormat.to_s + "年前"
|
||||
end
|
||||
updateAtValue
|
||||
end
|
||||
|
||||
# 计算到结束还有多长时间 **天**小时**分
|
||||
def how_much_time(time)
|
||||
if time.nil? || time < Time.now #6.21 -hs 增加小于time.now
|
||||
''
|
||||
else
|
||||
result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + " 天 "
|
||||
result += (((time - Time.now.to_i).to_i % (24*60*60)) / (60*60)).to_s + " 小时 "
|
||||
result + ((((time - Time.now.to_i).to_i % (24*60*60)) % (60*60)) / 60).to_s + " 分 "
|
||||
end
|
||||
end
|
||||
|
||||
def format_time(time)
|
||||
time.present? ? time.strftime("%Y-%m-%d %H:%M") : ''
|
||||
end
|
||||
|
||||
# 用户图像url,如果不存在的话,source为匿名用户,即默认使用匿名用户图像
|
||||
def url_to_avatar(source)
|
||||
if File.exist?(disk_filename(source&.class, source&.id))
|
||||
ctime = File.ctime(disk_filename(source.class, source.id)).to_i
|
||||
if source.class.to_s == 'User'
|
||||
File.join(relative_path, ["#{source.class}", "#{source.id}"]) + "?t=#{ctime}"
|
||||
else
|
||||
File.join("images/avatars", ["#{source.class}", "#{source.id}"]) + "?t=#{ctime}"
|
||||
end
|
||||
elsif source.class.to_s == 'User'
|
||||
str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g"
|
||||
File.join(relative_path, "#{source.class}", str)
|
||||
elsif source.class.to_s == 'Subject'
|
||||
File.join("images","educoder", "index", "subject", "subject#{rand(17)}.jpg")
|
||||
elsif source.class.to_s == 'Shixun'
|
||||
File.join("images","educoder", "index", "shixun", "shixun#{rand(23)}.jpg")
|
||||
end
|
||||
end
|
||||
|
||||
# 主页banner图
|
||||
def banner_img(source_type)
|
||||
if File.exist?(disk_filename(source_type, "banner"))
|
||||
ctime = File.ctime(disk_filename(source_type, "banner")).to_i
|
||||
File.join("images/avatars", ["#{source_type}", "banner"]) + "?t=#{ctime}"
|
||||
end
|
||||
end
|
||||
|
||||
def disk_filename(source_type,source_id,image_file=nil)
|
||||
File.join(storage_path, "#{source_type}", "#{source_id}")
|
||||
end
|
||||
|
||||
def disk_auth_filename(source_type, source_id, type)
|
||||
File.join(storage_path, "#{source_type}", "#{source_id}#{type}")
|
||||
end
|
||||
|
||||
def disk_real_name_auth_filename(source_id)
|
||||
disk_auth_filename('UserAuthentication', source_id, 'ID')
|
||||
end
|
||||
|
||||
def auth_file_url(source_type, source_id, type)
|
||||
File.join('/images', relative_path, source_type, "#{source_id}#{type}")
|
||||
end
|
||||
|
||||
def real_name_auth_file_url(source_id)
|
||||
auth_file_url('UserAuthentication', source_id, 'ID')
|
||||
end
|
||||
|
||||
def disk_professional_auth_filename(source_id)
|
||||
disk_auth_filename('UserAuthentication', source_id, 'PRO')
|
||||
end
|
||||
|
||||
def professional_auth_file_url(source_id)
|
||||
auth_file_url('UserAuthentication', source_id, 'PRO')
|
||||
end
|
||||
|
||||
def shixun_url_to_avatar(shixun)
|
||||
if File.exist?(disk_filename(shixun.class, shixun.id))
|
||||
File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}")
|
||||
else
|
||||
File.join("educoder", "index", "shixun", "shixun#{rand(23)}.jpg")
|
||||
end
|
||||
end
|
||||
|
||||
# 选用实训的学校情况
|
||||
def school_user_detail shixun
|
||||
user_ids = shixun.myshixuns.map(&:user_id).uniq # 走缓存取数据
|
||||
school_ids = UserExtension.where(user_id:user_ids).pluck(:school_id).uniq
|
||||
school_names = School.where(id: school_ids[0..1]).pluck(:name)
|
||||
school_size = school_ids.size
|
||||
str = school_size > 0 ? "#{school_names.join("、")}等 #{school_size}所" : "0所"
|
||||
end
|
||||
|
||||
# 普通/分组 作业作品状态数组
|
||||
def student_work_status homework, user_id, course, work
|
||||
status = []
|
||||
homework_setting = homework.homework_group_setting user_id, true
|
||||
work = work || StudentWork.create(homework_common_id: homework.id, user_id: user_id)
|
||||
late_time = homework.late_time || course.end_date
|
||||
|
||||
if course.is_end && work && work.work_status > 0
|
||||
status << "查看作品"
|
||||
elsif !course.is_end
|
||||
if homework_setting.publish_time && homework_setting.publish_time < Time.now
|
||||
# 作业未截止时
|
||||
if homework_setting.end_time > Time.now
|
||||
if homework.homework_type == "group" && homework.homework_detail_group.base_on_project
|
||||
if work.project_id.nil? || work.project_id == 0
|
||||
status << "创建项目"
|
||||
status << "关联项目"
|
||||
elsif work.work_status == 0
|
||||
status << "取消关联"
|
||||
status << "提交作品"
|
||||
else
|
||||
status << "修改作品"
|
||||
end
|
||||
else
|
||||
if work.work_status == 0
|
||||
status << "提交作品"
|
||||
else
|
||||
status << "修改作品"
|
||||
end
|
||||
end
|
||||
|
||||
# 补交阶段
|
||||
elsif homework.allow_late && (late_time.nil? || late_time > Time.now)
|
||||
if homework.homework_type == "group" && homework.homework_detail_group.base_on_project
|
||||
if work.project_id.nil? || work.project_id == 0
|
||||
status << "创建项目"
|
||||
status << "关联项目"
|
||||
elsif work.work_status == 0
|
||||
status << "取消关联"
|
||||
status << "补交作品"
|
||||
else
|
||||
status << "补交附件"
|
||||
status << "查看作品"
|
||||
end
|
||||
else
|
||||
if work.work_status == 0
|
||||
status << "补交作品"
|
||||
else
|
||||
status << "补交附件"
|
||||
status << "查看作品"
|
||||
end
|
||||
end
|
||||
|
||||
# 匿评阶段
|
||||
elsif work.work_status != 0
|
||||
if homework.homework_detail_manual.comment_status == 3
|
||||
work_ids = homework.student_works.has_committed.pluck(:id)
|
||||
if StudentWorksEvaluationDistribution.where(student_work_id: work_ids, user_id: user_id).size > 0
|
||||
status << "匿评作品"
|
||||
end
|
||||
end
|
||||
status << "查看作品"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def commit_des_status work, homework
|
||||
status = []
|
||||
homework_setting = homework.homework_group_setting work.user_id
|
||||
|
||||
# 作业已发布且作业未截止(补交未截止)且提交了作品才能提交或修改总结
|
||||
if homework_setting.publish_time && homework_setting.publish_time < Time.now && work.work_status > 0 &&
|
||||
((homework_setting.end_time && homework_setting.end_time > Time.now) ||
|
||||
(homework.allow_late && homework.late_time && homework.late_time > Time.now))
|
||||
work.description.present? ? status << "修改总结" : status << "提交总结"
|
||||
end
|
||||
end
|
||||
|
||||
def download_url attachment,options={}
|
||||
attachment_path(attachment,options)
|
||||
end
|
||||
|
||||
# 耗时:天、小时、分、秒
|
||||
# 小于1分钟则不显示
|
||||
def game_spend_time time
|
||||
day = time / 86400
|
||||
hour = time % (24*60*60) / (60*60)
|
||||
min = time % (24*60*60) % (60*60) / 60
|
||||
sec = time % (24*60*60) % (60*60) % 60
|
||||
if day < 1
|
||||
if hour < 1
|
||||
if min < 1
|
||||
if sec < 1
|
||||
time = "--"
|
||||
else
|
||||
time = "#{sec}秒"
|
||||
end
|
||||
else
|
||||
time = "#{min}分钟 #{sec}秒"
|
||||
end
|
||||
else
|
||||
time = "#{hour}小时 #{min}分钟 #{sec}秒"
|
||||
end
|
||||
else
|
||||
time = "#{day}天 #{hour}小时 #{min}分钟 #{sec}秒"
|
||||
end
|
||||
return time
|
||||
end
|
||||
|
||||
def absolute_path(file_path)
|
||||
File.join(edu_setting('attachment_folder'), file_path)
|
||||
end
|
||||
|
||||
def local_path(file)
|
||||
File.join(file.disk_directory, file.disk_filename)
|
||||
end
|
||||
|
||||
def update_downloads(file)
|
||||
file.update_attributes(:downloads => file.downloads + 1)
|
||||
end
|
||||
|
||||
# 项目信息,
|
||||
def project_info work, current_user, course_identity
|
||||
project = work.project
|
||||
if project
|
||||
if project.status == 9
|
||||
{id: -1, name: "#{project.name}(已删除)", title: "该项目已删除", author: project.creator, member_count: project.project_members.count}
|
||||
else
|
||||
project_score = project.project_score
|
||||
if project.is_public || current_user.manager_of_project?(project) || course_identity < Course::STUDENT
|
||||
{id: project.id, name: project.name, author: project.creator, member_count: project.project_members.count,
|
||||
all_score: project_score.all_score, code_score: project_score.code_score, issue_score: project_score.issue_score,
|
||||
attachment_score: project_score.attachment_score, message_score: project_score.message_score}
|
||||
else
|
||||
{id: -1, name: "#{project.name}", title: "该项目是私有的", author: project.creator, member_count: project.project_members.count,
|
||||
all_score: project_score.all_score, code_score: project_score.code_score, issue_score: project_score.issue_score,
|
||||
attachment_score: project_score.attachment_score, message_score: project_score.message_score}
|
||||
end
|
||||
end
|
||||
else
|
||||
{id: -1, name: "--", title: "--"}
|
||||
end
|
||||
end
|
||||
|
||||
def message_content(content)
|
||||
content = (strip_html content).strip
|
||||
content = content.gsub(/\s+/, " ")
|
||||
if content.gsub(" ", "") == ""
|
||||
content = "[非文本消息]"
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
def strip_html(text, len=0, endss="...")
|
||||
ss = ""
|
||||
if !text.nil? && text.length>0
|
||||
ss=text.gsub(/<\/?.*?>/, '').strip
|
||||
ss = ss.gsub(/ */, '')
|
||||
ss = ss.gsub(/\r\n/,'') #新增
|
||||
ss = ss.gsub(/\n/,'') #新增
|
||||
if len > 0 && ss.length > len
|
||||
ss = ss[0, len] + endss
|
||||
elsif len > 0 && ss.length <= len
|
||||
ss = ss
|
||||
#ss = truncate(ss, :length => len)
|
||||
end
|
||||
end
|
||||
ss
|
||||
end
|
||||
|
||||
def strip_export_title(content)
|
||||
con_ = ""
|
||||
if content.length > 0
|
||||
con_ = strip_tags(content)
|
||||
con_ = con_.gsub(/\r\n/,'').gsub(/ */, '').strip
|
||||
end
|
||||
con_
|
||||
end
|
||||
|
||||
def pdf_load_sources(*arg)
|
||||
arr = arg.map do |path|
|
||||
content_tag(:script) do
|
||||
File.open(Rails.root.join('public', path)).read.to_s.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
raw arr.join('')
|
||||
end
|
||||
|
||||
|
||||
|
||||
# 导出pdf时,转化markdown为html
|
||||
def to_markdown(text,origin_url)
|
||||
return nil if text.blank?
|
||||
options = {
|
||||
:autolink => true,
|
||||
:no_intra_emphasis => true,
|
||||
:fenced_code_blocks => true,
|
||||
:lax_html_blocks => true,
|
||||
:strikethrough => true,
|
||||
:superscript => false,
|
||||
:tables => true
|
||||
}
|
||||
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, options)
|
||||
m_t = markdown.render(text)
|
||||
m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{origin_url}") : m_t
|
||||
end
|
||||
|
||||
def shixun_status_class(shixun)
|
||||
case shixun.status
|
||||
when 0 then 'text-info'
|
||||
when 1 then 'text-warning'
|
||||
when 2 then 'text-success'
|
||||
when 3 then 'text-secondary'
|
||||
end
|
||||
end
|
||||
|
||||
def render_unix_time(date)
|
||||
date.to_time.to_i
|
||||
end
|
||||
end
|
||||
2
app/helpers/blob_helper.rb
Normal file
2
app/helpers/blob_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module BlobHelper
|
||||
end
|
||||
2
app/helpers/boards_helper.rb
Normal file
2
app/helpers/boards_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module BoardsHelper
|
||||
end
|
||||
10
app/helpers/challenges_helper.rb
Normal file
10
app/helpers/challenges_helper.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
module ChallengesHelper
|
||||
|
||||
def match_begin_symbol str
|
||||
str.gsub(/\A\r/, "\r\r")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
2
app/helpers/comments_helper.rb
Normal file
2
app/helpers/comments_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CommentsHelper
|
||||
end
|
||||
2
app/helpers/contents_helper.rb
Normal file
2
app/helpers/contents_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ContentsHelper
|
||||
end
|
||||
2
app/helpers/course_groups_helper.rb
Normal file
2
app/helpers/course_groups_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CourseGroupsHelper
|
||||
end
|
||||
2
app/helpers/course_modules_helper.rb
Normal file
2
app/helpers/course_modules_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CourseModulesHelper
|
||||
end
|
||||
2
app/helpers/course_second_categories_helper.rb
Normal file
2
app/helpers/course_second_categories_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CourseSecondCategoriesHelper
|
||||
end
|
||||
2
app/helpers/course_stages_helper.rb
Normal file
2
app/helpers/course_stages_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CourseStagesHelper
|
||||
end
|
||||
298
app/helpers/courses_helper.rb
Normal file
298
app/helpers/courses_helper.rb
Normal file
@@ -0,0 +1,298 @@
|
||||
module CoursesHelper
|
||||
|
||||
def member_manager group, teachers
|
||||
str = ""
|
||||
members = teachers.select{|teacher| teacher.teacher_course_groups.pluck(:course_group_id).include?(group.id) || teacher.teacher_course_groups.size == 0}
|
||||
str = members.uniq.size == teachers.size ? "全部教师" : members.map{|member| member.user.real_name}.join("、")
|
||||
str
|
||||
# teachers.each do |member|
|
||||
# if member.teacher_course_groups.exists?(course_group_id: group.id) || member.teacher_course_groups.size == 0
|
||||
# str << member.user.real_name
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def edit_auth group, teachers
|
||||
User.current.admin_or_business? ||
|
||||
teachers.select{|teacher| teacher.user_id == User.current.id &&
|
||||
(teacher.teacher_course_groups.pluck(:course_group_id).include?(group.id) || teacher.teacher_course_groups.size == 0)}.size > 0
|
||||
end
|
||||
|
||||
# 是否有切换为学生的入口
|
||||
def switch_student_role is_teacher, course, user
|
||||
is_teacher && course.course_members.where(user_id: user.id, role: %i(STUDENT)).exists?
|
||||
end
|
||||
|
||||
# 是否有切换为教师的入口
|
||||
def switch_teacher_role is_student, course, user
|
||||
is_student && course.course_members.where(user_id: user.id, role: %i(CREATOR PROFESSOR)).exists?
|
||||
end
|
||||
|
||||
# 是否有切换为助教的入口
|
||||
def switch_assistant_role is_student, course, user
|
||||
is_student && course.course_members.where(user_id: user.id, role: %i(ASSISTANT_PROFESSOR)).exists?
|
||||
end
|
||||
|
||||
# 课堂结束天数
|
||||
def course_end_date end_date
|
||||
if end_date.present?
|
||||
curr = Time.new
|
||||
date = ((Date.parse(end_date.to_s) - Date.parse(curr.to_s)).to_i)
|
||||
date > 0 ? "#{date}天后" : ""
|
||||
end
|
||||
end
|
||||
|
||||
# 课堂模块的url
|
||||
def module_url mod, course
|
||||
return nil if mod.blank? or course.blank?
|
||||
case mod.module_type
|
||||
when "announcement"
|
||||
"/courses/#{course.id}/informs"
|
||||
when "online_learning"
|
||||
"/courses/#{course.id}/online_learning"
|
||||
when "shixun_homework"
|
||||
"/courses/#{course.id}/shixun_homeworks/#{mod.id}"
|
||||
when "common_homework"
|
||||
"/courses/#{course.id}/common_homeworks/#{mod.id}"
|
||||
when "group_homework"
|
||||
"/courses/#{course.id}/group_homeworks/#{mod.id}"
|
||||
when "graduation"
|
||||
"/courses/#{course.id}/graduation_topics/#{mod.id}"
|
||||
when "exercise"
|
||||
"/courses/#{course.id}/exercises/#{mod.id}"
|
||||
when "poll"
|
||||
"/courses/#{course.id}/polls/#{mod.id}"
|
||||
when "attachment"
|
||||
"/courses/#{course.id}/files/#{mod.id}"
|
||||
when "board"
|
||||
course_board = course.course_board
|
||||
"/courses/#{course.id}/boards/#{course_board.id}"
|
||||
when "course_group"
|
||||
"/courses/#{course.id}/course_groups"
|
||||
when "statistics"
|
||||
"/courses/#{course.id}/statistics"
|
||||
when "video"
|
||||
"/courses/#{course.id}/course_videos"
|
||||
end
|
||||
end
|
||||
|
||||
# 子目录对应的url
|
||||
def category_url category, course
|
||||
case category.category_type
|
||||
when "shixun_homework"
|
||||
"/courses/#{course.id}/shixun_homework/#{category.id}"
|
||||
when "graduation"
|
||||
if category.name == "毕设选题"
|
||||
"/courses/#{course.id}/graduation_topics/#{category.course_module_id}"
|
||||
else
|
||||
"/courses/#{course.id}/graduation_tasks/#{category.course_module_id}"
|
||||
end
|
||||
when "attachment"
|
||||
"/courses/#{course.id}/file/#{category.id}"
|
||||
end
|
||||
end
|
||||
|
||||
# 子目录下的任务数
|
||||
def category_task_count course, category, user
|
||||
case category.category_type
|
||||
when "shixun_homework"
|
||||
get_homework_commons_count(course, 4, category.id)
|
||||
when "graduation"
|
||||
if category.name == "毕设选题"
|
||||
course.graduation_topics_count
|
||||
else
|
||||
course.graduation_tasks_count
|
||||
end
|
||||
when "attachment"
|
||||
get_attachment_count(course, category.id)
|
||||
end
|
||||
end
|
||||
|
||||
# 课堂模块的任务数
|
||||
def course_task_count(course, module_type)
|
||||
case module_type
|
||||
when "shixun_homework"
|
||||
get_homework_commons_count(course, 4, 0)
|
||||
when "common_homework"
|
||||
get_homework_commons_count(course, 1, 0)
|
||||
when "group_homework"
|
||||
get_homework_commons_count(course, 3, 0)
|
||||
when "graduation"
|
||||
0
|
||||
when "exercise"
|
||||
course.exercises_count
|
||||
when "poll"
|
||||
course.polls_count
|
||||
when "attachment"
|
||||
get_attachment_count(course, 0)
|
||||
when "board"
|
||||
course_board = course.course_board
|
||||
course_board.present? ? course_board.messages.size : 0
|
||||
when "course_group"
|
||||
course.course_groups_count
|
||||
when "announcement"
|
||||
course.informs.count
|
||||
when "online_learning"
|
||||
course.shixuns.count
|
||||
when "video"
|
||||
course.course_videos.count + course.live_links.count
|
||||
end
|
||||
end
|
||||
|
||||
# 当前用户可见的课堂作业,type指定作业类型, category_id指定二级目录
|
||||
def visible_homework course, user, type, category_id=0
|
||||
if user.teacher_of_course?(course)
|
||||
homeworks = course.homework_commons.where("homework_type = #{type} and course_second_category_id = #{category_id}")
|
||||
elsif user.member_of_course?(course)
|
||||
member = course.course_members.find_by(user_id: user.id, role: 4)
|
||||
if member.try(:course_group_id).to_i == 0
|
||||
homeworks = course.homework_commons.where("homework_commons.homework_type = #{type} and publish_time <= '#{Time.now}'
|
||||
and unified_setting = 1 and course_second_category_id = #{category_id}")
|
||||
else
|
||||
not_homework_ids = course.homework_group_settings.where("course_group_id = #{member.try(:course_group_id)} and
|
||||
(publish_time > '#{Time.now}' or publish_time is null)").pluck(:homework_common_id)
|
||||
# not_homework_ids = not_homework_ids.blank? ? "(-1)" : "(" + not_homework_ids.map(&:homework_common_id).join(",") + ")"
|
||||
homeworks = course.homework_commons.where.not(id: not_homework_ids).where("homework_commons.homework_type = #{type} and publish_time <= '#{Time.now}'
|
||||
and course_second_category_id = #{category_id}")
|
||||
end
|
||||
else
|
||||
homeworks = course.homework_commons.where("homework_type = #{type} and publish_time <= '#{Time.now}' and unified_setting = 1
|
||||
and course_second_category_id = #{category_id}")
|
||||
end
|
||||
homeworks
|
||||
end
|
||||
|
||||
# 当前用户可见的课堂试卷
|
||||
def visible_exercise course, user
|
||||
if user.teacher_of_course?(course)
|
||||
exercises = course.exercises
|
||||
elsif user.member_of_course?(course)
|
||||
member = course.course_members.find_by(user_id: user.id, role: 4)
|
||||
if member.try(:course_group_id).to_i == 0
|
||||
exercises = course.exercises.where("publish_time <= '#{Time.now}' and unified_setting = 1")
|
||||
else
|
||||
not_exercise_ids = course.exercise_group_settings.where("course_group_id = #{member.try(:course_group_id)} and
|
||||
(publish_time > '#{Time.now}' or publish_time is null)").pluck(:exercise_id)
|
||||
exercises = course.exercises.where.not(id: not_exercise_ids).where("publish_time <= '#{Time.now}'")
|
||||
end
|
||||
else
|
||||
exercises = course.exercises.where("publish_time <= '#{Time.now}' and unified_setting = 1")
|
||||
end
|
||||
exercises
|
||||
end
|
||||
|
||||
# 当前用户可见的课堂问卷
|
||||
def visible_poll course, user
|
||||
if user.teacher_of_course?(course)
|
||||
polls = course.polls
|
||||
elsif user.member_of_course?(course)
|
||||
member = course.course_members.find_by(user_id: user.id, role: 4)
|
||||
if member.try(:course_group_id).to_i == 0
|
||||
polls = course.polls.where("publish_time <= '#{Time.now}' and unified_setting = 1")
|
||||
else
|
||||
not_poll_ids = course.poll_group_settings.where("course_group_id = #{member.try(:course_group_id)} and
|
||||
(publish_time > '#{Time.now}' or publish_time is null)").pluck(:poll_id)
|
||||
polls = course.polls.where.not(id: not_poll_ids).where("publish_time <= '#{Time.now}'")
|
||||
end
|
||||
else
|
||||
polls = course.polls.where("publish_time <= '#{Time.now}' and unified_setting = 1")
|
||||
end
|
||||
polls
|
||||
end
|
||||
|
||||
# 当前用户可见的课堂资源,category_id指定资源的目录
|
||||
def visible_attachment course, user, category_id=0
|
||||
result = []
|
||||
course.attachments.where(course_second_category_id: category_id).each do |attachment|
|
||||
if attachment.unified_setting
|
||||
if attachment.is_public == 1 && attachment.is_publish == 1 || user == attachment.author || user.teacher_of_course?(course) || (user.member_of_course?(course) && attachment.is_publish == 1)
|
||||
result << attachment
|
||||
end
|
||||
else
|
||||
if attachment.is_public == 1 && attachment.is_publish == 1 && !user.member_of_course?(course) || user == attachment.author || user.teacher_of_course?(course)
|
||||
result << attachment
|
||||
elsif user.member_of_course?(course) && attachment.is_publish == 1
|
||||
member = course.course_members.find_by(user_id: user.id, role: 4)
|
||||
if member.try(:course_group_id).to_i == 0 && attachment.unified_setting
|
||||
result << attachment
|
||||
elsif attachment.attachment_group_settings.where("course_group_id = #{member.try(:course_group_id)} and publish_time > '#{Time.now}'").count == 0
|
||||
result << attachment
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# 获取课堂的资源数
|
||||
def get_attachment_count(course, category_id)
|
||||
category_id.to_i == 0 ? course.attachments.size : course.attachments.where(course_second_category_id: category_id).size
|
||||
end
|
||||
|
||||
# 获取课堂的作业数
|
||||
def get_homework_commons_count(course, type, category_id)
|
||||
category_id == 0 ? HomeworkCommon.where(course_id: course.id, homework_type: type).size :
|
||||
HomeworkCommon.where(course_id: course.id, homework_type: type, course_second_category_id: category_id).size
|
||||
end
|
||||
|
||||
|
||||
# 获取课堂的任务数(作业数+试卷数+问卷数)
|
||||
def get_tasks_count(course)
|
||||
course.homework_commons_count + course.exercises_count + course.polls_count
|
||||
end
|
||||
|
||||
# 当前用户可见的毕设任务
|
||||
def visible_graduation_task course, user
|
||||
if user.teacher_of_course?(course)
|
||||
tasks = course.graduation_tasks
|
||||
else
|
||||
tasks = course.graduation_tasks.where("publish_time <= '#{Time.now}'")
|
||||
end
|
||||
tasks
|
||||
end
|
||||
|
||||
# 分班情况
|
||||
def course_group_info course, user_id
|
||||
course_group_ids = course.group_course_power(user_id)
|
||||
course_groups =
|
||||
if course_group_ids.present?
|
||||
course.course_groups.where(id: course_group_ids).includes(:course_members)
|
||||
else
|
||||
course.course_groups.includes(:course_members)
|
||||
end
|
||||
group_info = []
|
||||
if !course_groups.blank?
|
||||
course_groups.each do |group|
|
||||
group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count}
|
||||
end
|
||||
|
||||
none_group_count = course.students.where(course_group_id: 0).size
|
||||
group_info << {course_group_id: 0, group_group_name: "未分班", count: none_group_count} if none_group_count > 0 && !course_group_ids.present?
|
||||
end
|
||||
|
||||
return group_info
|
||||
end
|
||||
|
||||
def left_group_info course
|
||||
group_info = []
|
||||
if course.course_groups_count > 0
|
||||
none_group_count = course.students.where(course_group_id: 0).size
|
||||
group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1,
|
||||
category_count: none_group_count, category_type: false,
|
||||
second_category_url: "/courses/#{@course.id}/course_groups/0"}
|
||||
course.course_groups.each do |course_group|
|
||||
group_info << {category_id: course_group.id, category_name: course_group.name, position: course_group.position,
|
||||
category_count: course_group.course_members_count, category_type: false,
|
||||
second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"}
|
||||
end
|
||||
end
|
||||
group_info
|
||||
end
|
||||
|
||||
def last_subject_shixun course, myshixuns
|
||||
myshixun = myshixuns.sort{|x,y| y[:updated_at] <=> x[:updated_at] }.first
|
||||
return "" unless myshixun
|
||||
stage_shixun = course.course_stage_shixuns.where(shixun_id: myshixun.shixun_id).take
|
||||
progress = stage_shixun&.course_stage&.position.to_s + "-" + stage_shixun&.position.to_s + " " + myshixun.shixun&.name
|
||||
end
|
||||
end
|
||||
2
app/helpers/discusses_helper.rb
Normal file
2
app/helpers/discusses_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module DiscussesHelper
|
||||
end
|
||||
2
app/helpers/edu_datas_helper.rb
Normal file
2
app/helpers/edu_datas_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module EduDatasHelper
|
||||
end
|
||||
2
app/helpers/edu_settings_helper.rb
Normal file
2
app/helpers/edu_settings_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module EduSettingsHelper
|
||||
end
|
||||
2
app/helpers/forks_helper.rb
Normal file
2
app/helpers/forks_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ForksHelper
|
||||
end
|
||||
150
app/helpers/graduation_tasks_helper.rb
Normal file
150
app/helpers/graduation_tasks_helper.rb
Normal file
@@ -0,0 +1,150 @@
|
||||
module GraduationTasksHelper
|
||||
include CoursesHelper
|
||||
# 教师评阅
|
||||
def teacher_comment task, user_id
|
||||
[{ id: 0 ,name: "未评", count: task.uncomment_count(user_id)}, {id: 1, name: "已评", count: task.comment_count(user_id)}]
|
||||
end
|
||||
|
||||
# 作品状态
|
||||
def task_status task, user_id
|
||||
[{id: 0, name: "未提交", count: task.unfinished_count(user_id)},
|
||||
{id: 1, name: "按时提交", count: task.finished_count(user_id)},
|
||||
{id: 2, name: "延时提交", count: task.delay_finished_count(user_id)}]
|
||||
end
|
||||
|
||||
# 交叉评阅
|
||||
def cross_comment task, user_id
|
||||
if task.cross_comment && task.status >= 3
|
||||
[{id: 1, name: "只看我的交叉评阅", count: task.graduation_work_comment_assignations.myself(user_id).count}]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def task_curr_status task, course
|
||||
result = {}
|
||||
status = []
|
||||
time = ""
|
||||
|
||||
if course.try(:is_end)
|
||||
status << "已结束"
|
||||
time = course.end_date.present? ? course.end_date.strftime("%Y-%m-%d") : ""
|
||||
else
|
||||
if task.status > 1 && task.allow_late && (task.late_time.nil? || task.late_time > Time.now)
|
||||
status << "补交中"
|
||||
end
|
||||
|
||||
case task.status
|
||||
when 0
|
||||
status << "未发布"
|
||||
time = task.publish_time.present? ? "将于 #{format_time(task.publish_time)} 发布" : "创建于#{time_from_now(task.created_at)}"
|
||||
when 1
|
||||
if task.end_time && task.end_time >= Time.now
|
||||
status << "提交中"
|
||||
time = how_much_time(task.end_time)
|
||||
end
|
||||
when 2
|
||||
status << "评阅中"
|
||||
time = task.comment_time.present? ? how_much_time(task.comment_time) : course.end_date.present? ? how_much_time(course.end_date.end_of_day) : ""
|
||||
when 3
|
||||
status << "交叉评阅中"
|
||||
time = course.end_date.present? ? how_much_time(course.end_date.end_of_day) : ""
|
||||
end
|
||||
|
||||
status << "未开启补交" if (!task.allow_late && task.status != 0) #6.11 -hs 新增status不等于0
|
||||
|
||||
# 如果还在补交阶段则显示补交结束时间
|
||||
if task.status > 1 && task.allow_late && task.late_time && task.late_time > Time.now
|
||||
time = how_much_time(task.late_time)
|
||||
end
|
||||
end
|
||||
|
||||
result[:status] = status
|
||||
result[:time] = time
|
||||
result
|
||||
end
|
||||
|
||||
# 作品数统计:type: 1 已提交 0 未提交
|
||||
def grduationwork_count task, type
|
||||
works = task.graduation_works
|
||||
type == 1 ? works.select{|work| work.work_status != 0}.size : works.select{|work| work.work_status == 0}.size
|
||||
end
|
||||
|
||||
# 普通/分组 作业作品状态数组
|
||||
def graduation_work_status task, user_id, course
|
||||
status = []
|
||||
work = task.graduation_works.find_by(user_id: user_id)
|
||||
|
||||
work = work || GraduationWork.create(graduation_task_id: task.id, user_id: user_id)
|
||||
late_time = task.late_time || course.end_date
|
||||
|
||||
if course.is_end && work && work.work_status > 0
|
||||
status << "查看作品"
|
||||
elsif !course.is_end
|
||||
if task.publish_time && task.publish_time < Time.now
|
||||
# 作业未截止时
|
||||
if task.end_time > Time.now
|
||||
if task.task_type == 2 && task.base_on_project
|
||||
if work.project_id.nil? || work.project_id == 0
|
||||
status << "创建项目"
|
||||
status << "关联项目"
|
||||
elsif work.work_status == 0
|
||||
status << "取消关联"
|
||||
status << "提交作品"
|
||||
else
|
||||
status << "修改作品"
|
||||
end
|
||||
else
|
||||
if work.work_status == 0
|
||||
status << "提交作品"
|
||||
else
|
||||
status << "修改作品"
|
||||
end
|
||||
end
|
||||
|
||||
# 补交阶段
|
||||
elsif task.allow_late && (late_time.nil? || late_time > Time.now)
|
||||
if task.task_type == 2 && task.base_on_project
|
||||
if work.project_id.nil? || work.project_id == 0
|
||||
status << "创建项目"
|
||||
status << "关联项目"
|
||||
elsif work.work_status == 0
|
||||
status << "取消关联"
|
||||
status << "补交作品"
|
||||
else
|
||||
status << "补交附件"
|
||||
status << "查看作品"
|
||||
end
|
||||
else
|
||||
if work.work_status == 0
|
||||
status << "补交作品"
|
||||
else
|
||||
status << "补交附件"
|
||||
status << "查看作品"
|
||||
end
|
||||
end
|
||||
|
||||
# 匿评阶段
|
||||
elsif work.work_status != 0
|
||||
status << "查看作品"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 阶段剩余时间
|
||||
def task_left_time task
|
||||
if task.publish_time && task.publish_time < Time.now
|
||||
if task.end_time > Time.now
|
||||
status = "剩余提交时间"
|
||||
time = "#{how_much_time(task.end_time)}"
|
||||
else
|
||||
if task.allow_late && task.late_time && task.late_time >= Time.now
|
||||
status = "剩余补交时间"
|
||||
time = "#{how_much_time(task.late_time)}"
|
||||
end
|
||||
end
|
||||
end
|
||||
{status: status, time: time}
|
||||
end
|
||||
end
|
||||
30
app/helpers/graduation_topics_helper.rb
Normal file
30
app/helpers/graduation_topics_helper.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module GraduationTopicsHelper
|
||||
|
||||
# 课题类型
|
||||
def topic_type
|
||||
[{id: 1, name: "设计"}, {id: 2, name: "论文"}, {id: 3, name: "创作"}]
|
||||
end
|
||||
|
||||
# 课程来源
|
||||
def topic_source
|
||||
[{id: 1, name: "生产/社会实际"}, {id: 2, name:"结合科研"}, {id: 3, name: "其它"}]
|
||||
end
|
||||
|
||||
# 课题性质1
|
||||
def topic_property_first
|
||||
[{id: 1, name: "真题"}, {id: 2, name:"模拟题"}]
|
||||
end
|
||||
|
||||
# 课题性质2
|
||||
def topic_property_second
|
||||
[{id: 1, name: "纵向课题"}, {id: 2, name:"横向课题"}, {id: 3, name: "自选"}]
|
||||
end
|
||||
|
||||
# 课题重复
|
||||
def topic_repeat
|
||||
[{id: 1, name: "新题"}, {id: 2, name:"往届题,有新要求"}, {id: 3, name: "往届题,无新要求"}]
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
20
app/helpers/graduation_works_helper.rb
Normal file
20
app/helpers/graduation_works_helper.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module GraduationWorksHelper
|
||||
include GraduationTasksHelper
|
||||
|
||||
# 作品最终成绩
|
||||
# 参数: work作品, current_user用户,course_identity用户在课堂的身份
|
||||
def work_final_score work, current_user, course_identity
|
||||
work_score =
|
||||
if work.work_score.nil?
|
||||
"--"
|
||||
else
|
||||
if work.check_score_power? current_user, course_identity
|
||||
format("%.1f", work.work_score < 0 ? 0 : work.work_score.round(1))
|
||||
else
|
||||
"**"
|
||||
end
|
||||
end
|
||||
# work_score 最终成绩; late_penalty 迟交扣分; final_score 最终评分
|
||||
{username: work.user.full_name, login: work.user.login, work_score: work_score, final_score: work.final_score}
|
||||
end
|
||||
end
|
||||
2
app/helpers/hack_user_lastest_codes_helper.rb
Normal file
2
app/helpers/hack_user_lastest_codes_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module HackUserLastestCodesHelper
|
||||
end
|
||||
2
app/helpers/hacks_helper.rb
Normal file
2
app/helpers/hacks_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module HacksHelper
|
||||
end
|
||||
2
app/helpers/home_helper.rb
Normal file
2
app/helpers/home_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module HomeHelper
|
||||
end
|
||||
2
app/helpers/issue_depends_helper.rb
Normal file
2
app/helpers/issue_depends_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module IssueDependsHelper
|
||||
end
|
||||
2
app/helpers/issue_times_helper.rb
Normal file
2
app/helpers/issue_times_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module IssueTimesHelper
|
||||
end
|
||||
47
app/helpers/issues_helper.rb
Normal file
47
app/helpers/issues_helper.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
module IssuesHelper
|
||||
|
||||
def issue_status
|
||||
{
|
||||
"新增": "1",
|
||||
"正在解决": "2",
|
||||
"已解决": "3",
|
||||
"反馈": "4",
|
||||
"关闭": "5",
|
||||
"拒绝": "6"
|
||||
}
|
||||
end
|
||||
|
||||
def version_status
|
||||
{
|
||||
"开启": "open",
|
||||
"关闭": "closed",
|
||||
"锁定": "locked"
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
def children_content(journal_id)
|
||||
children_journals = Journal.children_journals(journal_id).journal_includes
|
||||
children_journal_content = []
|
||||
if children_journals.present?
|
||||
children_journals.each do |j|
|
||||
journal_info = {
|
||||
id: j.id,
|
||||
content: j.try(:notes),
|
||||
format_time: time_from_now(j.created_on),
|
||||
created_at: format_time(j.created_on),
|
||||
user_name: j.user.try(:show_real_name),
|
||||
user_login: j.user.try(:login),
|
||||
user_pictrue: url_to_avatar(j.user)
|
||||
}
|
||||
children_journal_content.push(journal_info)
|
||||
end
|
||||
end
|
||||
children_journal_content
|
||||
end
|
||||
|
||||
# def get_issue_tags(issue_tag_ids)
|
||||
# IssueTag.where(id: issue_tag_ids).select(:id,:name,:color).as_json
|
||||
# end
|
||||
|
||||
end
|
||||
116
app/helpers/manage_back_helper.rb
Normal file
116
app/helpers/manage_back_helper.rb
Normal file
@@ -0,0 +1,116 @@
|
||||
module ManageBackHelper
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def sidebar_item_group(url, text, **opts)
|
||||
link_opts = url.start_with?('/') ? {} : { 'data-toggle': 'collapse', 'aria-expanded': false }
|
||||
content =
|
||||
link_to url, link_opts do
|
||||
content_tag(:i, '', class: "fa fa-#{opts[:icon]}", 'data-toggle': 'tooltip', 'data-placement': 'right', 'data-boundary': 'window', title: text) +
|
||||
content_tag(:span, text)
|
||||
end
|
||||
|
||||
content +=
|
||||
content_tag(:ul, id: url[1..-1], class: 'collapse list-unstyled', "data-parent": '#sidebar') do
|
||||
yield
|
||||
end
|
||||
|
||||
raw content
|
||||
end
|
||||
|
||||
def sidebar_item(url, text, **opts)
|
||||
content =
|
||||
link_to url, 'data-controller': opts[:controller] do
|
||||
content_tag(:i, '', class: "fa fa-#{opts[:icon]} fa-fw", 'data-toggle': 'tooltip', 'data-placement': 'right', 'data-boundary': 'window', title: text) +
|
||||
content_tag(:span, text)
|
||||
end
|
||||
|
||||
raw content
|
||||
end
|
||||
|
||||
def admin_sidebar_controller
|
||||
key = params[:controller].to_s.gsub(/\//, '-')
|
||||
SidebarUtil.controller_name(key) || key
|
||||
end
|
||||
alias_method :sidebar_controller, :admin_sidebar_controller
|
||||
|
||||
def define_admin_breadcrumbs(&block)
|
||||
content_for(:setup_admin_breadcrumb, &block)
|
||||
end
|
||||
alias_method :define_breadcrumbs, :define_admin_breadcrumbs
|
||||
|
||||
def add_admin_breadcrumb(text, url = nil)
|
||||
@_breadcrumbs ||= []
|
||||
@_breadcrumbs << OpenStruct.new(text: text, url: url)
|
||||
end
|
||||
alias_method :add_breadcrumb, :add_admin_breadcrumb
|
||||
|
||||
def display_text(str, default = '--')
|
||||
str.presence || default
|
||||
end
|
||||
|
||||
def overflow_hidden_span(text, width: 300, placement: nil)
|
||||
opts = { class: 'd-inline-block text-truncate', style: "max-width: #{width}px" }
|
||||
opts.merge!('data-toggle': 'tooltip', title: text) if text != '--'
|
||||
opts.merge!('data-placement': placement) if placement
|
||||
|
||||
content_tag(:span, text, opts)
|
||||
end
|
||||
|
||||
def sort_tag(content = '', **opts)
|
||||
options = {}
|
||||
options[:sort_by] = opts.delete(:name)
|
||||
is_current_sort = params[:sort_by].to_s == options[:sort_by]
|
||||
options[:sort_direction] = is_current_sort && params[:sort_direction].to_s == 'desc' ? 'asc' : 'desc'
|
||||
|
||||
path = opts.delete(:path) + "?" + unsafe_params.merge(options).to_query
|
||||
arrow_class = case params[:sort_direction].to_s
|
||||
when 'desc' then 'fa-sort-amount-desc'
|
||||
when 'asc' then 'fa-sort-amount-asc'
|
||||
else ''
|
||||
end
|
||||
opts[:style] = "#{opts[:style]} ;position: relative;"
|
||||
|
||||
content_tag(:span, opts) do
|
||||
link_to path, remote: true do
|
||||
content = content_tag(:span) { yield } if block_given?
|
||||
|
||||
content += content_tag(:i, '', class: "fa color-light-green ml-1 #{arrow_class}", style: 'position: absolute;top:0;') if is_current_sort
|
||||
raw content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def javascript_void_link(name, **opts)
|
||||
raw link_to(name, 'javascript:void(0)', opts)
|
||||
end
|
||||
|
||||
def agree_link(name, url, **opts)
|
||||
klass = ['action agree-action', opts.delete(:class)].compact.join(' ')
|
||||
|
||||
refresh_url_data = "refresh_url=#{CGI::escape(request.fullpath)}"
|
||||
url = url + (url.index('?') ? '&' : '?') + refresh_url_data
|
||||
|
||||
raw link_to(name, url, { method: :post, remote: true, class: klass, 'data-confirm': '确认审核通过?'}.merge(opts))
|
||||
end
|
||||
|
||||
def delete_link(name, url, **opts, &block)
|
||||
klass = ['action delete-action', opts.delete(:class)].compact.join(' ')
|
||||
|
||||
refresh_url_data = "refresh_url=#{CGI::escape(request.fullpath)}"
|
||||
url = url + (url.index('?') ? '&' : '?') + refresh_url_data
|
||||
|
||||
if block_given?
|
||||
raw link_to(url, { method: :delete, remote: true, class: klass, 'data-confirm': '确认删除?'}.merge(opts), &block)
|
||||
else
|
||||
raw link_to(name, url, { method: :delete, remote: true, class: klass, 'data-confirm': '确认删除?'}.merge(opts))
|
||||
end
|
||||
end
|
||||
|
||||
def unsafe_params
|
||||
params.except(:controller, :action).to_unsafe_h
|
||||
end
|
||||
|
||||
def list_index_no(page,index)
|
||||
(page - 1) * 20 + index + 1
|
||||
end
|
||||
end
|
||||
2
app/helpers/members_helper.rb
Normal file
2
app/helpers/members_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module MembersHelper
|
||||
end
|
||||
6
app/helpers/memos_helper.rb
Normal file
6
app/helpers/memos_helper.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module MemosHelper
|
||||
|
||||
def forum_list
|
||||
[{id: 5, name: "技术分享"}, {id: 3, name: "操作指南"}, {id: 16, name: "通知公告"}]
|
||||
end
|
||||
end
|
||||
67
app/helpers/messages_helper.rb
Normal file
67
app/helpers/messages_helper.rb
Normal file
@@ -0,0 +1,67 @@
|
||||
module MessagesHelper
|
||||
|
||||
def by_user_liked?(obj, user)
|
||||
obj.praise_treads.user_liker(user).present?
|
||||
end
|
||||
# 置顶降序排序(置顶排最前面)
|
||||
def sort_by_sticky(messages)
|
||||
messages = messages.sort_by {|message| -message.sticky } if messages.map(&:sticky).include?(1)
|
||||
return messages
|
||||
end
|
||||
|
||||
# 根据回复数(包含二级回复)排序
|
||||
def sort_by_all_replies(sort, sort_type, arr)
|
||||
return arr unless sort_type == "hot"
|
||||
logger.info("####====> order by replies")
|
||||
arr.each do |message|
|
||||
message.total_replies_count = message.replies_count + message.children.sum(:replies_count)
|
||||
end
|
||||
return arr.sort_by { |msg| sort == 1 ? msg.total_replies_count : -msg.total_replies_count }
|
||||
end
|
||||
|
||||
def validate_delete_params
|
||||
return normal_status(403, "") unless current_user.teacher_of_course?(@board.course)
|
||||
return normal_status(2, "缺少ids参数!") if params[:ids].blank?
|
||||
return normal_status(2, "参数ids格式不对!") unless params[:ids].is_a? Array
|
||||
end
|
||||
|
||||
def validate_move_params
|
||||
return normal_status(2, "参数ids不能为空!") if params[:ids].blank?
|
||||
return normal_status(2, "参数ids格式错误!") unless params[:ids].is_a? Array
|
||||
return normal_status(2, "参数to_board_id不能为空!") if params[:to_board_id].blank?
|
||||
end
|
||||
|
||||
def message_validate_create_params
|
||||
msg = if params[:select_board_id].blank?
|
||||
"目录id不能为空!"
|
||||
elsif params[:subject].blank?
|
||||
"帖子标题不能为空!"
|
||||
elsif params[:content].blank?
|
||||
"帖子内容不能为空!"
|
||||
elsif params.has_key?(:attachment_ids) && !params[:attachment_ids].is_a?(Array)
|
||||
"参数attachment_ids格式错误!"
|
||||
else
|
||||
nil
|
||||
end
|
||||
normal_status(2, msg) unless msg.nil?
|
||||
end
|
||||
|
||||
def validate_update_params
|
||||
normal_status(2, "目录id不能为空!") if params.has_key?(:select_board_id) && params[:select_board_id].blank?
|
||||
normal_status(2, "帖子标题不能为空!") if params.has_key?(:subject) && params[:subject].blank?
|
||||
normal_status(2, "帖子内容不能为空!") if params.has_key?(:content) && params[:content].blank?
|
||||
end
|
||||
|
||||
def validate_send_message_to_course_params
|
||||
return normal_status(2, "ids参数不能为空!") if params[:ids].blank?
|
||||
return normal_status(2, "参数ids格式不对!") unless params[:ids].is_a? Array
|
||||
return normal_status(2, "to_course_ids参数不能为空!") if params[:to_course_ids].blank?
|
||||
return normal_status(2, "参数to_course_ids格式不对!") unless params[:to_course_ids].is_a? Array
|
||||
end
|
||||
|
||||
def validate_page_size
|
||||
return if !params.has_key?(:page_size)
|
||||
return normal_status(0, "每页请求的数量只能为5-50") if params[:page_size].to_i < 5 || params[:page_size].to_i > 50
|
||||
end
|
||||
|
||||
end
|
||||
5
app/helpers/pdfkit_helper.rb
Normal file
5
app/helpers/pdfkit_helper.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module PdfkitHelper
|
||||
def download_image(url)
|
||||
'data:image/png;base64,' + Base64.encode64(open(url) { |io| io.read })
|
||||
end
|
||||
end
|
||||
2
app/helpers/poll_votes_helper.rb
Normal file
2
app/helpers/poll_votes_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module PollVotesHelper
|
||||
end
|
||||
2
app/helpers/praise_tread_helper.rb
Normal file
2
app/helpers/praise_tread_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module PraiseTreadHelper
|
||||
end
|
||||
32
app/helpers/projects_helper.rb
Normal file
32
app/helpers/projects_helper.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
module ProjectsHelper
|
||||
|
||||
def render_zh_project_type(project_type)
|
||||
case project_type
|
||||
when 'common' then "开源托管项目"
|
||||
when 'mirror' then "开源镜像项目"
|
||||
end
|
||||
end
|
||||
|
||||
def render_zip_url(project, archive_name)
|
||||
[gitea_domain, project.owner.login, project.identifier, "archive", "#{archive_name}.zip"].join('/')
|
||||
end
|
||||
|
||||
def render_tar_url(project, archive_name)
|
||||
[gitea_domain, project.owner.login, project.identifier, "archive", "#{archive_name}.tar.gz"].join('/')
|
||||
end
|
||||
|
||||
def render_http_url(project)
|
||||
[gitea_domain, project.owner.login, "#{project.identifier}.git"].join('/')
|
||||
end
|
||||
|
||||
def gitea_domain
|
||||
Gitea.gitea_config[:domain]
|
||||
end
|
||||
|
||||
def render_edit_project_permission(user, project)
|
||||
permission = "Reporter"
|
||||
member = project.members.includes(:roles).find_by(user: user)
|
||||
|
||||
member&.roles&.last&.name || permission
|
||||
end
|
||||
end
|
||||
11
app/helpers/repositories_helper.rb
Normal file
11
app/helpers/repositories_helper.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module RepositoriesHelper
|
||||
def render_decode64_content(str)
|
||||
return nil if str.blank?
|
||||
Base64.decode64(str)
|
||||
end
|
||||
|
||||
def download_type(str)
|
||||
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe)
|
||||
default_type.include?(str)
|
||||
end
|
||||
end
|
||||
59
app/helpers/stages_helper.rb
Normal file
59
app/helpers/stages_helper.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
module StagesHelper
|
||||
|
||||
# 章节实训的通关情况
|
||||
def stage_myshixun_status myshixun
|
||||
# myshixun = Myshixun.where(user_id: user.id, shixun_id: shixun.id).take
|
||||
myshixun.try(:status) == 1 ? 1 : 0
|
||||
end
|
||||
|
||||
# 实训路径详情列表,右侧实训的状态显示栏
|
||||
def stage_shixun_status subject_status, shixun_status, shixun_hidden
|
||||
status = if shixun_hidden
|
||||
'暂未公开'
|
||||
else
|
||||
if subject_status < 2
|
||||
case shixun_status
|
||||
when 0, 1
|
||||
'暂未公开'
|
||||
when 2
|
||||
'已发布'
|
||||
when 3
|
||||
'已关闭'
|
||||
end
|
||||
else
|
||||
if shixun_status != 2
|
||||
case shixun_status
|
||||
when 0, 1
|
||||
'暂未公开'
|
||||
when 3
|
||||
'已关闭'
|
||||
end
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
end
|
||||
return status
|
||||
end
|
||||
|
||||
# 开启挑战的path
|
||||
def stage_tpi_path shixun, user, subject_id
|
||||
path = ""
|
||||
if shixun.status == 2 || user.manager_of_shixun?(shixun)
|
||||
myshixun = Myshixun.where(user_id: user.id, shixun_id: shixun.id).first
|
||||
if myshixun.present?
|
||||
if user.try(:mail).blank?
|
||||
path = security_settings_path
|
||||
elsif shixun.challenges_count > 0
|
||||
is_modify = ShixunModify.where(:myshixun_id => myshixun.try(:id), :shixun_id => shixun.try(:id), :status => 1).first
|
||||
if is_modify.blank?
|
||||
path = shixun_exec_shixun_path(shixun, :is_subject => subject_id)
|
||||
else
|
||||
path = myshixun_reset_myshixun_path(myshixun, :is_subject => subject_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return path
|
||||
end
|
||||
end
|
||||
205
app/helpers/tag_chosen_helper.rb
Normal file
205
app/helpers/tag_chosen_helper.rb
Normal file
@@ -0,0 +1,205 @@
|
||||
module TagChosenHelper
|
||||
|
||||
def issue_left_chosen(project,issue_id)
|
||||
issue_info = Array.new(11)
|
||||
use_tags = []
|
||||
issue_comment_users_array = []
|
||||
cost_time_array = []
|
||||
all_cost_time = 0
|
||||
be_depended_issues_array = []
|
||||
depended_issues_array = []
|
||||
all_issues = []
|
||||
depended_issues_id = []
|
||||
if issue_id.present?
|
||||
issue = Issue.find(issue_id)
|
||||
use_tags = issue.issue_tags.select(:id).pluck(:id)
|
||||
select_arrays = [:assigned_to_id, :tracker_id, :status_id, :priority_id, :fixed_version_id, :start_date, :due_date, :estimated_hours, :done_ratio, :issue_type, :token]
|
||||
issue_info = Issue.select(select_arrays).where(id: issue_id).pluck(select_arrays)
|
||||
issue_info = issue_info[0]
|
||||
|
||||
issue_comment_users_array = join_users(issue)
|
||||
#总耗时
|
||||
cost_time(issue)
|
||||
cost_time_array = @cost_time_array
|
||||
all_cost_time = @all_cost_time
|
||||
|
||||
#被依赖
|
||||
be_depended_issues_array = be_depended_issues(issue)
|
||||
|
||||
#依赖于
|
||||
depended_issues(issue)
|
||||
depended_issues_array = @depended_issues_array
|
||||
depended_issues_id = @depended_issues_id
|
||||
|
||||
end
|
||||
project_members = project.members_user_infos
|
||||
project_members_info = [] #指派给
|
||||
project_members.each do |member|
|
||||
user = member.user
|
||||
real_name = user.try(:show_real_name)
|
||||
user_id = user.id
|
||||
is_chosen = ((user.id.to_s == issue_info[0].to_s) ? "1" : "0")
|
||||
member_info = {id: user_id, name: real_name,avatar_url: url_to_avatar(user),is_chosen: is_chosen}
|
||||
project_members_info.push(member_info)
|
||||
end
|
||||
|
||||
tracker_info = Tracker&.pluck(:id, :name, :position)
|
||||
new_tracker_info = [] #类型
|
||||
if tracker_info.size > 0
|
||||
tracker_info.each do |t|
|
||||
is_chosen = (t[0] == issue_info[1]) ? "1" : "0"
|
||||
new_tracker = {id: t[0], name: t[1], position: t[2], is_chosen: is_chosen}
|
||||
new_tracker_info.push(new_tracker)
|
||||
end
|
||||
end
|
||||
|
||||
issue_status = IssueStatus&.pluck(:id,:name,:position)
|
||||
new_status_info = [] #缺陷类型
|
||||
if issue_status.size > 0
|
||||
issue_status.each do |t|
|
||||
is_chosen = (t[0] == issue_info[2]) ? "1" : "0"
|
||||
new_issue = {id: t[0], name: t[1], position: t[2], is_chosen: is_chosen}
|
||||
new_status_info.push(new_issue)
|
||||
end
|
||||
end
|
||||
|
||||
issue_priority = IssuePriority&.pluck(:id,:name, :position)
|
||||
new_priority_info = [] #优先度
|
||||
if issue_priority.size > 0
|
||||
issue_priority.each do |t|
|
||||
is_chosen = (t[0] == issue_info[3]) ? "1" : "0"
|
||||
new_issue = {id: t[0], name: t[1], position: t[2], is_chosen: is_chosen}
|
||||
new_priority_info.push(new_issue)
|
||||
end
|
||||
end
|
||||
|
||||
issue_versions = project.versions&.pluck(:id,:name, :status)
|
||||
new_version_info = [] #issue里程碑
|
||||
if issue_versions.size > 0
|
||||
issue_versions.each do |t|
|
||||
is_chosen = (t[0] == issue_info[4]) ? "1" : "0"
|
||||
new_issue = {id: t[0], name: t[1], status: t[2], is_chosen: is_chosen}
|
||||
new_version_info.push(new_issue)
|
||||
end
|
||||
end
|
||||
|
||||
issue_done_ratio = %w(0 10 20 30 40 50 60 70 80 90 100)
|
||||
new_done_info = [] #完成度
|
||||
if issue_done_ratio.size > 0
|
||||
issue_done_ratio.each do |t|
|
||||
is_chosen = (t == issue_info[8].to_s) ? "1" : "0"
|
||||
new_issue = {id:t.to_i, name: (t.to_s + "%"), is_chosen: is_chosen}
|
||||
new_done_info.push(new_issue)
|
||||
end
|
||||
end
|
||||
|
||||
issue_tags = project.issue_tags&.pluck(:id,:name, :color)
|
||||
new_tags_info = [] #issue标签
|
||||
if issue_tags.size > 0
|
||||
issue_tags.each do |t|
|
||||
is_chosen = (use_tags.size > 0 && use_tags.include?(t[0])) ? "1" : "0"
|
||||
new_issue = {id: t[0], name: t[1], color: t[2], is_chosen: is_chosen}
|
||||
new_tags_info.push(new_issue)
|
||||
end
|
||||
end
|
||||
|
||||
issue_types = %w(普通 悬赏)
|
||||
new_types_info = [] #issue标签
|
||||
issue_types.each_with_index do |i, index|
|
||||
is_chosen = (issue_info[9] == "#{index+1}") ? "1" : "0"
|
||||
is_token = (index.to_s == "1") ? issue_info[10] : nil
|
||||
new_type_info = {id: index+1, name: i, token: is_token, is_chosen: is_chosen}
|
||||
new_types_info.push(new_type_info)
|
||||
end
|
||||
|
||||
depend_other_issues = project.issues.issue_issue.where.not(id: issue_id)&.pluck(:id, :subject)
|
||||
if depend_other_issues.size > 0
|
||||
depend_other_issues.each do |t|
|
||||
is_chosen = depended_issues_id.include?(t[0]) ? "1" : "0"
|
||||
new_issue = {id: t[0], subject: t[1], is_chosen: is_chosen}
|
||||
all_issues.push(new_issue)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
{
|
||||
"assign_user": project_members_info,
|
||||
"tracker": new_tracker_info,
|
||||
"issue_status": new_status_info,
|
||||
"priority": new_priority_info,
|
||||
"issue_version": new_version_info,
|
||||
"start_date": issue_info[5],
|
||||
"due_date": issue_info[6],
|
||||
"joins_users": issue_comment_users_array,
|
||||
"cost_time_users": cost_time_array,
|
||||
"total_cost_time": Time.at(all_cost_time).utc.strftime('%H h %M min %S s'),
|
||||
"be_depended_issues": be_depended_issues_array,
|
||||
"depended_issues":depended_issues_array,
|
||||
"estimated_hours": issue_info[7],
|
||||
"done_ratio": new_done_info,
|
||||
"issue_tag": new_tags_info,
|
||||
"issue_type": new_types_info,
|
||||
"all_issues": all_issues
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
def join_users(issue)
|
||||
#协作者
|
||||
issue_comment_users_array = []
|
||||
issue_comment_users = issue.journals.select(:user_id).distinct
|
||||
if issue.present? && issue_comment_users.size > 0
|
||||
issue_comment_users.each do |j|
|
||||
user_avatar = url_to_avatar(j.user)
|
||||
issue_comment_users_array.push({login: j.user.try(:login), avatar_url: user_avatar})
|
||||
end
|
||||
end
|
||||
issue_comment_users_array
|
||||
end
|
||||
|
||||
def cost_time(issue)
|
||||
#总耗时
|
||||
@cost_time_array = []
|
||||
@all_cost_time = 0
|
||||
all_issue_times = issue.issue_times.includes(:user).where.not(end_time: nil)
|
||||
if issue.present? && all_issue_times.size > 0
|
||||
all_issue_times.each do |time|
|
||||
cost_time = time.end_time.to_i - time.start_time.to_i
|
||||
cost_time = cost_time > 0 ? cost_time : 0
|
||||
@all_cost_time = @all_cost_time + cost_time
|
||||
set_cost_time = Time.at(cost_time).utc.strftime('%H h %M min %S s')
|
||||
@cost_time_array.push({login: time.user.try(:login), avatar_url: url_to_avatar(time.user), cost_time: set_cost_time})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def depended_issues(issue)
|
||||
#依赖于
|
||||
@depended_issues_id = []
|
||||
@depended_issues_array = []
|
||||
depended_issues = issue.issue_depends.pluck(:id,:depend_issue_id).uniq
|
||||
if issue.present? && depended_issues.size > 0
|
||||
depended_issues.each do |de|
|
||||
@depended_issues_id.push(de[1])
|
||||
issues = Issue.select(:id, :subject).where(id: de[1]).as_json
|
||||
issues = issues.first.merge(depend_id: de[0])
|
||||
@depended_issues_array.push(issues)
|
||||
end
|
||||
@depended_issues_id.delete(issue.id)
|
||||
end
|
||||
end
|
||||
|
||||
def be_depended_issues(issue)
|
||||
be_depended_issues_array = []
|
||||
be_depended_issues = IssueDepend.where(depend_issue_id: issue.id).pluck(:id,:issue_id).uniq
|
||||
if issue.present? && be_depended_issues.size > 0
|
||||
be_depended_issues.each do |de|
|
||||
d_issues = Issue.select(:id, :subject).where(id: de[1]).as_json
|
||||
d_issues = d_issues.first.merge(depend_id: de[0])
|
||||
be_depended_issues_array.push(d_issues)
|
||||
end
|
||||
end
|
||||
be_depended_issues_array
|
||||
end
|
||||
|
||||
end
|
||||
2
app/helpers/trustie_hacks_helper.rb
Normal file
2
app/helpers/trustie_hacks_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module TrustieHacksHelper
|
||||
end
|
||||
2
app/helpers/users/banks_helper.rb
Normal file
2
app/helpers/users/banks_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Users::BanksHelper
|
||||
end
|
||||
2
app/helpers/users_helper.rb
Normal file
2
app/helpers/users_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module UsersHelper
|
||||
end
|
||||
2
app/helpers/version_releases_helper.rb
Normal file
2
app/helpers/version_releases_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module VersionReleasesHelper
|
||||
end
|
||||
2
app/helpers/watchers_helper.rb
Normal file
2
app/helpers/watchers_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module WatchersHelper
|
||||
end
|
||||
69
app/helpers/weapps/courses_helper.rb
Normal file
69
app/helpers/weapps/courses_helper.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
module Weapps::CoursesHelper
|
||||
require 'chinese_pinyin'
|
||||
|
||||
def teacher_list teachers, user_course_identity
|
||||
data = []
|
||||
teachers.each do |teacher|
|
||||
if teacher.user.present?
|
||||
teacher_user = teacher.user
|
||||
name = teacher_user.real_name
|
||||
role = teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教"
|
||||
member_roles = user_course_identity < Course::ASSISTANT_PROFESSOR ? teacher_user.course_role(teacher.course) : []
|
||||
item = {name: name, course_member_id: teacher.id, login: teacher_user.login, user_id: teacher.user_id, role: role,
|
||||
school: teacher_user.school_name, image_url: url_to_avatar(teacher_user), member_roles: member_roles}
|
||||
pinyin = Pinyin.t(name.strip, splitter: '')
|
||||
first_char = pinyin[0]
|
||||
letter = first_letter first_char
|
||||
if data.pluck(:letter).include?(letter)
|
||||
data.select{|a|a[:letter]==letter}.first[:items] << item
|
||||
else
|
||||
data << {letter: letter, items: [item]}
|
||||
end
|
||||
end
|
||||
end
|
||||
# data = data.sort do |a, b|
|
||||
# [a[:letter]] <=> [b[:letter]]
|
||||
# end
|
||||
# data.push(data.shift) if data.select{|a|a[:letter]=='#'}.first.present? # '#'排在最后
|
||||
return data
|
||||
end
|
||||
|
||||
|
||||
def student_list students, excellent, user_course_identity
|
||||
data = []
|
||||
students.each do |student|
|
||||
if student.user.present?
|
||||
student_user = student.user
|
||||
name = student_user.real_name
|
||||
phone = excellent ? "" : student_user.hidden_phone
|
||||
member_roles = user_course_identity < Course::ASSISTANT_PROFESSOR ? student_user.course_role(student.course) : []
|
||||
item = {name: name, course_member_id: student.id, login: student_user.login, user_id: student.user_id,
|
||||
student_id: student_user.student_id, image_url: url_to_avatar(student_user), phone: phone, member_roles: member_roles}
|
||||
pinyin = Pinyin.t(name.strip, splitter: '')
|
||||
first_char = pinyin[0]
|
||||
letter = first_letter first_char
|
||||
if data.pluck(:letter).include?(letter)
|
||||
data.select{|a|a[:letter]==letter}.first[:items] << item
|
||||
else
|
||||
data << {letter: letter, items: [item]}
|
||||
end
|
||||
end
|
||||
end
|
||||
# data = data.sort do |a, b|
|
||||
# [a[:letter]] <=> [b[:letter]]
|
||||
# end
|
||||
# data.push(data.shift) if data.select{|a|a[:letter]=='#'}.first.present? # '#'排在最后
|
||||
return data
|
||||
end
|
||||
|
||||
def first_letter char
|
||||
if char.ord >= 97 && char.ord <= 122
|
||||
letter = (char.ord - 32).chr.to_s
|
||||
elsif char.ord >= 65 && char.ord <= 90
|
||||
letter = char
|
||||
else
|
||||
letter = '#'
|
||||
end
|
||||
letter
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user