Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

dev_local_cqdsj
杨树明 5 years ago
commit 3cbca56431

@ -136,6 +136,33 @@ $(document).on('turbolinks:load', function(){
$('.sponsor-select').select2(selectOptions);
$('.allow-school-select').select2(selectOptions);
$('.manager-select').select2({
theme: 'bootstrap4',
placeholder: '请输入要添加的管理员姓名',
multiple: true,
minimumInputLength: 1,
ajax: {
delay: 500,
url: '/admins/users',
dataType: 'json',
data: function(params){
return { keyword: params.term };
},
processResults: function(data){
return { results: data.users }
}
},
templateResult: function (item) {
if(!item.id || item.id === '') return item.text;
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
},
templateSelection: function(item){
if (item.id) {
}
return item.real_name || item.text;
}
});
// 排行榜
//链接

@ -22,7 +22,7 @@ class Admins::CompetitionSettingsController < Admins::BaseController
def basic_form_params
params.permit(:identifier, :name, :sub_title, :start_time, :end_time, :mode,
:identifier, :bonus, :awards_count, :description, :course_id, :teach_start_time,
:teach_end_time, sponsor_schools: [], region_schools: [])
:teach_end_time, sponsor_schools: [], region_schools: [], manager_ids: [])
end
def nav_form_params

@ -5,6 +5,7 @@ class Competitions::CompetitionsController < Competitions::BaseController
before_action :allow_visit, except: [:index]
before_action :require_admin, only: [:update, :update_inform]
before_action :chart_visible, only: [:charts, :chart_rules]
before_action :check_manager_permission!, only: [:update_md_content]
def index
# 已上架 或者 即将上架
@ -152,6 +153,13 @@ class Competitions::CompetitionsController < Competitions::BaseController
render_forbidden unless (chart_module.present? && !chart_module.hidden) || admin_or_business?
end
def check_manager_permission!
return if current_user.admin_or_business?
return if current_competition.nearly_published? && current_competition.manager?(current_user)
render_forbidden
end
# 竞赛成绩导出
def chart_to_xlsx records, competition
@competition_head_cells = []

@ -1409,11 +1409,16 @@ class ExercisesController < ApplicationController
min_score = exercise_scores.min.present? ? exercise_scores.min : 0.0
max_score = exercise_scores.max.present? ? exercise_scores.max : 0.0
total_score = exercise_scores.sum.present? ? exercise_scores.sum : 0.0
average_score = @exercise_commit_user_counts > 0 ? (total_score / @exercise_commit_user_counts).round(1) : 0.0
fail_counts = exercise_scores.count{|a| a < 60.0}
pass_counts = exercise_scores.count{|a| a < 70.0 && a >= 60.0}
good_counts = exercise_scores.count{|a| a < 90.0 && a >= 70.0}
best_counts = exercise_scores.count{|a| a >= 90.0 && a <= 100.0}
average_score = @exercise_commit_user_counts > 0 ? (total_score.round(1) / @exercise_commit_user_counts).round(1) : 0.0
question_scores = @exercise.question_scores
fail_score = question_scores * 0.6.round(2)
pass_score = question_scores * 0.7.round(2)
good_score = question_scores * 0.9.round(2)
fail_counts = exercise_scores.count{|a| a < fail_score}
pass_counts = exercise_scores.count{|a| a < pass_score && a >= fail_score}
good_counts = exercise_scores.count{|a| a < good_score && a >= pass_score}
best_counts = exercise_scores.count{|a| a >= good_score && a <= question_scores}
end
@counts_array = {
:commit_percent => commit_percent,

@ -112,7 +112,7 @@ module ExportHelper
@work_cells_column.push(row_cells_column)
end
else #实训题
shixun = homework.shixuns.first
shixun = homework.shixuns.take
shixun_head_cells = %w(完成情况 通关时间 学员在EduCoder做实训花费的时间 总评测次数 获得经验值 关卡得分)
eff_boolean = homework.work_efficiency
if eff_boolean
@ -123,9 +123,12 @@ module ExportHelper
if allow_late_boolean #允许迟交
eff_score_cell.push("迟交扣分")
end
shixun_time_cells = %w(最终成绩 更新时间 作业发布到学员完成作业所耗的时间 评语)
shixun_time_cells = %w(最终成绩 更新时间 作业发布到学员完成作业所耗的时间 总评语)
for i in 1 .. shixun.challenges.size
shixun_time_cells << "#{i}关评语"
end
@work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?)
works.includes(:student_works_scores, user: :user_extension, myshixun: :games).each_with_index do |w, index|
works.includes(:shixun_work_comments, :student_works_scores, user: :user_extension, myshixun: :games).each_with_index do |w, index|
myshixun = w.try(:myshixun)
w_user = w.user
w_1 = (index + 1)
@ -165,21 +168,20 @@ module ExportHelper
w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间"
myshixun_complete = myshixun && myshixun.status == 1
w_17 = myshixun_complete && w.cost_time ? (game_spend_time w.cost_time) : "未完成"
teacher_comments = w.student_works_scores
if teacher_comments.present?
w_18 = ""
teacher_comments.each do |t|
user_name = t.user&.real_name
user_time = format_time(t.updated_at)
user_score = t&.score
user_comment = t.comment.present? ? t.comment : "--"
comment_title = "#{user_name} #{user_time.to_s} #{user_score.to_s}\n#{user_comment}\n\n"
w_18 = w_18 + comment_title
end
teacher_comment = w.shixun_work_comments.select{|comment| comment.challenge_id == 0}.first
if teacher_comment.present?
w_18 = "学生可见:\n #{teacher_comment.comment.to_s} \n\n 老师可见:\n#{teacher_comment.hidden_comment.to_s}"
else
w_18 = "--"
end
row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18]
# 关卡评语
shixun.challenges.pluck(:id).each do |challenge_id|
challenge_comment = w.shixun_work_comments.select{|comment| comment.challenge_id == challenge_id}.first
row_cells_column << (challenge_comment.present? ? "学生可见:\n #{challenge_comment.comment.to_s} \n\n 老师可见:\n#{challenge_comment.hidden_comment.to_s}" : "--")
end
row_cells_column = row_cells_column.reject(&:blank?)
@work_cells_column.push(row_cells_column)
end

