Merge branch 'develop' into dev_tieba

This commit is contained in:
huang 2017-01-19 15:56:44 +08:00
commit 0a0b3fbf9b
350 changed files with 77053 additions and 5890 deletions

View File

@ -54,6 +54,7 @@ gem 'elasticsearch-rails'
### profile
# gem 'oneapm_rpm'
# gem 'therubyracer'
group :development do
gem 'grape-swagger'

View File

@ -75,15 +75,9 @@ module Mobile
authenticate!
subscribe = 0 #默认未关注
#-------------------获取用户是否关注此公众号-----------------------------
openid = session[:wechat_openid]
raise "无法获取到openid,请在微信中打开本页面" unless openid
user_info = Wechat.api.user(openid)
Rails.logger.info "user_info!!!!!!!!!"
Rails.logger.info user_info
subscribe = user_info["subscribe"]
## 能进来的就是已关注
## 因为取消订阅的记录被删除了
subscribe = 1 #默认未关注
status = 0
tip = 0 #0班级1项目

View File

@ -23,6 +23,12 @@ class AccountController < ApplicationController
skip_before_filter :check_if_login_required
# Login request and validation
def login
if params[:type] == "activated"
@message = l(:notice_account_activated)
elsif params[:type] == "expired"
@message = l(:notice_account_expired)
end
if request.get?
@login = params[:login] || true
if User.current.logged?
@ -201,7 +207,8 @@ class AccountController < ApplicationController
def activate
(redirect_to(signin_path); return) unless Setting.self_registration? && params[:token].present?
token = Token.find_token('register', params[:token].to_s)
(redirect_to(signin_path); return) unless token and !token.expired?
type = l(:notice_account_expired) if (token && token.expired?)
(redirect_to(signin_path(:type => "expired")); return) unless token and !token.expired?
user = token.user
(redirect_to(signin_path); return) unless user.registered?
user.activate
@ -209,7 +216,7 @@ class AccountController < ApplicationController
token.destroy
flash[:notice] = l(:notice_account_activated)
end
redirect_to signin_url
redirect_to signin_url(:type => "activated")
end
def api_register login,password,email

View File

@ -124,6 +124,16 @@ class AdminController < ApplicationController
render :action => "projects", :layout => false if request.xhr?
end
def contests
@name = params[:name]
@contests = Contest.where("id >= 780 and name like '%#{@name}%'").order('created_at desc')
@contests = paginateHelper @contests,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.html
end
end
def syllabuses
@name = params[:name]
@syllabuses = Syllabus.like(@name).order('created_at desc')

View File

@ -577,19 +577,19 @@ class ApplicationController < ActionController::Base
end
def redirect_back_or_default(default, options={})
back_url = '' #params[:back_url].to_s
back_url = params[:back_url].to_s
if back_url.present?
begin
uri = URI.parse(back_url)
# do not redirect user to another host or to the login or register page
if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
back_url = back_url.gsub(%r{\/users\/(\d+)},"/users/"+default.id.to_s) if default.is_a?(:User)
back_url = back_url.gsub(%r{\/users\/(\d+)},"/users/"+default.id.to_s) if default.is_a?(User)
redirect_to(back_url)
return
end
rescue URI::InvalidURIError
logger.warn("Could not redirect to invalid URL #{back_url}")
# redirect to default
redirect to default
end
elsif options[:referer]
redirect_to_referer_or default

View File

@ -40,7 +40,7 @@ class AvatarController < ApplicationController
@urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file))
# 用户头像上传时进行特别处理
if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project' || @source_type == 'Organization')
if @is_direct == '1' && (@source_type == 'User' || @source_type == 'Course' || @source_type == 'Project' || @source_type == 'Organization'|| @source_type == 'Contest')
diskfile += "temp"
@urlfile += "temp"
end

View File

@ -173,12 +173,19 @@ class BlogCommentsController < ApplicationController
render_attachment_warning_if_needed(@blogComment)
#@article.save
# redirect_to user_blogs_path(:user_id=>params[:user_id])
# 给回复的人发消息
reply_user_id = params[:reply_id].nil? ? @blogComment.blog.author_id: params[:reply_id].to_i
# 回复的作业与评论的作者不是同一人则发送消息
if ( params[:reply_id].nil? && @blogComment.author.id != @blogComment.blog.author_id )|| (!params[:reply_id].nil? && @blogComment.author.id != params[:reply_id].to_i)
BlogMessage.create(:user_id => reply_user_id, :blog_id => params[:blog_id].to_i, :content => params[:blog_comment][:content],
:blog_commont_id => @blogComment.id, :blog_message_type => "BlogComment", :user_operator_id => @blogComment.author.id)
end
respond_to do |format|
format.html {
if params[:course_id] #如果呆了course_id过来了那么这是要跳到课程大纲去的
redirect_to syllabus_course_path(:id=>params[:course_id])
else
redirect_to user_blog_blog_comment_path(:user_id=>@article.author_id,:blog_id=>@article.blog_id,:id=>@article)
redirect_to user_blog_blog_comment_path( @article.author, :blog_id => @article.blog_id, :id => @article)
end
}

View File

