Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

problem_set
hjm 6 years ago
commit 63116768cf

@ -5,7 +5,69 @@ $(document).on('turbolinks:load', function() {
$imageElement.attr('src', data.url);
$imageElement.show();
$imageElement.next().html('重新上传');
})
});
}
$(".admin-competition-list-form").on("change", '.competitions-hot-select', function () {
var s_value = $(this).get(0).checked ? 1 : 0;
var json = {};
json["hot"] = s_value;
$.ajax({
url: "/admins/competitions/hot_setting",
type: "POST",
dataType:'json',
data: json,
success: function(){
$.notify({ message: '操作成功' });
}
});
});
// ============== 新增竞赛 ===============
var $modal = $('.modal.admin-create-competition-modal');
var $form = $modal.find('form.admin-create-competition-form');
var $competitionNameInput = $form.find('input[name="competition_name"]');
$form.validate({
errorElement: 'span',
errorClass: 'danger text-danger',
rules: {
competition_name: {
required: true
}
}
});
// modal ready fire
$modal.on('show.bs.modal', function () {
$competitionNameInput.val('');
});
$modal.on('click', '.submit-btn', function(){
$form.find('.error').html('');
if ($form.valid()) {
var url = $form.data('url');
$.ajax({
method: 'POST',
dataType: 'json',
url: url,
data: $form.serialize(),
success: function(){
$.notify({ message: '创建成功' });
$modal.modal('hide');
setTimeout(function(){
window.location.reload();
}, 500);
},
error: function(res){
var data = res.responseJSON;
$form.find('.error').html(data.message);
}
});
}
});
});

@ -0,0 +1,9 @@
$(document).on('turbolinks:load', function() {
if($('body.admins-enroll-lists-index-page').length > 0){
let search_form = $(".search-form");
//导出
$(".competition-enroll-list-form").on("click","#enroll-lists-export",function () {
window.location.href = "/admins/competitions/"+$(this).attr("data-competition-id")+"/enroll_lists.xls?" + search_form.serialize();
});
}
});

@ -18,12 +18,27 @@ class Admins::CompetitionsController < Admins::BaseController
end
end
def create
name = params[:competition_name].to_s.strip
Competition.create!(name: name)
render_ok
end
def hot_setting
if params[:hot].to_i == 1 && !ModuleSetting.exists?(module_type: "Competition", property: "hot")
ModuleSetting.create!(module_type: "Competition", property: "hot")
elsif params[:hot].to_i == 0 && ModuleSetting.exists?(module_type: "Competition", property: "hot")
ModuleSetting.where(module_type: "Competition", property: "hot").destroy_all
end
render_ok
end
def publish
@competition.update_attributes!(:published_at, Time.now)
@competition.update_attributes!(published_at: Time.now)
end
def unpublish
@competition.update_attributes!(:published_at, nil)
@competition.update_attributes!(published_at: nil)
end
def online_switch
@ -34,10 +49,6 @@ class Admins::CompetitionsController < Admins::BaseController
end
end
def enroll_list
end
private
def find_competition

@ -0,0 +1,25 @@
class Admins::EnrollListsController < Admins::BaseController
def index
@competition = current_competition
params[:sort_by] = params[:sort_by].presence || 'created_at'
params[:sort_direction] = params[:sort_direction].presence || 'desc'
enroll_lists = Admins::CompetitionEnrollListQuery.call(@competition, params)
@params_page = params[:page] || 1
@enroll_lists = paginate enroll_lists.preload(competition_team: [:user, :teachers], user: { user_extension: :school })
@personal = @competition.personal?
respond_to do |format|
format.js
format.html
format.xls
end
end
private
def current_competition
@_current_competition ||= Competition.find(params[:competition_id])
end
end

@ -59,6 +59,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
end
def index
@personal = current_competition.personal?
admin_or_business? ? all_competition_teams : user_competition_teams
end