@ -26,6 +26,9 @@ class Competition < ApplicationRecord
has_many :sponsor_schools, -> { where(source: :sponsor) }, class_name: 'CompetitionSchool' # 主办方
has_many :region_schools, -> { where(source: :region) }, class_name: 'CompetitionSchool' # 开放范围
has_many :competition_managers, dependent: :destroy
has_many :managers, through: :competition_managers, source: :user
after_create :create_competition_modules
def mode_type
@ -75,6 +78,11 @@ class Competition < ApplicationRecord
status?
end
# 即将发布
def nearly_published?
!published? && published_at.present?
end
# 是否为个人赛
def personal?
competition_staffs.sum(:maximum).to_i == 1 || (competition_staffs.nil? && max_num == 1)
@ -134,6 +142,10 @@ class Competition < ApplicationRecord
# competition_awards.pluck(:num)&.sum > 0 ? competition_awards.pluck(:num)&.sum : 20
# end
def manager?(user)
user && competition_managers.exists?(user_id: user.id)
end
private
def get_module_name type

@ -0,0 +1,4 @@
class CompetitionManager < ApplicationRecord
belongs_to :user
belongs_to :competition
end

@ -196,7 +196,7 @@ class Course < ApplicationRecord
end
def all_course_module_types
%w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board]
%w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics]
end
def get_course_module_by_type(type)
@ -386,6 +386,7 @@ class Course < ApplicationRecord
when 'attachment' then '资源'
when 'board' then '讨论'
when 'course_group' then '分班'
when 'statistics' then '统计'
else ''
end
end
@ -404,6 +405,7 @@ class Course < ApplicationRecord
when 'attachment' then 10
when 'board' then 11
when 'course_group' then 12
when 'statistics' then 13
else 100
end
end

@ -37,6 +37,9 @@ class Exercise < ApplicationRecord
DEADLINE = 3 #已截止
ENDED = 4 #课堂已结束
def question_scores
exercise_questions.pluck(:question_score).sum
end
def create_exercise_list
str = ""

@ -34,6 +34,18 @@ class Admins::CompetitionBasicSettingService < ApplicationService
setting.save!
end
# 管理员设置
params[:manager_ids] = Array.wrap(params[:manager_ids]).map(&:to_i)
old_manager_ids = competition.competition_managers.pluck(:user_id)
new_manager_ids = params[:manager_ids] - old_manager_ids
delete_manager_ids = old_manager_ids - params[:manager_ids]
CompetitionManager.bulk_insert(*%i[user_id competition_id created_at updated_at]) do |worker|
new_manager_ids.each do |manager_id|
worker.add(user_id: manager_id, competition_id: competition.id)
end
end
competition.competition_managers.where(user_id: delete_manager_ids).delete_all
# 主办方设置
params[:sponsor_schools] = Array.wrap(params[:sponsor_schools]).map(&:to_i)
new_sponsor_school_ids = competition.sponsor_schools.pluck(:school_id)