@ -33,7 +33,7 @@ class BoardsController < ApplicationController
#modify by nwb
@flag = params[:flag] || false
if @project
if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin?
if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin? && !User.current.allowed_to?(:view_messages, @project)
render_403
else
@boards = @project.boards.includes(:last_message => :author).all
@ -67,6 +67,30 @@ class BoardsController < ApplicationController
else
render_403
end
elsif @contest
if (User.current.admin? || @contest.is_public || (!@contest.is_public && User.current.member_of_contest?(@contest)))
@boards = @contest.boards.includes(:last_message => :author).all
if @contest.boards.empty?
@board = @contest.boards.build
@board.name = " #{l(:label_board_contest) }"
@board.description = @contest.name.to_s
@board.project_id = -1
@board.course_id = -1
if @board.save
@boards = @contest.boards.includes(:last_message => :author).all
end
end
if params[:board_id]
@board = Board.find params[:board_id].to_i
else
unless @contest.boards.where("parent_id is NULL").empty?
@board = @contest.boards.where("parent_id is NULL").first
end
end
show and return
else
render_403
end
end
end
@ -116,6 +140,25 @@ class BoardsController < ApplicationController
else
@topics = [];
end
elsif @contest
if (@board)
@topic_count = @board.topics.count();
@topic_pages = 0 #(params[:page] ? params[:page].to_i + 1 : 0) *10
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
else
@board = @contest.boards.build
@board.name = " #{l(:label_board_contest) }"#self.name
@board.description = @contest.name.to_s
@board.project_id = -1
@board.course_id = -1
if @board.save
@topic_count = @board.topics.count();
@topic_pages = 0 #(params[:page] ? params[:page].to_i + 1 : 0) *10
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
else
@topics = []
end
end
end
#根据 赞+回复数排序
@ -162,6 +205,10 @@ class BoardsController < ApplicationController
@left_nav_type = 2
@params=params
render :action => 'show', :layout => 'base_courses'
elsif @contest
@left_nav_type = 4
@params=params
render :action => 'show', :layout => 'base_contests'
end
}
format.atom {
@ -214,6 +261,18 @@ class BoardsController < ApplicationController
respond_to do |format|
format.js
end
elsif @contest
parent = Board.find params[:board_id].to_i
board = @contest.boards.build
board.name = params[:name]
board.description = board.name
board.project_id = -1
board.course_id = -1
board.position = parent.children.count + 1
parent.children << board
respond_to do |format|
format.js
end
end
end
@ -237,7 +296,7 @@ class BoardsController < ApplicationController
after_boards = @board.parent.children.where("position > #{@board.position}")
after_boards.update_all("position = position - 1")
@board.destroy
if @course
if @course || @contest
respond_to do |format|
format.js
end
@ -247,7 +306,7 @@ class BoardsController < ApplicationController
end
def update_position
if @course
if @course || @contest
boards = @board.parent.children
if params[:opr] == 'up' && @board.position > 1
before_board = boards.where("position = #{@board.position - 1}").first
@ -267,7 +326,7 @@ class BoardsController < ApplicationController
end
def update_name
if @course
if @course || @contest
@board.update_attribute("name", params[:name])
@board.update_attribute("description", params[:name])
respond_to do |format|
@ -296,6 +355,8 @@ private
@board = @project.boards.find(params[:id]) if params[:id]
elsif @course
@board = @course.boards.find(params[:id]) if params[:id]
elsif @contest
@board = @contest.boards.find(params[:id]) if params[:id]
end
rescue ActiveRecord::RecordNotFound
render_404

View File

@ -38,7 +38,7 @@ class ContestMembersController < ApplicationController
#status = 0 表示给学生发status = 1表示给老师发
course_join = ContestMessage.new(:user_id =>user_id, :contest_message_id=>User.current.id,:contest_id => @contest.id,:contest_message_type=>"JoinContest", :content => role_ids, :viewed => false, :status => 0)
course_join.save
ContestMessage.create(:user_id => User.current.id, :contest_message_id => user_id, :contest_message_id => @contest.id, :contest_message_type => "JoinContest",:content => role_ids, :viewed => false, :status => 1)
#ContestMessage.create(:user_id => User.current.id, :contest_message_id => user_id, :contest_message_id => @contest.id, :contest_message_type => "JoinContest",:content => role_ids, :viewed => false, :status => 1)
end
end
@contest.contest_members << members

View File

@ -15,6 +15,7 @@ class ContestantWorksController < ApplicationController
def new
#更新消息
if @contestwork.work_status == 1
noEvaluation = @contestwork.contest_messages.where("user_id =? and viewed =?", User.current.id, 0)
noEvaluation.update_all(:viewed => true)
@ -23,6 +24,9 @@ class ContestantWorksController < ApplicationController
respond_to do |format|
format.html{ render :layout => "base_contests"}
end
else
render_403
end
end
def index
@ -44,10 +48,13 @@ class ContestantWorksController < ApplicationController
@all_homework_commons = @contest.works.order("created_at desc")
@is_teacher = User.current.admin_of_contest?(@contest) || User.current.admin?
@is_judge = User.current.judge_of_contest?(@contest)
@is_evaluation = @is_judge && @contestwork.work_status == 3 && @contestwork.online_evaluation
@show_all = false
if @is_teacher || @is_judge
is_judge_open = @is_judge && (!@contestwork.online_evaluation || (@contestwork.online_evaluation && @contestwork.work_status == 4))
is_contestant_open = User.current.contestant_of_contest?(@contest) && ((!@contestwork.online_evaluation && @contestwork.work_status == 2 && @contestwork.score_open) || (@contestwork.online_evaluation && @contestwork.work_status == 4 && @contestwork.score_open))
if @is_teacher || is_judge_open || is_contestant_open
# if @order == 'lastname'
# @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
# elsif @order == 'student_id'
@ -56,7 +63,15 @@ class ContestantWorksController < ApplicationController
@stundet_works = @contestwork.contestant_works.no_copy.select("contestant_works.*,contestant_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :contestant_work_scores => {}).order("#{@order} #{@b_sort}")
#end
@show_all = true
elsif User.current.member_of_contest?(@contest)
elsif @is_evaluation
if @contestwork.work_detail_manual.evaluation_num == -1
@stundet_works = @contestwork.contestant_works.no_copy.select("contestant_works.*,contestant_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :contestant_work_scores => {}).order("#{@order} #{@b_sort}")
else
@stundet_works = User.current.contestant_work_evaluation_distributions.map(&:contestant_work).select { |cwork| cwork.work_id == @contestwork.id}
end
elsif User.current.judge_of_contest?(@contest)
@stundet_works = []
elsif User.current.contestant_of_contest?(@contest)
if @contestwork.work_type == 3
pro = @contestwork.contestant_work_projects.where(:user_id => User.current.id).first
if pro.nil?
@ -82,22 +97,23 @@ class ContestantWorksController < ApplicationController
respond_to do |format|
format.js
format.html
# format.xls {
# filename = "#{@contest.user.lastname.to_s + @contest.user.firstname}_#{@contest.name}_#{@contestwork.name}#{l(:excel_homework_list)}.xls"
# send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
# :filename => filename_for_content_disposition(filename))
# }
format.xls {
filename = "#{@contest.user.show_name.to_s}_#{@contest.name}_#{@contestwork.name}_#{l(:excel_homework_list)}_#{DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s}.xls"
send_data(work_score_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
:filename => filename_for_content_disposition(filename))
}
end
end
def show
#@score = student_work_score @work,User.current
@score = ContestantWorkScore.where(:user_id => User.current.id,:contestant_work_id => @work.id,:reviewer_role => 2).last
@is_evaluation = User.current.judge_of_contest?(@contest) && @contestwork.work_status == 3 && @contestwork.online_evaluation
@is_teacher = User.current.admin_of_contest?(@contest) || User.current.judge_of_contest?(@contest) || User.current.admin?
# if @homework.homework_detail_manual.comment_status == 2 && !@is_teacher && @work.user != User.current
# @student_work_scores = @work.student_works_scores.where("user_id = #{User.current.id} and reviewer_role = 3").order("updated_at desc")
# else
# @student_work_scores = student_work_score_record(@work)
# end
if @is_evaluation
@student_work_scores = @work.contestant_work_scores.where("user_id = #{User.current.id} and reviewer_role = 2").order("updated_at desc")
else
@student_work_scores = contestant_work_score_record(@work)
end
respond_to do |format|
format.js
end
@ -362,6 +378,57 @@ class ContestantWorksController < ApplicationController
end
end
def add_score
@is_last = params[:is_last] == "true"
@is_evaluation = User.current.judge_of_contest?(@contest) && @contestwork.work_status == 3 && @contestwork.online_evaluation
#@is_teacher = User.current.admin_of_contest?(@contest) || User.current.judge_of_contest?(@contest) || User.current.admin?
#老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分
render_403 and return unless @is_evaluation
@is_last_a = @work.contestant_work_scores.empty?
@new_score = ContestantWorkScore.new
@new_score.score = params[:score].to_i
@new_score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
@new_score.user_id = User.current.id
@new_score.contestant_work_id = @work.id
@new_score.reviewer_role = 2
# if User.current.admin?
# @new_score.reviewer_role = 1
# else
# role = User.current.members.where("course_id = ?",@course.id).first.roles.where("is_current = 1").first.name
# @new_score.reviewer_role = get_role_by_name(role)
# end
# if @score
# if @is_teacher
# @is_new = true
# @is_last_a = false
# else
# @is_new = false
# end
# else
# @is_new = true
# end
@new_score.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@new_score)
if @new_score.save
@contestwork.update_column('updated_at', Time.now)
update_contest_activity(@contestwork.class,@contestwork.id)
update_user_activity(@contestwork.class,@contestwork.id)
judge_score = ContestantWorkScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{@work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
@work.judge_score = judge_score.first.score.nil? ? nil : judge_score.first.score.try(:round, 2).to_f
if @work.save
@work = @contestwork.contestant_works.select("contestant_works.*,contestant_works.work_score as score").where(:id => @work.id).first
@count = @contestwork.contestant_works.has_committed.count
@student_work_scores = contestant_work_score_record @work
respond_to do |format|
format.js
end
end
end
end
private
def hsd_committed_work?(user, homework)
sw = ContestantWork.where("user_id =? and work_id =?", user, homework).first
@ -405,4 +472,140 @@ class ContestantWorksController < ApplicationController
def is_logged
redirect_to signin_path unless User.current.logged?
end
#提交成绩导出
def work_score_to_xls items
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "work"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
if @contestwork.work_type == 1 #普通作业
#开启在线评审
if @contestwork.online_evaluation
sheet1.row(0).concat([l(:excel_contestant_id),l(:excel_user_name),l(:excel_nickname),l(:excel_mail),l(:excel_school),l(:excel_homework_name),l(:excel_homework_des)])
if @contestwork.work_detail_manual.evaluation_num != -1
num = @contestwork.work_detail_manual.evaluation_num
n = num < (contest_judges @contest).size ? num : (contest_judges @contest).size
else
n = (contest_judges @contest).size
end
for i in 1 .. n do i
sheet1.row(0).concat([l(:label_judge_score, :num => i),l(:label_judge_comment, :num => i)])
end
sheet1.row(0).concat([l(:label_highest_score),l(:label_lowest_score),l(:excel_f_score),l(:excel_commit_time)])
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = contestant_work.user.id
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
sheet1[count_row,5] = contestant_work.name
sheet1[count_row,6] = strip_html contestant_work.description if !contestant_work.description.nil?
work_scores = contestant_work_score_record contestant_work
for i in 1 .. n do i
sheet1[count_row,6 + i*2 -1] = (work_scores.nil? || work_scores[i - 1].nil?) ? l(:label_without_score) : work_scores[i - 1].score
sheet1[count_row,6 + i*2] = (work_scores.nil? || work_scores[i - 1].nil?) ? "" : work_scores[i - 1].comment
end
sheet1[count_row,7+2*n] = (work_scores.nil? || work_scores.reorder("score desc").first.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").first.score
sheet1[count_row,8+2*n] = (work_scores.nil? || work_scores.reorder("score desc").last.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").last.score
sheet1[count_row,9+2*n] = contestant_work.work_score.nil? ? l(:label_without_score) : contestant_work.work_score.round(2)
sheet1[count_row,10+2*n] = format_time contestant_work.commit_time
count_row += 1
end
#未开启在线评审
else
sheet1.row(0).concat([l(:excel_contestant_id),l(:excel_user_name),l(:excel_nickname),l(:excel_mail),l(:excel_school),l(:excel_homework_name),l(:excel_homework_des),l(:excel_commit_time)])
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = contestant_work.user.id
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
sheet1[count_row,5] = contestant_work.name
sheet1[count_row,6] = strip_html contestant_work.description if !contestant_work.description.nil?
sheet1[count_row,7] = format_time contestant_work.commit_time
count_row += 1
end
end
elsif @contestwork.work_type == 3 #分组作业
if @contestwork.online_evaluation
sheet1.row(0).concat([l(:excel_group_member),l(:excel_group_leader),l(:excel_group_leader_login),l(:excel_group_leader_mail),l(:excel_school)])
if @contestwork.work_detail_group.base_on_project
sheet1.row(0).concat([l(:excel_homework_project),l(:excel_homework_name),l(:excel_homework_des)])
else
sheet1.row(0).concat([l(:excel_homework_name),l(:excel_homework_des)])
end
if @contestwork.work_detail_manual.evaluation_num != -1
num = @contestwork.work_detail_manual.evaluation_num
n = num < (contest_judges @contest).size ? num : (contest_judges @contest).size
else
n = (contest_judges @contest).size
end
for i in 1 .. n do i
sheet1.row(0).concat([l(:label_judge_score, :num => i),l(:label_judge_comment, :num => i)])
end
sheet1.row(0).concat([l(:label_highest_score),l(:label_lowest_score),l(:excel_f_score),l(:excel_commit_time)])
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = get_contest_group_member_names contestant_work
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
if @contestwork.work_detail_group.base_on_project
sheet1[count_row,5] = (contestant_work.project_id == 0 || contestant_work.project_id.nil?) ? l(:excel_no_project) : contestant_work.project.name
current_column = 6
else
current_column = 5
end
sheet1[count_row,current_column] = contestant_work.name
sheet1[count_row,current_column + 1] = strip_html contestant_work.description if !contestant_work.description.nil?
work_scores = contestant_work_score_record contestant_work
for i in 1 .. n do i
sheet1[count_row,current_column + 1 + i*2 -1] = (work_scores.nil? || work_scores[i - 1].nil?) ? l(:label_without_score) : work_scores[i - 1].score
sheet1[count_row,current_column + 1 + i*2] = (work_scores.nil? || work_scores[i - 1].nil?) ? "" : work_scores[i - 1].comment
end
sheet1[count_row,current_column + 2 +2*n] = (work_scores.nil? || work_scores.reorder("score desc").first.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").first.score
sheet1[count_row,current_column + 3 +2*n] = (work_scores.nil? || work_scores.reorder("score desc").last.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").last.score
sheet1[count_row,current_column + 4 +2*n] = contestant_work.work_score.nil? ? l(:label_without_score) : contestant_work.work_score.round(2)
sheet1[count_row,current_column + 5 +2*n] = format_time contestant_work.commit_time
count_row += 1
end
else
if @contestwork.work_detail_group.base_on_project
sheet1.row(0).concat([l(:excel_group_member),l(:excel_group_leader),l(:excel_group_leader_login),l(:excel_group_leader_mail),l(:excel_school),l(:excel_homework_project),l(:excel_homework_name),l(:excel_homework_des),l(:excel_commit_time)])
else
sheet1.row(0).concat([l(:excel_group_member),l(:excel_group_leader),l(:excel_group_leader_login),l(:excel_group_leader_mail),l(:excel_school),l(:excel_homework_name),l(:excel_homework_des),l(:excel_commit_time)])
end
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = get_contest_group_member_names contestant_work
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
if @contestwork.work_detail_group.base_on_project
sheet1[count_row,5] = (contestant_work.project_id == 0 || contestant_work.project_id.nil?) ? l(:excel_no_project) : contestant_work.project.name
current_column = 6
else
current_column = 5
end
sheet1[count_row,current_column] = contestant_work.name
sheet1[count_row,current_column + 1] = strip_html contestant_work.description if !contestant_work.description.nil?
sheet1[count_row,current_column + 2] = format_time contestant_work.commit_time
count_row += 1
end
end
end
book.write xls_report
xls_report.string
end
end

View File

@ -3,11 +3,17 @@ class ContestsController < ApplicationController
include ContestsHelper
helper :contest_members
helper :users
helper :attachments
helper :files
include AvatarHelper
before_filter :find_contest, :only => [:show, :settings, :update, :contest_activities, :search_member, :private_or_public, :switch_role]
before_filter :find_contest, :only => [:show, :settings, :update, :destroy, :contest_activities, :search_member, :private_or_public, :switch_role, :set_invite_code_halt, :renew,
:member, :export_all_members, :feedback]
before_filter :is_logged, :only => [:index, :new, :create]
before_filter :is_admin?, :only => [:settings]
before_filter :is_admin?, :only => [:settings, :set_invite_code_halt, :destroy]
before_filter :is_member?, :only => [:show, :contest_activities]
layout "base_contests"
def show
@ -105,6 +111,34 @@ class ContestsController < ApplicationController
end
end
def destroy
@contest.update_attributes(:is_delete => true)
end
def feedback
if (User.current.admin? || @contest.is_public || (!@contest.is_public && User.current.member_of_contest?(@contest)))
ContestMessage.where(:user_id => User.current.id, :contest_id => @contest.id, :contest_message_type => 'JournalsForMessage', :contest_message_id => @contest.journals_for_messages.map{|jour|jour.id}).update_all(:viewed => true)
page = params[:page]
# Find the page of the requested reply
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@jour_count = @jours.count
@limit = 10
if params[:r] && page.nil?
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
page = 1 + offset / @limit
end
@jour = paginateHelper @jours,10
@state = false
@left_nav_type = 6
respond_to do |format|
format.html{render :layout => 'base_contests'}
format.api
end
else
render_403
end
end
def private_or_public
@contest.update_attributes(:is_public => !@contest.is_public)
@ -125,11 +159,8 @@ class ContestsController < ApplicationController
end
def settings
if params[:tab] && params[:tab] == 'boards'
@tab = 2
else
@tab = 0
end
@select_tab = params[:tab]
@member ||= @contest.contest_members.new
@roles = Role.where("id in (13, 14, 15)")
@members = @contest.member_principals.includes(:roles, :principal).all.sort
@ -169,8 +200,12 @@ class ContestsController < ApplicationController
end
case params[:agree]
when 'Y'
if ContestMember.where(:user_id => apply_user.id, :contest_id => applied_contest.contest_id).first.nil?
member = ContestMember.new(:user_id => apply_user.id)
Contest.find(applied_contest.contest_id).contest_members << member
else
member = ContestMember.where(:user_id => apply_user.id, :contest_id => applied_contest.contest_id).first
end
contest_member_roles = member.contest_member_roles
if integer_ids.include?(14) && integer_ids.include?(13)
@ -181,8 +216,8 @@ class ContestsController < ApplicationController
end
ContestMessage.create(:user_id => apply_user.id, :contest_id => applied_contest.contest_id, :viewed => false,:contest_message_id=>User.current.id,:content=>applied_contest.role,:contest_message_type=>'ContestRequestDealResult',:status=>1)
applied_contest.applied_messages.update_all(:status => 1, :viewed => 1)
@msg.update_attributes(:status => 1, :viewed => 1)
applied_contest.applied_messages.update_all(:status => 1, :viewed => 1, :applied_user_id => User.current.id)
@msg.update_attributes(:status => 1, :viewed => 1, :applied_user_id => User.current.id)
applied_contest.update_attributes(:status => 1)
if integer_ids.include?(15)
ContestantForContest.create(:student_id => apply_user.id, :contest_id =>applied_contest.contest_id)
@ -190,8 +225,8 @@ class ContestsController < ApplicationController
when 'N'
ContestMessage.create(:user_id => apply_user.id, :contest_id => applied_contest.contest_id, :viewed => false,:contest_message_id=>User.current.id,:content=>applied_contest.role,:contest_message_type=>'ContestRequestDealResult',:status=>2)
applied_contest.applied_messages.update_all(:status => 2, :viewed => 1)
@msg.update_attributes(:status => 2, :viewed => 1)
applied_contest.applied_messages.update_all(:status => 2, :viewed => 1, :applied_user_id => User.current.id)
@msg.update_attributes(:status => 2, :viewed => 1, :applied_user_id => User.current.id)
applied_contest.update_attributes(:status => 2)
end
respond_to do |format|
@ -226,14 +261,109 @@ class ContestsController < ApplicationController
end
end
# 邀请码停用/启用
def set_invite_code_halt
if User.current.admin_of_contest?(@contest) || User.current.admin?
@contest.update_attribute('invite_code_halt', @contest.invite_code_halt == 0 ? 1 : 0)
end
end
# 恢复已删除的竞赛
def renew
if User.current.admin?
@contest.update_attributes(:is_delete => false)
redirect_to contest_path(@contest)
else
return 404
end
end
# 成员列表
def member
if (User.current.admin? || @contest.is_public || (!@contest.is_public && User.current.member_of_contest?(@contest)))
@role = params[:role].nil? ? '3' : params[:role]
case @role
when '1'
@members = contest_managers @contest
when '2'
@members = contest_judges @contest
when '3'
@members = contest_contestants @contest
end
if params[:name]
q = "#{params[:name].strip}"
@members = search_member_by_name_login_school @members, q
end
@limit = 50
@page = params[:page].nil? ? 1 : params['page'].to_i
@members_count = @members.count
@mem_pages = Paginator.new @members_count, @limit, @page
@members = paginateHelper @members, @limit
respond_to do |format|
format.html {render :layout => 'base_contests'}
format.js
end
else
render_403
end
end
def export_all_members
sql = "SELECT DISTINCT(cmr.id) AS cmr_id, cmr.role_id, users.`login`, users.id AS user_id, users.`mail`, cmr.created_at FROM users, contest_members cm, contest_member_roles cmr, user_extensions ue, schools " +
"WHERE users.id = cm.`user_id` AND users.id=ue.`user_id` AND cmr.`contest_member_id` = cm.`id` AND cm.`contest_id` = #{@contest.id} AND (ue.`school_id` IS NULL OR ue.`school_id` = schools.`id`) " +
"ORDER BY role_id ASC, CONVERT(schools.`name` USING gbk) COLLATE gbk_chinese_ci DESC, CONVERT(users.`lastname` USING gbk) COLLATE gbk_chinese_ci DESC"
@members = ContestMemberRole.find_by_sql sql
respond_to do |format|
format.xls {
filename = "#{@contest.name.to_s}-成员列表-#{DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s}.xls"
send_data(member_to_xls(@members), :type => "text/excel;charset=utf-8; header=present",
:filename => filename_for_content_disposition("#{filename}.xls"))
}
end
end
private
def member_to_xls members
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "成员列表"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
#sheet1.row(0).default_format = blue
#sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
sheet1[0,0] = "id"
sheet1[0,1] = "姓名"
sheet1[0,2] = "登录名"
sheet1[0,3] = "电子邮箱"
sheet1[0,4] = "单位"
sheet1[0,5] = "角色"
sheet1[0,6] = "加入时间"
count_row = 1
members.each_with_index do |member, i|
user = User.find(member.user_id)
sheet1[count_row,0]= user.id
sheet1[count_row,1] = user.show_name
sheet1[count_row,2] = user.login
sheet1[count_row,3] = user.mail
sheet1[count_row,4] = user.user_extensions.school_id.blank? ? "" : (user.user_extensions.school.blank? ? "" : user.user_extensions.school.name)
sheet1[count_row,5] = member.role_id == 13 ? "管理员" : (member.role_id == 14 ? "评委" : "参赛者")
sheet1[count_row,6] = format_time member.created_at
count_row += 1
end
book.write xls_report
xls_report.string
end
def find_contest
if params[:id].to_i < 780
render_403
return
end
@contest = Contest.find(params[:id])
if @contest.is_delete and !User.current.admin?
render_404
return
end
rescue ActiveRecord::RecordNotFound
render_404
end

View File

@ -187,6 +187,7 @@ class CoursesController < ApplicationController
# @is_remote = true
@sort_type = 'score'
@score_sort_by = "desc"
@search_name = "#{params[:name].strip}"
q = "#{params[:name].strip}"
if params[:incourse]
results = searchmember_by_name(student_homework_score(0,0,0,"desc"), q)
@ -350,19 +351,17 @@ class CoursesController < ApplicationController
@search = params[:search]
q = params[:search] ? "#{params[:search].strip}" : ""
@members = []
@members = @course.members.where("course_group_id = 0").joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id asc").select{|m| m.roles.to_s.include?("Student")}
if q.nil? || q == ""
@course.members.includes(:user =>[:user_extensions =>[]]).where("course_group_id = 0").each do |m|
if m && m.user && m.user.join_in?(@course)
@members << m
end
end
else
@course.members.includes(:user =>[:user_extensions =>[]]).where("course_group_id = 0").each do |m|
members = []
@members.each do |m|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
if m && m.user && m.user.join_in?(@course) && (m.user[:login].to_s.downcase.include?(q) || m.user.user_extensions[:student_id].to_s.downcase.include?(q) || username.include?(q))
@members << m
if m && m.user && (m.user[:login].to_s.downcase.include?(q) || m.user.user_extensions[:student_id].to_s.downcase.include?(q) || username.include?(q))
members << m
end
end
@members = members
end
@is_search = params[:is_search] ? 1 : 0
respond_to do |format|
@ -402,6 +401,7 @@ class CoursesController < ApplicationController
@is_remote = true
@sort_type = 'score'
@score_sort_by = "desc"
@search_name = ""
if params[:group_id] && params[:group_id] != "0" && params[:group_id] != "-1"
@group = CourseGroup.find(params[:group_id])
@results = student_homework_score(@group.id,0, 0,"desc")
@ -455,6 +455,7 @@ class CoursesController < ApplicationController
@is_remote = true
@course_groups = @course.course_groups if @course.course_groups
@show_serch = params[:role] == '2'
@search_name = ""
case @role
when '1'
@subPage_title = l :label_teacher_list
@ -490,14 +491,18 @@ class CoursesController < ApplicationController
end
def export_course_member_excel
if params[:group_id]
q = "#{params[:name].strip}"
if params[:group_id] && params[:group_id] != "0" && params[:group_id] != "-1"
group = CourseGroup.find params[:group_id]
unless group.nil?
@all_members = student_homework_score(group.id,0,0,"desc")
@all_members = searchmember_by_name(student_homework_score(group.id,0,0,"desc"), q)
end
elsif params[:group_id] && params[:group_id] == "-1"
@all_members = searchmember_by_name(student_homework_score(-1, 0, 10,"desc"), q)
else
@all_members = student_homework_score(0,0,0,"desc")
@all_members = searchmember_by_name(student_homework_score(0, 0, 10,"desc"), q)
end
@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc")
filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}";
@ -654,6 +659,7 @@ class CoursesController < ApplicationController
course_status.destroy if course_status
course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
end
@syllabus = @course.syllabus
respond_to do |format|
format.js
end

View File

@ -144,8 +144,8 @@ class ForumsController < ApplicationController
preload(:author, {:last_reply => :author}).
all
@forums = Forum.reorder("topic_count desc,updated_at desc")
@my_forums_count = Forum.where(:creator_id => User.current.id).count
@my_memos_count = Memo.where(:author_id => User.current.id).count
@my_forums_count = Memo.where("author_id =? and parent_id is null", User.current.id).count
@my_memos_count = Memo.where("author_id =? and parent_id is not null", User.current.id).count
@errors = params[:errors]
respond_to do |format|
format.js
@ -187,8 +187,8 @@ class ForumsController < ApplicationController
reorder(order).
preload(:author, {:last_reply => :author}).
all
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is not null").count
@errors = params[:errors]
# 推荐贴吧
@forums = Forum.where("id !=?", @forum.id).reorder("topic_count desc,updated_at desc").first(3)
@ -340,7 +340,11 @@ class ForumsController < ApplicationController
def check_forum_name
begin
forum_name = params[:forum_name]
result = Forum.find_by_name(forum_name).blank? ? {:result => true} : {:result => false}
if params[:forum_id]
result = Forum.where("name = '#{forum_name}' and id != #{params[:forum_id]}").first.blank? ? {:result => true} : {:result => false}
else
result = Forum.where(:name => forum_name).first.blank? ? {:result => true} : {:result => false}
end
rescue Exception => e
puts e
end

View File

@ -89,7 +89,7 @@ class HomeworkCommonController < ApplicationController
end
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
param_end_time = Time.parse(params[:homework_common][:end_time]).strftime("%Y-%m-%d")
homework_end_time = Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d")
homework_end_time = @homework.end_time ? Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") : ''
if homework_end_time != param_end_time
if homework_end_time > param_end_time
@homework.student_works.where("work_status = 1").each do |st|
@ -172,7 +172,7 @@ class HomeworkCommonController < ApplicationController
end
#分组作业
if @homework.homework_type == 3
if @homework.homework_type == 3 && @homework.student_works.has_committed.count == 0
@homework.homework_detail_group ||= HomeworkDetailGroup.new
@homework_detail_group = @homework.homework_detail_group
@homework_detail_group.min_num = params[:min_num].to_i if params[:min_num]
@ -180,6 +180,12 @@ class HomeworkCommonController < ApplicationController
@homework_detail_group.base_on_project = params[:base_on_project] ? 1 : 0
end
if anonymous != @homework.anonymous_comment
@homework.student_works.where("work_status != 0").each do |student_work|
student_work.save
end
end
@homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 1
if @homework.save
homework_detail_manual.save if homework_detail_manual
@ -192,11 +198,11 @@ class HomeworkCommonController < ApplicationController
@hw_status = params[:hw_status].to_i
if params[:is_manage] == "1"
redirect_to manage_or_receive_homeworks_user_path(User.current.id)
redirect_to user_manage_homeworks_user_path(User.current.id)
elsif params[:is_manage] == "2"
redirect_to my_homeworks_user_path(User.current.id)
redirect_to user_receive_homeworks_user_path(User.current.id)
elsif @hw_status == 1
redirect_to user_path(User.current.id)
redirect_to user_course_community_path(User.current.id)
elsif @hw_status == 2
redirect_to course_path(@course.id)
elsif @hw_status == 5

View File

@ -58,7 +58,7 @@ class MembersController < ApplicationController
applied_project = @applied_message.applied
user = User.find(@applied_message.applied_user_id)
project = Project.find(applied_project.project_id) if !applied_project.nil?
if user.member_of?(project)|| AppliedMessage.where(:applied_id => @applied_message.applied_id, :status => 1).count == 0
if user.member_of?(project)|| AppliedMessage.where(:applied_id => @applied_message.applied_id, :status => 0).count == 0
@flash_message = "该申请已被其他管理员处理"
# @applied_message.update_attribute(:status, 2)
else
@ -77,7 +77,7 @@ class MembersController < ApplicationController
project.user_grades << user_grades unless user_grades.first.user_id.nil?
# 添加成功后所有管理员收到的消息状态都要更新
applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 1,
applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 0,
:applied_type => "AppliedProject")
applied_messages.update_all(:status => 7, :viewed => true)
@applied_message = AppliedMessage.find(params[:applied_message_id])
@ -106,7 +106,7 @@ class MembersController < ApplicationController
applied_project = @applied_message.applied
project = Project.find(@applied_message.project_id) if !applied_project.nil?
user = User.find(@applied_message.applied_user_id)
if user.member_of?(project) || AppliedMessage.where(:applied_id => @applied_message.applied_id, :status => 1).count == 0
if user.member_of?(project) || AppliedMessage.where(:applied_id => @applied_message.applied_id, :status => 0).count == 0
@flash_message = "该申请已被其他管理员处理"
# @applied_message.update_attribute(:status, 2)
else
@ -115,7 +115,7 @@ class MembersController < ApplicationController
:viewed => false, :applied_user_id => @applied_message.user_id, :role => applied_project.role, :project_id => applied_project.project_id)
# 拒绝功后所有管理员收到的消息状态都要更新
applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 1,
applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 0,
:applied_type => "AppliedProject")
applied_messages.update_all(:status => 5, :viewed => true)
@applied_message = AppliedMessage.find(params[:applied_message_id])

View File

@ -29,8 +29,8 @@ class MemosController < ApplicationController
def new
@memo = Memo.new
@my_forums_count = Forum.where(:creator_id => User.current.id).count
@my_memos_count = Memo.where(:author_id => User.current.id).count
@my_forums_count = Memo.where("author_id =? and parent_id is null", User.current.id).count
@my_memos_count = Memo.where("author_id =? and parent_id is not null", User.current.id).count
@forums = Forum.reorder("topic_count desc,updated_at desc")
respond_to do |format|
format.js
@ -72,7 +72,7 @@ class MemosController < ApplicationController
end
end
format.js
format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" }
format.html {redirect_to back_memo_url}
format.json { render json: @memo, status: :created, location: @memo }
else
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
@ -132,8 +132,8 @@ class MemosController < ApplicationController
@memo_new = Memo.new
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
@my_topic_count = 0
@my_replies_count = Memo.where(:parent_id => @memo.id).count
respond_to do |format|
format.js
@ -144,8 +144,8 @@ class MemosController < ApplicationController
end
def edit
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
@my_topic_count = 0
@my_replies_count = Memo.where(:parent_id => @memo.id).count
@forums = Forum.reorder("topic_count desc,updated_at desc")
@replying = false
respond_to do |format|

View File

@ -82,6 +82,13 @@ class MessagesController < ApplicationController
format.js
format.html {render :layout => 'base_projects'}
end
elsif @contest
@left_nav_type = 4
respond_to do |format|
format.js
format.html { render :layout => 'base_contests' }
end
#render :action => "show", :layout => "base_courses"#by young
else
# @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
# @replies = @topic.children.
@ -94,7 +101,7 @@ class MessagesController < ApplicationController
@organization = @org_subfield.organization
respond_to do |format|
format.js
format.html {render :layout => 'base_org'}
format.html { render :layout => 'base_org' }
end
end
end
@ -111,6 +118,8 @@ class MessagesController < ApplicationController
is_public = @project.is_public
elsif @course
is_public = @course.is_public
elsif @contest
is_public = @contest.is_public
end
# 公开项目/课程上传的资源是公开的,私有项目上传的是私有的
@message.save_attachments_containers(params[:attachments], User.current, is_public)
@ -128,6 +137,8 @@ class MessagesController < ApplicationController
redirect_to project_boards_path(@project)
elsif @course
redirect_to course_boards_path(@course, :board_id => @board.id)
elsif @contest
redirect_to contest_boards_path(@contest, :board_id => @board.id)
end
else
redirect_to board_message_url(@board, @message)
@ -138,9 +149,11 @@ class MessagesController < ApplicationController
redirect_to project_boards_path(@project, :flag => true)
elsif @course
redirect_to course_boards_path(@course, :board_id => @board.id, :flag => true)
elsif @contest
redirect_to contest_boards_path(@contest, :board_id => @board.id, :flag => true)
end
else
layout_file = @project ? 'base_projects' : 'base_courses'
layout_file = @project ? 'base_projects' : (@course ? 'base_courses' : 'base_contests')
render :action => 'new', :layout => layout_file
end
@ -149,7 +162,7 @@ class MessagesController < ApplicationController
@left_nav_type = 2
respond_to do |format|
format.html {
layout_file = @project ? 'base_projects' : 'base_courses'
layout_file = @project ? 'base_projects' : (@course ? 'base_courses' : 'base_contests')
render :layout => layout_file
}
end
@ -187,6 +200,7 @@ class MessagesController < ApplicationController
end
update_course_activity(@topic.class,@topic.id)
update_contest_activity(@topic.class,@topic.id)
update_user_activity(@topic.class,@topic.id)
update_forge_activity(@topic.class,@topic.id)
update_org_activity(@topic.class,@topic.id)
@ -226,6 +240,8 @@ class MessagesController < ApplicationController
(render_403; return false) unless @message.editable_by?(User.current)
elsif @course
(render_403; return false) unless @message.course_editable_by?(User.current)
elsif @contest
(render_403; return false) unless @message.contest_editable_by?(User.current)
else
(render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end
@ -243,12 +259,16 @@ class MessagesController < ApplicationController
redirect_to project_path(@project)
elsif @course
redirect_to course_activity_path(@course)
elsif @contest
redirect_to contest_activities_contest_path(@contest)
end
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
if @project
redirect_to project_boards_path(@project)
elsif @course
redirect_to course_boards_path(@course)
elsif @contest
redirect_to contest_boards_path(@contest)
end
else
redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id))
@ -265,6 +285,9 @@ class MessagesController < ApplicationController
elsif @course
@left_nav_type = 2
layout_file = 'base_courses'
elsif @contest
@left_nav_type = 4
layout_file = 'base_contests'
elsif @org_subfield
@organization = @org_subfield.organization
layout_file = 'base_org'
@ -292,6 +315,8 @@ class MessagesController < ApplicationController
(render_403; return false) unless @message.destroyable_by?(User.current)
elsif @course
(render_403; return false) unless @message.course_destroyable_by?(User.current)
elsif @contest
(render_403; return false) unless @message.contest_destroyable_by?(User.current)
else
(render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end
@ -320,7 +345,19 @@ class MessagesController < ApplicationController
elsif @message.parent
redirect_to board_message_url(@board, @message.parent, :r => r)
else
redirect_to course_boards_path(@course)
redirect_to course_boards_path(@course, :board_id => @board.id)
end
elsif @contest
if params[:is_course] && params[:is_course].to_i == 0
redirect_to user_contest_community_path(User.current.id)
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
redirect_to contest_activities_contest_path(@contest)
elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
redirect_to contest_boards_path(@contest)
elsif @message.parent
redirect_to board_message_url(@board, @message.parent, :r => r)
else
redirect_to contest_boards_path(@contest, :board_id => @board.id)
end
elsif @org_subfield
if params[:is_board]
@ -400,8 +437,10 @@ class MessagesController < ApplicationController
@board = Board.find(params[:board_id])
if @board.project_id != -1 && @board.project_id != nil
@project = @board.project
elsif @board.course_id
elsif @board.course_id && @board.course_id != -1
@course = @board.course
elsif @board.contest_id
@contest = @board.contest
else
@org_subfield = @board.org_subfield
@organization = @org_subfield

View File

@ -93,6 +93,9 @@ class MyController < ApplicationController
if params[:course]
@course = Course.find params[:course]
diskfile = disk_filename('Course', @course.id)
elsif params[:contest]
@contest = Contest.find params[:contest]
diskfile = disk_filename('Contest', @contest.id)
elsif params[:project]
@project = Project.find params[:project]
diskfile = disk_filename('Project', @project.id)
@ -116,6 +119,9 @@ class MyController < ApplicationController
when 'Course'
@course = Course.find params[:source_id]
diskfile = disk_filename('Course', @course.id)
when 'Contest'
@contest = Contest.find params[:source_id]
diskfile = disk_filename('Contest', @contest.id)
when 'Project'
@project = Project.find params[:source_id]
diskfile = disk_filename('Project', @project.id)

View File

@ -273,7 +273,7 @@ class NewsController < ApplicationController
elsif @news.contest_id
@contest = Contest.find(@news.contest_id)
if @contest
@left_nav_type = 4
@left_nav_type = 5
respond_to do |format|
format.js
format.html {render :layout => 'base_contests'}

View File

@ -51,7 +51,12 @@ class OrgSubfieldsController < ApplicationController
@organization = Organization.find(params[:id])
else
domain = Secdomain.where("subname=?", request.subdomain).first
begin
@organization = Organization.find(domain.pid)
rescue
render_404
return
end
end
if @organization.is_public? or User.current.admin? or User.current.member_of_org?(@organization)
@org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+

View File

@ -635,24 +635,74 @@ class OrganizationsController < ApplicationController
end
end
def apply_subdomain
@organization = Organization.find(params[:id])
organization = Organization.find(params[:id])
@applied_message_count = AppliedMessage.where(:applied_id => organization.id, :name => params[:domain].downcase, :status => 1).count
# 如果申请过该名字,怎不能重复申请
if @applied_message_count > 0
@flag = 1
else
admins = User.where("admin=1")
admins.each do |admin|
OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain].downcase)
AppliedMessage.create(:user_id => admin.id, :applied_id => organization.id, :applied_type => 'Organization', :viewed => 0, :satus => 1, :applied_user_id => User.current.id, :name => params[:domain].downcase)
# OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain].downcase)
end
end
end
# stauts: 0申请 2申请人收到已接受消息
# @flag 1申请同名提醒 2操作的时候已经被人提前处理了
def agree_apply_subdomain
@organization = Organization.find(params[:organization_id])
OrgMessage.find(params[:act_id]).update_attribute(:viewed, 1)
if Secdomain.where("pid=? and sub_type=2",@organization.id).count > 0
domain = Secdomain.where("pid=? and sub_type=2",params[:organization_id]).first
organization_id = params[:organization_id]
org_domain = params[:org_domain]
@applied_message = AppliedMessage.find(params[:ma_id])
# 处理的时候判断是否有人已经处理了
if @applied_message.status == 0
# 事务处理:消息和数据的创建应该是同步的
ActiveRecord::Base.transaction do
applied_messages = AppliedMessage.where(:applied_type => "Organization", :applied_id => organization_id, :name => org_domain, :status => 0)
applied_messages.update_all(:status => 2, :viewed => true, :updated_at => Time.now)
secdomain = Secdomain.where(:pid => organization_id, :sub_type => 2)
if secdomain.count > 0
domain = Secdomain.where("pid=? and sub_type=2",organization_id).first
Secdomain.update(domain.id, :subname => params[:org_domain])
else
Secdomain.create(:sub_type => 2, :pid => params[:organization_id], :subname => params[:org_domain])
Secdomain.create(:sub_type => 2, :pid => organization_id, :subname => params[:org_domain])
end
if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=?",params[:org_domain]).count == 0
OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain])
# 自己处理自己的消息则不需要另外发送消息
if User.current.id != @applied_message.applied_user_id
AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_id => organization_id, :applied_type => 'Organization', :viewed => 0, :satus => 2, :applied_user_id => User.current.id, :name => org_domain.downcase)
end
@applied_message.status = 2
@applied_message.updated_at = Time.now
end
else
@flag = 2
end
end
# stauts: 0申请 2申请人收到已接受消息 4已拒绝
# @flag 1申请同名提醒 2操作的时候已经被人提前处理了
def refused_apply_subdomain
organization_id = params[:organization_id]
org_domain = params[:org_domain]
@applied_message = AppliedMessage.find(params[:ma_id])
# 多人同时操作处理
secdomain = Secdomain.where(:pid => organization_id, :sub_type => 2)
# 处理过程中,如果已经被其他管理员处理,则弹框提示
if @applied_message.status == 0
# 事务处理:消息和数据的创建应该是同步的
ActiveRecord::Base.transaction do
applied_messages = AppliedMessage.where(:applied_type => "Organization", :applied_id => organization_id, :name => org_domain, :status => 0)
applied_messages.update_all(:status => 4, :viewed => true, :updated_at => Time.now)
# 自己处理自己的消息则不需要另外发送消息
if User.current.id != @applied_message.applied_user_id
AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_id => organization_id, :applied_type => 'Organization', :viewed => 0, :satus => 4, :applied_user_id => User.current.id, :name => org_domain.downcase)
end
@applied_message.status = 4
@applied_message.updated_at = Time.now
end
else
@flag = 2
end
end
end