@ -1129,7 +1129,7 @@ class ExercisesController < ApplicationController
:subjective_score => subjective_score,
:commit_method => @answer_committed_user&.commit_method.to_i > 0 ? @answer_committed_user&.commit_method.to_i : params[:commit_method].to_i
}
@answer_committed_user.update_attributes(commit_option)
@answer_committed_user.update_attributes!(commit_option)
CommitExercsieNotifyJobJob.perform_later(@exercise.id, current_user.id)
normal_status(0,"试卷提交成功!")
else

@ -414,7 +414,7 @@ module ExercisesHelper
score2 = 0.0 #填空题
score5 = 0.0 #实训题
ques_stand = [] #问题是否正确
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges)
exercise_questions&.each do |q|
begin
if q.question_type != 5

@ -55,7 +55,7 @@ class Competition < ApplicationRecord
# 是否为个人赛
def personal?
competition_staffs.maximum(:maximum) == 1
competition_staffs.maximum(:maximum) == 1 || max_num == 1
end
# 报名是否结束
@ -101,7 +101,7 @@ class Competition < ApplicationRecord
private
def create_competition_modules
CompetitionModule.bulk_insert(*%i[competition_id name position]) do |worker|
CompetitionModule.bulk_insert(*%i[competition_id name position created_at updated_at]) do |worker|
%w(首页 报名 通知公告 排行榜 资料下载).each_with_index do |name, index|
worker.add(competition_id: id, name: name, position: index + 1)
end

@ -32,6 +32,15 @@ class CompetitionTeam < ApplicationRecord
code
end
def teachers_info
info = ""
teachers.each do |teacher|
teacher_info = "#{teacher.user.real_name}/#{teacher.user.school_name}"
info += info == "" ? teacher_info : "#{teacher_info}"
end
info
end
def teachers_name
teachers.map{|teacher| teacher.user.real_name}.join(",")
end

@ -237,6 +237,11 @@ class User < ApplicationRecord
professional_certification
end
# 学校所在的地区
def school_province
user_extension&.school&.province || ''
end
# 用户的学校名称
def school_name
user_extension&.school&.name || ''

@ -0,0 +1,40 @@
class Admins::CompetitionEnrollListQuery < ApplicationQuery
include CustomSortable
attr_reader :competition, :params
sort_columns :created_at, :competition_team_id, default_by: :created_at, default_direction: :desc
def initialize(competition, params)
@competition = competition
@params = params
end
def call
members = competition.team_members
only_teacher = competition.competition_staffs.count == 1 && competition.competition_staffs.first.category == 'teacher'
members = members.where("team_members.is_teacher = 0") unless only_teacher # 只有老师报名时才显示老师,此时老师作为队员
school = params[:school].to_s.strip
if school.present?
school_ids = School.where("schools.name like ?", "%#{school}%").pluck(:id)
school_ids = school_ids.size == 0 ? "(-1)" : "(" + school_ids.join(",") + ")"
members = members.joins(user: :user_extension).where("user_extensions.school_id in #{school_ids}")
end
location = params[:location].to_s.strip
if location.present?
members = members.joins(user: { user_extension: :school }).where("schools.province like ?", "%#{location}%")
end
# 关键字模糊查询
keyword = params[:keyword].to_s.strip
if keyword.present?
members = members.joins(:competition_team)
.where('competition_teams.name LIKE :keyword', keyword: "%#{keyword}%")
end
custom_sort(members, params[:sort_by], params[:sort_direction])
end
end

@ -69,7 +69,7 @@ class ExercisePublishTask
:subjective_score => subjective_score,
:commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3
}
exercise_user.update_attributes(commit_option)
exercise_user.update_attributes!(commit_option)
end
rescue Exception => e
Rails.logger.info("rescue errors ___________________________#{e}")