@ -10,13 +10,15 @@ class Admins::CompetitionStageCreateService < ApplicationService
ActiveRecord::Base.transaction do
stage = CompetitionStage.create!(competition_id: competition.id, name: params[:stage_name], score_rate: (params[:score_rate].to_i / 100).round(2))
params[:stage].each do |section|
stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id,
start_time: section["start_time"], end_time: section["end_time"],
entry: section["entry"], score_source: section["score_source"])
section["identifiers"].each do |identifier|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
shixun_identifier: identifier)
unless params[:stage].blank?
params[:stage].each do |section|
stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id,
start_time: section["start_time"], end_time: section["end_time"],
entry: section["entry"], score_source: section["score_source"])
section["identifiers"].each do |identifier|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
shixun_identifier: identifier)
end
end
end

@ -13,13 +13,15 @@ class Admins::CompetitionStageUpdateService < ApplicationService
stage.competition_stage_sections.destroy_all
params[:stage].each do |section|
stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id,
start_time: section["start_time"], end_time: section["end_time"],
entry: section["entry"], score_source: section["score_source"])
section["identifiers"].each do |identifier|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
shixun_identifier: identifier)
unless params[:stage].blank?
params[:stage].each do |section|
stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id,
start_time: section["start_time"], end_time: section["end_time"],
entry: section["entry"], score_source: section["score_source"])
section["identifiers"].each do |identifier|
CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id,
shixun_identifier: identifier)
end
end
end

@ -93,6 +93,16 @@
</div>
</div>
<div class="row align-items-center d-flex mb-2">
<div class="col-1 text-right">
管理员
</div>
<div class="col-5 text-left sponsorPanel">
<% manager_data = @competition.managers.map { |u| [u.name, u.id] } %>
<%= select_tag :manager_ids, options_for_select(manager_data, @competition.managers.map(&:id)), class: 'form-control manager-select', multiple: true %>
</div>
</div>
<div class="row align-items-center d-flex mb-2">
<div class="col-1 text-right">
主办方
@ -360,7 +370,7 @@
</div><span class=" mt-2">%</span>
<div class="flex-1">
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20 add-task-sub">新增子阶段</a>
<% if stage.max_end_time > Time.now %>
<% if stage.max_end_time && stage.max_end_time > Time.now %>
<%= agree_link '发送短信提醒', send_message_admins_competition_competition_stage_path(@competition, stage, element: ".send-message-#{stage.id}"),
class: 'btn btn-outline-primary ml20', 'data-confirm': '确认执行发送短信操作?' %>
<% end %>
@ -492,6 +502,7 @@
</div>
<% end %>
<% end %>
<div class="error my-2 danger text-danger"></div>
</div>
</div>
</div>

@ -30,3 +30,7 @@ if @competition.mode == 2
json.member_of_course @user.member_of_course?(@competition.competition_mode_setting&.course)
end
json.permission do
json.editable @user.admin_or_business? || (@competition.nearly_published? && @competition.manager?(@user))
end

@ -0,0 +1,10 @@
class CreateCompetitionManagers < ActiveRecord::Migration[5.2]
def change
create_table :competition_managers do |t|
t.references :user
t.references :competition
t.timestamps
end
end
end

@ -0,0 +1,7 @@
class AddStatisticsToCourseModule < ActiveRecord::Migration[5.2]
def change
Course.includes(:course_modules).all.each do |course|
CourseModule.create!(course_id: course.id, module_type: "statistics", hidden:0, module_name: "统计", position: course.course_modules.pluck(:position).max + 1)
end
end
end

File diff suppressed because one or more lines are too long

@ -136184,6 +136184,33 @@ $(document).on('turbolinks:load', function(){
$('.sponsor-select').select2(selectOptions);
$('.allow-school-select').select2(selectOptions);
$('.manager-select').select2({
theme: 'bootstrap4',
placeholder: '请输入要添加的管理员姓名',
multiple: true,
minimumInputLength: 1,
ajax: {
delay: 500,
url: '/admins/users',
dataType: 'json',
data: function(params){
return { keyword: params.term };
},
processResults: function(data){
return { results: data.users }
}
},
templateResult: function (item) {
if(!item.id || item.id === '') return item.text;
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
},
templateSelection: function(item){
if (item.id) {
}
return item.real_name || item.text;
}
});
// 排行榜
//链接
Loading…
Cancel
Save