View File

@ -28,7 +28,8 @@ class ProjectsController < ApplicationController
menu_item :feedback, :only => :feedback
menu_item :share, :only => :share
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project]
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,
:view_homework_attaches,:join_project, :project_home]
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar]
@ -72,6 +73,22 @@ class ProjectsController < ApplicationController
### added by william
include ActsAsTaggableOn::TagsHelper
# 仅仅为了转换Gitlab地址
def project_home
rep = params[:rep]
login = params[:username]
begin
user = User.find_by_login(login)
project = Project.find_by_sql("SELECT projects.* FROM `repositories`,`projects` where repositories.project_id = projects.id and projects.user_id =#{user.try(:id)} and repositories.identifier='#{rep}'").first
respond_to do |format|
format.html{redirect_to(:controller => 'repositories', :action => 'show', :id => project.id, :repository_id => rep)}
end
rescue
render_404
return
end
end
#查找组织
def search_public_orgs_not_in_project
condition = '%%'

View File

@ -157,6 +157,9 @@ class PullRequestsController < ApplicationController
def show
# compare_pull_request source_project, source_branch, target_project, target_branch
# compare_pull_request
# 如何从个人主页点击进入,则将该消息设为“已读”
ForgeMessage.where(:forge_message_id => params[:id], :forge_message_type => "PullRequest", :user_id => User.current.id, :viewed => false).update_all(:viewed => true)
@project_menu_type = 6
@type = params[:type]
@request = @g.merge_request(@project.gpid, params[:id])
@ -189,9 +192,13 @@ class PullRequestsController < ApplicationController
def accept_pull_request
begin
@status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid)
user = User.find_by_login(@status.author.try(:username))
# 更新管理员的pullrequest消息
update_pullrequest_message(params[:id].to_i, @project.id, "PullRequest", 2)
# 接受后,给用户发消息
if ForgeMessage.where(:forge_message_id => params[:id].to_i, :project_id => @project.id, :forge_message_type => "PullRequest", :user_id => user.id).count == 0
send_message_to_author(@project.id, @status.author.try(:username), params[:id], 2)
end
respond_to do |format|
format.js{redirect_to project_pull_request_path(@status.id, :project_id => @project.id)}
end
@ -225,8 +232,10 @@ class PullRequestsController < ApplicationController
request = @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state])
user = User.find_by_login(request.author.try(:username))
status = params[:state] == "close" ? 4 : 3
send_message_to_manager(@project.id, params[:id], status)
if is_project_manager?(User.current.id, @project.id)
#send_message_to_manager(@project.id, params[:id], status)
update_pullrequest_message(request.id, @project.id, "PullRequest", status)
# 给作者发送消息,如何已经发送了消息,则不发
if is_project_manager?(User.current.id, @project.id) && ForgeMessage.where(:forge_message_id => request.id, :project_id => @project.id, :forge_message_type => "PullRequest", :user_id => user.id).count == 0
send_message_to_author(@project.id, user.login, request.id, status)
end
respond_to do |format|
@ -360,12 +369,21 @@ class PullRequestsController < ApplicationController
:project_id => project_id,
:forge_message_id => pull_request_id,
:forge_message_type => "PullRequest",
:viewed => true,
:viewed => false,
:status => status,
:operate_user_id => User.current.id,
)
end
def update_pullrequest_message forge_message_id, project_id, forge_message_type, status
# 更新这条pullrequest消息所有相关的信息
ForgeMessage.where(:forge_message_id => forge_message_id, :project_id => project_id, :forge_message_type => forge_message_type).update_all(:status => status, :operate_user_id => User.current.id, :updated_at => Time.now)
# 更新自己的消息为已读
ForgeMessage.where(:forge_message_id => forge_message_id, :project_id => project_id, :forge_message_type => forge_message_type, :user_id => User.current.id).update_all(:viewed => true)
# 更新pullrequest的status字段
PullRequest.where(:pull_request_id => forge_message_id).update_all(:status => status)
end
def authorize_logged
if !User.current.logged?
redirect_to signin_path

View File

@ -6,7 +6,7 @@ class QualityAnalysisController < ApplicationController
layout "base_projects"
include ApplicationHelper
include QualityAnalysisHelper
require 'jenkins_api_client'
# require 'jenkins_api_client'
require 'nokogiri'
require 'json'
require 'open-uri'
@ -230,7 +230,7 @@ class QualityAnalysisController < ApplicationController
# resource_id: login + @repository.id
def index
# 顶部导
# 顶部导
@project_menu_type = 5
begin

View File

@ -407,7 +407,8 @@ update
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
else
unless @entries.blank?
@changesets_latest_coimmit = @g.commit(@project.gpid, @entries.first.try(:lastrev))
@changesets_latest_coimmit = @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path)
# @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path)
# 总的提交数
@changesets_all_count = @g.user_static(@project.gpid, :rev => @rev).count
# 获取默认分支
@ -497,7 +498,8 @@ update
entry_and_raw(false)
@content = @repository.cat(@path, @rev)
@changesets_latest_coimmit = @g.commit(@project.gpid, @entry.try(:lastrev))
# @changesets_latest_coimmit = @g.commit(@project.gpid, @entry.try(:lastrev))
@changesets_latest_coimmit = @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path)
# 总的提交数
@changesets_all_count = @g.user_static(@project.gpid, :rev => @rev).count
if is_entry_text_data?(@content, @path)

View File

@ -8,7 +8,7 @@ class StudentWorkController < ApplicationController
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,
:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,
:search_course_students,:work_canrepeat,:add_group_member,:change_project]
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment]
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work, :retry_work, :revise_attachment, :hide_score_detail]
before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work]
before_filter :author_of_work, :only => [:edit, :update, :destroy]
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment]
@ -778,7 +778,7 @@ class StudentWorkController < ApplicationController
end
end
end
redirect_to student_homeworks_user_path(User.current.id)
redirect_to student_work_index_path(:homework => @homework.id)
end
def retry_work
@ -868,8 +868,12 @@ class StudentWorkController < ApplicationController
end
when 2 #教辅评分 教辅评分显示平均分
#@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
if @homework.homework_detail_manual.ta_mode == 1
ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
@work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f
else
@work.teaching_asistant_score = @new_score.score
end
if @is_group_leader && params[:same_score]
add_score_to_member @work, @homework, @new_score
end
@ -946,6 +950,19 @@ class StudentWorkController < ApplicationController
end
end
def hide_score_detail
student_work_score = StudentWorksScore.where(:id => params[:score_id]).first
if student_work_score
student_work_score.update_attributes(:is_hidden => 1)
end
@is_member_work = @homework.homework_type == 3 && @work.student_work_projects.empty?
@student_work_scores = student_work_score_record(@work)
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
respond_to do |format|
format.js
end
end
#缺评列表显示
def student_work_absence_penalty
order = params[:order] || "desc"
@ -1072,6 +1089,24 @@ class StudentWorkController < ApplicationController
homework_detail_manual.save if homework_detail_manual
end
if params[:ta_mode] && homework_detail_manual.ta_mode.to_i != params[:ta_mode].to_i
homework_detail_manual.ta_mode = params[:ta_mode].to_i
homework_detail_manual.save
if homework_detail_manual.ta_mode == 1
@homework.student_works.where("work_status != 0").each do |student_work|
ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
student_work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f
student_work.save
end
else
@homework.student_works.where("work_status != 0").each do |student_work|
ts_score = StudentWorksScore.where("student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL").order("created_at DESC")
student_work.teaching_asistant_score = ts_score.first.nil? ? nil : ts_score.first.score
student_work.save
end
end
end
teacher_priority = params[:teacher_priority].to_i
if homework_detail_manual.ta_proportion.to_s != params[:ta_proportion].to_s || @homework.teacher_priority.to_s != teacher_priority.to_s || (homework_detail_programing && homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s)
homework_detail_manual.ta_proportion = params[:ta_proportion]

View File

@ -35,15 +35,16 @@ class UsersController < ApplicationController
#
before_filter :can_show_course, :only => [:user_courses,:user_homeworks]
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :unsolved_issues_list, :unfinished_homework_list,
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :unsolved_issues_list, :unfinished_homework_list, :user_manage_homeworks,
:unfinished_poll_list, :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :user_receive_homeworks,
:unapproval_applied_list, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,:user_contestlist,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,:user_contestlist, :user_manage_issues, :user_receive_issues,
:user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list,
:sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community]
before_filter :auth_user_extension, only: :show
before_filter :show_system_message, :only => [:show]
#before_filter :rest_user_score, only: :show
#before_filter :select_entry, only: :user_projects
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
@ -150,6 +151,100 @@ class UsersController < ApplicationController
end
end
# 我发布的issue
def user_manage_issues
@manage_issues = "我发布的Issue"
# 排序(默认以更新时间降序)
order = "updated_on desc"
if params[:reorder_release_time]
order = "created_on #{params[:reorder_release_time]}"
elsif params[:reorder_turnover_time]
order = "updated_on #{params[:reorder_turnover_time]}"
end
@subject = params[:subject]
params[:assigned_to_id].to_i == 0 ? @assigned_to = nil : @assigned_to = params[:assigned_to_id].to_i
params[:author_id].to_i == 0 ? author_id = nil : author_id = params[:author_id].to_i
params[:project_id].to_i == 0 ? @project_id = nil : @project_id = params[:project_id]
if @project_id.nil?
@issues = Issue.where("author_id =? and subject like ?",
@user.id, "%#{@subject}%").order(order)
else
@issues = Issue.where("author_id =? and project_id=? and subject like ?",
@user.id, @project_id, "%#{@subject}%").order(order)
end
@issues_filter = Issue.where("author_id =?", @user.id)
@issue_open_count = @issues_filter.where(:status_id => [1, 2, 3, 4, 6]).count
@issue_close_count = @issues_filter.where(:status_id => 5).count
# @issue_open_count = Issue.where(:author_id => @user.id, :status_id => [1, 2, 3, 4, 6]).count
# @issue_close_count = Issue.where(:author_id => @user.id, :status_id => 5).count
# 导出excel的issues
@excel_issues = @issues
@issue_count = @issues.count
@limit = 10
@is_remote = true
@issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1
@offset ||= @issue_pages.offset
@issues = paginateHelper @issues, @limit
# @issues.limit(@issue_pages.per_page).offset(@issue_pages.offset).reorder(order).all
respond_to do |format|
format.html{render :layout => 'static_base'}
format.xls{
filename = "我发布的_#{l(:label_issue_list_xls)}.xls"
send_data(issue_list_xls(@excel_issues), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
}
format.api
format.js
end
end
# 我收到的issue
def user_receive_issues
@receive_issues = "我收到的Issue"
# 排序(默认以更新时间降序)
order = "updated_on desc"
if params[:reorder_release_time]
order = "created_on #{params[:reorder_release_time]}"
elsif params[:reorder_turnover_time]
order = "updated_on #{params[:reorder_turnover_time]}"
end
@subject = params[:subject]
params[:assigned_to_id].to_i == 0 ? @assigned_to = nil : @assigned_to = params[:assigned_to_id].to_i
params[:author_id].to_i == 0 ? author_id = nil : author_id = params[:author_id].to_i
params[:project_id].to_i == 0 ? @project_id = nil : @project_id = params[:project_id]
if @project_id.nil?
@issues = Issue.where("assigned_to_id =? and subject like ?",
@user.id, "%#{@subject}%").order(order)
else
@issues = Issue.where("assigned_to_id =? and project_id=? and subject like ?",
@user.id, @project_id, "%#{@subject}%").order(order)
end
@issues_filter = Issue.where("assigned_to_id =?", @user.id)
@issue_open_count = @issues_filter.where(:status_id => [1, 2, 3, 4, 6]).count
@issue_close_count = @issues_filter.where(:status_id => 5).count
# 导出excel的issues
@excel_issues = @issues
@issue_count = @issues.count
@limit = 10
@is_remote = true
@issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1
@offset ||= @issue_pages.offset
@issues = paginateHelper @issues, @limit
# @issues.limit(@issue_pages.per_page).offset(@issue_pages.offset).reorder(order).all
respond_to do |format|
format.html{render :layout => 'static_base'}
format.xls{
filename = "我发布的_#{l(:label_issue_list_xls)}.xls"
send_data(issue_list_xls(@excel_issues), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
}
format.api
format.js
end
end
#展开所有回复
def show_all_replies
case params[:type]
@ -296,6 +391,16 @@ class UsersController < ApplicationController
comment.reply_id = params[:reply_id]
comment.root_id = reply.root_id
reply.children << comment
# 评论后,给回复人发消息(如果是本人就不发)
if comment.author.id != BlogComment.find(comment.reply_id).author_id
BlogMessage.create(:user_id => BlogComment.find(comment.reply_id).author_id,
:blog_commont_id => comment.id,
:blog_id => comment.blog_id,
:blog_message_type => "BlogComment",
:content => comment.content,
:user_operator_id => comment.author.id
)
end
when 'OrgDocumentComment'
@root = reply.root
comment = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:reply_id])
@ -362,7 +467,7 @@ class UsersController < ApplicationController
messages.each do |message_all|
# 未读的消息存放在数组
mess = message_all.message
if (message_all.message_type != "SystemMessage"&& !mess.nil? && (mess.viewed == 0 || !mess.viewed)) || (message_all.message_type == "SystemMessage"&& !mess.nil? && mess.created_at > onclick_time)
if (message_all.message_type != "SystemMessage" && !mess.nil? && (mess.viewed == 0 || !mess.viewed)) || (message_all.message_type == "SystemMessage"&& !mess.nil? && mess.created_at > onclick_time)
unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
@message_alls << mess
end
@ -394,7 +499,7 @@ class UsersController < ApplicationController
when nil
# 系统消息为管理员发送,我的消息中包含有系统消息
@message_alls = []
messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc")
messages = MessageAll.where(:user_id => @user.id).includes(:message).order("created_at desc")
messages.each do |message_all|
mess = message_all.message
unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
@ -474,12 +579,18 @@ class UsersController < ApplicationController
forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0)
org_querys = OrgMessage.where("user_id=? and viewed=0", user)
at_querys = AtMessage.where("user_id=? and viewed=0", user)
contest_querys = ContestMessage.where(:user_id => user, :viewed => 0)
blog_querys = BlogMessage.where(:user_id => user, :viewed => 0)
applied_querys = AppliedMessage.where("user_id=? and viewed =?", user, 0)
course_querys.update_all(:viewed => true) unless course_querys.nil?
forge_querys.update_all(:viewed => true) unless forge_querys.nil?
user_querys.update_all(:viewed => true) unless user_querys.nil?
forum_querys.update_all(:viewed => true) unless forum_querys.nil?
org_querys.update_all(:viewed => true) unless org_querys.nil?
at_querys.update_all(:viewed => true) unless at_querys.nil?
contest_querys.update_all(:viewed => true) unless contest_querys.nil?
blog_querys.update_all(:viewed => true) unless blog_querys.nil?
applied_querys.update_all(:viewed => true) unless applied_querys.nil?
end
end
@ -1738,6 +1849,72 @@ class UsersController < ApplicationController
end
end
# 用户发布的作业
def user_manage_homeworks
@manage_homeworks = "我发布的作业"
@order,@b_sort,@type = params[:order] || "created_at",params[:sort] || "desc", 1
@r_sort = @b_sort == "desc" ? "asc" : "desc"
@type = @type.to_i
tea_courses = @user.courses.visible.not_deleted.select{|course| @user.has_teacher_role(course)}
tea_course_ids = tea_courses.empty? ? "(-1)" : "(" + tea_courses.map{|course| course.id}.join(',') + ")"
@homeworks = HomeworkCommon.where("course_id in #{tea_course_ids}").order("#{@order} #{@b_sort}")
if params[:property]
all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")"
if params[:property] == "1"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1")
elsif params[:property] == "2"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2")
elsif params[:property] == "3"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3")
end
end
@limit = 10
@is_remote = true
@hw_count = @homeworks.count
@hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
@offset ||= @hw_pages.offset
@homeworks = paginateHelper @homeworks,@limit
@search = ""
@property = params[:property]
respond_to do |format|
format.js
format.html {render :layout => 'static_base'}
end
end
# 用户收到的作业
def user_receive_homeworks
@receive_homeworks = "我收到的作业"
@order,@b_sort,@type = params[:order] || "created_at",params[:sort] || "desc", 2
@r_sort = @b_sort == "desc" ? "asc" : "desc"
@type = @type.to_i
stu_courses = @user.courses.visible.not_deleted.select{|course| @user.has_student_role(course)}
stu_course_ids = stu_courses.empty? ? "(-1)" : "(" + stu_courses.map{|course| course.id}.join(',') + ")"
@homeworks = HomeworkCommon.where("course_id in #{stu_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
if params[:property]
all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")"
if params[:property] == "1"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1")
elsif params[:property] == "2"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2")
elsif params[:property] == "3"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3")
end
end
@limit = 10
@is_remote = true
@hw_count = @homeworks.count
@hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
@offset ||= @hw_pages.offset
@homeworks = paginateHelper @homeworks,@limit
@search = ""
@property = params[:property]
respond_to do |format|
format.js
format.html {render :layout => 'static_base'}
end
end
#我管理/收到的作业
def manage_or_receive_homeworks
@order,@b_sort,@type = params[:order] || "created_at",params[:sort] || "desc",params[:type] || 1
@ -1755,11 +1932,11 @@ class UsersController < ApplicationController
if params[:property]
all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")"
if params[:property] == "1"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1")
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1 order by created_at desc")
elsif params[:property] == "2"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2")
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2 order by created_at desc")
elsif params[:property] == "3"
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3")
@homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3 order by created_at desc")
end
end
@limit = 10
@ -1832,26 +2009,25 @@ class UsersController < ApplicationController
end
def show
if is_current_user
if User.current == @user
# 全部设为已读
if params[:viewed] == "set_viewed"
update_message_viewed(@user)
end
# 自己的主页显示消息
# 系统消息为管理员发送,我的消息中包含有系统消息
@message_alls = []
messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" , @user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc")
messages.each do |message_all|
mess = message_all.message
unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1)
if (message_all.message_type =="SystemMessage" && !many_days_ago(mess.created_at, 30))
next
else
@message_alls << mess
end
end
end
@message_count = @message_alls.count
@message_alls = paginateHelper @message_alls, 20
messages_all = MessageAll.where(:user_id => @user.id)
@message_count = messages_all.count
# REDO:已删除的内容应该在页面中显示不点击
@message_all_pages = Paginator.new @message_count, per_page_option, params['page']
@message_alls = messages_all.includes(:message).
limit(@message_all_pages.per_page).
offset(@message_all_pages.offset).
reorder("#{MessageAll.table_name}.created_at desc")
@unsolved_issues_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).count
# 用户待完成的作业
my_course_ids = StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").blank? ? "(-1)" : "(" + StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").map{|sc| sc.course_id}.join(",") + ")"
my_course_ids = StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").blank? ? "(-1)" : "(" + StudentsForCourse.includes(:course).
where("student_id = #{@user.id} and courses.is_delete = 0").map{|sc| sc.course_id}.join(",") + ")"
homeworks = HomeworkCommon.where("course_id in #{my_course_ids} and publish_time <= '#{Date.today}'")
homework_ids = homeworks.blank? ? "(-1)" : "(" + homeworks.map{|homework| homework.id}.join(",") + ")"
student_works = StudentWork.where("user_id = #{@user.id} and homework_common_id in #{homework_ids} and work_status != 0")
@ -1878,33 +2054,10 @@ class UsersController < ApplicationController
# @unreview_homework = 1
# 待审批的申请
@applied_message_alls = []
applied_messages_all = MessageAll.where(:user_id => @user.id, :message_type => ["OrgMessage", "AppliedMessage", "CourseMessage"]).includes(:message)
applied_messages_all.each do |message_all|
mess = message_all.message
if !mess.nil?
if (message_all.message_type == "OrgMessage")
if mess.message_type == "ApplySubdomain" && OrgMessage.where(:organization_id => mess.organization_id, :message_type => "AgreeApplySubdomain").count == 0
@applied_message_alls << mess
end
elsif (message_all.message_type == "AppliedMessage" )
if (mess.applied_type == "AppliedContest" && mess.status == 0) || (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1 && AppliedMessage.where("applied_id = #{mess.applied_id} and status != 1").count == 0) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
@applied_message_alls << mess
end
elsif message_all.message_type == "CourseMessage"
if mess.course_message_type == "JoinCourseRequest" && mess.status == 0
@applied_message_alls << mess
end
end
end
end
@applied_message_alls_count = @applied_message_alls.count
# org_applied_messages = MessageAll.where(:message_type => "OrgMessage").includes(:message).order("created_at desc")
# org_applied_messages = org_applied_messages.message.map{|message| message.message_type == "ApplySubdomain" and OrgMessage.where(:organization_id => message.organization_id, :message_type => "AgreeApplySubdomain").count == 0}.length
# project_message_applied_count = AppliedMessage.where(:user_id => @user.id, :message_type => "AppliedProject", :status => 1)
# school_message_applied_count = AppliedMessage.where(:user_id => @user.id, :message_type => "ApplyAddSchools", :status => 0)
# course_message_applied_count = CourseMessage.where(:message_type => "JoinCourse", :satus => 0)
# @applied_message_count = org_message_applied_count + project_message_applied_count + school_message_applied_count + course_message_applied_count
applied_message_count = AppliedMessage.where(:applied_type => ["Organization", "AppliedContest", "StudentWorksScoresAppeal", "AppliedProject", "ApplyAddSchools"], :user_id => User.current.id, :status => 0).count
applied_course_message_count = CourseMessage.where(:user_id => User.current.id, :course_message_type => "JoinCourseRequest", :status => 0).count
applied_pull_request_message_count = ForgeMessage.where(:user_id => User.current.id, :forge_message_type => "PullRequest", :status => [1,3]).count
@applied_message_alls_count = applied_message_count + applied_course_message_count + applied_pull_request_message_count
else
# 看别人的主页显示动态
#更新用户申请成为课程老师或教辅消息的状态
@ -2087,34 +2240,15 @@ class UsersController < ApplicationController
end
# 待审批的申请
# 待审批的消息一般不多,可以特殊处理
def unapproval_applied_list
@message_alls = []
# messages_all = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc")
messages_all = MessageAll.where(:user_id => @user.id, :message_type => ["OrgMessage", "AppliedMessage", "CourseMessage"]).includes(:message).order("created_at desc")
messages_all.each do |message_all|
mess = message_all.message
if !mess.nil?
if (message_all.message_type == "OrgMessage")
if mess.message_type == "ApplySubdomain" && OrgMessage.where(:organization_id => mess.organization_id, :message_type => "AgreeApplySubdomain").count == 0
@message_alls << mess
end
elsif (message_all.message_type == "AppliedMessage" )
if (mess.applied_type == "AppliedContest" && mess.status == 0) || (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1 && AppliedMessage.where("applied_id = #{mess.applied_id} and status != 1").count == 0) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
@message_alls << mess
end
elsif message_all.message_type == "CourseMessage"
if mess.course_message_type == "JoinCourseRequest" && mess.status == 0
@message_alls << mess
end
=begin
elsif message_all.message_type == "ForgeMessage"
if mess.forge_message_type == "PullRequest" && PullRequest.where(:forge_message_id => mess.forge_message_id, :status =>0 )
@message_alls << mess
end
=end
end
end
end
user_id = User.current.id
sql = "SELECT * FROM `message_alls` ma left join `forge_messages` fm on ma.message_id=fm.id
left join `course_messages` cm on ma.message_id=cm.id left join `applied_messages` apm on ma.message_id=apm.id
where (ma.user_id =#{user_id} and ma.message_type = 'ForgeMessage' and fm.forge_message_type='PullRequest' and fm.status=0 and fm.user_id=#{user_id} ) or
(ma.user_id=#{user_id} and ma.message_type='AppliedMessage' and apm.applied_type in ('Organization', 'AppliedContest', 'StudentWorksScoresAppeal', 'AppliedProject', 'ApplyAddSchools') and apm.user_id =#{user_id} and apm.status =0 ) or
(ma.user_id=#{user_id} and ma.message_type='CourseMessage' and cm.course_message_type='JoinCourseRequest' and cm.status=0 and cm.user_id=#{user_id} );"
@message_alls = MessageAll.find_by_sql(sql)
@message_count = @message_alls.count
@message_alls = paginateHelper @message_alls, 20
respond_to do |format|
@ -2122,7 +2256,7 @@ class UsersController < ApplicationController
end
end
# 课程社区
# 课程社区
def course_community
@course_community = "课程"
if params[:course_id] != nil
@ -2191,7 +2325,7 @@ class UsersController < ApplicationController
end
end
# 项目社区
# 项目社区
def project_community
# 看别人的主页显示动态
#更新用户申请成为课程老师或教辅消息的状态
@ -2244,7 +2378,7 @@ class UsersController < ApplicationController
end
end
# 竞赛社区
# 竞赛社区
def contest_community
@contest_community = "竞赛"
shield_contest_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Contest'").map(&:shield_id)
@ -2446,7 +2580,7 @@ class UsersController < ApplicationController
end
#Modified by nie
#Modified by nie
unless User.current.admin?
if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
# redirect_to home_path
@ -2461,9 +2595,9 @@ class UsersController < ApplicationController
end
end
##end fq
##end fq
#### added by fq
#### added by fq
def info
message = []
@ -2492,7 +2626,7 @@ class UsersController < ApplicationController
format.api
end
end
#### end
#### end
def new
@ -2606,7 +2740,7 @@ class UsersController < ApplicationController
end
end
# 上传用户资源
# 上传用户资源
def user_resource_create
user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
@ -2661,7 +2795,7 @@ class UsersController < ApplicationController
end
end
# 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源
# 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源
def user_resource_delete
if params[:resource_id].present?
Attachment.where("author_id =? and id =?", User.current.id, params[:resource_id]).first.destroy
@ -2719,7 +2853,7 @@ class UsersController < ApplicationController
end
end
#根据id或者名称搜索教师或者助教为当前用户的课程
#根据id或者名称搜索教师或者助教为当前用户的课程
def search_user_course
@user = User.current
if !params[:search].nil?
@ -2739,7 +2873,7 @@ class UsersController < ApplicationController
end
end
# 根据id或者名称搜索当前用户所在的项目
# 根据id或者名称搜索当前用户所在的项目
def search_user_project
@user = User.current
if !params[:search].nil?
@ -2759,7 +2893,7 @@ class UsersController < ApplicationController
end
end
# 将资源发送到对应的课程,分为发送单个,或者批量发送
# 将资源发送到对应的课程,分为发送单个,或者批量发送
def add_exist_file_to_course
@flag = true
if params[:send_id].present?
@ -2870,7 +3004,7 @@ class UsersController < ApplicationController
end
end
# 添加资源到对应的项目
# 添加资源到对应的项目
def add_exist_file_to_project
@flag = true
# 发送单个资源
@ -3290,7 +3424,7 @@ class UsersController < ApplicationController
end
# 资源预览
# 资源预览
def resource_preview
preview_id = params[:resource_id]
@file = Attachment.find(preview_id)
@ -3303,7 +3437,7 @@ class UsersController < ApplicationController
end
end
# 重命名资源
# 重命名资源
def rename_resource
@attachment = Attachment.find(params[:res_id]) if params[:res_id].present?
if @attachment != nil
@ -3348,7 +3482,7 @@ class UsersController < ApplicationController
end
end
################# added by william
################# added by william
def tag_save
@tags = params[:tag_for_save][:name]
@obj_id = params[:tag_for_save][:object_id]
@ -3434,7 +3568,7 @@ class UsersController < ApplicationController
format.html
end
end
###add by huang
###add by huang
def user_watchlist
limit = 10;
query = User.watched_by(@user.id);
@ -3444,7 +3578,7 @@ class UsersController < ApplicationController
@action = 'watch'
render :template=>'users/user_fanslist',:layout=>'new_base_user'
end
###add by huang
###add by huang
def user_fanslist
limit = 10;
query = @user.watcher_users;
@ -3466,7 +3600,7 @@ class UsersController < ApplicationController
render :template=>'users/user_fanslist',:layout=>'base_users_new'
end
#william
#william
def update_extensions(user_extensions)
user_extensions = params[:user_extensions]
unless user_extensions.nil?
@ -3480,7 +3614,7 @@ class UsersController < ApplicationController
@user = User.find(params[:id])
end
#修改个人简介
#修改个人简介
def edit_brief_introduction
if @user && @user.extensions
@user.extensions.update_column("brief_introduction",params[:brief_introduction])
@ -3490,133 +3624,133 @@ class UsersController < ApplicationController
end
end
# 获取公共资源
# 获取公共资源
def get_public_resources user_course_ids, user_project_ids, order, score
attachments = Attachment.where("(is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取公共资源搜索
# 获取公共资源搜索
def get_public_resources_search user_course_ids, user_project_ids, order, score, search
attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的资源
# 获取我的资源
def get_my_resources author_id, user_course_ids, user_project_ids, order, score
attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的资源查询结果
# 获取我的资源查询结果
def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search)
@attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的课程资源
# 获取我的课程资源
def get_course_resources author_id, user_course_ids, order, score
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and container_type = 'Course')"+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})
and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# # 获取我的私有资源分享结果
# def get_my_private_resources apply_ids, resource_type, order, score
# attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type})").order("#{order.nil? ? 'created_on' : order} #{score}")
# end
#
# # 获取我的私有资源分享搜索结果
# def get_my_private_resources_search apply_ids, resource_type, order, score, search
# attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type}) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
# end
# # 获取我的私有资源分享结果
# def get_my_private_resources apply_ids, resource_type, order, score
# attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type})").order("#{order.nil? ? 'created_on' : order} #{score}")
# end
#
# # 获取我的私有资源分享搜索结果
# def get_my_private_resources_search apply_ids, resource_type, order, score, search
# attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type}) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
# end
# 获取我的课程资源中搜索结果
# 获取我的课程资源中搜索结果
def get_course_resources_search author_id, user_course_ids, order, score, search
attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})
and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取公共资源中课程资源
# 获取公共资源中课程资源
def get_course_resources_public user_course_ids, order, score
attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取公共资源中课程资源搜索结果
# 获取公共资源中课程资源搜索结果
def get_course_resources_public_search user_course_ids, order, score, search
attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的项目资源
# 获取我的项目资源
def get_project_resources author_id, user_project_ids, order, score
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')})
and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的项目资源搜索
# 获取我的项目资源搜索
def get_project_resources_search author_id, user_project_ids, order, score, search
attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')})
and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取公共资源的项目资源
# 获取公共资源的项目资源
def get_project_resources_public user_project_ids, order, score
attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取公共资源的项目资源搜索
# 获取公共资源的项目资源搜索
def get_project_resources_public_search user_project_ids, order, score, search
attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我上传的附件
# 获取我上传的附件
def get_attch_resources author_id, order, score
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我上传的附件搜索结果
# 获取我上传的附件搜索结果
def get_attch_resources_search author_id, order, score, search
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取公共资源中我上传的附件
# 获取公共资源中我上传的附件
def get_attch_resources_public order, score
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取公共资源中我上传的附件
# 获取公共资源中我上传的附件
def get_attch_resources_public_search order, score, search
attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的用户类型资源
# 获取我的用户类型资源
def get_principal_resources author_id, order, score
attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的用户类型资源搜索
# 获取我的用户类型资源搜索
def get_principal_resources_search author_id, order, score, search
attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的用户类型资源
# 获取我的用户类型资源
def get_principal_resources_public order, score
attchments = Attachment.where("container_type = 'Principal' and is_public =1 and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 获取我的用户类型资源
# 获取我的用户类型资源
def get_principal_resources_public_search order, score, search
attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
end
# 资源库 分为全部 课程资源 项目资源 附件
# 资源库 分为全部 课程资源 项目资源 附件
def user_resource
# 别人的资源库是没有权限去看的
if User.current.id.to_i != @user.id.to_i
@ -3683,7 +3817,7 @@ class UsersController < ApplicationController
end
end
# 导入资源
# 导入资源
def import_resources
@resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id]
@resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"
@ -3746,7 +3880,7 @@ class UsersController < ApplicationController
end
end
# 内容导入到对象中
# 内容导入到对象中
def import_into_container
send_ids = params[:checkbox1]
# mul_id为当前课程id、项目id、组织id的多种形态
@ -3803,7 +3937,7 @@ class UsersController < ApplicationController
end
end
# 根据资源关键字进行搜索
# 根据资源关键字进行搜索
def resource_search
@order, @b_sort = params[:order] || "created_on", params[:sort] || "desc"
@score = @b_sort == "desc" ? "asc" : "desc"
@ -3951,7 +4085,7 @@ class UsersController < ApplicationController
end
end
#课程列表的排序
#课程列表的排序
def sort_syllabus_list
@order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1
@ -3997,7 +4131,7 @@ class UsersController < ApplicationController
end
end
#归档班级列表
# 归档班级列表
def user_archive_courses
if User.current.logged?
@order, @c_sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
@ -4035,12 +4169,12 @@ class UsersController < ApplicationController
end
respond_to do |format|
format.js
format.html {render :layout => 'new_base_user'}
format.html {render :layout => 'base_course_community'}
end
end
end
#展开课程下的班级
# 展开课程下的班级
def expand_courses
@syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first
unless @syllabus.nil?
@ -4055,7 +4189,7 @@ class UsersController < ApplicationController
end
end
#收藏班级/项目/竞赛
# 收藏班级/项目/竞赛
def cancel_or_collect
if params[:project]
@project = Project.find params[:project]
@ -4087,6 +4221,7 @@ class UsersController < ApplicationController
# 用户竞赛列表
def user_contestlist
# 我创建的竞赛
@contest_community = "竞赛"
@my_contests = @user.contests.where(:user_id => @user.id).order("created_at desc")
@my_contests_count = @my_contests.count
# 我参与的竞赛
@ -4223,6 +4358,10 @@ class UsersController < ApplicationController
end
private
def show_system_message
# 系统消息总显示在最前面,显示周期30天
@system_messages = SystemMessage.where("created_at > ?", Time.now - 86400 * 30)
end
def find_user
if params[:id] == 'current'

View File

@ -515,8 +515,8 @@ class WechatsController < ActionController::Base
private
def get_openid_from_code(code)
if code =='only-for-test'
openid = 'o3ss_wHOOnHkz1khBJxH8RF4SfPY'
if code =='test'
openid = 'orgVLv8TlS6e7FDiI6xdTGHRaaRo'
session[:wechat_openid] = openid
return openid
end
@ -545,6 +545,8 @@ class WechatsController < ActionController::Base
return openid
end
## 能进来的就是已关注
## 因为取消订阅的记录被删除了
def user_binded?(openid)
uw = UserWechat.where(openid: openid).first
if uw && uw.bindtype == 0

View File

@ -109,6 +109,19 @@ class WordsController < ApplicationController
end
return
end
elsif @journal_destroyed.jour_type == "Contest"
@contest = Contest.find(@journal_destroyed.jour_id)
@jours_count = @contest.journals_for_messages.where('m_parent_id IS NULL').count
@user_activity_id = params[:user_activity_id] if params[:user_activity_id]
@activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id]
unless @activity
if params[:user_activity_id] == params[:activity_id]
redirect_to feedback_contest_path(@contest)
else
redirect_to contest_activities_contest_path(@contest)
end
return
end
elsif @journal_destroyed.jour_type == 'HomeworkCommon'
@homework = HomeworkCommon.find @journal_destroyed.jour_id
if params[:user_activity_id]
@ -305,6 +318,18 @@ class WordsController < ApplicationController
end
end
def leave_contest_message
if User.current.logged?
@contest = Contest.find params[:id]
if params[:new_form][:content].size>0 && User.current.logged?
@contest.journals_for_messages << JournalsForMessage.new(:user_id => User.current.id, :notes => params[:new_form][:content], :reply_id => 0, :status => true, :is_readed => false)
end
redirect_to feedback_contest_path(@contest)
else
render_403
end
end
#作业的回复
def leave_homework_message
if User.current.logged?