@ -2,22 +2,26 @@
<% add_admin_breadcrumb('竞赛列表', admins_competitions_path) %>
<% end %>
<div class="box mb-5">
<div class="d-flex flex-column w-100">
<div class="d-flex">
<% imageExists = File.exist?(disk_filename("Competition", "banner")) %>
<% imageUrl = imageExists ? '/' + banner_img("Competition") + "?#{Time.now.to_i}" : '' %>
<span class="mr-3">竞赛主页banner</span>
<%= image_tag(imageUrl, width: 150, height: 50, class: "preview-image competition-image-banner mr-1", data: { toggle: 'tooltip', title: '点击预览' }) %>
<%= javascript_void_link imageExists ? '重新上传' : '上传图片', class: 'action upload-competition-image-action', data: { source_id: "banner", source_type: 'Competition', toggle: 'modal', target: '.admin-upload-file-modal' } %>
</div>
<div class="box mb-5 admin-competition-list-form">
<div class="d-flex align-items-center w-100">
<div class="flex-1 d-flex align-items-center">
<div class="mr-5">
<% imageExists = File.exist?(disk_filename("Competition", "banner")) %>
<% imageUrl = imageExists ? '/' + banner_img("Competition") + "?#{Time.now.to_i}" : '' %>
<span class="mr-3">竞赛主页banner</span>
<%= image_tag(imageUrl, width: 150, height: 50, class: "preview-image competition-image-banner mr-1", data: { toggle: 'tooltip', title: '点击预览' }) %>
<%= javascript_void_link imageExists ? '重新上传' : '上传图片', class: 'action upload-competition-image-action', data: { source_id: "banner", source_type: 'Competition', toggle: 'modal', target: '.admin-upload-file-modal' } %>
</div>
<div class="d-flex">
<label for="hot">
<%= check_box_tag :hot, (@competition_hot ? "1" : "0"), @competition_hot, class:"shixun-settings-select" %>
<span class="only_view">只看可ssh</span>
</label>
<div class="mr-5">
<label for="hot">
<%= check_box_tag :hot,(@competition_hot ? 1 : 0),@competition_hot,remote:true,data:{toggle:"tooltip",placement:"top"},class:"competitions-hot-select"%>
<span class="only_view">hot标识勾选则"在线竞赛"显示hot标识</span>
</label>
</div>
</div>
<%= javascript_void_link '新增', class: 'btn btn-primary', data: { toggle: 'modal', target: '.admin-create-competition-modal' } %>
</div>
</div>
@ -25,4 +29,5 @@
<%= render partial: 'admins/competitions/shared/list', locals: { competitions: @competitions } %>
</div>
<%= render 'admins/competitions/shared/create_competition_modal' %>
<%= render partial: 'admins/shared/modal/upload_file_modal', locals: { title: '上传图片' } %>

@ -0,0 +1 @@
$('.competitions-list-container').html("<%= j( render partial: 'admins/competitions/shared/list', locals: { competitions: @competitions } ) %>");

@ -0,0 +1,4 @@
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
show_success_flash();

@ -0,0 +1,4 @@
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
show_success_flash();

@ -0,0 +1,28 @@
<div class="modal fade admin-create-competition-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">新增竞赛</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form class="admin-create-competition-form" data-url="<%= admins_competitions_path %>">
<div class="form-group d-flex">
<label for="new_mirror_id" class="col-form-label">竞赛名称:</label>
<div class="w-75 d-flex flex-column">
<%= text_field_tag(:competition_name, nil, class: 'form-control', placeholder: '请输入竞赛名称') %>
</div>
</div>
<div class="error text-danger"></div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary submit-btn">确认</button>
</div>
</div>
</div>
</div>

@ -18,7 +18,7 @@
<% competitions.each_with_index do |competition, index| %>
<tr id="competition-item-<%= competition.id %>">
<% page_no = list_index_no(@params_page.to_i, index) %>
<%= render partial: "admins/competitions/shared/td",locals: {competition: competition, page_no: page_no} %>
<%= render partial: "admins/competitions/shared/td", locals: {competition: competition, page_no: page_no} %>
</tr>
<% end %>
<% else %>

@ -1,6 +1,6 @@
<td><%= page_no %></td>
<td class="text-left">
<span><%= link_to competition.name, enroll_list_admins_competition_path(competition), :target => "_blank", :title => competition.name %></span>
<span><%= link_to competition.name, admins_competition_enroll_lists_path(competition), :title => competition.name %></span>
</td>
<td><%= competition.sub_title %></td>
<td><%= competition.mode_type %></td>
@ -15,7 +15,7 @@
</td>
<td><%= competition.created_at.strftime('%Y-%m-%d %H:%M') %></td>
<td class="action-container">
<%= link_to '配置', admins_competition_competition_setting_path(competition), class: 'action edit-action' %>
<%= link_to '配置', admins_competition_competition_settings_path(competition), class: 'action edit-action' %>
<% if !competition.status? && competition.published_at.blank? %>
<%= link_to '发布', publish_admins_competition_path(competition), class: 'action publish-action', method: :post, remote: true %>

@ -0,0 +1,4 @@
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
show_success_flash();

@ -0,0 +1,42 @@
<table class="table text-center shixun-settings-list-table">
<thead class="thead-light">
<tr>
<th width="4%" class="text-left">序号</th>
<th width="6%"><%= sort_tag('战队ID', name: 'competition_team_id', path: admins_competition_enroll_lists_path(@competition)) %></th>
<th width="12%">战队名称</th>
<th width="10%">创建者</th>
<th width="10%">队员姓名</th>
<th width="6%">职业</th>
<th width="12%">学号</th>
<th width="10%">队员学校</th>
<th width="6%">地区</th>
<th width="16%">指导老师</th>
<th width="8%"><%= sort_tag('报名时间', name: 'created_at', path: admins_competition_enroll_lists_path(@competition)) %></th>
</tr>
</thead>
<tbody>
<% if enroll_lists.present? %>
<% enroll_lists.each_with_index do |member, index| %>
<tr id="competition-team-member-<%= member.id %>">
<% team = member.competition_team %>
<% page_no = list_index_no(@params_page.to_i, index) %>
<td><%= page_no %></td>
<td><%= member.competition_team_id %></td>
<td><%= @personal ? "--" : team.name %></td>
<td><%= team.user.real_name %></td>
<td><%= member.user.real_name %></td>
<td><%= member.user.identity %></td>
<td><%= member.user.student_id %></td>
<td><%= member.user.school_name %></td>
<td><%= member.user.school_province %></td>
<td><%= @personal ? "--" : team.teachers_info %></td>
<td><%= member.created_at.strftime('%Y-%m-%d %H:%M') %></td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: enroll_lists } %>