View File

@ -2,8 +2,9 @@ class WorksController < ApplicationController
layout "base_contests"
before_filter :find_contest, :only => [:index,:new,:create]
before_filter :find_contestwork, :only => [:edit,:update,:destroy,:score_rule_set,:alert_open_student_works,:open_student_works,:set_score_open,:alert_score_open_modal]
before_filter :admin_of_contest, :only => [:new, :create, :edit, :update, :destroy,:score_rule_set,:alert_open_student_works,:open_student_works]
before_filter :find_contestwork, :only => [:edit,:update,:destroy,:score_rule_set,:open_contestant_works,:set_score_open,:alert_score_open_modal,
:set_score_rule]
before_filter :admin_of_contest, :only => [:new, :create, :edit, :update, :destroy,:score_rule_set,:open_contestant_works]
before_filter :member_of_contest, :only => [:index]
def index
@ -69,7 +70,14 @@ class WorksController < ApplicationController
homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(homework)
homework.work_status = homework.publish_time > Date.today ? 0 : 1
homework.work_status = homework.publish_time > Date.today ? 0 : (homework.end_time < Date.today ? 2 : 1)
work_detail_manual = WorkDetailManual.new
work_detail_manual.evaluation_start = homework.end_time + 7
work_detail_manual.evaluation_end = work_detail_manual.evaluation_start + 7
work_detail_manual.evaluation_num = 3
homework.work_detail_manual = work_detail_manual
#分组作业
if homework.work_type == 3
@ -81,6 +89,7 @@ class WorksController < ApplicationController
end
if homework.save
work_detail_manual.save if work_detail_manual
homework_detail_group.save if homework_detail_group
redirect_to works_path(:contest => @contest.id)
end
@ -101,7 +110,14 @@ class WorksController < ApplicationController
end
param_end_time = Time.parse(params[:homework_common][:end_time]).strftime("%Y-%m-%d")
homework_end_time = Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d")
work_detail_manual = @contestwork.work_detail_manual
if homework_end_time != param_end_time
eval_start = work_detail_manual.evaluation_start
if eval_start.nil? || (eval_start <= param_end_time && @contestwork.work_status <= 2)
work_detail_manual.evaluation_start = @contestwork.end_time + 7
work_detail_manual.evaluation_end = work_detail_manual.evaluation_start + 7
end
if homework_end_time > param_end_time
@contestwork.contestant_works.each do |st|
if param_end_time < Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d")
@ -129,6 +145,8 @@ class WorksController < ApplicationController
#status = false
if @contestwork.publish_time <= Date.today && @contestwork.work_status == 0
@contestwork.work_status = 1
elsif @contestwork.end_time < Date.today && @contestwork.work_status == 1
@contestwork.work_status = 2
#status = true
end
@ -146,6 +164,7 @@ class WorksController < ApplicationController
if @contestwork.save
@homework_detail_group.save if @homework_detail_group
work_detail_manual.save if work_detail_manual
@hw_status = params[:hw_status].to_i
if @hw_status == 1
@ -180,20 +199,81 @@ class WorksController < ApplicationController
def destroy
if @contestwork.destroy
respond_to do |format|
format.html {
format.js {
@hw_status = params[:hw_status].to_i
if @hw_status == 1
redirect_to user_contest_community_path(User.current.id)
elsif @hw_status == 2
redirect_to contest_path(@contest.id)
else
redirect_to works_path(:contest => @contest.id)
end
}
end
end
end
def alert_score_open_modal
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
else
@user_activity_id = -1
end
@hw_status = params[:hw_status].to_i
end
def set_score_open
@contestwork.update_attribute('score_open', params[:score_open].to_i)
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i
@is_teacher = User.current.admin? || User.current.admin_of_contest?(@contest)
end
def open_contestant_works
@contestwork.update_attributes(:is_open => !@contestwork.is_open)
@user_activity_id = params[:user_activity_id]
@hw_status = params[:hw_status].to_i
@is_teacher = User.current.admin? || User.current.admin_of_contest?(@contest)
end
def score_rule_set
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
else
@user_activity_id = -1
end
@hw_status = params[:hw_status].to_i
end
def set_score_rule
# 未启动在线评审时才能更改评审参数
if @contestwork.work_status < 3
@contestwork.online_evaluation = params[:online_evaluation].to_i ? 1 : 0
@contestwork.save
# 如果开启在线评审
if params[:online_evaluation]
work_detail_manual = @contestwork.work_detail_manual
work_detail_manual.evaluation_start = params[:evaluation_start]
work_detail_manual.evaluation_end = params[:evaluation_end]
work_detail_manual.evaluation_num = params[:evaluation_limit].to_i == 1 ? params[:evaluation_num] : -1
work_detail_manual.save
end
end
score_valid = params[:score_valid].to_i == 1 ? true : false
if score_valid != @contestwork.score_valid
@contestwork.score_valid = score_valid
@contestwork.save
@contestwork.contestant_works.has_committed.each do |c_work|
c_work.save
end
end
if params[:student_path] && params[:student_path] == "true"
redirect_to contestant_works_path(:work => @contestwork.id)
else
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i
respond_to do |format|
format.js
end
end
end
private
#获取竞赛

View File

@ -1,16 +1,14 @@
#coding=utf-8
require "base64"
require 'zip'
class ZipdownController < ApplicationController
#查找项目(课程)
before_filter :find_project_by_bid_id, :only => [:assort]
#检查权限
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
SAVE_FOLDER = "#{Rails.root}/files"
OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
MAX_PATH = 50
## 200M
MAX_DOWN_SIZE = 200 * 1024 * 1024
include ZipService
#统一下载功能
def download
@ -35,34 +33,21 @@ class ZipdownController < ApplicationController
if params[:obj_class] == "Bid"
bid = Bid.find params[:obj_id]
render_403 if User.current.allowed_to?(:as_teacher,bid.courses.first)
file_count = 0
bid.homeworks.map { |homework| file_count += homework.attachments.count}
if file_count > 0
zipfile = zip_bid bid
else
zipfile = {:message => "no file"}
end
zipfile = checkfileSize(bid.homeworks) {
zip_bid bid
}
elsif params[:obj_class] == "HomeworkCommon"
homework = HomeworkCommon.find params[:obj_id]
render_403 if User.current.allowed_to?(:as_teacher,homework.course)
file_count = 0
homework.student_works.map { |work| file_count += work.attachments.count}
if file_count > 0
zipfile = zip_homework_common homework
else
zipfile = {:message => "no file"}
end
zipfile = checkfileSize(homework.student_works) {
zip_homework_common homework
}
elsif params[:obj_class] == "Work"
homework = Work.find params[:obj_id]
render_403 if User.current.admin_of_contest?(homework.contest)
file_count = 0
homework.contestant_works.map { |work| file_count += work.attachments.count}
if file_count > 0
zipfile = zip_homework_common homework
else
zipfile = {:message => "no file"}
end
contest_work = Work.find params[:obj_id]
render_403 if User.current.admin_of_contest?(contest_work.contest)
zipfile = checkfileSize(contest_work.contestant_works) {
zip_contest_work contest_work
}
else
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
end
@ -98,7 +83,6 @@ class ZipdownController < ApplicationController
end
private
#通过作业Id找到项目课程
def find_project_by_bid_id
obj_class = params[:obj_class]
@ -110,275 +94,23 @@ class ZipdownController < ApplicationController
end
end
def zip_bid(bid)
# Todo: User Access Controll
bid_homework_path = []
digests = []
bid.homeworks.each do |homeattach|
unless homeattach.attachments.empty?
out_file = zip_homework_by_user(homeattach)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
end
end
homework_id = bid.id
user_id = bid.author_id
out_file = find_or_pack(homework_id, user_id, digests.sort){
zipping("#{Time.now.to_i}_#{bid.name}.zip",
bid_homework_path, OUTPUT_FOLDER)
}
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
def encode64(str)
Base64.urlsafe_encode64(str)
end
def decode64(str)
Base64.urlsafe_decode64(str)
end
def zip_homework_common homework_common
bid_homework_path = []
digests = []
homework_common.student_works.each do |work|
unless work.attachments.empty?
out_file = zip_student_work_by_user(work)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
end
end
homework_id = homework_common.id
user_id = homework_common.user_id
out_file = find_or_pack(homework_id, user_id, digests.sort){
zipping("#{Time.now.to_i}_#{homework_common.name}.zip",
bid_homework_path, OUTPUT_FOLDER)
}
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
def zip_contest_work homework_common
bid_homework_path = []
digests = []
homework_common.contestant_works.each do |work|
unless work.attachments.empty?
out_file = zip_student_work_by_user(work)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
end
end
homework_id = homework_common.id
user_id = homework_common.user_id
out_file = find_or_pack(homework_id, user_id, digests.sort){
zipping("#{Time.now.to_i}_#{homework_common.name}.zip",
bid_homework_path, OUTPUT_FOLDER)
}
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
def zip_homework_by_user(homework_attach)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
digests = []
homework_attach.attachments.each do |attach|
if File.exist?(attach.diskfile)
homeworks_attach_path << attach.diskfile
digests << attach.digest
else
not_exist_file << attach.filename
digests << 'not_exist_file'
end
end
out_file = find_or_pack(homework_attach.bid_id, homework_attach.user_id, digests.sort){
zipping("#{homework_attach.user.show_name}_#{((homework_attach.user.user_extensions.nil? || homework_attach.user.user_extensions.student_id.nil?) ? "" : homework_attach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}
end
def make_zip_name(work)
"#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}"
end
def zip_student_work_by_user(work)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
digests = []
def checkfileSize(works)
file_count = 0
file_size = 0
works.each do |work|
file_count += work.attachments.count
work.attachments.each do |attach|
if File.exist?(attach.diskfile)
homeworks_attach_path << attach.diskfile
digests << attach.digest
file_size += attach.filesize
end
end
if file_size > MAX_DOWN_SIZE
{err: -1, message: 'file size to large'}
elsif file_count > 0
yield if block_given?
else
not_exist_file << attach.filename
digests << 'not_exist_file'
{err: -2, :message => "no file"}
end
end
#单个文件的话,不需要压缩,只改名
out_file = nil
if homeworks_attach_path.size == 1
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}"
FileUtils.cp homeworks_attach_path.first, des_path
des_path
}
else
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
zipping("#{make_zip_name(work)}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}
end
out_file
end
def zip_student_work_by_user(work)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
digests = []
work.attachments.each do |attach|
if File.exist?(attach.diskfile)
homeworks_attach_path << attach.diskfile
digests << attach.digest
else
not_exist_file << attach.filename
digests << 'not_exist_file'
end
end
#单个文件的话,不需要压缩,只改名
out_file = nil
if homeworks_attach_path.size == 1
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}"
FileUtils.cp homeworks_attach_path.first, des_path
des_path
}
else
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
zipping("#{make_zip_name(work)}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}
end
out_file
end
def find_or_pack(homework_id, user_id, digests)
raise "please given a pack block" unless block_given?
out_file = ZipPack.packed?(homework_id, user_id, digests.sort)
unless out_file && out_file.file_valid?
file = yield
ZipPack.where(homework_id: homework_id,
user_id: user_id).delete_all
out_file = ZipPack.create(homework_id: homework_id,
user_id: user_id,
file_digest: Trustie::Utils.digest(file),
file_path: file,
pack_size: File.size(file),
file_digests: digests.join(',')
)
else
out_file.pack_times = out_file.pack_times + 1
out_file.save
end
out_file
end
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[])
rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip"
# 文件名过长
if rename_zipfile.size > MAX_PATH
rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4]
end
zipfile_name = "#{output_path}/#{rename_zipfile}"
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files_paths.each do |filename|
rename_file = File.basename(filename)
rename_file = filename_to_real( File.basename(filename)) if is_attachment
begin
zipfile.add(rename_file, filename)
rescue Exception => e
zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)}
next
end
end
unless not_exist_file.empty?
zipfile.get_output_stream('FILE_LOST.txt'){|os| os.write l(:label_file_lost) + not_exist_file.join(',').to_s}
end
end
zipfile_name
end
# 合理分配文件打包
# 如果小于 pack_attachment_max_size, 则返回单个文件
# 反之则切分为多个文件组返回
def split_pack_files(files, pack_attachment_max_size)
max_size = 0
last_files = []
ret_files = []
files.each_with_index do |f,i|
if (max_size += File.size(f)) > pack_attachment_max_size
max_size = 0
if last_files.empty? #如果单个文件超过大小,也将此文件作为一组
ret_files << {files: [f], count: 1, index: ret_files.count+1}
last_files.clear
else
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1}
last_files.clear
redo
end
else
last_files << f
end
end
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} unless last_files.empty?
ret_files
end
def detect_content_type(name)
content_type = Redmine::MimeType.of(name)
content_type.to_s
end
def filename_to_real(name)
attach = Attachment.find_by_disk_filename(name)
attach.filename
end
end

View File

@ -46,6 +46,10 @@ module ApplicationHelper
@objs = paginateHelper @attachments,25
end
# 判断当前用户能否对消息进行操作
def allow_to_show applied_message
(User.current.id == applied_message.user_id && applied_message.status == 0) ? true : false
end
# 获取竞赛的管理人员
def contest_managers contest
@ -1341,6 +1345,8 @@ module ApplicationHelper
title << @contest.name
elsif @organization
title << @organization.name
elsif @forum || params[:controller] == "forums"
title << "问吧"
elsif @user
if !@project_community.blank?
title << @project_community
@ -1348,6 +1354,14 @@ module ApplicationHelper
title << @course_community
elsif !@contest_community.blank?
title << @contest_community
elsif !@manage_issues.blank?
title << @manage_issues
elsif !@receive_issues.blank?
title << @receive_issues
elsif !@manage_homeworks.blank?
title << @manage_homeworks
elsif !@receive_homeworks.blank?
title << @receive_homeworks
else
title << @user.try(:realname)
end
@ -2896,8 +2910,7 @@ module ApplicationHelper
# 用户竞赛总数
def user_contest_count
count = @user.favorite_contests.visible.where("is_delete =?", 0).count
return count
@user.favorite_contests.visible.where("is_delete =?", 0).count
end
# 用户项目总数
@ -2920,16 +2933,28 @@ module ApplicationHelper
@user_course_total = @my_joined_course_count + @my_course_count
end
# 用户发布的作业数
def user_manage_homework_count
tea_courses = @user.courses.visible.not_deleted.select{|course| @user.has_teacher_role(course)}
tea_course_ids = tea_courses.map{|course| course.id}
@manage_homeworks = HomeworkCommon.where(:course_id => tea_course_ids).count
end
# 用户收到的作业数
def user_receive_homework_count
stu_courses = @user.courses.visible.not_deleted.select{|course| @user.has_student_role(course)}
stu_course_ids = stu_courses.empty? ? "(-1)" : "(" + stu_courses.map{|course| course.id}.join(',') + ")"
@homeworks = HomeworkCommon.where("course_id in #{stu_course_ids} and publish_time <= '#{Date.today}'").count
end
# 用户发布的issue数
def issues_author_is_self_count
@issues = Issue.where( :author_id => @user.id )
@issues_author_is_self_count = @issues.count
Issue.where(:author_id => @user.id).count
end
# 用户收到的issue数
def issues_assigned_is_self_count
@issues = Issue.where( :assigned_to_id => @user.id )
@issues_assigned_is_self_count = @issues.count
Issue.where( :assigned_to_id => @user.id ).count
end
def get_user_roll user
@ -3107,20 +3132,14 @@ module ApplicationHelper
else #学生显示提交作品、修改作品等按钮
work = cur_user_works_for_work homework
project = cur_user_projects_for_work homework
if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
if work.nil? && homework.work_status == 1
if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project
link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
else
link_to "提交作品(#{count})", new_contestant_work_path(:work => homework.id),:class => 'c_blue'
end
elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d")
if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project
link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
else
link_to "补交作品(#{count})", new_contestant_work_path(:work => homework.id),:class => 'c_red'
end
else
if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") && work.user_id == User.current.id
if homework.work_status == 1 && work.user_id == User.current.id
link_to "修改作品(#{count})", edit_contestant_work_path(work.id),:class => 'c_blue'
else
link_to "查看作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => 'c_blue', :title => "不可修改作品"
@ -3968,6 +3987,12 @@ def get_cw_status contest_work
else
str += '<span class="red_homework_btn_cir ml5">作品补交中</span>'
end
elsif contest_work.work_status == 2
str += '<span class="red_homework_btn_cir ml5">提交已截止</span>'
elsif contest_work.work_status == 3
str += '<span class="green_homework_btn_cir ml5">在线评审中</span>'
elsif contest_work.work_status == 4
str += '<span class="red_homework_btn_cir ml5">评审已截止</span>'
end
str
end
@ -3990,6 +4015,23 @@ def get_group_member_names work
result
end
def get_contest_group_member_names work
result = ""
unless work.nil?
work.contestant_work_projects.each do |member|
user = User.where(:id => member.user_id).first
unless user.nil?
if result != ""
result += "#{user.show_name}"
else
result += user.show_name
end
end
end
end
result
end
def course_syllabus_option user = User.current
syllabus_members = SyllabusMember.where("user_id = #{user.id}")
syllabus_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|mem| mem.syllabus_id}.join(',') + ")"
@ -4105,6 +4147,10 @@ def searchstudent_by_name users, name
mems
end
def contest_feedback_count
@contest.journals_for_messages.where('m_parent_id IS NULL').count
end
def add_reply_adapter obj, options
#modify by nwb
#添加对课程留言的支持
@ -4116,6 +4162,8 @@ def add_reply_adapter obj, options
Project.add_new_jour(nil, nil, obj.jour_id, options)
when 'Course'
Course.add_new_jour(nil, nil, obj.jour_id, options)
when 'Contest'
Contest.add_new_jour(nil, nil, obj.jour_id, options)
#when 'Bid'
# obj.jour.add_jour(nil, nil, nil, options)
#when 'Contest'

View File

@ -13,4 +13,42 @@ module ContestantWorksHelper
end
str
end
#成绩计算
def set_final_score contestwork, contestant_work
if contestwork.online_evaluation
if contestwork.score_valid
contestant_work.work_score = contestant_work.judge_score
else
if ContestantWorkScore.find_by_sql("SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{contestant_work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id").count <= 2
contestant_work.work_score = contestant_work.judge_score
else
judge_score = ContestantWorkScore.find_by_sql("SELECT (SUM(score)-MIN(score)-MAX(score))/(COUNT(score)-2) AS score FROM (SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{contestant_work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
contestant_work.work_score = judge_score.first.score.try(:round, 2).to_f
end
end
else
contestant_work.work_score = nil
end
end
#获取学生作品的评分记录:同一个评委只显示最后一次评分
def contestant_work_score_record work
sql = "SELECT MAX(id) id FROM contestant_work_scores WHERE reviewer_role = 2 AND score IS NOT NULL AND contestant_work_id = #{work.id} GROUP BY user_id"
tea_ts_ids = ContestantWorkScore.find_by_sql sql
scores = work.contestant_work_scores.where(:id => tea_ts_ids.map{|tea| tea.id}).order("updated_at desc")
return scores
end
#获取指定评分的角色
def student_work_score_role score
case score.reviewer_role
when 1
role = "管理员"
when 2
role = "评委"
when 3
role = "参赛者"
end
end
end

View File

@ -76,4 +76,21 @@ module ContestsHelper
end
result
end
def search_member_by_name_login_school members, name
mems = []
if name != ""
name = name.to_s.downcase
school_ids = School.where("name like '%#{name}%'").map{|school| school.id}
members.each do |m|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
if(m.user[:login].to_s.downcase.include?(name) || school_ids.include?(m.user.user_extensions[:school_id]) || username.include?(name))
mems << m
end
end
else
mems = members
end
mems
end
end

View File

@ -130,7 +130,7 @@ module IssuesHelper
end
def options_for_version_isuue_list(project)
versions = Version.where(:project_id => project, :status => "open").map{|version| [version.name, version.id]}.unshift(["里程碑", 0])
versions = Version.where(:project_id => project, :status => "open").order("created_on desc").map{|version| [version.name, version.id]}.unshift(["里程碑", 0])
end
def render_issue_subject_with_tree(issue)

View File

@ -69,12 +69,13 @@ module StudentWorkHelper
str
end
#获取学生作品的评分记录:同一个教师或教辅只显示最后一次评分
#获取学生作品的评分记录:同一个教师或教辅只显示未隐藏的评分
def student_work_score_record work
sql = "SELECT MAX(id) id FROM student_works_scores WHERE (reviewer_role = 2 OR reviewer_role = 1) AND score IS NOT NULL AND student_work_id = #{work.id} GROUP BY user_id"
tea_ts_ids = StudentWorksScore.find_by_sql sql
tea_ts_ids = tea_ts_ids.empty? ? "(-1)" : "(" + tea_ts_ids.map{|tea| tea.id}.join(",") + ")"
scores = work.student_works_scores.where("score IS NULL or reviewer_role = 3 or id in #{tea_ts_ids}").order("updated_at desc")
# sql = "SELECT MAX(id) id FROM student_works_scores WHERE (reviewer_role = 2 OR reviewer_role = 1) AND score IS NOT NULL AND is_hidden = 0 AND student_work_id = #{work.id} GROUP BY user_id"
# tea_ts_ids = StudentWorksScore.find_by_sql sql
# tea_ts_ids = tea_ts_ids.empty? ? "(-1)" : "(" + tea_ts_ids.map{|tea| tea.id}.join(",") + ")"
# scores = work.student_works_scores.where("score IS NULL or reviewer_role = 3 or id in #{tea_ts_ids}").order("updated_at desc")
scores = work.student_works_scores.where(:is_hidden => false).order("created_at desc")
return scores
end

View File

@ -134,10 +134,6 @@ module UsersHelper
end
end
# 判断当前用户能否对消息进行操作
def allow_to_show applied_message
(User.current.id == applied_message.user_id && applied_message.status == 1) ? true : false
end
# 项目申请消息通过状态判断用户
# status(1申请的消息2已操作过该消息包括同意或者拒绝消息状态更新3拒绝消息4:被拒人收到消息5拒绝者收到消息6同意后申请人收到消息7同意后批准人收到消息)
@ -307,7 +303,10 @@ module UsersHelper
user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count
user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count
at_count = user.at_messages.where(viewed: false).count
messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count + org_count
contest_count = ContestMessage.where(:user_id => user, :viewed => 0).count
applied_count = AppliedMessage.where("user_id=? and viewed =?", user, 0).count
blog_count = BlogMessage.where(:user_id => user, :viewed => 0).count
messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count + org_count + contest_count + blog_count + applied_count
end
def user_mail_notification_options(user)
@ -869,4 +868,20 @@ module UsersHelper
end
return user_ids
end
# 获取竞赛申请者的角色
def get_role_str role
str = ""
case role
when 1
str = "管理员"
when 2
str = "评委"
when 3
str = "参赛者"
when 4
str = "管理员、评委"
end
str
end
end

View File

@ -355,7 +355,7 @@ module WatchersHelper
text = collected == 1 ? l(:label_project_collect_cancel) : l(:label_project_collect)
url = store_mine_project_path(project_id)
method = 'post'
link = link_to(text, url, :remote => true, :method => method, :id => "#{project_id}", :class => "pro_new_topbtn_left fl", :title => "#{collected == 1 ? '点击将其从个人主页的项目列表中移除' : '点击将其添加至人主页的项目列表中'}")
link = link_to(text, url, :remote => true, :method => method, :id => "#{project_id}", :class => "pro_new_topbtn_left fl", :title => "#{collected == 1 ? '点击将其从左侧导航的项目列表中移除' : '点击将其添加至左侧导航的项目列表中'}")
# link.html_safe
end

View File

@ -8,7 +8,7 @@ class AppliedContest < ActiveRecord::Base
has_many :applied_messages, :class_name => 'AppliedMessage', :as => :applied, :dependent => :destroy
after_create :send_appliled_message
# 仅仅给项目管理人员发送消息
# 仅仅给竞赛管理人员发送消息
def send_appliled_message
case self.role
when '13'
@ -17,11 +17,9 @@ class AppliedContest < ActiveRecord::Base
role = 2
when '15'
role = 3
else
role = 4
end
contest_managers(self.contest).each do |member|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :applied_user_id => self.user_id, :role => role)
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :role => role)
end
# end
end

View File

@ -11,7 +11,7 @@ class AppliedProject < ActiveRecord::Base
# 仅仅给项目管理人员发送消息
def send_appliled_message
self.project.managers.each do |member|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => true, :viewed => false, :applied_user_id => self.user_id, :role => self.role, :project_id => self.project_id)
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => false, :viewed => false, :applied_user_id => self.user_id, :role => self.role, :project_id => self.project_id)
#----------------微信通知----------------------
count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count

View File

@ -6,6 +6,7 @@ class BlogComment < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :blog
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :blog_messages, :class_name => 'BlogMessage', :as => :blog_message, :dependent => :destroy
acts_as_tree :counter_cache => :comments_count, :order => "#{BlogComment.table_name}.sticky desc ,#{BlogComment.table_name}.created_on ASC"
acts_as_attachable

View File

@ -0,0 +1,20 @@
class BlogMessage < ActiveRecord::Base
# attr_accessible :title, :body
attr_accessible :content, :blog_commont_id, :blog_message_type, :viewed, :user_id, :blog_id, :user_operator_id
belongs_to :blog_comment ,:polymorphic => true
belongs_to :user
has_many :message_alls, :class_name => 'MessageAll', :as => :message, :dependent => :destroy
validates :user_id, presence: true
validates :blog_id, presence: true
validates :blog_commont_id, presence: true
validates :blog_message_type, presence: true
after_create :add_user_message
def add_user_message
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end
end

View File

@ -20,6 +20,7 @@ class Board < ActiveRecord::Base
belongs_to :project,:touch => true
belongs_to :course,:touch=>true
belongs_to :org_subfield, :touch => true
belongs_to :contest, :touch => true
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
@ -55,6 +56,8 @@ class Board < ActiveRecord::Base
@valid_parents ||= project.boards - self_and_descendants
elsif course
@valid_parents ||= course.boards - self_and_descendants
elsif contest
@valid_parents ||= contest.boards - self_and_descendants
end
end

View File

@ -26,6 +26,7 @@ class Comment < ActiveRecord::Base
# 课程/项目 消息
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy
has_many :contest_messages, :class_name => 'ContestMessage', :as => :contest_message, :dependent => :destroy
#end
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
@ -54,12 +55,22 @@ class Comment < ActiveRecord::Base
# ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
# end
end
elsif self.commented.contest
if self.author_id != self.commented.author_id
self.contest_messages << ContestMessage.new(:user_id => self.commented.author_id, :contest_id => self.commented.contest.id, :viewed => false)
# count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count
# if count == 0
# content = strip_html self.comments.html_safe, 200
# ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
# end
end
else # 项目相关
# if self.author_id != self.commented.author_id
# self.forge_messages << ForgeMessage.new(:user_id => self.commented.author_id, :project_id => self.commented.project.id, :viewed => false)
# #content = strip_html self.comments.html_safe, 200
# #ws.comment_template self.commented.author_id, "blog_comment", self.id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
# end
end
end

View File

@ -13,6 +13,10 @@ class Contest < ActiveRecord::Base
has_many :users, :through => :members
has_many :contestants, :class_name => 'ContestantForContest', :source => :user
has_many :works
has_many :contestant_work_projects, :dependent => :destroy
has_many :boards, :dependent => :destroy, :order => "position ASC"
has_many :files
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :news, :dependent => :destroy, :include => :author
@ -24,10 +28,14 @@ class Contest < ActiveRecord::Base
validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]*$/
before_destroy :delete_all_members
#after_create :act_as_contest_activity
after_create :create_board_sync
scope :visible, lambda {|*args| where(Contest.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) }
def contest_judges
self.contest_members.select{|cm| cm.roles.to_s.include?("Judge")}
end
# 删除竞赛所有成员
def delete_all_members
if self.contest_members && self.contest_members.count > 0
@ -108,4 +116,31 @@ class Contest < ActiveRecord::Base
end
code
end
# 创建竞赛讨论区
def create_board_sync
@board = self.boards.build
#self.name=" #{l(:label_borad_course) }"
@board.name = " #{l(:label_board_contest) }"#self.name
@board.description = self.name.to_s
@board.project_id = -1
@board.course_id = -1
if @board.save
logger.debug "[Contest Model] ===> #{@board.to_json}"
else
logger.error "[Contest Model] ===> Auto create board when contest saved, because #{@board.full_messages}"
end
end
# 新增竞赛留言
def self.add_new_jour(user, notes, id, options={})
contest = Contest.find(id)
if options.count == 0
pjfm = contest.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0)
else
pjfm = contest.journals_for_messages.build(options)
end
pjfm.save
pjfm
end
end

View File

@ -1,4 +1,7 @@
class ContestMessage < ActiveRecord::Base
# Workstatus
# nil发布了作业 1截止时间到了提醒2:开启在线评审; 3关闭在线评审 4匿评开始失败 5在线评审时间快到了
attr_accessible :content, :contest_message_id, :contest_message_type, :status, :viewed, :user_id, :contest_id
belongs_to :contest_message ,:polymorphic => true

View File

@ -1,4 +1,5 @@
class ContestantWork < ActiveRecord::Base
include ContestantWorksHelper
belongs_to :work
belongs_to :user
belongs_to :project
@ -8,6 +9,9 @@ class ContestantWork < ActiveRecord::Base
has_many :contestant_work_scores, :dependent => :destroy
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
has_many :attachments, :dependent => :destroy
has_many :contestant_work_evaluation_distributions
before_save :set_work_score
scope :has_committed, lambda{where("work_status != 0 and work_status != 3")}
scope :no_copy, lambda{where("work_status != 3")}
@ -20,4 +24,10 @@ class ContestantWork < ActiveRecord::Base
self.contest_messages << ContestMessage.new(:user_id => self.user_id, :contest_id => self.work.contest_id, :viewed => false, :status => false)
end
end
def set_work_score
if self.id
set_final_score self.work,self
end
end
end

View File

@ -0,0 +1,5 @@
class ContestantWorkEvaluationDistribution < ActiveRecord::Base
belongs_to :user
belongs_to :contestant_work
attr_accessible :user_id, :contestant_work_id
end

View File

@ -2,4 +2,7 @@ class ContestantWorkScore < ActiveRecord::Base
belongs_to :contestant_work
belongs_to :user
attr_accessible :comment, :reviewer_role, :score, :contestant_work_id, :user_id
acts_as_attachable
has_many :journals_for_messages
end

View File

@ -76,7 +76,7 @@ class JournalsForMessage < ActiveRecord::Base
has_one :praise_tread_cache, as: :object, dependent: :destroy
validates :notes, presence: true, if: :is_homework_jour?
after_create :act_as_course_activity, :act_as_course_message,
after_create :act_as_course_activity, :act_as_course_message, :act_as_contest_activity,
act_as_at_message(:notes, :user_id), :act_as_user_feedback_message,
:act_as_principal_activity
# after_create :reset_counters!
@ -222,6 +222,13 @@ class JournalsForMessage < ActiveRecord::Base
end
end
#竞赛动态公共表记录
def act_as_contest_activity
if self.jour_type == 'Contest' && self.m_parent_id.nil?
self.contest_acts << ContestActivity.new(:user_id => self.user_id,:contest_id => self.jour_id)
end
end
# 课程/作品回复 留言消息通知
def act_as_course_message
if self.jour_type == 'StudentWorksScore'

View File

@ -203,7 +203,7 @@ class Memo < ActiveRecord::Base
end
def destroyable_by? user
(user && self.author == user) || user.admin?
(user && self.author == user) || user.admin? || self.forum.creator == user
#self.author == user || user.admin?
end

View File