@ -0,0 +1,33 @@
<%
define_admin_breadcrumbs do
add_admin_breadcrumb('竞赛列表', admins_competitions_path)
add_admin_breadcrumb(@competition.name)
end
%>
<div class="box search-form-container flex-column mb-0 pb-0 competition-enroll-list-form">
<ul class="nav nav-tabs w-100 search-form-tabs">
<li class="nav-item">
<%= link_to '报名列表', admins_competition_enroll_lists_path(@competition), class: "nav-link search-form-tab active" %>
</li>
<li class="nav-item">
<%= link_to '获奖证书审批', admins_competition_enroll_lists_path(@competition), class: "nav-link search-form-tab" %>
</li>
</ul>
<div class="d-flex">
<%= form_tag(admins_competition_enroll_lists_path(unsafe_params), method: :get, class: 'form-inline search-form mt-3 flex-1 d-flex', remote: true) do %>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '战队名称检索') %>
<%= text_field_tag(:school, params[:school], class: 'form-control col-sm-2 ml-3', placeholder: '队员学校名称检索') %>
<%= text_field_tag(:location, params[:location], class: 'form-control col-sm-2 ml-3', placeholder: '队员地区检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<%= link_to "清除", admins_competition_enroll_lists_path(@competition), class: "btn btn-default",'data-disable-with': '清除中...' %>
<% end %>
<a href="javascript:void(0)" class="btn btn-primary mt-3" id="enroll-lists-export" data-competition-id="<%= @competition.id %>" data-disable-with = '导出中...'>导出</a>
</div>
</div>
<div class="box competition-enroll-list-container">
<%= render(partial: 'admins/enroll_lists/list', locals: { enroll_lists: @enroll_lists }) %>
</div>

@ -0,0 +1 @@
$('.competition-enroll-list-container').html("<%= j( render(partial: 'admins/enroll_lists/list', locals: { enroll_lists: @enroll_lists }) ) %>");

@ -1,4 +1,5 @@
json.count @count
json.personal @personal
json.competition_teams do
json.array! @teams.each do |team|
json.extract! team, :id, :name, :invite_code

@ -1012,14 +1012,18 @@ Rails.application.routes.draw do
end
end
resources :competitions, only: [:index, :destroy] do
resources :competitions, only: [:index, :destroy, :create] do
member do
post :publish
post :unpublish
post :online_switch
get :enroll_list
end
resource :competition_setting, only: [:show, :update]
collection do
post :hot_setting
end
resources :competition_settings, only: [:index, :update]
resources :enroll_lists, only: [:index]
end
end

@ -0,0 +1,25 @@
class MigrateExerciseChallengeScore < ActiveRecord::Migration[5.2]
include ExercisesHelper
def change
exercise = Exercise.find_by(id: 2734)
if exercise
exercise.exercise_users.where("start_at is not null").each do |exercise_user|
if exercise_user.end_at.nil?
calculate_score = calculate_student_score(exercise, exercise_user.user)[:total_score]
subjective_score = exercise_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = calculate_score + total_score_subjective_score
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score,end_at:exercise.end_time,commit_status:1,status:1,commit_method:3)
puts exercise_user.id
else
calculate_score = ExerciseShixunAnswer.where(user_id: exercise_user.user_id, exercise_question_id: exercise.exercise_questions.pluck(:id)).pluck(:score).sum
subjective_score = exercise_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = calculate_score + total_score_subjective_score
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score) if total_score > exercise_user.score
puts exercise_user.id
end
end
end
end
end

@ -47,7 +47,8 @@ export function initAxiosInterceptors(props) {
proxy="https://pre-newweb.educoder.net"
proxy="https://test-newweb.educoder.net"
// 在这里使用requestMap控制避免用户通过双击等操作发出重复的请求
// 在这里使用requestMap控制避免用户通过双击等操作发出重复的请求
// 如果需要支持重复的请求考虑config里面自定义一个allowRepeat参考来控制
const requestMap = {};

@ -25,6 +25,7 @@ class PollDetailTabSecond extends Component{
axios.get(url).then((result)=>{
if(result){
this.setState({
page: page,
questions:result.data.questions,
questionsInfo:result.data.question_types
})
@ -55,7 +56,7 @@ class PollDetailTabSecond extends Component{
}
render(){
let{page,limit,questions,question_types}=this.state;
let {page, limit, questions, questionsInfo} = this.state;
return(
<div>
{
@ -160,9 +161,10 @@ class PollDetailTabSecond extends Component{
}):<NoneData></NoneData>
}
{
question_types && question_types.q_counts>limit &&
questionsInfo && questionsInfo.q_counts > limit &&
<div className="edu-txt-center mt20 mb50">
<Pagination showQuickJumper current={page} total={question_types.q_counts} pageSize={limit} onChange={this.changePage}></Pagination>
<Pagination showQuickJumper current={page} total={questionsInfo.q_counts} pageSize={limit}
onChange={this.changePage}></Pagination>
</div>
}

Loading…
Cancel
Save