@ -86,7 +86,7 @@ class Message < ActiveRecord::Base
# after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
after_update :update_messages_board, :update_activity
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message, :delay_message_send
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_contest_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message, :delay_message_send
#before_save :be_user_score
scope :visible, lambda {|*args|
@ -103,8 +103,10 @@ class Message < ActiveRecord::Base
:if => lambda {|message, user|
if message.project
user.allowed_to?(:edit_messages, message.project)
else
elsif message.course
user.allowed_to?(:edit_messages, message.course)
elsif message.contest
user.admin_of_contest?(message.contest)
end
}
@ -188,6 +190,18 @@ class Message < ActiveRecord::Base
board.course
end
def contest
board.contest
end
def contest_editable_by?(usr)
usr && usr.logged? && (usr.admin_of_contest?(contest) || self.author == usr || usr.admin?)
end
def contest_destroyable_by?(usr)
usr && usr.logged? && (usr.admin_of_contest?(contest) || self.author == usr || usr.admin?)
end
def course_editable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:edit_messages, course) || (self.author == usr && usr.allowed_to?(:edit_own_messages, course)))
end
@ -223,6 +237,7 @@ class Message < ActiveRecord::Base
#动态的更新
def update_activity
update_course_activity(self.class, self.id)
update_contest_activity(self.class, self.id)
update_user_activity(self.class, self.id)
update_forge_activity(self.class, self.id)
update_org_activity(self.class, self.id)
@ -269,6 +284,13 @@ class Message < ActiveRecord::Base
end
end
#竞赛动态公共表记录
def act_as_contest_activity
if self.contest && self.parent_id.nil?
self.contest_acts << ContestActivity.new(:user_id => self.author_id,:contest_id => self.board.contest_id)
end
end
# 课程讨论区添加消息:
# 老师发帖所有人都能收到消息
# 学生发帖,有人回复则给该学生消息,没回复则不给其它人发送消息
@ -324,6 +346,29 @@ class Message < ActiveRecord::Base
# end
end
end
elsif self.contest
if self.parent_id.nil? # 主贴
self.contest.contest_members.includes(:user).each do |m|
if self.author.admin_of_contest?(self.contest) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息
#self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
# count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count
# if count == 0
# content = strip_html self.subject, 200
# ws.topic_publish_template m.user_id, "course_discussion", self.id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on)
# end
end
end
else # 回帖
parent_author_id = Message.find(self.parent_id).author_id
if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
self.contest_messages << ContestMessage.new(:user_id => parent_author_id, :contest_id => self.board.contest_id, :viewed => false)
# count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count
# if count == 0
# content = strip_html self.content.html_safe, 200
# ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content
# end
end
end
end
end
@ -346,6 +391,25 @@ class Message < ActiveRecord::Base
self.delay.contain_messages_message(dm)
end
end
elsif self.contest
if self.parent_id.nil? # 发帖
dm = []
self.contest.contest_members.includes(:user).each do |m|
if self.author.admin_of_contest?(self.contest) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息
dm << {contest_message_type:'Message',contest_message_id:self.id, :user_id => m.user_id,
:contest_id => self.board.contest_id, :viewed => false}
if dm.size >= 30
self.delay.contain_contest_messages_message(dm)
dm.clear
end
end
end
unless dm.empty?
self.delay.contain_contest_messages_message(dm)
end
end
end
end
@ -354,6 +418,10 @@ class Message < ActiveRecord::Base
CourseMessage.create(vs)
end
def contain_contest_messages_message vs
ContestMessage.create(vs)
end
#更新用户分数 -by zjc
def be_user_score
#新建message且无parent的为发帖

View File

@ -1,5 +1,15 @@
class MessageAll < ActiveRecord::Base
attr_accessible :message_id, :message_type, :user_id
belongs_to :user
# 虚拟关联---项目消息表/课程消息表/用户留言消息表/贴吧消息表
belongs_to :forge_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'ForgeMessage'"
belongs_to :course_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'CourseMessage'"
belongs_to :applied_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'AppliedMessage'"
belongs_to :at_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'AtMessage'"
belongs_to :memo_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'MemoMessage'"
belongs_to :org_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'OrgMessage'"
belongs_to :system_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'SystemMessage'"
belongs_to :user_feedback_message, foreign_key: 'message_id', conditions: "message_alls.message_type = 'UserFeedbackMessage'"
belongs_to :message ,:polymorphic => true
end

View File

@ -69,7 +69,7 @@ class News < ActiveRecord::Base
:author_key => :author_id
acts_as_watchable
after_create :act_as_course_activity, :add_author_as_watcher, :add_news_count, :act_as_student_score,:delay_news_wechat_send, :delay_news_send
after_create :act_as_course_activity, :add_author_as_watcher, :add_news_count, :act_as_student_score,:delay_news_wechat_send, :delay_news_send, :act_as_contest_message
after_update :update_activity
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score
@ -216,6 +216,16 @@ class News < ActiveRecord::Base
end
end
def act_as_contest_message
if self.contest_id
self.contest.contest_members.each do | m|
if m.user_id != self.author_id
self.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => self.contest_id, :viewed => false)
end
end
end
end
def delay_news_send
if self.course
@ -225,6 +235,8 @@ class News < ActiveRecord::Base
vs << {course_message_type:'News',course_message_id:self.id, :user_id => m.user_id,
:course_id => self.course_id, :viewed => false}
#delayed_job卡住的原因是一次执行的条数太多导致超时。
#现在把每次只执行不超过30条就不会超了。
if vs.size >= 30
self.delay.contain_news_message(vs)
vs.clear
@ -240,7 +252,7 @@ class News < ActiveRecord::Base
vs = []
self.contest.contest_members.each do | m|
if m.user_id != self.author_id
vs << {course_message_type:'Contest',course_message_id:self.id, :user_id => m.user_id,
vs << {contest_message_type:'Contest',contest_message_id:self.id, :user_id => m.user_id,
:contest_id => self.contest_id, :viewed => false}
if vs.size >= 30

View File

@ -1,7 +1,7 @@
class OrgMessage < ActiveRecord::Base
belongs_to :user
belongs_to :organization
has_many :message_alls, :as => :message, :dependent => :destroy
has_many :message_alls, :class_name => 'MessageAll', :as => :message, :dependent => :destroy
validates :message_type, :presence => true
validates :message_id, :presence => true
validates :organization_id, :presence => true

View File

@ -10,6 +10,7 @@ class Organization < ActiveRecord::Base
has_many :users, :through => :org_members
has_many :files
has_many :org_messages, :class_name => 'OrgMessage', :dependent => :destroy
has_many :applied_messages, :class_name => 'AppliedMessage', :dependent => :destroy
acts_as_attachable
validates_uniqueness_of :name
after_create :save_as_org_activity, :add_default_subfields

View File

@ -43,7 +43,8 @@ class Project < ActiveRecord::Base
end
end
has_many :student_work_projects,:dependent => :destroy
has_many :student_work_projects, :dependent => :destroy
has_many :contestant_work_projects, :dependent => :destroy
has_many :student_works
has_many :time_entry_activities
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"

View File

@ -1,6 +1,6 @@
class PullRequest < ActiveRecord::Base
# status 1创建 2接受 3重新打开 4关闭
attr_accessible :gpid, :pull_request_id, :user_id, :project_id, :title
attr_accessible :gpid, :pull_request_id, :user_id, :project_id, :title, :status
validates_uniqueness_of :pull_request_id
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy

View File

@ -2,7 +2,7 @@
class StudentWorksScore < ActiveRecord::Base
#reviewer_role: 1:教师评分;2:教辅评分;3:学生匿评
#appeal_status: 0正常1申诉中2撤销申诉3申诉成功4申诉被拒绝
attr_accessible :student_work_id, :user_id, :score, :comment, :reviewer_role
attr_accessible :student_work_id, :user_id, :score, :comment, :reviewer_role, :is_hidden
belongs_to :user
belongs_to :student_work

View File

@ -1,3 +1,4 @@
#encoding: utf-8
class StudentsForCourse < ActiveRecord::Base
attr_accessible :course_id, :student_id
@ -9,7 +10,7 @@ class StudentsForCourse < ActiveRecord::Base
validates_uniqueness_of :student_id, :scope => :course_id
after_destroy :delete_student_works
after_create :recovery_student_works
after_create :recovery_student_works, :create_student_works
#退出班级或删除学生时隐藏学生的作品
def delete_student_works
@ -26,4 +27,14 @@ class StudentsForCourse < ActiveRecord::Base
student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}")
student_works.update_all(:is_delete => 0)
end
#加入班级时创建已发布作业的作品
def create_student_works
course = self.course
course.homework_commons.each do |hw|
if hw.homework_type != 3 && hw.student_works.where("user_id = #{self.student_id}").count == 0
hw.student_works << StudentWork.new(:user_id => self.student_id, :name => hw.name.to_s+"的作品提交", :work_status => 0)
end
end
end
end

View File

@ -114,6 +114,13 @@ class User < Principal
has_many :apply_homeworks, :dependent => :destroy
has_many :apply_resources, :dependent => :destroy
#end
#竞赛
has_many :contests, :dependent => :destroy
has_many :works, :dependent => :destroy
has_many :contestant_works, :dependent => :destroy
has_many :contestant_work_evaluation_distributions, :dependent => :destroy
has_many :contestant_work_scores
has_many :contestant_work_projects
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
:after_remove => Proc.new {|user, group| group.user_removed(user)}
@ -392,6 +399,7 @@ class User < Principal
user = User.current
onclick_time = user.onclick_time.onclick_time
course_count = CourseMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
contest_count = ContestMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
forge_count = ForgeMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
user_memo_count = MemoMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
@ -399,7 +407,8 @@ class User < Principal
at_count = AtMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count
org_count = OrgMessage.where("user_id=? and viewed =? and created_at >?", user.id,0, onclick_time).count
applied_count = AppliedMessage.where("user_id=? and viewed =? and created_at >?", user.id, 0, onclick_time).count
messages_count = course_count + forge_count + user_feedback_count + user_memo_count + system_messages_count + at_count + org_count + applied_count
blog_message_count = BlogMessage.where("user_id=? and viewed=? and created_at >?", user.id, 0, onclick_time).count
messages_count = course_count + contest_count + forge_count + user_feedback_count + user_memo_count + system_messages_count + at_count + org_count + applied_count + blog_message_count
end
# 查询指派给我的缺陷记录
@ -1063,6 +1072,7 @@ class User < Principal
# Admin users are authorized for anything else
return true if admin?
# 课程:作品关联项目的老师也可以访问私有项目
course_ids = context.student_work_projects.blank? ? "(-1)" : "(" + context.student_work_projects.map{|swp| swp.course_id}.join(",") + ")"
courses = Course.where("id in #{course_ids}")
courses.each do |course|
@ -1070,6 +1080,16 @@ class User < Principal
return true
end
end
# 竞赛:作品关联项目的管理员也可以访问私有项目
contest_ids = context.contestant_work_projects.map{|swp| swp.contest_id}
contests = Contest.where(:id => contest_ids)
contests.each do |contest|
if self.admin_of_contest?(contest)
return true
end
end
roles = roles_for_project(context)
return false unless roles
roles.any? {|role|

View File

@ -1,10 +1,12 @@
class Work < ActiveRecord::Base
# work_status 0未发布/挂起 1提交中 2提交截止 3启动在线评审 4评审结束
belongs_to :user
belongs_to :contest
attr_accessible :description, :end_time, :is_delete, :is_open, :name, :publish_time, :score_open, :work_status, :work_type, :contest_id, :user_id
include ApplicationHelper
has_one :work_detail_group, :dependent => :destroy
has_one :work_detail_manual, :dependent => :destroy
has_many :contestant_work_projects, :dependent => :destroy
has_many :contestant_works, :dependent => :destroy, :conditions => "is_delete != 1"
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
@ -60,10 +62,8 @@ class Work < ActiveRecord::Base
if self.work_status == 0
self.contest_messages.destroy_all
else
self.contest.contest_members.each do |m|
if m.user_id != self.user_id
self.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => self.contest_id, :viewed => false)
end
self.contest.contestants.each do |m|
self.contest_messages << ContestMessage.new(:user_id => m.student_id, :contest_id => self.contest_id, :viewed => false)
end
end
end

View File

@ -0,0 +1,4 @@
class WorkDetailManual < ActiveRecord::Base
belongs_to :work
attr_accessible :evaluation_end, :evaluation_num, :evaluation_start, :work_id
end

View File

@ -23,13 +23,18 @@ class ContestsService
else
if params[:invite_code].present?
role_ids = params[:role]
role_str = role_ids.join(",").to_s
#如果已经发送过消息了,那么就要给个提示
if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :role => role_str, :status => 0).count != 0
if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :status => 0).count != 0
@state = 7
else
AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_str, :status => 0)
if role_ids.size == 1
AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_ids[0], :status => 0)
else
role_ids.each do |role_id|
AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_id, :status => 0)
end
end
@state = 6
end
else

281
app/services/zip_service.rb Normal file
View File

@ -0,0 +1,281 @@
require "base64"
require 'zip'
module ZipService
SAVE_FOLDER = "#{Rails.root}/files"
OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
MAX_PATH = 50
def zip_bid(bid)
# Todo: User Access Controll
bid_homework_path = []
digests = []
bid.homeworks.each do |homeattach|
unless homeattach.attachments.empty?
out_file = zip_homework_by_user(homeattach)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
end
end
homework_id = bid.id
user_id = bid.author_id
out_file = find_or_pack(homework_id, user_id, digests.sort){
zipping("#{Time.now.to_i}_#{bid.name}.zip",
bid_homework_path, OUTPUT_FOLDER)
}
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
def encode64(str)
Base64.urlsafe_encode64(str)
end
def decode64(str)
Base64.urlsafe_decode64(str)
end
def zip_homework_common homework_common
bid_homework_path = []
digests = []
homework_common.student_works.each do |work|
unless work.attachments.empty?
out_file = zip_student_work_by_user(work)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
end
end
homework_id = homework_common.id
user_id = homework_common.user_id
out_file = find_or_pack(homework_id, user_id, digests.sort){
zipping("#{Time.now.to_i}_#{homework_common.name}.zip",
bid_homework_path, OUTPUT_FOLDER)
}
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
def zip_contest_work homework_common
bid_homework_path = []
digests = []
homework_common.contestant_works.each do |work|
unless work.attachments.empty?
out_file = zip_contestant_work_by_user(work)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
end
end
homework_id = homework_common.id
user_id = homework_common.user_id
out_file = find_or_pack(homework_id, user_id, digests.sort){
zipping("#{Time.now.to_i}_#{homework_common.name}.zip",
bid_homework_path, OUTPUT_FOLDER)
}
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
def zip_homework_by_user(homework_attach)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
digests = []
homework_attach.attachments.each do |attach|
if File.exist?(attach.diskfile)
homeworks_attach_path << attach.diskfile
digests << attach.digest
else
not_exist_file << attach.filename
digests << 'not_exist_file'
end
end
out_file = find_or_pack(homework_attach.bid_id, homework_attach.user_id, digests.sort){
zipping("#{homework_attach.user.show_name}_#{((homework_attach.user.user_extensions.nil? || homework_attach.user.user_extensions.student_id.nil?) ? "" : homework_attach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}
end
def make_zip_name(work)
"#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}"
end
def zip_student_work_by_user(work)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
digests = []
work.attachments.each do |attach|
if File.exist?(attach.diskfile)
homeworks_attach_path << attach.diskfile
digests << attach.digest
else
not_exist_file << attach.filename
digests << 'not_exist_file'
end
end
#单个文件的话,不需要压缩,只改名
out_file = nil
if homeworks_attach_path.size == 1
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}"
FileUtils.cp homeworks_attach_path.first, des_path
des_path
}
else
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
zipping("#{make_zip_name(work)}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}
end
out_file
end
def zip_contestant_work_by_user(work)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
digests = []
work.attachments.each do |attach|
if File.exist?(attach.diskfile)
homeworks_attach_path << attach.diskfile
digests << attach.digest
else
not_exist_file << attach.filename
digests << 'not_exist_file'
end
end
#单个文件的话,不需要压缩,只改名
out_file = nil
if homeworks_attach_path.size == 1
out_file = find_or_pack(work.work_id, work.user_id, digests.sort){
des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}"
FileUtils.cp homeworks_attach_path.first, des_path
des_path
}
else
out_file = find_or_pack(work.work_id, work.user_id, digests.sort){
zipping("#{make_zip_name(work)}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}
end
out_file
end
def find_or_pack(homework_id, user_id, digests)
raise "please given a pack block" unless block_given?
out_file = ZipPack.packed?(homework_id, user_id, digests.sort)
unless out_file && out_file.file_valid?
file = yield
ZipPack.where(homework_id: homework_id,
user_id: user_id).delete_all
out_file = ZipPack.create(homework_id: homework_id,
user_id: user_id,
file_digest: Trustie::Utils.digest(file),
file_path: file,
pack_size: File.size(file),
file_digests: digests.join(',')
)
else
out_file.pack_times = out_file.pack_times + 1
out_file.save
end
out_file
end
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[])
rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip"
# 文件名过长
if rename_zipfile.size > MAX_PATH
rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4]
end
zipfile_name = "#{output_path}/#{rename_zipfile}"
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files_paths.each do |filename|
rename_file = File.basename(filename)
rename_file = filename_to_real( File.basename(filename)) if is_attachment
begin
zipfile.add(rename_file, filename)
rescue Exception => e
zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)}
next
end
end
unless not_exist_file.empty?
zipfile.get_output_stream('FILE_LOST.txt'){|os| os.write l(:label_file_lost) + not_exist_file.join(',').to_s}
end
end
zipfile_name
end
# 合理分配文件打包
# 如果小于 pack_attachment_max_size, 则返回单个文件
# 反之则切分为多个文件组返回
def split_pack_files(files, pack_attachment_max_size)
max_size = 0
last_files = []
ret_files = []
files.each_with_index do |f,i|
if (max_size += File.size(f)) > pack_attachment_max_size
max_size = 0
if last_files.empty? #如果单个文件超过大小,也将此文件作为一组
ret_files << {files: [f], count: 1, index: ret_files.count+1}
last_files.clear
else
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1}
last_files.clear
redo
end
else
last_files << f
end
end
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} unless last_files.empty?
ret_files
end
def detect_content_type(name)
content_type = Redmine::MimeType.of(name)
content_type.to_s
end
def filename_to_real(name)
attach = Attachment.find_by_disk_filename(name)
attach.filename
end
end

View File

@ -136,6 +136,9 @@
<p>在这里您的创新意识和创新潜力将得到充分发挥目前已有超过200所高校和科研机构在平台中开展在线协同开发、协同学习和协同研究。</p>
</div>
<div class="new_login_box fr mr45 mt100">
<% if @message %>
<p class="f14 mb5" style=" color:#fff;"><i class="icon-ok mr5"></i><%= h @message %></p>
<% end %>
<h2 class="new_login_h2">登录
<a href="<%= register_url_without_domain %>" class="fr mt5">立即注册</a><div class="cl"></div>
</h2>

View File

@ -0,0 +1,88 @@
<h3>
<%=l(:label_contest_plural)%>
</h3>
<%= form_tag({}, :method => :get) do %>
<fieldset>
<label for='name'>
竞赛:
</label>
<%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '竞赛名称' %>
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
<%= link_to l(:button_clear), {:controller => 'admin', :action => 'contests'}, :class => 'icon icon-reload' %>
</fieldset>
<% end %>
&nbsp;
<div class="autoscroll">
<table class="list" style="width: 100%;table-layout: fixed">
<thead>
<tr>
<th style="width: 40px;">
序号
</th>
<th style="width: 180px;">
竞赛
</th>
<th style="width: 40px;">
公开
</th>
<th style="width: 80px;">
创建者
</th>
<th style="width: 40px;">
成员数
</th>
<th style="width: 40px;">
提交数
</th>
<th style="width: 80px;">
创建于
</th>
<th style="width: 130px;">
最新动态时间
</th>
</tr>
</thead>
<tbody>
<% @contests.each do |contest| %>
<tr class="<%= cycle("odd", "even") %>">
<td style="text-align: center;">
<%= contest.id %>
</td>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=contest.name%>'>
<span>
<%= link_to contest.name, contest_path(contest), :target => '_blank' %>
</span>
</td>
<td align="center">
<%= checked_image contest.is_public %>
</td>
<td style="text-align: center; white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=contest.user.show_name%>'>
<span>
<%= link_to contest.user.show_name, user_path(contest.user), :target => '_blank' %>
</span>
</td>
<td align="center">
<%=contest.contest_members.count %>
</td>
<td align="center">
<%=contest.works.count %>
</td>
<td align="center">
<%= format_date(contest.created_at) %>
</td>
<td align="center">
<%= contest.contest_acts.order("updated_at asc").last.updated_at.strftime('%Y-%m-%d %H:%M:%S') %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="pagination">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
</div>
<% html_title(l(:label_project_plural)) -%>

View File

@ -38,6 +38,9 @@
<th style="width: 60px;">
<%=l(:field_created_on)%>
</th>
<th style="width: 30px;">
开源检索
</th>
</tr>
</thead>
<tbody>
@ -57,6 +60,7 @@
<td class="center">
<%= format_date(syllabus.created_at) %>
</td>
<td></td>
</tr>
<% courses = syllabus.courses.not_deleted %>
<% courses.each do |course| %>
@ -75,6 +79,7 @@
<td class="center">
<%= format_date(course.created_at) %>
</td>
<td style="text-align: center;"><a><%= course.try(:os_allow) == 0 ? 不允许 : 允许 %></a></td>
</tr>
<% end %>
<% end %>

View File

@ -0,0 +1,31 @@
<% if source.id == 786 %>
<img src="/images/game/appbanner.jpg" width="968" height="110" id="avatar_image"/>
<% else %>
<%= image_tag(url_to_avatar(source), :width => "968", :height => "110", :id => "avatar_image", :alt => "竞赛图片")%>
<% end %>
<% if is_admin %>
<a class="banner-inner" href="javascript:void(0)" onclick="$('#upload_contest_logo').click();"></a>
<a class="banner-notice" href="javascript:void(0)" onclick="$('#upload_contest_logo').click();">点击替换图片(968*110)</a>
<%= file_field_tag 'avatar[image]',
:id => 'upload_contest_logo',
:class => 'undis upload_file',
:size => "1",
:multiple => true,
:data => {
:max_file_size => Setting.upload_avatar_max_size,
:max_file_size_message => l(:error_upload_avatar_to_large, :max_size => number_to_human_size(Setting.upload_avatar_max_size.to_i)),
:max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
:file_type => Redmine::Configuration['pic_types'].to_s,
:type_support_message => l(:error_pic_type),
:upload_path => upload_avatar_path(:format => 'js'),
:description_placeholder => nil ,# l(:label_optional_description)
:source_type => source.class.to_s,
:source_id => source.id.to_s,
:is_direct => 0
} %>
<!--</span>-->
<%#= content_for(:header_tags) do %>
<%#= javascript_include_tag '/javascripts/jq-upload/jquery.ui.widget', '/javascripts/jq-upload/jquery.iframe-transport', '/javascripts/jq-upload/jquery.fileupload', '/javascripts/jq-upload/upload' %>
<%# end %>
<% end %>
<div class="cl"></div>

View File

@ -1,4 +1,4 @@
<% if @is_direct == '1' && (@source_type=='User'|| @source_type == 'Course' || @source_type == 'Project' || @source_type == 'Organization') %>
<% if @is_direct == '1' && (@source_type=='User'|| @source_type == 'Course' || @source_type == 'Project' || @source_type == 'Organization'|| @source_type == 'Contest') %>
var imgSpan = $("img[nhname='avatar_image']");
imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'});
<% else %>

View File

@ -0,0 +1,80 @@
<div class = "cl"> </div>
<div id="course-boardlist">
<div class="listbox mt10" >
<p class="list-h2">讨论区列表</p>
<div class="category">
<span class="grayTxt ">排序:</span>
<%= link_to "时间", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %>
<% if @type.to_i == 1 %>
<%= link_to "", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<%= link_to "人气", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "sortTxt", :remote => true %>
<% if @type.to_i == 2 %>
<%= link_to "", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<div class="cl"></div>
</div>
<div class="bloglistbox">
<% if topics.any? %>
<% topics.each do |activity| %>
<div class="list-file">
<div><span class="item_list fl"></span>
<% if activity.parent_id.nil? %> <!--+"(帖子标题)"-->
<%= link_to activity.subject.to_s.html_safe, User.current.logged? ? board_message_path(activity.board_id, activity) : signin_url_without_domain, :class => "list-title-normal fl" %>
<% else %>
<%= link_to activity.parent.subject.to_s.html_safe, User.current.logged? ? board_message_path(activity.board_id, activity) : signin_url_without_domain, :class => "list-title-normal f1" %>
<% end %>
<% if activity.sticky == 1 %>
<span class="fl ml10 red-cir-btn">顶</span>
<% end%>
<% if activity.locked %>
<span class="fl ml10 green-cir-btn" title="已锁定">锁</span>
<% end %>
<%# u = User.where("id=?",activity.author_id).first%>
<div class="cl"></div>
</div>
<!--<div class="massages-content ml15">-->
<!--<%# if activity.parent_id.nil? %>-->
<!--<% content = activity.content %>-->
<!--<%# else %>-->
<!--<%# content = activity.parent.content %>-->
<!--<%# end %>-->
<!--<p><%#=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>content, :maxheight=>54, :maxwordsnum=>75, :maxwidth=>563} %></p>-->
<!--</div>-->
<div class="ml15 mt10">
<span class="grayTxt mr15">
发帖人:<%= link_to activity.author.show_name, user_path(activity.author), :class => "link-blue" %>
</span>
<span class="grayTxt">更新:<%= format_time(activity.children.any? ? activity.children.last[:created_on] : activity[:created_on] ) %></span>
<% all_comments = []%>
<% count=Message.where("root_id = #{activity.id}").count %>
<p class="list-info fr grayTxt"><span><%= count>0 ? "#{count}" : "0" %></span><span>回复</span><span>|</span><span><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "0" %></span><span>赞</span></p>
</div>
<div class="cl"></div>
</div>
<% end %>
<div>
<ul class="wlist" id="pages" >
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
</ul>
<div class="cl"></div>
</div>
<% else %>
<div class="icons_tishi"><img src="/images/sy/icons_smile.png" width="110" height="110" alt="" ></div>
<p class="sy_tab_con_p">没有数据可以显示!</p>
<% end %>
</div>
</div>
</div>
<script type="text/javascript">
//如果右边的博客列表比左边的高度低则将右边的高度设为与左边对齐
$(function(){
var leftHeight = $("#LSide").height()-$(".fontGrey5").height()-20;
var rightHeight = $(".homepageRight").height();
if (rightHeight < leftHeight){
var diffHeight = leftHeight - rightHeight;
var tmpHeight = $(".listbox").height()+diffHeight;
$(".listbox").css("height",tmpHeight);
}
});
</script>

View File

@ -0,0 +1,16 @@
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
$("#message_subject").focus();
});
</script>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName">
编辑帖子
</div>
</div>
<%= render :partial => 'boards/contest_new',
:locals => {:f => f, :edit_mode => edit_mode, :topic => topic, :contest => contest} %>
</div>

View File

@ -0,0 +1,194 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: true, prettify: false, init_activity: false) %>
<% end %>
<script type="text/javascript">
var first_click = true;
function nh_check_field(params){
var result=true;
if(!regexTopicSubject()) {
result=false;
return result;
}
if(params.content!=undefined){
if(params.content.isEmpty()){
result=false;
}
if(params.content.html()!=params.textarea.html() || params.issubmit==true){
params.textarea.html(params.content.html());
params.content.sync();
if(params.content.isEmpty())
{
params.contentmsg.text("描述不能为空");
params.contentmsg.css('color','#ff0000');
result=false;
}
else
{
params.contentmsg.text("填写正确");
params.contentmsg.css('color','#008000');
}
}
}
return result;
}
function init_homework_form(params){
params.form.submit(function(){
params.textarea.html(params.editor.html());
params.editor.sync();
var flag = false;
if(params.form.attr('data-remote') != undefined ){
flag = true
}
var is_checked = false;
is_checked = nh_check_field({
issubmit:true,
content:params.editor,
contentmsg:params.contentmsg,
textarea:params.textarea
});
if(first_click && is_checked){
if(flag){
first_click = false;
return true;
}else{
first_click = false;
$(this)[0].submit();
return false;
}
}
return false;
});
}
function init_homework_editor(params){
params.textarea.removeAttr('placeholder');
var editor = params.kindutil.create(params.textarea, {
resizeType : 1,minWidth:"1px",width:"100%",minHeight:"30px",height:"30px",
items : ['code','emoticons','fontname',
'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|',
'formatblock', 'fontsize', '|','indent', 'outdent',
'|','imagedirectupload','table', 'media', 'preview',"more"
],
afterChange:function(){//按键事件
var edit = this.edit;
var body = edit.doc.body;
//paramsHeight = params.kindutil.removeUnit(this.height);
edit.iframe.height(150);
this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) + 33, 150));
},
afterCreate:function(){
//init
var edit = this.edit;
var body = edit.doc.body;
edit.iframe[0].scroll = 'no';
body.style.overflowY = 'hidden';
//reset height
var edit = this.edit;
var body = edit.doc.body;
edit.html(params.textarea.innerHTML);
//paramsHeight = params.kindutil.removeUnit(this.height);
edit.iframe.height(150);
this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) , 150));
elocalStorage(message_content_editor,'topic_contest_<%=contest.id %>');
}
}).loadPlugin('paste');
return editor;
}
KindEditor.ready(function(K){
$("div[nhname='topic_form']").each(function(){
var params = {};
params.kindutil = K;
params.div_form = $(this);
params.form = $("form",params.div_form);
if(params.form==undefined || params.form.length==0){
return;
}
params.textarea = $("textarea[nhname='topic_textarea']",params.div_form);
params.contentmsg = $("#message_content_span");
params.submit_btn = $("#new_message_submit_btn");
if(params.textarea.data('init') == undefined) {
params.editor = init_homework_editor(params);
message_content_editor = params.editor;
init_homework_form(params);
params.submit_btn.click(function () {
params.form.submit();
});
params.textarea.data('init', 1);
}
});
});
</script>
<%= error_messages_for 'message' %>
<div class="resources mt10">
<div id="new_course_topic">
<div class="homepagePostBrief c_grey">
<div>
<input type="text" name="message[subject]" id="message_subject" class="InputBox w713" maxlength="128" onfocus="$('#topic_editor').show()" onkeyup="regexTopicSubject();" placeholder="发布帖子,请先输入帖子标题" value="<%= topic.subject%>" >
<p id="subjectmsg"></p>
</div>
<div id="topic_editor" style="display: none;">
<%if User.current.member_of_contest?(contest) %>
<div class="mt10">
<% if User.current.id == contest.user_id %>
<%= f.check_box :sticky, :value => topic.sticky %>
<%= label_tag 'message_sticky', l(:label_board_sticky) %>
<%= f.check_box :locked, :value => topic.locked %>
<%= label_tag 'message_locked', l(:label_board_locked) %>
<% end %>
<div class="cl"></div>
</div>
<% end %>
<div class="mt10">
<div id="message_quote" class="wiki" style="width: 92%;word-break: break-all;word-wrap: break-word;margin-left: 40px;"></div>
<%= text_area :quote,:quote,:style => 'display:none' %>
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
<%#= f.kindeditor :content, :editor_id => 'message_content_editor',
:owner_id => topic.nil? ? 0: topic.id,
:owner_type => OwnerTypeHelper::MESSAGE,
:width => '100%',
:height => 300,
:minHeight=>300,
:class => 'talk_text fl',
:input_html => { :id => 'message_content',
:class => 'talk_text fl',
:maxlength => 5000 },
at_id: topic.id, at_type: topic.class.to_s
%>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='topic_textarea' name="message[content]"><%=topic.content %></textarea>
<div class="cl"></div>
<p id="message_content_span"></p>
<p id="e_tip" class="c_grey"></p>
<p id="e_tips" class="c_grey"></p>
</div>
<div class="cl"></div>
<div class="mt10">
<div class="fl" id="topic_attachments">
<%= render :partial => 'attachments/form_course', :locals => {:container => topic, :isReply => @isReply} %>
</div>
</div>
<div class="cl"></div>
<div class="mt5">
<%if !edit_mode %>
<a href="javascript:void(0);" class="BlueCirBtnMini fr" id="new_message_submit_btn">确定</a>
<span class="fr mr10 mt3">或</span>
<a href="javascript:void(0);" class="fr mr10 mt3" onclick="reset_topic();">取消</a>
<% else %>
<a href="javascript:void(0);" class="BlueCirBtnMini fr" id="new_message_submit_btn">确定</a>
<span class="fr mr10 mt3">或</span>
<%= link_to "取消",board_message_url(topic.board, topic.root, :r => (topic.parent_id && topic.id)), :class => "fr mr10 mt3"%>
<% end %>
</div>
<div class="cl"></div>
</div>
</div>
<%#= render :partial => 'course_new_topic', :locals => {:f => f, :topic => @message} %>
<!--<li>
<div class="ml55 fl" nhname="toolbar_container"></div>
<a href="javascript:void(0);" nhname="cancelbtn" class="grey_btn fr ml10"><%#= l(:button_cancel) %></a>
<a href="javascript:void(0);" nhname="submitbtn" class="blue_btn fr " style="margin-left: 55px">
<%#= l(:button_submit)%>
</a>
<div class="cl"></div>
</li>-->
</div>
</div>

View File

@ -0,0 +1,43 @@
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
});
function reset_topic(){
$("#message_subject").val("");
$("#subjectmsg").text("");
document.getElementById("message_sticky").checked=false;
document.getElementById("message_locked").checked=false;
$("#topic_attachments").html("<%= escape_javascript(render :partial => 'attachments/form_course', :locals => {:container => Message.new, :isReply => @isReply})%>");
message_content_editor.html("");
$("#topic_editor").toggle();
}
<% if @is_new%>
$(function(){
$("#message_subject").focus();
});
<%end%>
</script>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName break_word" style="width: 600px;">
<%= @board.parent_id.nil? ? "竞赛讨论区" : "#{@board.name}" %>
</div>
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.admin_of_contest?(@board.contest)) %>
<% if is_teacher %>
<%= link_to "添加子栏目", settings_contest_path(@board.contest.id, :tab => 'boards'), :class => "link-blue fr mt5" %>
<% end %>
</div>
<div nhname="topic_form">
<% if User.current.logged? %>
<%= labelled_form_for @message, :url =>{:controller=>'messages',:action => 'new', :board_id => @board.id, :is_board => 'true'},
:html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'contest_new', :locals => {:f => f, :topic => @message, :edit_mode => false, :contest => @board.contest} %>
<% end %>
<% end %>
</div>
<%= render :partial=> 'contest_show_detail',:locals =>{:topics => @topics, :page => 0} %>
</div>

View File

@ -0,0 +1,8 @@
<%= content_for(:header_tags) do %>
<%= import_ke(enable_at: false, prettify: false) %>
<%= javascript_include_tag "create_kindeditor" %>
<% end %>
<% if @topics || topics %>
<%= render :partial => 'boards/contest_boardlist', :locals => {:topics => @topics ? @topics: topics , :is_course => 1, :is_board=>1} %>
<% end %>

View File

@ -2,4 +2,8 @@
$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>");
<% course_board = @course.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>");
<% elsif @contest %>
$("#game-setting-content-3").html("<%=escape_javascript(render :partial => 'contests/boards') %>");
<% contest_board = @contest.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/contest_board_children_list', :locals => {:contest_board => contest_board})%>");
<% end %>

View File

@ -2,4 +2,9 @@
$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>");
<% course_board = @course.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>");
<% elsif @contest %>
hideModal();
$("#game-setting-content-3").html("<%=escape_javascript(render :partial => 'contests/boards') %>");
<% contest_board = @contest.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/contest_board_children_list', :locals => {:contest_board => contest_board})%>");
<% end %>

View File

@ -36,6 +36,8 @@
<%= render :partial => 'project_show', locals: {:topics => @topics, :page => 0, project: @project} %>
<% elsif @course %>
<%= render :partial => 'course_show', :locals => {:topics => @topics, :page => 0, :course => @course} %>
<% elsif @contest %>
<%= render :partial => 'contest_show', :locals => {:topics => @topics, :page => 0, :contest => @contest} %>
<% end %>

View File

@ -2,4 +2,9 @@
$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>");
<% course_board = @course.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>");
<% elsif @contest %>
hideModal();
$("#game-setting-content-3").html("<%=escape_javascript(render :partial => 'contests/boards') %>");
<% contest_board = @contest.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/contest_board_children_list', :locals => {:contest_board => contest_board})%>");
<% end %>

View File

@ -2,4 +2,8 @@
$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>");
<% course_board = @course.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>");
<% elsif @contest %>
$("#game-setting-content-3").html("<%=escape_javascript(render :partial => 'contests/boards') %>");
<% contest_board = @contest.boards.where("parent_id is NULL").first %>
$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/contest_board_children_list', :locals => {:contest_board => contest_board})%>");
<% end %>

View File

@ -1,12 +1,14 @@
<%if @contest%>
<% if @create_member_error_messages%>
alert("<%= @create_member_error_messages%>");
notice_box("<%= @create_member_error_messages%>");
//alert("<%= @create_member_error_messages%>");
<% else %>
$('#game-setting-content-2').html('<%= escape_javascript(render :partial => 'contests/members') %>');
$("#admin_num").html("<%= contest_managers(@contest).count %>");
$("#judge_num").html("<%= contest_judges(@contest).count %>");
$("#contestant_num").html("<%= contest_contestants(@contest).count %>");
alert("添加成功");
notice_box("添加成功");
//alert("添加成功");
<% end%>
hideOnLoad();
<%end%>

View File

@ -1,3 +1,4 @@
hideModal();
$('#game-setting-content-2').html('<%= escape_javascript(render :partial => 'contests/members') %>');
$("#admin_num").html("<%= contest_managers(@contest).count %>");
$("#judge_num").html("<%= contest_judges(@contest).count %>");

View File

@ -0,0 +1,43 @@
<%= form_for('new_form', :remote => true, :method => :post,:url => add_score_contestant_work_path(work.id),:id=>'add_score_'+work.id.to_s) do |f|%>
<li >
<span class="tit_fb"> 评价:</span>
<%= f.text_area 'user_message', :class => 'hwork_ping_text', :id => 'score_comment_'+work.id.to_s, :placeholder => l(:text_caracters_maximum,:count=>500),:maxlength => 500 %>
<div class="cl"></div>
</li>
<p id="hint_message_<%=work.id %>" style="margin-left: 65px;"></p>
<li >
<span class="tit_fb mt2"> 评分:</span>
<input type="number" name="score" id="score_<%= work.id%>" value="<%= (score.nil? || score.score.nil?) ? -1 : score.score%>" min="-1" max="100" size="4" data-units="dollars" />
<span class="ml5">分</span>
<span id="score_notice_span_<%= work.id%>" class="ml5 c_red" style="display: none;">未评分</span>
<div class="cl"></div></li>
<li >
<span class="tit_fb"> 批阅结果:</span>
<div>
<%= render :partial => 'student_work/student_work_attachment_form', :locals => {:work => work,:score => score} %>
</div>
<div class="cl"></div>
<span class="c_red ml5" style="display: none;" id="none_notice_<%= work.id%>">评语、评分、批阅结果至少有一个不为空。</span>
<a href="javascript:void(0);" id="work_submit_<%= work.id %>" class="blue_n_btn fr evaluation_submit" onclick="score_submit('<%=work.id %>');">提交</a>
<div class="cl"></div>
</li>
<% end%>
<script type="text/javascript">
var first_click_score = true;
function score_submit(id){
if ($.trim($('#score_comment_'+id).val()) == "") {
$('#hint_message_'+id).html("为了对参赛者的作品负责,请您务必填写评语");
$("#hint_message_"+id).css('color','#ff0000');
$("#score_comment_"+id).focus();
} else if (parseFloat($("#score_"+id).val()) == -1) {
$('#score_notice_span_'+id).html("请先评分");
$('#score_notice_span_'+id).show();
$("#score_"+id).focus();
}
else if(first_click_score) {
first_click_score = false;
$("#work_submit_"+id).parent().parent().submit();
$('#about_hwork_'+id).html('');
}
}
</script>

View File

@ -0,0 +1,9 @@
<div class="syllabus_courses_box">
<% @stundet_works.each_with_index do |student_work, i| %>
<div class="syllabus_courses_list" id="student_work_<%= student_work.id%>" style="cursor: default; background-color:#f6f6f6;">
<%= render :partial => 'contest_evaluation_group_work', :locals => {:student_work => student_work} %>
</div>
<div id="about_hwork_<%= student_work.id %>" class="about_hwork"></div>
<% end %>
</div>
<div class="cl"></div>

View File

@ -0,0 +1,68 @@
<div class="sy_courses_open f14 fontGrey3">
<div>
<span class="fl" style="width:280px;" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">
<span class="hidden fl" style="max-width:220px;"><%= student_work.name %></span>
<span class="fontGrey2 ml5 fl">
<% if student_work.work_status %>
<%= get_status student_work.work_status %>
<% end %>
</span>
</span>
<a href="javascript:void(0)" class="linkBlue2 fr" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">评分</a>
<div class="cl"></div>
<% if @contestwork.work_detail_group.base_on_project %>
<div class="pr">
<span class="fl fontGrey2">关联项目:</span>
<div class="fl projectName">
<% if student_work.project.status != 9 && (student_work.project.is_public || User.current.member_of?(student_work.project) || User.current.admin? || User.current.admin_of_contest?(@contestwork.contest) || User.current.judge_of_contest?(@contestwork.contest)) %>
<%= link_to student_work.project.name, project_path(student_work.project.id), :class => 'link-blue fl hidden', :style => "max-width:550px;", :title => "项目名称", :target => "_blank" %>
<% elsif student_work.project.status != 9 %>
<span class="fontBlue fr hidden" style="max-width:550px;" title="该项目是私有的"><%= student_work.project.name %></span>
<% else %>
<span class="fontGrey2 fr hidden" style="max-width:550px;" title="该项目已删除"><%= student_work.project.name %>(已删除)</span><% end %>
<% project = student_work.project %>
<div class="score-tip none tl f12" style="width:300px; top:-48px; right:-372px;">
<em style="bottom:45px;"></em>
<font style="bottom:45px;"></font>
<p class="fb break_word mw280"><%= project.name %><%= project.status == 9 ? "(已删除)" : ""%></p>
<p class="mb10">
<span class="mr15">创建者:<%= project.creater %></span><span>成员数量:<%= project.members.count %></span></p>
<% project_score = project.project_score %>
<p>项目综合得分:<%= project.status == 9 ? 0 : static_project_score(project_score).to_i %></p>
<% if project.status != 9 %>
<p>= 代码提交得分 + issue得分 + 资源得分 + 帖子得分</p>
<p>= <%= (project_score.changeset_num||0) * 4 %>
+ <%= project_score.issue_num * 4 + project_score.issue_journal_num %> + <%= project_score.attach_num * 5 %>
+ <%= project_score.board_num * 2 + project_score.board_message_num + project_score.news_num %></p>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
<div class="cl"></div>
</div>
<div class="fl sy_p_grey" style="margin-left: 0px;" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">
<span class="fl" style="width:180px;">提交时间:<%= format_date(student_work.commit_time) %></span>
<span class="fl" style="width:105px; text-align: center">人数:<%=student_work.contestant_work_projects.count %>人</span>
<div class="flex-container fl" style="width:400px;">
<div class="flex-cell">我的评分:
<% my_score = ContestantWorkScore.where(:user_id => User.current.id,:contestant_work_id => student_work.id,:reviewer_role => 2).last %>
<span class="<%= my_score.nil? ? 'c_grey' : score_color(my_score.score) %>"><%= my_score.nil? ? "--" : format("%.1f",my_score.score)%></span>
</div>
</div>
</div>
<div class="cl"></div>
<script>
$(".projectName").mouseenter(function () {
$(this).children().next().show();
}).mouseleave(function () {
$(this).children().next().hide();
});
</script>

View File

@ -0,0 +1,29 @@
<table class="hwork-table-wrap" id="homework_table">
<tr class="b_grey hworkH30">
<th class="hworkList40 hworkH30 pl5 pr5">序号</th>
<th class="hworkList50">&nbsp;</th>
<th class="hworkList230 pl5 pr5 hide-text">
姓名
</th>
<th class="hworkList190">
提交时间
</th>
<th class="hworkList140">
我的评分
</th>
<th class="hworkList40 pl5 pr5 hide-text">
</th>
</tr>
<%# end %>
<% @stundet_works.each_with_index do |student_work, i| %>
<% score_open = true %>
<a name="<%= student_work.id%>"></a>
<%= render :partial => "contest_evaluation_work", :locals => {:student_work => student_work, :index => i, :score_open => score_open} %>
<tr>
<td colspan="12">
<div id="about_hwork_<%= student_work.id %>" class="about_hwork">
</div>
</td>
</tr>
<% end %>
</table>

View File

@ -1,9 +1,16 @@
<div class="syllabus_courses_box">
<% if @is_judge && @contestwork.online_evaluation && @contestwork.work_status < 3 %>
<div class="pro_new_info mt50" style="width:720px;height:405px;">
<div class="icons_tishi"><img src="/images/new_project/icons_smile.png" width="110" height="110" alt=""></div>
<p class="sy_tab_con_p ">在线评审启动之前,无法查看具体作品</p>
</div>
<% else %>
<div class="syllabus_courses_box">
<% @stundet_works.each_with_index do |student_work, i| %>
<div class="syllabus_courses_list" id="student_work_<%= student_work.id%>" onclick="show_student_work('<%= contestant_work_path(student_work)%>');" style="cursor: default; background-color:#f6f6f6;">
<div class="syllabus_courses_list" id="student_work_<%= student_work.id%>" style="cursor: default; background-color:#f6f6f6;">
<%= render :partial => 'contest_evaluation_un_group_work', :locals => {:student_work => student_work} %>
</div>
<div id="about_hwork_<%= student_work.id %>" class="about_hwork"></div>
<% end %>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
<% end %>

View File

@ -1,6 +1,6 @@
<div class="sy_courses_open f14 fontGrey3">
<div>
<span class="fl" style="width:280px;">
<span class="fl" style="width:280px;" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">
<span class="hidden fl" style="max-width:220px;"><%= student_work.name %></span>
<span class="fontGrey2 ml5 fl">
<% if student_work.work_status %>
@ -8,6 +8,7 @@
<% end %>
</span>
</span>
<a href="javascript:void(0)" class="linkBlue2 fr" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">查看</a>
<div class="cl"></div>
<% if @contestwork.work_detail_group.base_on_project %>
<div class="pr">
@ -45,13 +46,37 @@
</div>
<div class="cl"></div>
</div>
<div class="fl sy_p_grey" style="margin-left: 0px;">
<div class="fl sy_p_grey" style="margin-left: 0px;" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">
<span class="fl" style="width:180px;">提交时间:<%= format_date(student_work.commit_time) %></span>
<span class="fl" style="width:105px; text-align: center">人数:<%=student_work.contestant_work_projects.count %>人</span>
<div class="flex-container fl" style="width:400px;">
<div class="flex-cell">评委评分:--</div>
<div class="flex-cell">最终成绩:--</div>
<div class="flex-cell">评委评分:
<span class="<%= score_color student_work.judge_score %>"><%=student_work.judge_score.nil? ? "--" : format("%.1f",student_work.judge_score) %></span>
<% unless student_work.judge_score.nil? %>
<span class="<%= score_color student_work.judge_score %>">(<%= student_work.contestant_work_scores.where(:reviewer_role => 2).group_by(&:user_id).count%>)</span>
<% end %>
</div>
<div class="flex-cell student_final_scor_info pr">最终成绩:
<span class="<%= score_color student_work.work_score %>"><%=student_work.work_score.nil? ? "--" : format("%.1f",student_work.work_score) %></span>
<% unless student_work.work_score.nil? %>
<div class="contest-group-score-tip none tl" style="line-height: 18px;">
<em></em>
<font></font>
评委平均分
<span class="c_red">&nbsp;<%= format("%.1f",student_work.judge_score < 0 ? 0 : student_work.judge_score)%>&nbsp;</span>分<br/>
<% if !@contestwork.score_valid && student_work.contestant_work_scores.where(:reviewer_role => 2).group_by(&:user_id).count > 2 %>
<% work_scores = student_work.contestant_work_scores.where(:reviewer_role => 2).order("score desc") %>
去除最高分
<span class="c_red">&nbsp;<%= format("%.1f",work_scores.first.score < 0 ? 0 : work_scores.first.score) %>&nbsp;</span>分<br/>
去除最低分
<span class="c_red">&nbsp;<%= format("%.1f",work_scores.last.score < 0 ? 0 : work_scores.last.score) %>&nbsp;</span>分<br/>
<% end %>
作品最终成绩为
<span class="c_red">&nbsp;<%= format("%.1f",student_work.work_score < 0 ? 0 : student_work.work_score)%>&nbsp;</span>分<br/>
</div>
<% end %>
</div>
</div>
</div>
<div class="cl"></div>

View File

@ -1,33 +1,29 @@
<table class="hwork-table-wrap" id="homework_table">
<%# if @homework.homework_type == 1 %>
<%#= render :partial => 'evaluation_un_common_title' %>
<%# elsif @homework.homework_type == 2 %>
<%#= render :partial => 'evaluation_un_pro_title' %>
<%# elsif @homework.homework_type == 3 %>
<%#= render :partial => 'evaluation_un_group_title' %>
<%# else %>
<%# end %>
<% if @is_judge && @contestwork.online_evaluation && @contestwork.work_status < 3 %>
<div class="pro_new_info mt50" style="width:720px;height:405px;">
<div class="icons_tishi"><img src="/images/new_project/icons_smile.png" width="110" height="110" alt=""></div>
<p class="sy_tab_con_p ">在线评审启动之前,无法查看具体作品</p>
</div>
<% else %>
<table class="hwork-table-wrap" id="homework_table">
<tr class="b_grey hworkH30">
<th class="hworkList40 hworkH30 pl5 pr5">序号</th>
<th class="hworkList50">&nbsp;</th>
<th class="hworkList190 pl5 pr5 hide-text">
<th class="hworkList230 pl5 pr5 hide-text">
姓名
</th>
<th class="hworkList80 pl5 pr5 hide-text">
</th>
<th class="hworkList130">
状态
提交时间
</th>
<th class="hworkList100">
评委评分
</th>
<th class="hworkList100">
最终成绩
</th>
<th class="hworkList40 pl5 pr5 hide-text">
</th>
</tr>
<%# end %>
<% @stundet_works.each_with_index do |student_work, i| %>
<% score_open = true %>
<a name="<%= student_work.id%>"></a>
@ -39,4 +35,5 @@
</td>
</tr>
<% end %>
</table>
</table>
<% end %>

View File

@ -3,24 +3,42 @@
<td class="hworkPortrait pr10 float-none">
<%= link_to(image_tag(url_to_avatar(student_work.user),:width =>"40",:height => "40",:style => "display:block;"),user_path(student_work.user), :target => '_blank') %>
</td>
<td class="hworkStName190 pr10 float-none hidden" title="<%= student_work.user.show_name%>" style="cursor:pointer; text-align: center;">
<td class="hworkList230 pl5 pr5 float-none hidden" title="<%= student_work.user.show_name%>" style="cursor:pointer; text-align: center;">
<%= link_to student_work.user.show_name ,user_path(student_work.user), :target => '_blank' %>
</td>
<td class="hworkList80 student_work_<%= student_work.id%>" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">
</td>
<td class="hworkList130 c_grey student_work_<%= student_work.id%>" onclick="show_student_work('<%= contestant_work_path(student_work)%>');" style="cursor: pointer;">
<% if student_work.work_status%>
<%=get_status student_work.work_status %>
<%=format_time student_work.commit_time %>
</td>
<td class="hworkList100 <%= score_color student_work.judge_score %>">
<%=student_work.judge_score.nil? ? "--" : format("%.1f",student_work.judge_score) %>
<% unless student_work.judge_score.nil? %>
<span>(<%= student_work.contestant_work_scores.where(:reviewer_role => 2).group_by(&:user_id).count%>)</span>
<% end %>
</td>
<td class="hworkList100 <%= score_color nil %>">
--
</td>
<td class="hworkList100 <%= score_color nil %> student_final_scor_info pr">
--
<td class="hworkList100 <%= score_color student_work.work_score %> student_final_scor_info pr">
<%=student_work.work_score.nil? ? "--" : format("%.1f",student_work.work_score) %>
<% unless student_work.work_score.nil? %>
<div class="contest-score-tip none tl" style="line-height: 18px;">
<em></em>
<font></font>
评委平均分
<span class="c_red">&nbsp;<%= format("%.1f",student_work.judge_score < 0 ? 0 : student_work.judge_score)%>&nbsp;</span>分<br/>
<% if !@contestwork.score_valid && student_work.contestant_work_scores.where(:reviewer_role => 2).group_by(&:user_id).count > 2 %>
<% work_scores = student_work.contestant_work_scores.where(:reviewer_role => 2).order("score desc") %>
去除最高分
<span class="c_red">&nbsp;<%= format("%.1f",work_scores.first.score < 0 ? 0 : work_scores.first.score) %>&nbsp;</span>分<br/>
去除最低分
<span class="c_red">&nbsp;<%= format("%.1f",work_scores.last.score < 0 ? 0 : work_scores.last.score) %>&nbsp;</span>分<br/>
<% end %>
作品最终成绩为
<span class="c_red">&nbsp;<%= format("%.1f",student_work.work_score < 0 ? 0 : student_work.work_score)%>&nbsp;</span>分<br/>
</div>
<% end %>
</td>
<td class="hworkList40 student_work_<%= student_work.id%>">
<a href="javascript:void(0)" class="linkBlue2" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">查看</a>
</td>
<td><div style="position:relative;"><div class="hworkTip" style="display: none" id="work_click_<%= student_work.id%>"><em></em><span></span><font class="fontGrey2">点击查看详情</font></div></div></td>
</tr>

View File

@ -0,0 +1,33 @@
<tr class="hworkListRow" id="student_work_<%= student_work.id%>">
<td class="hworkList40 pl5 pr5" id="work_num_<%=student_work.id %>"><%=index + 1 %></td>
<td class="hworkPortrait pr10 float-none">
<%= link_to(image_tag(url_to_avatar(student_work.user),:width =>"40",:height => "40",:style => "display:block;"),user_path(student_work.user), :target => '_blank') %>
</td>
<td class="hworkList230 pl5 pr5 float-none hidden" title="<%= student_work.user.show_name%>" style="cursor:pointer; text-align: center;">
<%= link_to student_work.user.show_name ,user_path(student_work.user), :target => '_blank' %>
</td>
<td class="hworkList190 c_grey student_work_<%= student_work.id%>" onclick="show_student_work('<%= contestant_work_path(student_work)%>');" style="cursor: pointer;">
<%=format_time student_work.commit_time %>
</td>
<% my_score = ContestantWorkScore.where(:user_id => User.current.id,:contestant_work_id => student_work.id,:reviewer_role => 2).last %>
<td class="hworkList140 <%= my_score.nil? ? 'c_grey' : score_color(my_score.score) %> student_final_scor_info pr">
<%= my_score.nil? ? "--" : format("%.1f",my_score.score)%>
</td>
<td class="hworkList40 student_work_<%= student_work.id%>">
<a href="javascript:void(0)" class="linkBlue2" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">评分</a>
</td>
<td><div style="position:relative;"><div class="hworkTip" style="display: none" id="work_click_<%= student_work.id%>"><em></em><span></span><font class="fontGrey2">点击进行评分</font></div></div></td>
</tr>
<%# end %>
<script type="text/javascript">
$(".student_work_<%= student_work.id%>").mouseenter(function(){
if($("#about_hwork_<%= student_work.id%>").html().trim() == "") {
$("#work_click_<%= student_work.id%>").show();
}
}).mouseleave(function(){
$("#work_click_<%= student_work.id%>").hide();
}).mouse;
</script>

View File

@ -13,12 +13,12 @@
<% my_work = cur_user_works_for_work @contestwork %>
<% if !@is_teacher && !@is_judge && my_work.nil? && User.current.member_of_contest?(@contest) %>
<span class="f12 c_red">您尚未提交作品</span>
<% unless @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project %>
<% if @contestwork.work_status == 1 && (@contestwork.work_type != 3 ||(@contestwork.work_type == 3 && !@contestwork.work_detail_group.base_on_project)) %>
<%=link_to "提交作品", new_contestant_work_path(:work => @contestwork.id),:class => 'blueCir ml5 f12' %>
<% end %>
<% elsif !@is_teacher && !@is_judge && my_work &&Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%>
<% elsif !@is_teacher && !@is_judge && my_work && @contestwork.work_status > 1 && !@stundet_works.empty?%>
<span class="f12 c_red">截止日期已过,已提交且不可修改</span>
<% elsif !@is_teacher && !@is_judge && my_work &&Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") >= Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%>
<% elsif !@is_teacher && !@is_judge && my_work && @contestwork.work_status == 1 && !@stundet_works.empty?%>
<% if @contestwork.work_type == 3 %>
<span class="f12 c_red">组长已提交,组长还可修改</span>
<% else %>
@ -38,9 +38,17 @@
<div class="fl">
<% if @contestwork.work_type != 3%>
<% if @is_evaluation && !@stundet_works.empty? %>
<%= render :partial => "contest_evaluation_title"%>
<% else%>
<%= render :partial => "contest_evaluation_un_title"%>
<% end%>
<% else %>
<% if @is_evaluation && !@stundet_works.empty? %>
<%= render :partial => "contest_evaluation_group"%>
<% else %>
<%= render :partial => "contest_evaluation_un_group"%>
<% end%>
<% end %>
</div>
<div class="cl"></div>

View File

@ -0,0 +1,42 @@
<ul class="ping_box_ul <%= is_last ? '' : 'ping_line'%> fl">
<%= link_to image_tag(url_to_avatar(score.user), :width => "34", :height => "34"), user_path(score.user), :class => "ping_pic fl" %>
<div class="pingBoxTit">
<%= link_to score.user.show_name, user_path(score.user), :title => score.user.show_name, :class => "linkBlue fl" %>
<span class="ml5 fl">
(评委)
</span>
<% unless score.score.nil? %>
<span class="ml20 fl">评分:</span>
<a href="javascript:void(0);" class="c_orange fl" >
<%= score.score %>分
</a>
<% end %>
<!--<a href="javascript:void(0);" class="fr linkBlue mr5" onclick="$('#add_score_reply_<%#= score.id%>').slideToggle();">回复</a>-->
<span class="fr c_grey mr20">
<%=format_time score.updated_at %>
</span>
<div class="cl mb5"></div>
<p class="break_word">
<%= score.comment%>
</p>
<div class="cl"></div>
<%= render :partial => 'student_work/work_attachments', :locals => {:attachments => score.attachments} %>
<div class="cl"></div>
<!--<div id="add_score_reply_<%#= score.id%>" class="undis">-->
<!--<%#= render :partial => 'add_score_reply',:locals => {:score => score,:is_last => is_last}%>-->
<!--</div>-->
<div class="cl"></div>
<!--<div id="replay_histroy_<%#= score.id%>">-->
<!--<%# score.journals_for_messages.order("created_on desc").each do |jour|%>-->
<!--<%# show_real_name = @is_teacher || score.reviewer_role != 3 || @contestwork.work_status != 3 %>-->
<!--<%#= render :partial => 'jour_replay',:locals => {:jour => jour, :show_real_name => show_real_name || jour.user == User.current}%>-->
<!--<%# end%>-->
<!--</div>-->
<div class="cl"></div>
</div>
</ul>

View File

@ -0,0 +1,8 @@
<%student_work_scores.each do |student_score|%>
<div id="work_score_<%= student_score.id%>">
<%= render :partial => 'contestant_work_score',:locals => {:score => student_score,:is_last => student_score == student_work_scores.last}%>
</div>
<% end%>
<% if is_member_work && student_work_scores.empty? && !@is_teacher %>
<p class="c_red" style="text-align: center">暂无评分</p>
<% end %>

View File

@ -1,12 +1,17 @@
<div id="popbox02">
<div class="ni_con">
<div><p align='center' style='margin-top: 35px'>您已提交过作品,请不要重复提交,如果想修改作品请点击编辑。</p></div>
<div id="muban_popup_box" style="width:500px;">
<div class="muban_popup_top">
<h3 class="fl">提示</h3>
<a href="javascript:void(0);" class="muban_icons_close fr"></a>
<div class="cl"></div>
</div>
<div class="muban_popup_con clear">
<div><p align='center' style='margin-top: 30px'>您已提交过作品,请不要重复提交,如果想修改作品请点击编辑。</p></div>
<div class="cl"></div>
<div class="ni_btn mt10">
<a href="javascript:" class="tijiao" onclick="clickOK();" style="margin-bottom: 15px;margin-top:15px;" >
<a href="javascript:" class="fr sy_btn_blue mr30" onclick="clickOK();" style="margin-bottom: 15px;margin-top:15px;" >
编&nbsp;&nbsp;辑
</a>
<a href="javascript:" class="tijiao" onclick="clickCanel();" style="margin-bottom: 15px;margin-top:15px;" >
<a href="javascript:" class="fr sy_btn_grey mr5" onclick="clickCanel();" style="margin-bottom: 15px;margin-top:15px;" >
取&nbsp;&nbsp;消
</a>
</div>

View File

@ -15,7 +15,7 @@
<%=format_time work.commit_time %>
</li>
<% if work.user == User.current && Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") %>
<% if work.user == User.current && @contestwork.work_status == 1 %>
<!-- 我的作业 && 匿评作业 && 未开启匿评,显示编辑和删除按钮 -->
<li class="fr" >
<%= link_to("", contestant_work_path(work),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "pic_del",:title=>"删除") %>
@ -75,15 +75,15 @@
<% end%>
<div class="cl"></div>
</li>
<!--<li >-->
<!--<%# if @is_teacher || (@homework.homework_detail_manual.comment_status == 2 && !is_my_work)%>-->
<!--&lt;!&ndash; 老师 || 开启匿评状态 && 不是当前用户自己的作品 &ndash;&gt;-->
<!--<div id="add_student_score_<%#= work.id%>" class="mt10 evaluation">-->
<!--<%#= render :partial => 'add_score',:locals => {:work => work,:score => score,:is_member_work => is_member_work}%>-->
<!--</div>-->
<!--<%# end%>-->
<!--<div class="cl"></div>-->
<!--</li>-->
<li >
<% if @is_evaluation %>
<!-- 评委&&评审中 -->
<div id="add_student_score_<%= work.id%>" class="mt10 evaluation">
<%= render :partial => 'add_score',:locals => {:work => work,:score => score,:is_member_work => is_member_work}%>
</div>
<% end%>
<div class="cl"></div>
</li>
</ul>
<!--<div id="revise_attachment">-->
@ -94,7 +94,7 @@
<!--<ul>-->
<!--<li >-->
<!--<%# if @is_teacher %>-->
<!--&lt;!&ndash; 老师 &ndash;&gt;-->
<!--<!-- 老师 -->-->
<!--<div id="add_student_score_<%#= work.id%>" class="mt10 evaluation">-->
<!--<%#= render :partial => 'add_score',:locals => {:work => work,:score => score,:is_member_work => is_member_work}%>-->
<!--</div>-->
@ -104,9 +104,9 @@
<!--</ul>-->
<% end %>
<!--<div class="ping_box fl" id="score_list_<%#= work.id%>" style="<%#= student_work_scores.empty? ? 'padding:0px;' : ''%>">-->
<!--<%#= render :partial => 'student_work_score_records', :locals => {:student_work_scores => student_work_scores, :is_member_work => is_member_work} %>-->
<!--</div>-->
<div class="ping_box fl" id="score_list_<%= work.id%>" style="<%= student_work_scores.empty? ? 'padding:0px;' : ''%>">
<%= render :partial => 'contestant_work_score_records', :locals => {:student_work_scores => student_work_scores, :is_member_work => is_member_work} %>
</div>
<div class="cl"></div>
<!---ping_box end--->
<a href="javascript:void(0);" class="linkBlue mt5 mb5" style="margin-left:auto; margin-right: auto; display:block; width: 24px;" onclick="$('#about_hwork_<%= work.id%>').html('');">收起</a>

View File

@ -1,25 +1,34 @@
<div id="popbox02">
<div class="ni_con">
<div id="muban_popup_box" style="width:500px;">
<div class="muban_popup_top">
<h3 class="fl">作品确认</h3>
<a href="javascript:void(0);" class="muban_icons_close fr"></a>
<div class="cl"></div>
</div>
<div class="muban_popup_con clear">
<div class="clear mt15 ml20" style="color:#808181;">
<span class="f16 fontBlue fb">请您确认刚刚上传的作品信息</span>
<p class="f14 mt5 break_word">
<span class="fb">作品名称:</span><%=@student_work.name%>
<span class="fb">作品名称:</span><%= @student_work.name %>
</p>
<div class="f14 mt5 break_word" style="max-width: 425px; color:#808181; max-height:300px; overflow-x:hidden; overflow-y: auto;">
<div class="f14 mt5 break_word" style="max-width: 425px; max-height:300px; overflow-x:hidden; overflow-y: auto;">
<div class="fb fl dis">作品描述:</div>
<div class="upload_img fl" style="max-width: 330px;"><%=@student_work.description.html_safe %></div>
<div class="upload_img fl" style="max-width: 330px;"><%= @student_work.description.html_safe %></div>
<div class="cl"></div>
</div>
<p class="mt5">
<span class="fl fb mr30">附</span><span class="fb fl">件:</span>
<% if @student_work.attachments.empty? %>
<span class="fl c_red"><%= "无附件"%></span>
<span class="fl c_red">无附件</span>
<% else %>
<div class="fl grey_c">
<% @student_work.attachments.each_with_index do |attachment,i| %>
<div id="attachment_<%= attachment.id%>">
<% @student_work.attachments.each_with_index do |attachment, i| %>
<div id="attachment_<%= attachment.id %>">
<%= link_to_short_attachment attachment, :class => 'link_file_a fl', :download => true -%>
<%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :format => 'js'), :method => 'delete', :remote => true, :title => '删除', :class => 'remove-upload fl', :confirm => l(:text_are_you_sure)) %>
<span class="ml5 fl">(<%= number_to_human_size attachment.filesize %>)</span>
<div class="cl"></div>
</div>
<% end -%>
@ -29,11 +38,12 @@
</p>
<div class="cl"></div>
<div class="ni_btn mt10">
<a href="javascript:" class="tijiao" onclick="clickOK();" style="margin-bottom: 15px; margin-left: 55px;" >
<a href="javascript:" class="sy_btn_blue" onclick="clickOK();" style="margin-left: 55px;">
确&nbsp;&nbsp;定
</a>
</div>
</div>
</div>
</div>
<script type="text/javascript">

View File

@ -1,25 +1,34 @@
<div id="popbox02">
<div class="ni_con">
<div id="muban_popup_box" style="width:500px;">
<div class="muban_popup_top">
<h3 class="fl">作品确认</h3>
<a href="javascript:void(0);" class="muban_icons_close fr"></a>
<div class="cl"></div>
</div>
<div class="muban_popup_con clear">
<div class="clear mt15 ml20" style="color:#808181;">
<span class="f16 fontBlue fb">请您确认刚刚上传的作品信息</span>
<p class="f14 mt5 break_word">
<span class="fb">作品名称:</span><%=@student_work.name%>
<span class="fb">作品名称:</span><%= @student_work.name %>
</p>
<div class="f14 mt5 break_word" style="max-width: 425px; color:#808181; max-height:300px; overflow-x:hidden; overflow-y: auto;">
<div class="fb fl dis">作品描述:</div>
<div id="worksDescription" class="upload_img fl" style="max-width: 330px;"><%=@student_work.description.html_safe %></div>
<div id="worksDescription" class="upload_img fl" style="max-width: 330px;"><%= @student_work.description.html_safe %></div>
<div class="cl"></div>
</div>
<p class="mt5">
<span class="fl fb mr30">附</span><span class="fb fl">件:</span>
<% if @student_work.attachments.empty? %>
<span class="fl c_red"><%= "无附件"%></span>
<span class="fl c_red"><%= "无附件" %></span>
<% else %>
<div class="fl grey_c">
<% @student_work.attachments.each_with_index do |attachment,i| %>
<div id="attachment_<%= attachment.id%>">
<% @student_work.attachments.each_with_index do |attachment, i| %>
<div id="attachment_<%= attachment.id %>">
<%= link_to_short_attachment attachment, :class => 'link_file_a fl', :download => true -%>
<%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :format => 'js'), :method => 'delete', :remote => true, :title => '删除', :class => 'remove-upload fl', :confirm => l(:text_are_you_sure)) %>
<span class="ml5 fl">(<%= number_to_human_size attachment.filesize %>)</span>
<div class="cl"></div>
</div>
<% end -%>
@ -29,10 +38,11 @@
</p>
<div class="cl"></div>
<div class="ni_btn mt10">
<a href="javascript:" class="tijiao" onclick="clickOK();" style="margin-bottom: 15px;margin-top:15px;" >
<a href="javascript:" class="fr sy_btn_blue mr45" onclick="clickOK();" style="margin-bottom: 15px;margin-top:15px;">
确&nbsp;定
</a>
<%= link_to("重 试", retry_work_contestant_work_path(@student_work.id),:class => "tijiao",:style =>"margin-bottom: 15px;margin-top:15px;",:remote => true)%>
<%= link_to("重 试", retry_work_contestant_work_path(@student_work.id), :class => "fr sy_btn_blue mr5", :style => "margin-bottom: 15px;margin-top:15px;", :remote => true) %>
</div>
</div>
</div>
</div>

View File

@ -7,7 +7,7 @@
</div>
<div class="homepagePostTitle hidden fl m_w505">
<% index = get_work_index(homework, is_teacher) %>
<%= link_to "<span class='fontBlue2'>题目#{index + 1}</span>".html_safe + homework.name,contestant_works_path(:work => homework.id),:class => "postGrey"%>
<%= link_to homework.name,contestant_works_path(:work => homework.id),:class => "postGrey"%>
</div>
<%=get_cw_status(homework).html_safe %>
<div class="cl"></div>

View File

@ -0,0 +1,18 @@
<% is_member_work = @contestwork.work_type == 3 && @work.contestant_work_projects.empty? %>
$("#add_student_score_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'add_score',:locals => {:work => @work,:score => @new_score,:is_member_work => is_member_work}) %>");
$('#score_<%= @work.id%>').peSlider({range: 'min'});
<% score_open = @is_teacher || @contestwork.score_open == 1 || @work.user == User.current %>
$("#score_list_<%= @work.id%>").html("<%=escape_javascript(render :partial => 'contestant_work_score_records', :locals => {:student_work_scores => @student_work_scores, :is_member_work => is_member_work}) %>");
var num = $("#work_num_<%= @work.id%>").html();
$("#score_list_<%= @work.id%>").removeAttr("style");
<% if @contestwork.work_type == 3 %>
$("#student_work_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'contest_evaluation_group_work', :locals => {:student_work => @work}) %>");
<% else %>
$("tr[id='student_work_<%= @work.id%>']").replaceWith("<%= escape_javascript(render :partial => 'contest_evaluation_work',:locals => {:student_work => @work, :index => 1, :score_open => score_open}) %>");
$("#work_num_<%= @work.id%>").html(num);
<% end %>
$("#student_work_count").html("<%=@count %>");

Some files were not shown because too many files have changed in this diff Show More