diff --git a/app/assets/javascripts/admins/disciplines/index.js b/app/assets/javascripts/admins/disciplines/index.js
new file mode 100644
index 000000000..e5153516a
--- /dev/null
+++ b/app/assets/javascripts/admins/disciplines/index.js
@@ -0,0 +1,124 @@
+$(document).on('turbolinks:load', function() {
+ if ($('body.admins-disciplines-index-page').length > 0) {
+
+ // ============== 新建 ===============
+ var $modal = $('.modal.admin-create-discipline-modal');
+ var $form = $modal.find('form.admin-create-discipline-form');
+ var $nameInput = $form.find('input[name="name"]');
+
+ $form.validate({
+ errorElement: 'span',
+ errorClass: 'danger text-danger',
+ rules: {
+ name: {
+ required: true
+ }
+ }
+ });
+
+ // modal ready fire
+ $modal.on('show.bs.modal', function () {
+ $nameInput.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);
+ }
+ });
+ }
+ });
+
+ $(".discipline-list-container").on("change", '.discipline-source-form', function () {
+ var s_id = $(this).attr("data-id");
+ var s_value = $(this).val();
+ var s_name = $(this).attr("name");
+ var json = {};
+ json[s_name] = s_value;
+ $.ajax({
+ url: "/admins/disciplines/" + s_id,
+ type: "PUT",
+ dataType:'script',
+ data: json
+ });
+ });
+
+ // 导入学生
+ var $importDisciplineModal = $('.modal.admin-import-discipline-modal');
+ var $importDisciplineForm = $importDisciplineModal.find('form.admin-import-discipline-form');
+
+ $importDisciplineModal.on('show.bs.modal', function(){
+ resetFileInputFunc($importDisciplineModal.find('.upload-file-input'));
+ $importDisciplineModal.find('.file-names').html('选择文件');
+ $importDisciplineModal.find('.upload-file-input').trigger('click');
+ });
+ $importDisciplineModal.on('change', '.upload-file-input', function(e){
+ var file = $(this)[0].files[0];
+ $importDisciplineModal.find('.file-names').html(file ? file.name : '请选择文件');
+ });
+
+ var importDisciplineFormValid = function(){
+ if($importDisciplineForm.find('input[name="file"]').val() == undefined || $importDisciplineForm.find('input[name="file"]').val().length == 0){
+ $importDisciplineForm.find('.error').html('请选择文件');
+ return false;
+ }
+
+ return true;
+ };
+
+ var buildResultMessage = function(data){
+ var messageHtml = "
导入结果:成功" + data.success + "条,失败"+ data.fail.length + "条
";
+
+ return messageHtml;
+ };
+
+ $importDisciplineModal.on('click', '.submit-btn', function(){
+ $importDisciplineForm.find('.error').html('');
+
+ if (importDisciplineFormValid()) {
+ $('body').mLoading({ text: '正在导入...' });
+
+ $.ajax({
+ method: 'POST',
+ dataType: 'json',
+ url: '/admins/import_disciplines',
+ data: new FormData($importDisciplineForm[0]),
+ processData: false,
+ contentType: false,
+ success: function(data){
+ $('body').mLoading('destroy');
+ $importDisciplineModal.modal('hide');
+
+ showMessageModal(buildResultMessage(data), function(){
+ window.location.reload();
+ });
+ },
+ error: function(res){
+ $('body').mLoading('destroy');
+ var data = res.responseJSON;
+ $importDisciplineForm.find('.error').html(data.message);
+ }
+ });
+ }
+ });
+ }
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/admins/modals/admin-edit-discipline-modal.js b/app/assets/javascripts/admins/modals/admin-edit-discipline-modal.js
new file mode 100644
index 000000000..729d9e9c5
--- /dev/null
+++ b/app/assets/javascripts/admins/modals/admin-edit-discipline-modal.js
@@ -0,0 +1,31 @@
+$(document).on('turbolinks:load', function() {
+ $('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-discipline-modal', function(){
+ var $modal = $('.modal.admin-edit-discipline-modal');
+ var $form = $modal.find('form.admin-edit-discipline-form');
+
+ $form.validate({
+ errorElement: 'span',
+ errorClass: 'danger text-danger',
+ rules: {
+ 'discipline[name]': {
+ required: true,
+ maxlength: 20
+ }
+ }
+ });
+
+ $modal.on('click', '.submit-btn', function(){
+ $form.find('.error').html('');
+ var url = $form.attr('action');
+
+ if ($form.valid()) {
+ $.ajax({
+ method: 'PATCH',
+ dataType: 'script',
+ url: url,
+ data: $form.serialize()
+ });
+ }
+ });
+ });
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/admins/modals/admin-edit-sub-discipline-modal.js b/app/assets/javascripts/admins/modals/admin-edit-sub-discipline-modal.js
new file mode 100644
index 000000000..8a81f4959
--- /dev/null
+++ b/app/assets/javascripts/admins/modals/admin-edit-sub-discipline-modal.js
@@ -0,0 +1,31 @@
+$(document).on('turbolinks:load', function() {
+ $('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-sub-discipline-modal', function(){
+ var $modal = $('.modal.admin-edit-sub-discipline-modal');
+ var $form = $modal.find('form.admin-edit-sub-discipline-form');
+
+ $form.validate({
+ errorElement: 'span',
+ errorClass: 'danger text-danger',
+ rules: {
+ 'sub_discipline[name]': {
+ required: true,
+ maxlength: 20
+ }
+ }
+ });
+
+ $modal.on('click', '.submit-btn', function(){
+ $form.find('.error').html('');
+ var url = $form.attr('action');
+
+ if ($form.valid()) {
+ $.ajax({
+ method: 'PATCH',
+ dataType: 'script',
+ url: url,
+ data: $form.serialize()
+ });
+ }
+ });
+ });
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/admins/modals/admin-edit-tag-discipline-modal.js b/app/assets/javascripts/admins/modals/admin-edit-tag-discipline-modal.js
new file mode 100644
index 000000000..e126fff40
--- /dev/null
+++ b/app/assets/javascripts/admins/modals/admin-edit-tag-discipline-modal.js
@@ -0,0 +1,31 @@
+$(document).on('turbolinks:load', function() {
+ $('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-tag-discipline-modal', function(){
+ var $modal = $('.modal.admin-edit-tag-discipline-modal');
+ var $form = $modal.find('form.admin-edit-tag-discipline-form');
+
+ $form.validate({
+ errorElement: 'span',
+ errorClass: 'danger text-danger',
+ rules: {
+ 'tag_discipline[name]': {
+ required: true,
+ maxlength: 20
+ }
+ }
+ });
+
+ $modal.on('click', '.submit-btn', function(){
+ $form.find('.error').html('');
+ var url = $form.attr('action');
+
+ if ($form.valid()) {
+ $.ajax({
+ method: 'PATCH',
+ dataType: 'script',
+ url: url,
+ data: $form.serialize()
+ });
+ }
+ });
+ });
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/admins/sub_disciplines/index.js b/app/assets/javascripts/admins/sub_disciplines/index.js
new file mode 100644
index 000000000..74eb614f9
--- /dev/null
+++ b/app/assets/javascripts/admins/sub_disciplines/index.js
@@ -0,0 +1,65 @@
+$(document).on('turbolinks:load', function() {
+ if ($('body.admins-sub-disciplines-index-page').length > 0) {
+
+ // ============== 新建 ===============
+ var $modal = $('.modal.admin-create-sub-discipline-modal');
+ var $form = $modal.find('form.admin-create-sub-discipline-form');
+ var $nameInput = $form.find('input[name="name"]');
+
+ $form.validate({
+ errorElement: 'span',
+ errorClass: 'danger text-danger',
+ rules: {
+ name: {
+ required: true
+ }
+ }
+ });
+
+ // modal ready fire
+ $modal.on('show.bs.modal', function () {
+ $nameInput.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);
+ }
+ });
+ }
+ });
+
+ $(".sub-discipline-list-container").on("change", '.sub-discipline-source-form', function () {
+ var s_id = $(this).attr("data-id");
+ var s_value = $(this).val();
+ var s_name = $(this).attr("name");
+ var json = {};
+ json[s_name] = s_value;
+ $.ajax({
+ url: "/admins/sub_disciplines/" + s_id,
+ type: "PUT",
+ dataType:'script',
+ data: json
+ });
+ });
+ }
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/admins/tag_disciplines/index.js b/app/assets/javascripts/admins/tag_disciplines/index.js
new file mode 100644
index 000000000..f4998f006
--- /dev/null
+++ b/app/assets/javascripts/admins/tag_disciplines/index.js
@@ -0,0 +1,65 @@
+$(document).on('turbolinks:load', function() {
+ if ($('body.admins-tag-disciplines-index-page').length > 0) {
+
+ // ============== 新建 ===============
+ var $modal = $('.modal.admin-create-tag-discipline-modal');
+ var $form = $modal.find('form.admin-create-tag-discipline-form');
+ var $nameInput = $form.find('input[name="name"]');
+
+ $form.validate({
+ errorElement: 'span',
+ errorClass: 'danger text-danger',
+ rules: {
+ name: {
+ required: true
+ }
+ }
+ });
+
+ // modal ready fire
+ $modal.on('show.bs.modal', function () {
+ $nameInput.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);
+ }
+ });
+ }
+ });
+
+ $(".tag-discipline-list-container").on("change", '.tag-discipline-source-form', function () {
+ var s_id = $(this).attr("data-id");
+ var s_value = $(this).val();
+ var s_name = $(this).attr("name");
+ var json = {};
+ json[s_name] = s_value;
+ $.ajax({
+ url: "/admins/tag_disciplines/" + s_id,
+ type: "PUT",
+ dataType:'script',
+ data: json
+ });
+ });
+ }
+});
\ No newline at end of file
diff --git a/app/controllers/admins/base_controller.rb b/app/controllers/admins/base_controller.rb
index f90c8a1ed..0451b77d1 100644
--- a/app/controllers/admins/base_controller.rb
+++ b/app/controllers/admins/base_controller.rb
@@ -6,10 +6,10 @@ class Admins::BaseController < ApplicationController
layout 'admin'
skip_before_action :verify_authenticity_token
-
before_action :require_login, :require_admin!
after_action :rebind_event_if_ajax_render_partial
+ skip_before_action :check_sign
private
diff --git a/app/controllers/admins/customers_controller.rb b/app/controllers/admins/customers_controller.rb
index 80b01757b..8235bdb80 100644
--- a/app/controllers/admins/customers_controller.rb
+++ b/app/controllers/admins/customers_controller.rb
@@ -1,4 +1,5 @@
class Admins::CustomersController < Admins::BaseController
+ # skip_before_action :check_sign
helper_method :current_partner
def index
diff --git a/app/controllers/admins/disciplines_controller.rb b/app/controllers/admins/disciplines_controller.rb
new file mode 100644
index 000000000..7681bea42
--- /dev/null
+++ b/app/controllers/admins/disciplines_controller.rb
@@ -0,0 +1,49 @@
+class Admins::DisciplinesController < Admins::BaseController
+
+ def index
+ @disciplines = Discipline.all
+ end
+
+ def create
+ name = params[:name].to_s.strip
+ return render_error('名称重复') if Discipline.where(name: name).exists?
+ Discipline.create!(name: name)
+ render_ok
+ end
+
+ def edit
+ @discipline = current_discipline
+ end
+
+ def update
+ if params[:discipline] && params[:discipline][:name].present?
+ name = params[:discipline][:name].to_s.strip
+ current_discipline.update_attributes!(name: name)
+ else
+ ActiveRecord::Base.transaction do
+ current_discipline.update_attributes!(setting_params)
+ current_discipline.sub_disciplines.each do |sub|
+ sub.tag_disciplines.each do |tag|
+ tag.update_attributes!(setting_params)
+ end
+ sub.update_attributes!(setting_params)
+ end
+ end
+ end
+ @disciplines = Discipline.all
+ end
+
+ def destroy
+ @discipline_id = params[:id]
+ current_discipline.destroy!
+ end
+
+ private
+ def current_discipline
+ @_current_discipline = Discipline.find params[:id]
+ end
+
+ def setting_params
+ params.permit(:shixun, :subject, :question)
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/admins/import_disciplines_controller.rb b/app/controllers/admins/import_disciplines_controller.rb
new file mode 100644
index 000000000..bf0f324b9
--- /dev/null
+++ b/app/controllers/admins/import_disciplines_controller.rb
@@ -0,0 +1,10 @@
+class Admins::ImportDisciplinesController < Admins::BaseController
+ def create
+ return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
+
+ result = Admins::ImportDisciplineService.call(params[:file].to_io)
+ render_ok(result)
+ rescue Admins::ImportDisciplineService::Error => ex
+ render_error(ex)
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/admins/shixun_settings_controller.rb b/app/controllers/admins/shixun_settings_controller.rb
index 6dbbc077a..37ca45674 100644
--- a/app/controllers/admins/shixun_settings_controller.rb
+++ b/app/controllers/admins/shixun_settings_controller.rb
@@ -5,9 +5,10 @@ class Admins::ShixunSettingsController < Admins::BaseController
shixun_settings = Admins::ShixunSettingsQuery.call(params)
@editing_shixuns = shixun_settings.where(status:0).size
- @pending_shixuns = shixun_settings.where(status:1).size
- @processed_shixuns = shixun_settings.where(status:2).size
+ @processed_shixuns = shixun_settings.where(status:2, public: 0).size
@closed_shixuns = shixun_settings.where(status:3).size
+ @pending_public_shixuns = shixun_settings.where(public:1).size
+ @processed_pubic_shixuns = shixun_settings.where(public:2).size
@sort_json = {
can_copy: params[:can_copy].present? ? params[:can_copy] : false,
@@ -83,9 +84,9 @@ class Admins::ShixunSettingsController < Admins::BaseController
sheet1[count_row, 6] = shixun.myshixuns_count
sheet1[count_row, 7] = shixun.myshixuns.select{|m| m.status == 1}.size
sheet1[count_row, 8] = shixun.shixun_status
- sheet1[count_row, 9] = shixun.user.show_real_name
- sheet1[count_row, 10] = shixun.user.school_name
- sheet1[count_row, 11] = shixun.user.identity
+ sheet1[count_row, 9] = shixun.user&.show_real_name
+ sheet1[count_row, 10] = shixun.user&.school_name
+ sheet1[count_row, 11] = shixun.user&.identity
shixun.challenges.each do |challenge|
sheet1[count_row, 12] = "第#{challenge.position}关"
sheet1[count_row, 13] = challenge.subject
@@ -112,13 +113,16 @@ class Admins::ShixunSettingsController < Admins::BaseController
sheet1[count_row, 2] = shixun.mirror_repositories.select{|mr| mr.main_type == "1"}.first&.type_name
sheet1[count_row, 3] = shixun.fork_from
sheet1[count_row, 4] = shixun.shixun_status
- sheet1[count_row, 5] = shixun.user.show_real_name
- sheet1[count_row, 6] = shixun.user.school_name
- sheet1[count_row, 7] = shixun.user.identity
- shixun.challenges.each do |challenge|
+ sheet1[count_row, 5] = shixun.user&.show_real_name
+ sheet1[count_row, 6] = shixun.user&.school_name
+ sheet1[count_row, 7] = shixun.user&.identity
+ challenge_count = shixun.challenges.count
+ shixun.challenges.each_with_index do |challenge, index|
sheet1[count_row, 8] = "第#{challenge.position}关"
sheet1[count_row, 9] = challenge.subject
- count_row += 1
+ if index + 1 != challenge_count
+ count_row += 1
+ end
end
count_row += 1
end
diff --git a/app/controllers/admins/shixuns_controller.rb b/app/controllers/admins/shixuns_controller.rb
index 6593f27c2..86cb9b45f 100644
--- a/app/controllers/admins/shixuns_controller.rb
+++ b/app/controllers/admins/shixuns_controller.rb
@@ -5,10 +5,8 @@ class Admins::ShixunsController < Admins::BaseController
params[:sort_direction] = params[:sort_direction].presence || 'desc'
shixuns = Admins::ShixunQuery.call(params)
@editing_shixuns = shixuns.where(status:0).size
- @pending_shixuns = shixuns.where(status:1).size
- @processed_shixuns = shixuns.where(status:2).size
+ @processed_shixuns = shixuns.where(status:2, public: 0).size
@closed_shixuns = shixuns.where(status:3).size
- @none_public_shixuns = shixuns.where(public:0).size
@pending_public_shixuns = shixuns.where(public:1).size
@processed_pubic_shixuns = shixuns.where(public:2).size
@shixuns_type_check = MirrorRepository.pluck(:type_name,:id)
diff --git a/app/controllers/admins/sub_disciplines_controller.rb b/app/controllers/admins/sub_disciplines_controller.rb
new file mode 100644
index 000000000..25c268ca6
--- /dev/null
+++ b/app/controllers/admins/sub_disciplines_controller.rb
@@ -0,0 +1,52 @@
+class Admins::SubDisciplinesController < Admins::BaseController
+
+ def index
+ @discipline = current_discipline
+ @sub_disciplines = current_discipline.sub_disciplines
+ end
+
+ def create
+ name = params[:name].to_s.strip
+ return render_error('名称重复') if current_discipline.sub_disciplines.where(name: name).exists?
+ SubDiscipline.create!(name: name, discipline_id: current_discipline.id)
+ render_ok
+ end
+
+ def edit
+ @sub_discipline = current_sub_discipline
+ end
+
+ def update
+ if params[:sub_discipline] && params[:sub_discipline][:name].present?
+ name = params[:sub_discipline][:name].to_s.strip
+ current_sub_discipline.update_attributes!(name: name)
+ else
+ ActiveRecord::Base.transaction do
+ current_sub_discipline.update_attributes!(setting_params)
+ current_sub_discipline.tag_disciplines.each do |tag|
+ tag.update_attributes!(setting_params)
+ end
+ end
+ end
+ @sub_disciplines = current_sub_discipline.discipline&.sub_disciplines
+ end
+
+ def destroy
+ @sub_discipline_id = params[:id]
+ current_sub_discipline.destroy!
+ end
+
+ private
+
+ def current_sub_discipline
+ @_current_sub_discipline = SubDiscipline.find params[:id]
+ end
+
+ def current_discipline
+ @_current_discipline = Discipline.find params[:discipline_id]
+ end
+
+ def setting_params
+ params.permit(:shixun, :subject, :question)
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/admins/tag_disciplines_controller.rb b/app/controllers/admins/tag_disciplines_controller.rb
new file mode 100644
index 000000000..352146bcd
--- /dev/null
+++ b/app/controllers/admins/tag_disciplines_controller.rb
@@ -0,0 +1,47 @@
+class Admins::TagDisciplinesController < Admins::BaseController
+
+ def index
+ @sub_discipline = current_sub_discipline
+ @tag_disciplines = current_sub_discipline.tag_disciplines
+ end
+
+ def create
+ name = params[:name].to_s.strip
+ return render_error('名称重复') if current_sub_discipline.tag_disciplines.where(name: name).exists?
+ TagDiscipline.create!(name: name, sub_discipline_id: current_sub_discipline.id, user_id: current_user.id)
+ render_ok
+ end
+
+ def edit
+ @tag_discipline = current_tag_discipline
+ end
+
+ def update
+ if params[:tag_discipline] && params[:tag_discipline][:name].present?
+ name = params[:tag_discipline][:name].to_s.strip
+ current_tag_discipline.update_attributes!(name: name)
+ else
+ current_tag_discipline.update_attributes!(setting_params)
+ end
+ @tag_disciplines = current_tag_discipline.sub_discipline&.tag_disciplines
+ end
+
+ def destroy
+ @tag_discipline_id = params[:id]
+ current_tag_discipline.destroy!
+ end
+
+ private
+
+ def current_sub_discipline
+ @_current_sub_discipline = SubDiscipline.find params[:sub_discipline_id]
+ end
+
+ def current_tag_discipline
+ @_current_tag_discipline = TagDiscipline.find params[:id]
+ end
+
+ def setting_params
+ params.permit(:shixun, :subject, :question)
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/admins/users_controller.rb b/app/controllers/admins/users_controller.rb
index 9630394b4..b9a07ba1e 100644
--- a/app/controllers/admins/users_controller.rb
+++ b/app/controllers/admins/users_controller.rb
@@ -61,7 +61,7 @@ class Admins::UsersController < Admins::BaseController
private
def update_params
- params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id
+ params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker
mail phone location location_city school_id department_id admin business is_test
password professional_certification authentication])
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 9630caaec..89d53e73c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery prepend: true, unless: -> { request.format.json? }
+ before_action :check_sign
before_action :user_setup
#before_action :check_account
@@ -20,12 +21,39 @@ class ApplicationController < ActionController::Base
helper_method :current_user
+ # 所有请求必须合法签名
+ def check_sign
+ unless Rails.env.development?
+ Rails.logger.info("66666 #{params}")
+ suffix = request.url.split(".").last.split("?").first
+ suffix_arr = ["xls", "xlsx", "pdf"] # excel文件先注释
+ unless suffix_arr.include?(suffix)
+ if params[:client_key].present?
+ randomcode = params[:randomcode]
+ # tip_exception(501, "请求不合理") unless (Time.now.to_i - randomcode.to_i).between?(0,5)
+
+ sign = Digest::MD5.hexdigest("#{OPENKEY}#{randomcode}")
+ Rails.logger.info("2222 #{sign}")
+ tip_exception(501, "请求不合理") if sign != params[:client_key]
+ else
+ tip_exception(501, "请求不合理")
+ end
+ end
+ end
+ end
+
# 全局配置参数
# 返回name对应的value
def edu_setting(name)
EduSetting.get(name)
end
+ def shixun_marker
+ unless current_user.is_shixun_marker? || current_user.admin_or_business?
+ tip_exception(403, "..")
+ end
+ end
+
# 实训的访问权限
def shixun_access_allowed
if !current_user.shixun_permission(@shixun)
@@ -256,9 +284,10 @@ class ApplicationController < ActionController::Base
end
def user_setup
- # reacct静态资源加载不需要走这一步
+ # # reacct静态资源加载不需要走这一步
return if params[:controller] == "main"
# Find the current user
+ #Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}")
User.current = find_current_user
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
@@ -400,7 +429,7 @@ class ApplicationController < ActionController::Base
end
rescue Exception => e
uid_logger("--uri_exec: exception #{e.message}")
- raise Educoder::TipException.new("实训平台繁忙(繁忙等级:84)")
+ raise Educoder::TipException.new(message)
end
end
@@ -603,7 +632,7 @@ class ApplicationController < ActionController::Base
end
def paginate(relation)
- limit = params[:limit].to_i.zero? ? 20 : params[:limit].to_i
+ limit = (params[:limit].to_i.zero? || params[:limit].to_i > 20) ? 20 : params[:limit].to_i
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
offset = (page - 1) * limit
@@ -678,4 +707,5 @@ class ApplicationController < ActionController::Base
HotSearchKeyword.add(keyword)
end
+
end
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 5fc81c5d5..e0dd71467 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -5,6 +5,7 @@ class AttachmentsController < ApplicationController
before_action :require_login, :check_auth, except: [:show]
before_action :find_file, only: %i[show destroy]
before_action :attachment_candown, only: [:show]
+ skip_before_action :check_sign, only: [:show, :create]
include ApplicationHelper
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 851567c92..c5d3082ba 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -22,7 +22,7 @@ class CommentsController < ApplicationController
@discuss = @hack.discusses.new(reply_params)
@discuss.hidden = false
@discuss.user_id = current_user.id
- @discuss.root_id = params[:parent_id]
+ @discuss.root_id = params[:comments][:parent_id]
@discuss.save!
rescue Exception => e
uid_logger_error("reply discuss failed : #{e.message}")
@@ -32,9 +32,14 @@ class CommentsController < ApplicationController
# 列表
def index
- disscusses = @hack.disscusses.where(:root_id => nil)
- @disscuss_count = disscusses.count
- @disscusses= paginate disscusses
+ discusses =
+ if current_user.admin_or_business?
+ @hack.discusses.where(root_id: nil)
+ else
+ @hack.discusses.where(root_id: nil, hidden: false)
+ end
+ @discusses_count = discusses.count
+ @discusses= paginate discusses
end
# 删除
@@ -43,10 +48,21 @@ class CommentsController < ApplicationController
render_ok
end
+ # 隐藏、取消隐藏
+ def hidden
+ if current_user.admin_or_business?
+ @discuss = @hack.discusses.where(id: params[:id]).first
+ @discuss.update_attribute(:hidden, params[:hidden].to_i == 1)
+ sucess_status
+ else
+ Educoder::TipException(403, "..")
+ end
+ end
+
private
def find_hack
- @hack = Hack.find_by_identifier params[:identifier]
+ @hack = Hack.find_by_identifier(params[:hack_identifier])
end
def comment_params
diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb
index 085fec360..0d8604aac 100644
--- a/app/controllers/concerns/git_helper.rb
+++ b/app/controllers/concerns/git_helper.rb
@@ -45,6 +45,16 @@ module GitHelper
content: content, author_name: username, author_email: mail)
end
+ # 添加目录
+ def git_add_folder(folder_path, author_name, author_email, message)
+ GitService.add_tree(file_path: folder_path, message: message, author_name: author_name, author_email: author_email)
+ end
+
+ # 删除文件
+ def git_delete_file(file_path, author_name, author_email, message)
+ GitService.delete_file(file_path: file_path, message: message, author_name: author_name, author_email: author_email)
+ end
+
# 版本库Fork功能
def project_fork(container, original_rep_path, username)
raise Educoder::TipException.new("fork源路径为空,fork失败!") if original_rep_path.blank?
diff --git a/app/controllers/cooperative/base_controller.rb b/app/controllers/cooperative/base_controller.rb
index 51af05ed2..5d21598aa 100644
--- a/app/controllers/cooperative/base_controller.rb
+++ b/app/controllers/cooperative/base_controller.rb
@@ -10,13 +10,14 @@ class Cooperative::BaseController < ApplicationController
before_action :laboratory_exist!, :require_login, :require_cooperative_manager!
after_action :rebind_event_if_ajax_render_partial
+ skip_before_action :check_sign
helper_method :current_laboratory, :current_setting_or_default
private
def current_laboratory
- @_current_laboratory ||= Laboratory.find_by_subdomain(request.subdomain)
+ @_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.first)
# @_current_laboratory ||= Laboratory.find 1
end
diff --git a/app/controllers/departments_controller.rb b/app/controllers/departments_controller.rb
index 5e82b2c51..73cb19156 100644
--- a/app/controllers/departments_controller.rb
+++ b/app/controllers/departments_controller.rb
@@ -1,4 +1,6 @@
class DepartmentsController < ApplicationController
+ skip_before_action :check_sign
+
def for_option
render_ok(departments: current_school.departments.without_deleted.select(:id, :name).as_json)
end
diff --git a/app/controllers/disciplines_controller.rb b/app/controllers/disciplines_controller.rb
new file mode 100644
index 000000000..09d6f49a0
--- /dev/null
+++ b/app/controllers/disciplines_controller.rb
@@ -0,0 +1,6 @@
+class DisciplinesController < ApplicationController
+
+ def index
+
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb
index cbb19cb7f..c2cc8f933 100644
--- a/app/controllers/discusses_controller.rb
+++ b/app/controllers/discusses_controller.rb
@@ -14,14 +14,14 @@ class DiscussesController < ApplicationController
@disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count
disscusses = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s,
:root_id => nil)
- @discusses = disscusses.limit(LIMIT).joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id")
- .select("discusses.*, games.identifier").includes(:user, :praise_treads).offset(offset)
+ @discusses = disscusses.joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id")
+ .select("discusses.*, games.identifier").includes(:user, :praise_treads).limit(LIMIT).offset(offset)
else
disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and
(discusses.hidden = :hidden or discusses.user_id = :user_id)",
{dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id})
@disscuss_count = disscusses.count("discusses.id")
- @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset)
+ @discusses = disscusses.includes(:user, :praise_treads).limit(LIMIT).offset(offset)
end
@current_user = current_user
@@ -117,13 +117,13 @@ class DiscussesController < ApplicationController
# 0 取消赞;
def plus
pt = PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type],
- :user_id => current_user, :praise_or_tread => 1).first
+ :user_id => current_user, :praise_or_tread => 1)
# 如果当前用户已赞过,则不能重复赞
if params[:type] == 1 && pt.blank?
PraiseTread.create!(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type],
- :user_id => current_user.id, :praise_or_tread => 1) if pt.blank?
+ :user_id => current_user.id, :praise_or_tread => 1)
else
- pt.destroy if pt.present? # 如果已赞过,则删掉这条赞(取消);如果没赞过,则为非法请求不处理
+ pt.destroy_all if pt.present? # 如果已赞过,则删掉这条赞(取消);如果没赞过,则为非法请求不处理
end
@praise_count = PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type],
diff --git a/app/controllers/edu_settings_controller.rb b/app/controllers/edu_settings_controller.rb
index 6baf38e5b..d3b796da7 100644
--- a/app/controllers/edu_settings_controller.rb
+++ b/app/controllers/edu_settings_controller.rb
@@ -1,7 +1,7 @@
class EduSettingsController < ApplicationController
before_action :require_admin
before_action :set_edu_setting, only: [:show, :edit, :update, :destroy]
-
+ skip_before_action :check_sign
# GET /edu_settings
# GET /edu_settings.json
def index
diff --git a/app/controllers/examination_banks_controller.rb b/app/controllers/examination_banks_controller.rb
new file mode 100644
index 000000000..e5e9ca4ca
--- /dev/null
+++ b/app/controllers/examination_banks_controller.rb
@@ -0,0 +1,85 @@
+class ExaminationBanksController < ApplicationController
+ include PaginateHelper
+ before_action :require_login
+ before_action :find_exam, except: [:index, :create]
+ before_action :edit_auth, only: [:update, :destroy, :set_public]
+
+ def index
+ exams = ExaminationBankQuery.call(params)
+ @exams_count = exams.size
+ @exams = paginate exams.includes(:user, :examination_items)
+ end
+
+ def show
+ @items = @exam.examination_items
+ @single_questions = @items.where(item_type: "SINGLE")
+ @multiple_questions = @items.where(item_type: "MULTIPLE")
+ @judgement_questions = @items.where(item_type: "JUDGMENT")
+ @program_questions = @items.where(item_type: "PROGRAM")
+ end
+
+ def create
+ ActiveRecord::Base.transaction do
+ exam = ExaminationBank.new(user: current_user)
+ # 保存试卷基础信息
+ exam = ExaminationBanks::SaveExaminationBankService.call(exam, form_params)
+
+ # 将试题篮中的试题发送到试卷,试卷的题目与试题独立
+ current_user.item_baskets.includes(:item_bank).each do |basket|
+ item = basket.item_bank
+ if item.present?
+ new_item = ExaminationItem.new(examination_bank: exam, item_bank: item, name: item.name, item_type: item.item_type,
+ difficulty: item.difficulty, score: basket.score, position: basket.position)
+ new_item.save!
+ item.increment!(:quotes)
+
+ if item.item_type == "PROGRAM"
+ new_hack = item.container.fork
+ new_item.update_attributes!(container: new_hack)
+ else
+ new_item.examination_item_analysis.create!(analysis: item.analysis)
+ item.item_choices.each do |choice|
+ new_item.examination_item_choices << ExaminationItemChoice.new(choice_text: choice.choice_text, is_answer: choice.is_answer)
+ end
+ end
+ end
+ end
+
+ current_user.item_baskets.destroy_all
+ end
+ render_ok
+ end
+
+ def edit
+
+ end
+
+ def update
+
+ end
+
+ def destroy
+ @exam.destroy!
+ render_ok
+ end
+
+ def set_public
+ tip_exception(-1, "该试卷已公开") if @exam.public?
+ @exam.update_attributes!(public: 1)
+ render_ok
+ end
+
+ private
+
+ def form_params
+ params.permit(:discipline_id, :sub_discipline_id, :difficulty, :name, :duration, tag_discipline_id: [])
+ end
+
+ def find_exam
+ @exam = ExaminationBank.find_by!(id: params[:id])
+ end
+
+ def edit_auth
+ current_user.admin_or_business? || @exam.user == current_user
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index d55eb9211..938d42c2f 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -10,9 +10,6 @@ class GamesController < ApplicationController
include GamesHelper
include ApplicationHelper
-
-
-
def show
uid_logger("--games show start")
# 防止评测中途ajaxE被取消;3改成0是为了处理首次进入下一关的问题
@@ -91,7 +88,6 @@ class GamesController < ApplicationController
end
end
-
def jupyter
# Jupyter没有challenge
@myshixun = Myshixun.find_by_identifier params[:identifier]
@@ -103,7 +99,7 @@ class GamesController < ApplicationController
begin
@tpm_modified = @myshixun.repository_is_modified(@shixun.repo_path) # 判断TPM和TPI的版本库是否被改了
rescue
- uid_logger("实训平台繁忙,繁忙等级(81)")
+ uid_logger("服务器出现问题,请重置刷新页面")
end
end
diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb
index bbb0e293e..0767eab02 100644
--- a/app/controllers/gits_controller.rb
+++ b/app/controllers/gits_controller.rb
@@ -1,5 +1,5 @@
class GitsController < ApplicationController
-
+ skip_before_action :check_sign
# 说明:
# 以下Git认证只针对新版git,Gitlab的Git认证不走该控制器
# 思路:
@@ -39,7 +39,7 @@ class GitsController < ApplicationController
# 用户是否对对象拥有权限
system_user = User.find_by_login(input_username) || User.find_by_mail(input_username) || User.find_by_phone(input_username)
# 如果用户名密码错误
- if system_user && !system_user.check_password?(input_password)
+ if system_user.blank? || system_user && !system_user.check_password?(input_password)
uid_logger_error("git start: password is wrong")
result = false
else
diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb
index 0e6135e8c..9b3021994 100644
--- a/app/controllers/graduation_topics_controller.rb
+++ b/app/controllers/graduation_topics_controller.rb
@@ -140,8 +140,8 @@ class GraduationTopicsController < ApplicationController
update_graduation_topic_status
# 拒绝后将该学生移动到未分班中
- student_member = @course.course_members.where(:user_id => student_graduation_topic.user_id).first
- student_member.update_attributes(:course_group_id => 0) if student_member.present?
+ # student_member = @course.course_members.where(:user_id => student_graduation_topic.user_id).first
+ # student_member.update_attributes(:course_group_id => 0) if student_member.present?
student_graduation_topic.tidings.update_all(:status => 1)
Tiding.create(:user_id => student_graduation_topic.user_id, :trigger_user_id => current_user.id,
@@ -170,14 +170,15 @@ class GraduationTopicsController < ApplicationController
teacher_group = @course.teacher_course_groups.where(:user_id => @graduation_topic.tea_id, :id => params[:group_id]).first
unless teacher_group.present?
member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first
- tip_exception("分班名称不能为空") if params[:course_group_name].blank?
- course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id)
- teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :course_member_id => member.try(:id),
- :user_id => @graduation_topic.tea_id,
- :course_group_id => course_group.try(:id))
+ if params[:course_group_name].present?
+ course_group = CourseGroup.find_or_create_by!(:name => params[:course_group_name], :course_id => @course.id)
+ teacher_group = TeacherCourseGroup.find_or_create_by!(:course_id => @course.id, :course_member_id => member.try(:id),
+ :user_id => @graduation_topic.tea_id,
+ :course_group_id => course_group.try(:id))
+ student_member = @course.course_members.where(:user_id => student_graduation_topic.user_id).first
+ student_member.update_attributes(:course_group_id => teacher_group.course_group_id) if student_member.present?
+ end
end
- student_member = @course.course_members.where(:user_id => student_graduation_topic.user_id).first
- student_member.update_attributes(:course_group_id => teacher_group.course_group_id) if student_member.present?
student_graduation_topic.tidings.update_all(:status => 1)
Tiding.create(:user_id => student_graduation_topic.user_id, :trigger_user_id => current_user.id,
diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb
index 814d16d51..353833ee2 100644
--- a/app/controllers/hack_user_lastest_codes_controller.rb
+++ b/app/controllers/hack_user_lastest_codes_controller.rb
@@ -1,10 +1,11 @@
class HackUserLastestCodesController < ApplicationController
before_action :require_login, except: [:listen_result]
- before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code,
+ before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, :add_notes,
:listen_result, :result, :submit_records, :restore_initial_code]
before_action :update_user_hack_status, only: [:code_debug, :code_submit]
- before_action :require_auth_identity, only: [:update_code, :restore_initial_code, :sync_code]
- before_action :require_manager_identity, only: [:update_code]
+ before_action :require_auth_identity, only: [:add_notes]
+ before_action :require_manager_identity, only: [:show, :update_code, :restore_initial_code, :sync_code]
+ skip_before_action :check_sign, only: [:listen_result]
def show
@my_hack.update_attribute(:submit_status, 0) if @my_hack.submit_status == 1
@@ -61,13 +62,18 @@ class HackUserLastestCodesController < ApplicationController
# 提交记录
def submit_records
- @records = @my_hack.hack_user_codes.created_order
- end
+ records = @my_hack.hack_user_codes
+ @records_count = records.count
+ @records = paginate records.created_order
+ end
# 提交记录详情
def record_detail
@hack_user = HackUserCode.find params[:id]
+ set = HackSet.find_by(id: @hack_user.error_test_set_id)
+ @pass_set_count = set ? set.position - 1 : 0
+ @set_count = @hack_user.hack.hack_sets.count
@my_hack = @hack_user.hack_user_lastest_code
end
@@ -80,7 +86,7 @@ class HackUserLastestCodesController < ApplicationController
testCase = ojEvaResult['testCase']
# 只有编译出错时,才正则匹配错误行数
error_line=
- if params[:status] == "-4"
+ if ojEvaResult['status'] == "4" || ojEvaResult['status'] == "5"
regular_match_error_line ojEvaResult['outPut'], @my_hack.hack.language
end
# debug 与submit 公用的参数
@@ -94,7 +100,8 @@ class HackUserLastestCodesController < ApplicationController
if ojEvaResult['execMode'] == "debug"
save_debug_data ds_params
elsif ojEvaResult['execMode'] == "submit"
- save_submit_data ds_params.merge(expected_output: testCase['expectedOutput'])
+ save_submit_data ds_params.merge(expected_output: testCase['expectedOutput'],
+ error_test_set_id: ojEvaResult['failCaseNum'])
end
# 评测完成后,还原评测中的状态
@my_hack.update_attribute(:submit_status, 0)
@@ -106,6 +113,11 @@ class HackUserLastestCodesController < ApplicationController
end
+ def add_notes
+ @my_hack.update_attribute(:notes, params[:notes])
+ render_ok
+ end
+
private
def find_my_hack
@my_hack = HackUserLastestCode.find_by(identifier: params[:identifier])
@@ -137,11 +149,12 @@ class HackUserLastestCodesController < ApplicationController
# 正则错误行数
def regular_match_error_line content, language
content = Base64.decode64(content).force_encoding("utf-8")
+ logger.info("######content: #{content}")
case language
when 'Java'
content.scan(/.java.\d+/).map{|s| s.match(/\d+/)[0].to_i}.min
when 'C', 'C++'
- content.scan(/\d:\d+: error/).map{|s| s.match(/\d+/)[0]}.min
+ content.scan(/\d:\d+:/).map{|s| s.match(/\d+/)[0].to_i}.min
when 'Python'
content.scan(/line \d+/).map{|s| s.match(/\d+/)[0].to_i}.min
end
@@ -163,12 +176,12 @@ class HackUserLastestCodesController < ApplicationController
# 通关
if submit_params[:status] == "0"
# 编程题已经发布,且之前未通关奖励积分
+ @hack.increment!(:pass_num)
if @hack.status == 1 && !@my_hack.passed?
- reward_attrs = { container_id: game.id, container_type: 'Hack', score: @hack.score }
+ reward_attrs = { container_id: @hack.id, container_type: 'Hack', score: @hack.score }
RewardGradeService.call(@my_hack.user, reward_attrs)
RewardExperienceService.call(@my_hack.user, reward_attrs)
# 评测完成更新通过数
- @hack.increment!(:pass_num)
@my_hack.update_attributes(passed: true, passed_time: Time.now)
end
end
diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb
index b7f6a30a2..fb4f497bd 100644
--- a/app/controllers/hacks_controller.rb
+++ b/app/controllers/hacks_controller.rb
@@ -30,10 +30,10 @@ class HacksController < ApplicationController
# 筛选过滤与排序
params_filter_or_order
# 我解决的编程题数
- user_codes = HackUserLastestCode.joins(:hack).mine_hack(current_user).passed
+ user_codes = HackUserLastestCode.joins(:hack).mine_hack(current_user).passed
@simple_count = user_codes.where(hacks: {difficult: 1}).count
@medium_count = user_codes.where(hacks: {difficult: 2}).count
- @diff_count = user_codes.where(hacks: {difficult: 3}).count
+ @diff_count = user_codes.where(hacks: {difficult: 3}).count
@pass_count = @simple_count + @medium_count + @diff_count
@hacks_count = @hacks.count("hacks.id")
@@ -43,16 +43,23 @@ class HacksController < ApplicationController
def create
begin
logger.info("##########{hack_params}")
+ tip_exception("一次只能增加50个测试集") if hack_sets_params.size > 50
+ tip_exception("一次只能增加50个知识点") if params[:tags].size > 50
hack = Hack.new(hack_params)
+ hack.user_id = current_user.id
+ hack.identifier = generate_identifier Hack, 8
+ tag_params = params[:tags].map{|tag| {tag_discipline_id: tag}}
ActiveRecord::Base.transaction do
- hack.user_id = current_user.id
- hack.identifier = generate_identifier Hack, 8
hack.save!
# 创建测试集与代码
hack.hack_sets.create!(hack_sets_params)
+ # 新建知识点
+ hack.tag_discipline_containers.create!(tag_params) if tag_params.present?
hack_codes = hack.hack_codes.new(hack_code_params)
hack_codes.modify_time = Time.now
hack_codes.save!
+ new_item_params = item_params.merge(container: hack, item_type: 'PROGRAM', difficulty: params[:hack][:difficult], user_id: current_user.id)
+ ItemBank.create!(new_item_params)
end
render_ok({identifier: hack.identifier})
rescue Exception => e
@@ -63,6 +70,10 @@ class HacksController < ApplicationController
def update
begin
+ # 知识点
+ tag_discipline_ids = @hack.tag_discipline_containers.pluck(:tag_discipline_id)
+ new_tag_ids = params[:tags].to_a - tag_discipline_ids
+ tag_params = new_tag_ids.map{|tag| {tag_discipline_id: tag}}
ActiveRecord::Base.transaction do
@hack.update_attributes!(hack_params)
set_ids = @hack.hack_sets.pluck(:id)
@@ -73,6 +84,14 @@ class HacksController < ApplicationController
# 更新代码
code_params = params[:hack_codes][:code] != @hack.code ? hack_code_params.merge(modify_time: Time.now) : hack_code_params
@hack.hack_codes.first.update_attributes!(code_params)
+ @hack.tag_discipline_containers.create!(tag_params) if tag_params
+ @hack.tag_discipline_containers.where.not(tag_discipline_id: params[:tags]).destroy_all
+
+ # 更新题库相关记录
+ if @hack.item_bank.present?
+ update_item_params = item_params.merge({difficulty: params[:hack][:difficult]})
+ @hack.item_bank.update!(update_item_params)
+ end
end
render_ok
rescue Exception => e
@@ -98,12 +117,22 @@ class HacksController < ApplicationController
# 发布功能
def publish
@hack.update_attribute(:status, 1)
+ base_attrs = {
+ trigger_user_id: current_user.id, viewed: 0, tiding_type: 'System', user_id: @hack.user_id,
+ parent_container_type: "HackPublish", extra: @hack.identifier
+ }
+ @hack.tidings.create!(base_attrs)
render_ok
end
# 取消发布
def cancel_publish
@hack.update_attribute(:status, 0)
+ base_attrs = {
+ trigger_user_id: current_user.id, viewed: 0, tiding_type: 'System', user_id: @hack.user_id,
+ parent_container_type: "HackUnPublish", extra: @hack.identifier
+ }
+ @hack.tidings.create!(base_attrs)
render_ok
end
@@ -116,16 +145,30 @@ class HacksController < ApplicationController
@hacks = hacks.includes(:hack_sets).page(page).per(limit)
end
- def edit;end
+ def edit;
+ end
- def new;end
+ def new;
+ end
def destroy
- @hack.destroy
- render_ok
+ begin
+ base_attrs = {
+ user_id: @hack.user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id,
+ parent_container_type: "HackDelete", extra: "#{@hack.name}"
+ }
+ @hack.tidings.create!(base_attrs)
+ @hack.destroy
+ render_ok
+ rescue => e
+ logger.error("####hack_delete_error: #{e.message}")
+ render_error("删除失败")
+ end
+
end
private
+
# 实名认证老师,管理员与运营人员权限
def require_teacher_identity
unless current_user.certification_teacher? || admin_or_business?
@@ -145,7 +188,11 @@ class HacksController < ApplicationController
end
def hack_params
- params.require(:hack).permit(:name, :description, :difficult, :category, :open_or_not, :time_limit, :score)
+ params.require(:hack).permit(:name, :description, :difficult, :open_or_not, :time_limit, :score, :sub_discipline_id)
+ end
+
+ def item_params
+ params.require(:hack).permit(:name, :sub_discipline_id)
end
def hack_sets_params
@@ -165,12 +212,15 @@ class HacksController < ApplicationController
end
def param_update_sets sets, all_sets_id
- delete_set_ids = all_sets_id - sets.map{|set|set[:id]}
+ delete_set_ids = all_sets_id - sets.map {|set| set[:id]}
@hack.hack_sets.where(id: delete_set_ids).destroy_all
+ logger.info("#######sets:#{sets}")
sets.each do |set|
+ logger.info("###set[:id]: #{set[:id]}")
+ logger.info("###all_sets: #{all_sets_id.include?(set[:id])}")
if all_sets_id.include?(set[:id])
update_attrs = {input: set[:input], output: set[:output], position: set[:position]}
- @hack.hack_sets.find_by!(id: set[:id]).update_attributes(update_attrs)
+ @hack.hack_sets.find_by!(id: set[:id]).update_attributes!(update_attrs)
end
end
end
@@ -190,7 +240,7 @@ class HacksController < ApplicationController
end
# 难度
if params[:difficult]
- hacks = hacks.where(difficult: params[:difficult])
+ hacks = hacks.where(difficult: params[:difficult])
end
# 状态
if params[:status]
@@ -208,6 +258,11 @@ class HacksController < ApplicationController
hacks = hacks.where(category: params[:category])
end
+ # 语言
+ if params[:language]
+ hacks = hacks.joins(:hack_codes).where(hack_codes: {language: params[:language]})
+ end
+
# 排序
sort_by = params[:sort_by] || "hack_user_lastest_codes_count"
sort_direction = params[:sort_direction] || "desc"
diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb
index 3a60dcde5..f9931c370 100644
--- a/app/controllers/homework_commons_controller.rb
+++ b/app/controllers/homework_commons_controller.rb
@@ -11,7 +11,7 @@ class HomeworkCommonsController < ApplicationController
before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results,
:code_review_detail, :show_comment, :settings, :works_list, :update_settings,
:reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation,
- :update_score, :update_student_score]
+ :update_score, :update_student_score, :batch_comment]
before_action :user_course_identity
before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer,
:update_student_score]
@@ -19,7 +19,7 @@ class HomeworkCommonsController < ApplicationController
:publish_homework, :end_homework, :set_public, :choose_category, :move_to_category,
:choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat,
:code_review_results, :code_review_detail, :update_explanation, :update_settings,
- :add_to_homework_bank, :publish_groups, :end_groups]
+ :add_to_homework_bank, :publish_groups, :end_groups, :batch_comment]
before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category,
:add_to_homework_bank]
before_action :course_manager, only: [:alter_name]
@@ -194,7 +194,7 @@ class HomeworkCommonsController < ApplicationController
# TODO user_extension 如果修改 请调整
unless params[:search].blank?
@student_works = @student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ?
- or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
+ or student_id like ?", "%#{params[:search].strip}%", "%#{params[:search].strip}%")
end
@work_count = @student_works.size
@@ -214,7 +214,7 @@ class HomeworkCommonsController < ApplicationController
limit = params[:limit] || 20
@student_works = @student_works.page(page).per(limit)
if @homework.homework_type == "practice"
- @student_works = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games)
+ @student_works = @student_works.includes(:student_works_scores, :shixun_work_comments, user: :user_extension, myshixun: :games)
else
@student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension)
end
@@ -453,105 +453,8 @@ class HomeworkCommonsController < ApplicationController
# 课堂结束后不能再更新
unless @course.is_end
+ # 发布设置
UpdateHomeworkPublishSettingService.call(@homework, publish_params)
- # 作业未发布时,unified_setting参数不能为空
-=begin
- if @homework.publish_time.nil? || @homework.publish_time > Time.now
- tip_exception("缺少统一设置的参数") if params[:unified_setting].nil?
- if params[:unified_setting] || @course.course_groups_count == 0
- tip_exception("发布时间不能为空") if params[:publish_time].blank?
- tip_exception("截止时间不能为空") if params[:end_time].blank?
- tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
- tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
- tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time]
- tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day
-
- @homework.unified_setting = 1
- @homework.homework_group_settings.destroy_all
- @homework.publish_time = params[:publish_time]
- # 截止时间为空时取发布时间后一个月
- @homework.end_time = params[:end_time]
-
- else
- tip_exception("分班发布设置不能为空") if params[:group_settings].blank?
- # 创建作业的分班设置
- create_homework_group_settings @homework
-
- setting_group_ids = []
-
- params[:group_settings].each do |setting|
- tip_exception("分班id不能为空") if setting[:group_id].length == 0
- tip_exception("发布时间不能为空") if setting[:publish_time].blank?
- tip_exception("截止时间不能为空") if setting[:end_time].blank?
- tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now)
- tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now)
- tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
- tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day
-
-
- publish_time = setting[:publish_time] == "" ? Time.now : setting[:publish_time]
- # 截止时间为空时取发布时间后一个月
- end_time = setting[:end_time]
- HomeworkGroupSetting.where(homework_common_id: @homework.id, course_group_id: setting[:group_id]).
- update_all(publish_time: publish_time, end_time: end_time)
- setting_group_ids << setting[:group_id]
- end
-
- # 未设置的分班:发布时间和截止时间都为nil
- HomeworkGroupSetting.where.not(course_group_id: setting_group_ids).where(homework_common_id: @homework.id).
- update_all(publish_time: nil, end_time: nil)
-
- # 记录已发布需要发消息的分班
- publish_group_ids = HomeworkGroupSetting.where(homework_common_id: @homework.id).group_published.pluck(:course_group_id)
-
- @homework.unified_setting = 0
- @homework.publish_time = @homework.min_group_publish_time
- @homework.end_time = @homework.max_group_end_time
- end
-
- # 如果作业立即发布则更新状态、发消息
- if @homework.publish_time <= Time.now and @homework_detail_manual.comment_status == 0
- @homework_detail_manual.comment_status = 1
- send_tiding = true
- end
-
- # 作业在"提交中"状态时
- else
- if @homework.end_time > Time.now && @homework.unified_setting
- tip_exception("截止时间不能为空") if params[:end_time].blank?
- tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
- tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
-
- @homework.end_time = params[:end_time]
-
- elsif !@homework.unified_setting
- create_homework_group_settings @homework
- tip_exception("分班发布设置不能为空") if params[:group_settings].blank?
- params[:group_settings].each do |setting|
- group_settings = HomeworkGroupSetting.where(homework_common_id: @homework.id, course_group_id: setting[:group_id])
-
- tip_exception("分班id不能为空") if setting[:group_id].length == 0
- tip_exception("发布时间不能为空") if setting[:publish_time].blank?
- tip_exception("截止时间不能为空") if setting[:end_time].blank?
- # 如果该发布规则 没有已发布的分班则需判断发布时间
- tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0
-
- tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) && group_settings.none_end.count > 0
- tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
- tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
- @course.end_date.present? && setting[:end_time] > strf_time(@course.end_date.end_of_day)
-
- group_settings.none_published.update_all(publish_time: setting[:publish_time])
- group_settings.none_end.update_all(end_time: setting[:end_time])
- end
-
- @homework.end_time = @homework.max_group_end_time
- end
- end
-=end
# 补交设置
tip_exception("缺少allow_late参数") if params[:allow_late].nil?
@@ -880,69 +783,6 @@ class HomeworkCommonsController < ApplicationController
## 分页参数
page = params[:page] || 1
@shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10)
-
- # 新版用下面的代码
- # ## 我的实训
- # @shixuns =
- # if params[:order_by] == 'mine'
- # current_user.my_shixuns.unhidden
- # else
- # if current_user.admin?
- # Shixun.unhidden
- # else
- # none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
- #
- # @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
- # end
- # end
- #
- # ## 方向
- # if params[:tag_level].present? && params[:tag_id].present?
- # @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i)
- # case params[:tag_level].to_i
- # when 1 #大类
- # @search_tags = Repertoire.find(params[:tag_id].to_i).name
- # when 2 #子类
- # @search_tags = SubRepertoire.find(params[:tag_id].to_i).name
- # when 3 #tag
- # tag = TagRepertoire.find(params[:tag_id].to_i)
- # @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}"
- # end
- # end
- #
- # ## 搜索关键字创建者、实训名称、院校名称
- # if params[:keyword].present?
- # keyword = params[:keyword].strip
- # @shixuns = @shixuns.joins(user: [user_extenison: :school]).
- # where("schools.name like '%#{keyword}%'
- # or concat(lastname, firstname) like '%#{keyword}%'
- # or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct
- # end
- #
- # ## 筛选 难度
- # if params[:diff].present? && params[:diff].to_i != 0
- # @shixuns = @shixuns.where(trainee: params[:diff])
- # end
- #
- # ## 排序参数
- # bsort = params[:sort] || 'desc'
- # case params[:order_by] || 'hot'
- # when 'hot'
- # @shixuns = @shixuns.order("myshixuns_count #{bsort}")
- # when 'mine'
- # @shixuns = @shixuns.order("shixuns.created_at #{bsort}")
- # else
- # @shixuns = @shixuns.order("myshixuns_count #{bsort}")
- # end
- #
- # @total_count = @shixuns.count
- #
- # ## 分页参数
- # page = params[:page] || 1
- # limit = params[:limit] || 15
- #
- # @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit)
- #
end
def create_shixun_homework
@@ -1046,7 +886,7 @@ class HomeworkCommonsController < ApplicationController
course_module_id: course_module.id, position: course_module.course_second_categories.count + 1)
# 去掉不对当前用户的单位公开的实训,已发布的实训
- stage.shixuns.where.not(shixuns: {id: none_shixun_ids}).unhidden.each do |shixun|
+ stage.shixuns.no_jupyter.where.not(shixuns: {id: none_shixun_ids}).unhidden.each do |shixun|
homework = HomeworksService.new.create_homework shixun, @course, category, current_user
@homework_ids << homework.id
CreateStudentWorkJob.perform_later(homework.id)
@@ -1248,31 +1088,6 @@ class HomeworkCommonsController < ApplicationController
# homework_challenge_settings = homework.homework_challenge_settings
unless student_works.blank?
student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if homework.allow_late
-
-=begin
- student_works.where("work_status != 0").includes(:myshixun).each do |student_work|
- unless student_work.myshixun.is_complete?
- student_work.update_attributes(work_status: 2, late_penalty: homework.late_penalty)
- student_work.late_penalty = homework.late_penalty
- end
- HomeworksService.new.set_shixun_final_score student_work, student_work.myshixun, homework_detail_manual.answer_open_evaluation,
- homework_challenge_settings
- end
-
- student_works.where("work_status = 0").each do |student_work|
- myshixun = Myshixun.where(shixun_id: shixun.id, user_id: student_work.user_id).first
- if myshixun.present?
- student_work.update_attributes(work_status: (myshixun.is_complete? ? 1 : 2),
- late_penalty: myshixun.is_complete? ? 0 : homework.late_penalty,
- commit_time: myshixun.created_at, myshixun_id: myshixun.id)
- student_work.late_penalty = myshixun.is_complete? ? 0 : homework.late_penalty
- HomeworksService.new.set_shixun_final_score student_work, myshixun, homework_detail_manual.answer_open_evaluation,
- homework_challenge_settings
- end
- end
-=end
-
- # 更新所有学生的效率分(重新取homework确保是更新后的)
end
end
homework.save!
@@ -1558,6 +1373,21 @@ class HomeworkCommonsController < ApplicationController
end
+ def batch_comment
+ tip_exception(-1, "作业还未发布,不能评阅") if @homework_detail_manual.comment_status == 0
+ tip_exception("请至少输入一个评阅") if params[:comment].blank? && params[:hidden_comment].blank?
+ ActiveRecord::Base.transaction do
+ work_ids = @homework.student_works.where(work_status: [1, 2], user_id: @course.teacher_group_user_ids(current_user.id)).pluck(:id)
+ has_comment_ids = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 0).pluck(:student_work_id)
+ batch_comment_works = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 1)
+ batch_comment_works.update_all(comment: params[:comment], hidden_comment: params[:hidden_comment])
+ work_ids = work_ids - has_comment_ids - batch_comment_works.pluck(:student_work_id)
+ # @homework.student_works.where(work_status: 0, id: work_ids).update_all(work_status: 1, commit_time: @homework.end_time, update_time: Time.now, work_score: 0, final_score: 0)
+ HomeworkBatchCommentJob.perform_later(params[:comment], params[:hidden_comment], work_ids, @homework.id, current_user.id)
+ normal_status("评阅成功")
+ end
+ end
+
private
def find_homework
diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb
index 104851676..1e7a8c961 100644
--- a/app/controllers/item_banks_controller.rb
+++ b/app/controllers/item_banks_controller.rb
@@ -1,14 +1,58 @@
-class LibrariesController < ApplicationController
+class ItemBanksController < ApplicationController
include PaginateHelper
+ before_action :require_login
+ before_action :find_item, except: [:index, :create]
+ before_action :edit_auth, only: [:update, :destroy, :set_public]
def index
- default_sort('updated_at', 'desc')
-
- @items = ItemBankQuery.call(params)
- @items = paginate courses.includes(:school, :students, :attachments, :homework_commons, teacher: :user_extension)
+ items = ItemBankQuery.call(params)
+ @items_count = items.size
+ @items = paginate items.includes(:item_analysis, :user, :container)
+ @item_basket_ids = current_user.item_baskets.pluck(:item_bank_id)
end
def create
+ item = ItemBank.new(user: current_user)
+ ItemBanks::SaveItemService.call(item, form_params)
+ render_ok
+ rescue ApplicationService::Error => ex
+ render_error(ex.message)
+ end
+
+ def edit
+
+ end
+
+ def update
+ ItemBanks::SaveItemService.call(@item, form_params)
+ render_ok
+ rescue ApplicationService::Error => ex
+ render_error(ex.message)
+ end
+
+ def destroy
+ @item.destroy!
+ render_ok
+ end
+ def set_public
+ tip_exception(-1, "该试题已公开") if @item.public?
+ @item.update_attributes!(public: 1)
+ render_ok
end
+
+ private
+
+ def find_item
+ @item = ItemBank.find_by!(id: params[:id])
+ end
+
+ def edit_auth
+ current_user.admin_or_business? || @item.user == current_user
+ end
+
+ def form_params
+ params.permit(:discipline_id, :sub_discipline_id, :item_type, :difficulty, :name, :analysis, tag_discipline_id: [], choices: %i[choice_text is_answer])
+ end
+
end
\ No newline at end of file
diff --git a/app/controllers/item_baskets_controller.rb b/app/controllers/item_baskets_controller.rb
new file mode 100644
index 000000000..21203346b
--- /dev/null
+++ b/app/controllers/item_baskets_controller.rb
@@ -0,0 +1,90 @@
+class ItemBasketsController < ApplicationController
+ before_action :require_login
+ before_action :validate_score, only: [:set_score, :batch_set_score]
+ helper_method :current_basket
+
+ def index
+ @item_baskets = current_user.item_baskets
+ @single_questions = @item_baskets.where(item_type: "SINGLE")
+ @multiple_questions = @item_baskets.where(item_type: "MULTIPLE")
+ @judgement_questions = @item_baskets.where(item_type: "JUDGMENT")
+ @program_questions = @item_baskets.where(item_type: "PROGRAM")
+ end
+
+ def basket_list
+ @single_questions_count = current_user.item_baskets.where(item_type: "SINGLE").count
+ @multiple_questions_count = current_user.item_baskets.where(item_type: "MULTIPLE").count
+ @judgement_questions_count = current_user.item_baskets.where(item_type: "JUDGMENT").count
+ @completion_questions_count = current_user.item_baskets.where(item_type: "COMPLETION").count
+ @subjective_questions_count = current_user.item_baskets.where(item_type: "SUBJECTIVE").count
+ @practical_questions_count = current_user.item_baskets.where(item_type: "PRACTICAL").count
+ @program_questions_count = current_user.item_baskets.where(item_type: "PROGRAM").count
+ end
+
+ def create
+ ItemBaskets::SaveItemBasketService.call(current_user, create_params)
+ render_ok
+ rescue ApplicationService::Error => ex
+ render_error(ex.message)
+ end
+
+ def destroy
+ item = current_user.item_baskets.find_by!(item_bank_id: params[:id])
+ ActiveRecord::Base.transaction do
+ current_user.item_baskets.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1")
+ item.destroy!
+ end
+ render_ok
+ end
+
+ def delete_item_type
+ baskets = ItemBasket.where(item_type: params[:item_type])
+ baskets.destroy_all
+ render_ok
+ end
+
+ def set_score
+ current_basket.update_attributes!(score: params[:score])
+ @questions_score = current_user.item_baskets.where(item_type: current_basket.item_type).pluck(:score).sum
+ @all_score = current_user.item_baskets.pluck(:score).sum
+ end
+
+ def batch_set_score
+ current_user.item_baskets.where(item_type: params[:item_type]).update_all(score: params[:score])
+ @questions_score = current_user.item_baskets.where(item_type: params[:item_type]).pluck(:score).sum
+ @all_score = current_user.item_baskets.pluck(:score).sum
+ end
+
+ def adjust_position
+ same_items = current_user.item_baskets.where(item_type: current_basket.item_type)
+ max_position = same_items.size
+ tip_exception("position超出范围") unless params[:position].present? && params[:position].to_i <= max_position && params[:position].to_i >= 1
+ ActiveRecord::Base.transaction do
+ if params[:position].to_i > current_basket.position
+ same_items.where("position > #{current_basket.position} and position <= #{params[:position].to_i}").update_all("position=position-1")
+ current_basket.update_attributes!(position: params[:position])
+ elsif params[:position].to_i < current_basket.position
+ same_items.where("position < #{current_basket.position} and position >= #{params[:position].to_i}").update_all("position=position+1")
+ current_basket.update_attributes!(position: params[:position])
+ else
+ return normal_status(-1, "排序无变化")
+ end
+ end
+ render_ok
+ end
+
+ private
+
+ def create_params
+ params.permit(item_ids: [])
+ end
+
+ def current_basket
+ @_current_basket = current_user.item_baskets.find_by!(id: params[:id])
+ end
+
+ def validate_score
+ tip_exception("分值不能为空") unless params[:score].present?
+ tip_exception("分值需大于0") unless params[:score].to_f > 0
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb
index 0e2628c3e..e8554300c 100644
--- a/app/controllers/main_controller.rb
+++ b/app/controllers/main_controller.rb
@@ -1,4 +1,10 @@
class MainController < ApplicationController
+ skip_before_action :check_sign
+
+ def first_stamp
+ render :json => { status: 0, message: Time.now.to_i }
+ end
+
def index
render file: 'public/react/build/index.html', :layout => false
end
diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb
index 255c0f42e..67bec877b 100644
--- a/app/controllers/myshixuns_controller.rb
+++ b/app/controllers/myshixuns_controller.rb
@@ -3,6 +3,7 @@ class MyshixunsController < ApplicationController
before_action :find_myshixun, :except => [:training_task_status, :code_runinng_message]
before_action :find_repo_name, :except => [:training_task_status, :code_runinng_message]
skip_before_action :verify_authenticity_token, :only => [:html_content]
+ skip_before_action :check_sign, only: [:training_task_status, :code_runinng_message]
## TPI关卡列表
def challenges
diff --git a/app/controllers/partners_controller.rb b/app/controllers/partners_controller.rb
index 7875e1780..dfa1b2017 100644
--- a/app/controllers/partners_controller.rb
+++ b/app/controllers/partners_controller.rb
@@ -1,4 +1,5 @@
class PartnersController < ApplicationController
+ skip_before_action :check_sign
include Base::PaginateHelper
include Admins::RenderHelper
diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb
index 0c442a613..3e6914dee 100644
--- a/app/controllers/polls_controller.rb
+++ b/app/controllers/polls_controller.rb
@@ -46,8 +46,8 @@ class PollsController < ApplicationController
@polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : []
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
# 已发布 当前用户班级分组的 试卷id
- not_poll_ids = @course.poll_group_settings.poll_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id)
- @polls = member_show_polls.where.not(id: not_poll_ids)
+ publish_poll_ids = @course.poll_group_settings.poll_group_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id)
+ @polls = member_show_polls.unified_setting.or(member_show_polls.where(id: publish_poll_ids))
end
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
@is_teacher_or = 0
@@ -722,19 +722,16 @@ class PollsController < ApplicationController
un_anonymous = params[:un_anonymous] ? true : false
# 统一设置或者分班为0,则更新问卷,并删除问卷分组
if unified_setting || (course_group_ids.size == 0)
- params_publish_time = params[:publish_time].present? ? params[:publish_time].to_time : nil
- params_end_time = nil
- if params[:end_time].blank?
- if params_publish_time.present?
- params_end_time = params_publish_time + 30.days
- end
- else
- params_end_time = params[:end_time].to_time
- end
- # params_end_time = params[:end_time].present? ? params[:end_time].to_time : nil
- if poll_status == 2 && @poll.publish_time != params_publish_time
- normal_status(-1,"不允许修改发布时间")
- elsif poll_status == 3 && (@poll.end_time != params_end_time || @poll.publish_time != params_publish_time)
+ tip_exception("发布时间不能为空") if params[:publish_time].blank?
+ tip_exception("截止时间不能为空") if params[:end_time].blank?
+ tip_exception("截止时间不能早于发布时间") if params[:publish_time].to_time > params[:end_time].to_time
+ tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
+ @course.end_date.present? && params[:end_time].to_time > @course.end_date.end_of_day
+
+ params_publish_time = params[:publish_time].to_time
+ params_end_time = params[:end_time].to_time
+
+ if poll_status != 1 && @poll.publish_time != params_publish_time
normal_status(-1,"不允许修改发布时间")
elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time
normal_status(-1,"截止时间不能小于发布时间")
@@ -761,24 +758,25 @@ class PollsController < ApplicationController
total_common_group = poll_groups_ids & total_common #传入的分班与问卷已存在的分班的交集
old_poll_groups = poll_groups_ids - total_common_group #后来传入的分班里,没有了的班级,即需要删除
params_times.each do |t|
- course_id = t[:course_group_id] #为数组,可能会设置分班为各个班级id的数组
- poll_publish_time = t[:publish_time].present? ? t[:publish_time].to_time : nil
- # poll_end_time = t[:end_time].present? ? t[:end_time].to_time : nil
- poll_end_time = nil
- if t[:end_time].blank?
- if poll_publish_time.present?
- poll_end_time = poll_publish_time + 30.days
- end
- else
- poll_end_time = t[:end_time].to_time
- end
+ tip_exception("发布时间不能为空") if t[:publish_time].blank?
+ tip_exception("截止时间不能为空") if t[:end_time].blank?
+ tip_exception("截止时间不能早于发布时间") if t[:publish_time].to_time > t[:end_time].to_time
+ tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if
+ @course.end_date.present? && t[:end_time].to_time > @course.end_date.end_of_day
+
+ course_id = t[:course_group_id]
+ poll_publish_time = t[:publish_time].to_time
+ poll_end_time = t[:end_time].to_time
+
poll_group = poll_groups.find_in_poll_group("course_group_id",course_id) #判断该分班是否存在
- if poll_group.present? && poll_group.first.end_time <= Time.now && (poll_end_time != poll_group.first.end_time || poll_publish_time != poll_group.first.publish_time) #已截止且时间改变的,则提示错误
+
+ if poll_group.present? && (poll_group.first.publish_time < Time.now) && (poll_publish_time != poll_group.first.publish_time)
error_count += 1
end
- if poll_group.present? && poll_group.first.publish_time < Time.now && poll_publish_time != poll_group.first.publish_time
+ if poll_group.present? && (poll_group.first.publish_time < Time.now && poll_group.first.end_time > Time.now) && (poll_end_time < Time.now)
error_count += 1
end
+
if error_count == 0
common_group = poll_groups_ids & course_id #传入的班级与问卷已存在的班级的交集,即表示已有分班的
new_group_ids = course_id - common_group #新传入的班级id
@@ -794,12 +792,12 @@ class PollsController < ApplicationController
if the_group_setting_status == 2
poll_group_params = {
:publish_time => the_group_setting.publish_time,
- :end_time => poll_end_time
+ :end_time => poll_end_time < Time.now ? the_group_setting.end_time : poll_end_time
}
elsif the_group_setting_status == 3
poll_group_params = {
:publish_time => the_group_setting.publish_time,
- :end_time => the_group_setting.end_time
+ :end_time => poll_end_time
}
end
the_group_setting.update_attributes(poll_group_params)
diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb
index 99ca62b4c..ae0315cdd 100644
--- a/app/controllers/schools_controller.rb
+++ b/app/controllers/schools_controller.rb
@@ -1,4 +1,5 @@
class SchoolsController < ApplicationController
+ skip_before_action :check_sign
def school_list
schools = School.all
@@ -14,7 +15,6 @@ class SchoolsController < ApplicationController
schools = School.all
keyword = params[:keyword].to_s.strip
schools = schools.where('name LIKE ?', "%#{keyword}%") if keyword
-
render_ok(schools: schools.select(:id, :name).as_json)
end
diff --git a/app/controllers/shixun_lists_controller.rb b/app/controllers/shixun_lists_controller.rb
index d0bfe3d88..c77da46e0 100644
--- a/app/controllers/shixun_lists_controller.rb
+++ b/app/controllers/shixun_lists_controller.rb
@@ -4,7 +4,8 @@ class ShixunListsController < ApplicationController
end
private
+
def search_params
- params.permit(:keyword, :type, :page, :limit, :order, :status, :diff)
+ params.permit(:keyword, :type, :page, :limit, :order, :status, :diff, :sort, :no_jupyter)
end
end
\ No newline at end of file
diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb
index 7c5964962..f86ade58f 100644
--- a/app/controllers/shixuns_controller.rb
+++ b/app/controllers/shixuns_controller.rb
@@ -18,12 +18,14 @@ class ShixunsController < ApplicationController
before_action :find_repo_name, only: [:repository, :commits, :file_content, :update_file, :shixun_exec, :copy,
:add_file, :jupyter_exec]
- before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish, :apply_public,
- :shixun_members_added, :change_manager, :collaborators_delete,
- :cancel_apply_public, :cancel_publish, :add_collaborators, :add_file]
+ before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish, :apply_public, :upload_git_folder,
+ :shixun_members_added, :change_manager, :collaborators_delete, :upload_git_file,
+ :cancel_apply_public, :cancel_publish, :add_collaborators, :add_file, :delete_git_file]
before_action :portion_allowed, only: [:copy]
before_action :special_allowed, only: [:send_to_course, :search_user_courses]
+ before_action :shixun_marker, only: [:new, :create]
+ skip_before_action :check_sign, only: [:download_file]
## 获取课程列表
def index
@@ -215,7 +217,8 @@ class ShixunsController < ApplicationController
if @shixun.shixun_info.present?
ShixunInfo.create!(shixun_id: @new_shixun.id,
description: @shixun.description,
- evaluate_script: @shixun.evaluate_script)
+ evaluate_script: @shixun.evaluate_script,
+ fork_reason: params[:reason].to_s.strip)
end
# 同步私密版本库
@@ -265,8 +268,20 @@ class ShixunsController < ApplicationController
# 如果是jupyter,先创建一个目录,为了挂载(因为后续数据集,开启Pod后环境在没销毁前,你上传数据集是挂载不上目录的,因此要先创建目录,方便中间层挂载)
if @new_shixun.is_jupyter?
folder = EduSetting.get('shixun_folder')
+ raise "存储目录未定义" unless folder.present?
path = "#{folder}/#{@new_shixun.identifier}"
FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path)
+ # 复制数据集
+ save_path = File.join(folder, @shixun.identifier)
+ @shixun.data_sets.each do |set|
+ new_date_set = Attachment.new
+ new_date_set.attributes = set.attributes.dup.except("id", "container_id", "disk_directory")
+ new_date_set.container_id = @new_shixun.id
+ new_date_set.disk_directory = @new_shixun.identifier
+ new_date_set.save!
+ FileUtils.cp("#{save_path}/#{set.relative_path_filename}", path)
+ end
+
end
# 同步复制关卡
if @shixun.challenges.present?
@@ -350,7 +365,7 @@ class ShixunsController < ApplicationController
page = params[:page] || 1
limit = params[:limit] || 10
@member_count = @shixun.shixun_members.count
- @members = @shixun.shixun_members.includes(:user).page(page).per(limit)
+ @members = @shixun.shixun_members.order("role = 1 desc, created_at asc").includes(:user).page(page).per(limit)
end
def fork_list
@@ -454,7 +469,13 @@ class ShixunsController < ApplicationController
def update_learn_setting
begin
ActiveRecord::Base.transaction do
- @shixun.update_attributes!(shixun_params)
+ update_params =
+ if params[:shixun][:vnc]
+ shixun_params.merge(vnc_evaluate: 1)
+ else
+ shixun_params
+ end
+ @shixun.update_attributes!(update_params)
end
rescue => e
uid_logger_error("实训学习页面设置失败--------#{e.message}")
@@ -753,7 +774,7 @@ class ShixunsController < ApplicationController
# jupyter开启挑战
def jupyter_exec
- begin
+
if is_shixun_opening?
tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}")
end
@@ -767,22 +788,23 @@ class ShixunsController < ApplicationController
commit_id = commit["id"]
cloud_bridge = edu_setting('cloud_bridge')
myshixun_identifier = generate_identifier Myshixun, 10
- ActiveRecord::Base.transaction do
- @myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier,
- modify_time: @shixun.modify_time, reset_time: @shixun.reset_time,
- onclick_time: Time.now, commit_id: commit_id)
- # fork仓库
- project_fork(@myshixun, @repo_path, current_user.login)
- rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path)
- uri = "#{cloud_bridge}/bridge/game/openGameInstance"
- params = {tpiID: "#{@myshixun.id}", tpmGitURL: rep_url, tpiRepoName: @myshixun.repo_name.split("/").last}
- interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)"
+ begin
+ ActiveRecord::Base.transaction do
+ @myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier,
+ modify_time: @shixun.modify_time, reset_time: @shixun.reset_time,
+ onclick_time: Time.now, commit_id: commit_id)
+ # fork仓库
+ project_fork(@myshixun, @repo_path, current_user.login)
+ rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path)
+ uri = "#{cloud_bridge}/bridge/game/openGameInstance"
+ params = {tpiID: "#{@myshixun.id}", tpmGitURL: rep_url, tpiRepoName: @myshixun.repo_name.split("/").last}
+ interface_post uri, params, 83, "服务器出现问题,请重置环境"
+ end
+ rescue => e
+ uid_logger_error(e.message)
+ tip_exception("服务器出现问题,请重置环境")
end
end
- rescue => e
- uid_logger_error(e.message)
- tip_exception("#{e.message}")
- end
end
def publish
@@ -862,7 +884,36 @@ class ShixunsController < ApplicationController
author_name = current_user.real_name
author_email = current_user.git_mail
@content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser"
- end
+ end
+
+ def upload_git_file
+ upload_file = params["file"]
+ uid_logger("#########################file_params####{params["#{params[:file]}"]}")
+ raise "未上传文件" unless upload_file
+ content = upload_file.tempfile.read
+ author_name = current_user.real_name
+ author_email = current_user.git_mail
+ message = params[:message] || "upload file by browser"
+ update_file_content(content, @repo_path, @path, author_email, author_name, message)
+ render_ok
+ end
+
+ # 上传目录
+ def upload_git_folder
+ author_name = current_user.real_name
+ author_email = current_user.git_mail
+ message = params[:message] || "upload folder by browser"
+ git_add_folder(@path, author_name, author_email, message)
+ render_ok
+ end
+
+ def delete_git_file
+ author_name = current_user.real_name
+ author_email = current_user.git_mail
+ message = params[:message] || "delete file by browser"
+ git_delete_file(@path, author_name, author_email, message)
+ render_ok
+ end
def add_collaborators
member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")"
@@ -896,16 +947,20 @@ class ShixunsController < ApplicationController
# 搜索成员
if request.get?
@collaborators = @shixun.shixun_members.where("user_id != #{@shixun.user_id}")
- else
- if params[:user_id]
- man_member = ShixunMember.where(:shixun_id => @shixun.id, :user_id => @shixun.user_id).first
- cha_member = ShixunMember.where(:user_id => params[:user_id], :shixun_id => @shixun.id).first
- if man_member && cha_member
- man_member.update_attribute(:role, 2)
- cha_member.update_attribute(:role, 1)
- @shixun.update_attribute(:user_id, cha_member.user_id)
- end
- end
+ else
+ begin
+ raise("请先选择成员") if params[:user_id].blank?
+ man_member = ShixunMember.where(:shixun_id => @shixun.id, :user_id => @shixun.user_id).first
+ cha_member = ShixunMember.where(:user_id => params[:user_id], :shixun_id => @shixun.id).first
+ if man_member && cha_member
+ man_member.update_attribute(:role, 2)
+ cha_member.update_attribute(:role, 1)
+ @shixun.update_attribute(:user_id, cha_member.user_id)
+ end
+ rescue => e
+ logger.error("######change_manager_error: #{e.message}")
+ render_error(e.message)
+ end
end
end
@@ -1127,4 +1182,5 @@ private
end
md5.hexdigest
end
+
end
diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb
index 6a9438a79..7df9aae89 100644
--- a/app/controllers/subjects_controller.rb
+++ b/app/controllers/subjects_controller.rb
@@ -7,6 +7,8 @@ class SubjectsController < ApplicationController
:search_members, :add_subject_members, :statistics, :shixun_report, :school_report,
:up_member_position, :down_member_position, :update_team_title]
before_action :require_admin, only: [:copy_subject]
+ before_action :shixun_marker, only: [:new, :create, :add_shixun_to_stage]
+
include ApplicationHelper
include SubjectsHelper
@@ -214,7 +216,15 @@ class SubjectsController < ApplicationController
GitService.add_repository(repo_path: repo_path)
# todo: 为什么保存的时候要去除后面的.git呢??
@shixun.update_column(:repo_name, repo_path.split(".")[0])
- mirror_id = MirrorRepository.find_by(type_name: 'Python3.6')&.id
+ mirror_id =
+ if @shixun.is_jupyter?
+ folder = EduSetting.get('shixun_folder')
+ path = "#{folder}/#{identifier}"
+ FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path)
+ MirrorRepository.where("type_name like '%Jupyter%'").first&.id
+ else
+ MirrorRepository.find_by(type_name: 'Python3.6')&.id
+ end
if mirror_id
ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror_id)
@shixun.shixun_service_configs.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror_id)
@@ -247,7 +257,7 @@ class SubjectsController < ApplicationController
CourseSecondCategory.create!(name: stage.name, course_id: @course.id, category_type: "shixun_homework",
course_module_id: course_module.id, position: course_module.course_second_categories.count + 1)
- stage.shixuns.where(id: params[:shixun_ids], status: 2).each do |shixun|
+ stage.shixuns.no_jupyter.where(id: params[:shixun_ids], status: 2).each do |shixun|
homework = HomeworksService.new.create_homework shixun, @course, category, current_user
homework_ids << homework.id
end
diff --git a/app/controllers/tag_disciplines_controller.rb b/app/controllers/tag_disciplines_controller.rb
new file mode 100644
index 000000000..2650f51eb
--- /dev/null
+++ b/app/controllers/tag_disciplines_controller.rb
@@ -0,0 +1,9 @@
+class TagDisciplinesController < ApplicationController
+ before_action :require_login
+
+ def create
+ sub_discipline = SubDiscipline.find_by!(id: params[:sub_discipline_id])
+ tag_discipline = TagDiscipline.create!(name: params[:name].to_s.strip, sub_discipline: sub_discipline, user_id: current_user.id)
+ render_ok({tag_discipline_id: tag_discipline.id})
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index a1f6a5495..c6dd7830c 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -2,6 +2,7 @@ class UsersController < ApplicationController
before_action :load_user, only: [:show, :homepage_info]
before_action :check_user_exist, only: [:show, :homepage_info]
+ skip_before_action :check_sign, only: [:attachment_show]
# 检查是否更新
def system_update
diff --git a/app/decorators/grade_decorator.rb b/app/decorators/grade_decorator.rb
index ffffa11c9..5e2b9deed 100644
--- a/app/decorators/grade_decorator.rb
+++ b/app/decorators/grade_decorator.rb
@@ -31,6 +31,9 @@ module GradeDecorator
when 'check_ta_answer' then
game = Game.find_by(id: container_id)
game.present? ? "查看实训“#{game.challenge.shixun.name}”第#{game.challenge.position}关的TA人解答消耗的金币" : ''
+ when 'hack' then
+ hack = Hack.find_by(id: container_id)
+ hack.present? ? "完成了题目解答“#{hack.name}”,获得金币奖励:#{hack.score}" : ''
end
end
end
\ No newline at end of file
diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb
index 130e7f4b8..58345b601 100644
--- a/app/decorators/tiding_decorator.rb
+++ b/app/decorators/tiding_decorator.rb
@@ -220,11 +220,14 @@ module TidingDecorator
when 'Journal' then
message = parent_container&.notes.present? ? ':' + message_content_helper(parent_container.notes) : ''
I18n.t(locale_format(parent_container_type)) % message
+ when 'Hack' then
+ I18n.t(locale_format(parent_container_type)) % parent_container.name
end
end
def discuss_content
- I18n.t(locale_format(container.parent_id.present?)) % message_content_helper(container.content)
+ I18n.t(locale_format(parent_container_type, container.parent_id.present?)) %
+ (parent_container_type == 'Hack' ? container.content : message_content_helper(container.content))
end
def grade_content
@@ -250,6 +253,9 @@ module TidingDecorator
when 'shixunPublish' then
name = Shixun.find_by(id: parent_container_id)&.name || '---'
I18n.t(locale_format(parent_container_type)) % [name, container.score]
+ when 'Hack' then
+ name = Hack.find_by(id: container_id)&.name || '---'
+ I18n.t(locale_format(parent_container_type)) % [name, container.score]
else
I18n.t(locale_format(parent_container_type)) % container.score
end
@@ -405,4 +411,8 @@ module TidingDecorator
def subject_start_course_content
I18n.t(locale_format) % belong_container&.name
end
+
+ def hack_content
+ I18n.t(locale_format(parent_container_type)) % (container&.name || extra)
+ end
end
diff --git a/app/forms/examination_banks/save_exam_form.rb b/app/forms/examination_banks/save_exam_form.rb
new file mode 100644
index 000000000..b84b32eb1
--- /dev/null
+++ b/app/forms/examination_banks/save_exam_form.rb
@@ -0,0 +1,15 @@
+class ExaminationBanks::SaveExamForm
+ include ActiveModel::Model
+
+ attr_accessor :discipline_id, :sub_discipline_id, :difficulty, :name, :duration, :tag_discipline_id
+
+ validates :discipline_id, presence: true
+ validates :sub_discipline_id, presence: true
+ validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
+ validates :name, presence: true, length: { maximum: 60 }
+ validate :validate_duration
+
+ def validate_duration
+ raise '时长应为大于0的整数' if duration.present? && duration.to_i < 1
+ end
+end
\ No newline at end of file
diff --git a/app/forms/item_banks/save_item_form.rb b/app/forms/item_banks/save_item_form.rb
new file mode 100644
index 000000000..2bfd99fc3
--- /dev/null
+++ b/app/forms/item_banks/save_item_form.rb
@@ -0,0 +1,33 @@
+class ItemBanks::SaveItemForm
+ include ActiveModel::Model
+
+ attr_accessor :discipline_id, :sub_discipline_id, :item_type, :difficulty, :name, :analysis, :tag_discipline_id, :choices
+
+ validates :discipline_id, presence: true
+ validates :sub_discipline_id, presence: true
+ validates :item_type, presence: true, inclusion: {in: %W(SINGLE MULTIPLE JUDGMENT COMPLETION SUBJECTIVE PRACTICAL PROGRAM)}
+ validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
+ validates :name, presence: true, length: { maximum: 1000 }
+ validates :analysis, length: { maximum: 1000 }
+
+ def validate!
+ super
+ return unless errors.blank?
+ choices.each { |item| SubForm.new(item).validate! } if %W(SINGLE MULTIPLE JUDGMENT).include?(item_type)
+ return unless errors.blank?
+ if [0, 2].include?(item_type) && choices.pluck(:is_answer).select{|item| item == 1}.length > 1
+ raise("正确答案只能有一个")
+ elsif item_type == 1 && choices.pluck(:is_answer).select{|item| item == 1}.length <= 1
+ raise("多选题至少有两个正确答案")
+ end
+ end
+
+ class SubForm
+ include ActiveModel::Model
+
+ attr_accessor :choice_text, :is_answer
+
+ validates :choice_text, presence: true, length: { maximum: 100 }
+ validates :is_answer, presence: true, inclusion: {in: 0..1}, numericality: { only_integer: true }
+ end
+end
\ No newline at end of file
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index cabf8d244..40e6cb365 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -64,7 +64,7 @@ module ApplicationHelper
shixun_id = shixun_id.blank? ? -1 : shixun_id.join(",")
Shixun.select([:id, :name, :user_id, :challenges_count, :myshixuns_count, :trainee, :identifier]).where("id
- in(#{shixun_id})").unhidden.order("homepage_show asc, myshixuns_count desc").limit(3)
+ in(#{shixun_id})").unhidden.publiced.order("homepage_show asc, myshixuns_count desc").limit(3)
end
diff --git a/app/imports/admins/import_discipline_excel.rb b/app/imports/admins/import_discipline_excel.rb
new file mode 100644
index 000000000..b457f4818
--- /dev/null
+++ b/app/imports/admins/import_discipline_excel.rb
@@ -0,0 +1,16 @@
+class Admins::ImportDisciplineExcel < BaseImportXlsx
+ DisciplineData = Struct.new(:discipline_name, :sub_discipline_name)
+
+ def read_each(&block)
+ sheet.each_row_streaming(pad_cells: true, offset: 2) do |row|
+ data = row.map(&method(:cell_value))[1..2]
+ block.call DisciplineData.new(*data)
+ end
+ end
+
+ private
+
+ def cell_value(obj)
+ obj&.cell_value
+ end
+end
diff --git a/app/jobs/homework_batch_comment_job.rb b/app/jobs/homework_batch_comment_job.rb
new file mode 100644
index 000000000..b9baa8557
--- /dev/null
+++ b/app/jobs/homework_batch_comment_job.rb
@@ -0,0 +1,20 @@
+# 作业的一键评阅
+class HomeworkBatchCommentJob < ApplicationJob
+ queue_as :default
+
+ def perform(comment, hidden_comment, work_ids, homework_id, user_id)
+ # Do something later
+ homework = HomeworkCommon.find_by(id: homework_id)
+ return if homework.blank?
+
+ attrs = %i[student_work_id challenge_id user_id comment hidden_comment batch_comment created_at updated_at]
+
+ same_attrs = {challenge_id: 0, user_id: user_id, comment: comment, hidden_comment: hidden_comment, batch_comment: 1}
+
+ ShixunWorkComment.bulk_insert(*attrs) do |worker|
+ work_ids.each do |work_id|
+ worker.add same_attrs.merge(student_work_id: work_id)
+ end
+ end
+ end
+end
diff --git a/app/models/course_group.rb b/app/models/course_group.rb
index d57edf497..9486c9043 100644
--- a/app/models/course_group.rb
+++ b/app/models/course_group.rb
@@ -2,13 +2,15 @@ class CourseGroup < ApplicationRecord
default_scope { order("course_groups.position ASC") }
belongs_to :course, counter_cache: true
has_many :course_members
-
has_many :exercise_group_settings,:dependent => :destroy
has_many :attachment_group_settings, :dependent => :destroy
has_many :homework_group_reviews, :dependent => :destroy
+ has_many :teacher_course_groups, :dependent => :destroy
+ has_many :homework_group_settings, :dependent => :destroy
scope :by_group_ids, lambda { |ids| where(id: ids)}
validates :name, length: { maximum: 60 }
+ validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班"
after_create :generate_invite_code
diff --git a/app/models/discipline.rb b/app/models/discipline.rb
new file mode 100644
index 000000000..8d6a16ced
--- /dev/null
+++ b/app/models/discipline.rb
@@ -0,0 +1,7 @@
+class Discipline < ApplicationRecord
+ has_many :sub_disciplines, dependent: :destroy
+
+ has_many :shixun_sub_disciplines, -> { where("shixun = 1") }, class_name: "SubDiscipline"
+ has_many :subject_sub_disciplines, -> { where("subject = 1") }, class_name: "SubDiscipline"
+ has_many :question_sub_disciplines, -> { where("question = 1") }, class_name: "SubDiscipline"
+end
diff --git a/app/models/discuss.rb b/app/models/discuss.rb
index a50b18a6f..4e6cd617c 100644
--- a/app/models/discuss.rb
+++ b/app/models/discuss.rb
@@ -10,7 +10,7 @@ class Discuss < ApplicationRecord
has_one :praise_tread_cache, as: :object, dependent: :destroy
belongs_to :dis, polymorphic: true
- belongs_to :challenge
+ belongs_to :challenge, optional: true
after_create :send_tiding
scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) }
@@ -52,11 +52,21 @@ class Discuss < ApplicationRecord
private
def send_tiding
+ if dis_type == 'Shixun'
+ send_user_id = has_parent? ? parent.user_id : Challenge.find(challenge_id).user_id
+ parent_container_type = 'Challenge'
+ challenge_id = challenge_id
+ extra = ''
+ elsif dis_type == 'Hack'
+ send_user_id = has_parent? ? parent.user_id : Hack.find(dis_id).user_id
+ parent_container_type = 'Hack'
+ challenge_id = dis_id
+ extra = HackUserLastestCode.where(user_id: user_id, hack_id: dis_id).first&.identifier
+ end
base_attrs = {
- trigger_user_id: user_id, parent_container_id: challenge_id, parent_container_type: 'Challenge',
- belong_container_id: dis_id, belong_container_type: 'Shixun', viewed: 0, tiding_type: 'Comment'
+ trigger_user_id: user_id, parent_container_id: challenge_id, parent_container_type: parent_container_type,
+ belong_container_id: dis_id, belong_container_type: dis_type, viewed: 0, tiding_type: 'Comment', extra: extra
}
- user_id = has_parent? ? parent.user_id : Challenge.find(challenge_id).user_id
- tidings.create!(base_attrs.merge(user_id: user_id))
+ tidings.create!(base_attrs.merge(user_id: send_user_id))
end
end
diff --git a/app/models/examination_bank.rb b/app/models/examination_bank.rb
new file mode 100644
index 000000000..9df13ccd3
--- /dev/null
+++ b/app/models/examination_bank.rb
@@ -0,0 +1,17 @@
+class ExaminationBank < ApplicationRecord
+ belongs_to :user
+ belongs_to :sub_discipline
+
+ has_many :tag_discipline_containers, as: :container, dependent: :destroy
+ has_many :tag_disciplines, through: :tag_discipline_containers
+
+ has_many :examination_items, dependent: :destroy
+
+ def question_count
+ examination_items.size
+ end
+
+ def total_score
+ examination_items.pluck(:score).sum
+ end
+end
diff --git a/app/models/examination_item.rb b/app/models/examination_item.rb
new file mode 100644
index 000000000..0cc515cae
--- /dev/null
+++ b/app/models/examination_item.rb
@@ -0,0 +1,27 @@
+class ExaminationItem < ApplicationRecord
+ enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
+
+ belongs_to :examination_bank, touch: true
+ belongs_to :item_bank, optional: true
+
+ has_many :examination_item_choices, dependent: :destroy
+ has_one :examination_item_analysis, dependent: :destroy
+ belongs_to :container, polymorphic: true, optional: true
+
+ def analysis
+ examination_item_analysis&.analysis
+ end
+
+ def item_choices
+ examination_item_choices
+ end
+
+ def public
+ 0
+ end
+
+ def quotes
+ 0
+ end
+
+end
diff --git a/app/models/examination_item_analysis.rb b/app/models/examination_item_analysis.rb
new file mode 100644
index 000000000..e96ab769f
--- /dev/null
+++ b/app/models/examination_item_analysis.rb
@@ -0,0 +1,3 @@
+class ExaminationItemAnalysis < ApplicationRecord
+ belongs_to :examination_item
+end
diff --git a/app/models/examination_item_choice.rb b/app/models/examination_item_choice.rb
new file mode 100644
index 000000000..2bc35e0b1
--- /dev/null
+++ b/app/models/examination_item_choice.rb
@@ -0,0 +1,3 @@
+class ExaminationItemChoice < ApplicationRecord
+ belongs_to :examination_item
+end
diff --git a/app/models/hack.rb b/app/models/hack.rb
index 506cd4942..79c7a0f82 100644
--- a/app/models/hack.rb
+++ b/app/models/hack.rb
@@ -11,7 +11,18 @@ class Hack < ApplicationRecord
has_many :hack_codes, :dependent => :destroy
has_many :hack_user_lastest_codes, :dependent => :destroy
has_many :discusses, as: :dis, dependent: :destroy
+ # 点赞
+ has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
+ # 消息
+ has_many :tidings, as: :container
+ # 知识点
+ has_many :tag_discipline_containers, as: :container, dependent: :destroy
+
belongs_to :user
+ belongs_to :sub_discipline
+
+ has_one :item_bank, as: :container, dependent: :destroy
+ has_one :examination_bank, as: :container, dependent: :destroy
scope :published, -> { where(status: 1) }
scope :unpublish, -> { where(status: 0) }
@@ -46,4 +57,31 @@ class Hack < ApplicationRecord
user_id == user.id || user.admin_or_business?
end
+ # 复制fork
+ def fork
+ new_hack = Hack.new
+ new_hack.attributes = self.attributes.dup.except("id", "user_id", "status", "identifier", "comments_count", "praises_count",
+ "pass_num", "created_at", "updated_at", "hack_user_lastest_codes_count",
+ "open_or_not", "submit_num")
+ new_hack.user_id = User.current.id
+ new_hack.identifier = Util::UUID.generate_identifier(Hack, 8)
+ new_hack.fork_id = self.id
+ new_hack.save!
+
+ # 创建测试集与代码
+ hack_sets.each do |set|
+ new_hack.hack_sets.create!(input: set.input, output: set.output, position: set.position)
+ end
+
+ # 新建知识点
+ tag_discipline_containers.each do |tag|
+ new_hack.tag_discipline_containers.create!(tag_discipline_id: tag.tag_discipline_id)
+ end
+
+ hack_codes.each do |code|
+ new_hack.hack_codes.create!(code: code.code, language: code.language, modify_time: Time.now)
+ end
+ new_hack
+ end
+
end
diff --git a/app/models/hack_set.rb b/app/models/hack_set.rb
index 6afe05663..9e2186fb5 100644
--- a/app/models/hack_set.rb
+++ b/app/models/hack_set.rb
@@ -1,5 +1,5 @@
class HackSet < ApplicationRecord
- #validates :input, presence: { message: "测试集输入不能为空" }
+ validates :input, presence: { message: "测试集输入不能为空" }
validates :output, presence: { message: "测试集输出不能为空" }
validates_uniqueness_of :input, scope: [:hack_id, :input], message: "多个测试集的输入不能相同"
# 编程题测试集
diff --git a/app/models/hack_user_code.rb b/app/models/hack_user_code.rb
index eee394e39..1e13f8bfb 100644
--- a/app/models/hack_user_code.rb
+++ b/app/models/hack_user_code.rb
@@ -1,4 +1,5 @@
class HackUserCode < ApplicationRecord
+ # error_test_set_id: 错误的测试集id
# 用户编程题的信息
belongs_to :hack
belongs_to :hack_user_lastest_code
diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb
index 830f16dde..99582af41 100644
--- a/app/models/hack_user_lastest_code.rb
+++ b/app/models/hack_user_lastest_code.rb
@@ -12,4 +12,6 @@ class HackUserLastestCode < ApplicationRecord
scope :mine_hack, ->(author_id){ where(user_id: author_id) }
scope :passed, -> {where(status: 1)}
+ validates_length_of :notes, maximum: 5000, message: "笔记不能超过5000个字"
+
end
diff --git a/app/models/item_bank.rb b/app/models/item_bank.rb
index 8078a55e0..ff5fb6d42 100644
--- a/app/models/item_bank.rb
+++ b/app/models/item_bank.rb
@@ -1,11 +1,20 @@
class ItemBank < ApplicationRecord
# difficulty: 1 简单 2 适中 3 困难
- # item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
+ # item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程
belongs_to :user
+ belongs_to :sub_discipline
has_one :item_analysis, dependent: :destroy
has_many :item_choices, dependent: :destroy
has_many :item_baskets, dependent: :destroy
+ has_many :tag_discipline_containers, as: :container, dependent: :destroy
+ has_many :tag_disciplines, through: :tag_discipline_containers
+
+ belongs_to :container, polymorphic: true, optional: true
+
+ def analysis
+ item_analysis&.analysis
+ end
end
diff --git a/app/models/item_basket.rb b/app/models/item_basket.rb
index d736d9bc0..a3ff865ba 100644
--- a/app/models/item_basket.rb
+++ b/app/models/item_basket.rb
@@ -1,4 +1,14 @@
class ItemBasket < ApplicationRecord
+ enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
+
belongs_to :item_bank
belongs_to :user
+
+ def all_score
+ User.current.item_baskets.map(&:score).sum
+ end
+
+ def question_count
+ User.current.item_baskets.size
+ end
end
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 5c1a9a64c..365e46008 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -19,6 +19,7 @@ class Poll < ApplicationRecord
scope :poll_by_ids, lambda { |ids| where(id: ids) unless ids.blank? }
scope :poll_by_status, lambda { |s| where(polls_status: s) unless s.blank? }
scope :poll_group_ended, -> {where("end_time is NOT NULL AND end_time <= ?",Time.now)}
+ scope :unified_setting, -> { where("unified_setting = ?",true) }
scope :poll_search, lambda { |keywords|
where("polls_name LIKE ?", "%#{keywords}%") unless keywords.blank?}
@@ -103,7 +104,7 @@ class Poll < ApplicationRecord
if course.is_end
status = 4
else
- if user.present? && user.student_of_course?(course)
+ if user.present? && user.course_identity(course) == Course::STUDENT
ex_time = get_poll_times(user.id,false)
pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time]
diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb
index 58ec965b4..8e96b7d47 100644
--- a/app/models/praise_tread.rb
+++ b/app/models/praise_tread.rb
@@ -12,7 +12,7 @@ class PraiseTread < ApplicationRecord
case self.praise_tread_object_type
when "Memo","Message","Issue"
self.tidings << Tiding.new(:trigger_user_id => self.user_id, :user_id => self.praise_tread_object.author_id, :parent_container_id => self.praise_tread_object_id, :parent_container_type => self.praise_tread_object_type, :viewed => 0, :tiding_type => "Praise")
- when "Discuss","Challenge","HomeworkCommon","JournalsForMessage","Journal","GraduationTopic","GraduationTask"
+ when "Discuss","Challenge","HomeworkCommon","JournalsForMessage","Journal","GraduationTopic","GraduationTask", "Hack"
self.tidings << Tiding.new(:trigger_user_id => self.user_id, :user_id => self.praise_tread_object.user_id, :parent_container_id => self.praise_tread_object_id, :parent_container_type => self.praise_tread_object_type, :viewed => 0, :tiding_type => "Praise")
end
end
diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb
index 359b8b4dc..e01920490 100644
--- a/app/models/searchable/shixun.rb
+++ b/app/models/searchable/shixun.rb
@@ -16,7 +16,9 @@ module Searchable::Shixun
name: name,
description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH],
status: status,
- myshixuns_count: myshixuns_count
+ myshixuns_count: myshixuns_count,
+ created_at: created_at,
+ publish_time: publish_time
}.merge!(searchable_user_data)
.merge!(searchable_challenge_data)
end
diff --git a/app/models/shixun.rb b/app/models/shixun.rb
index de014f87b..d8a41ba6a 100644
--- a/app/models/shixun.rb
+++ b/app/models/shixun.rb
@@ -83,6 +83,7 @@ class Shixun < ApplicationRecord
scope :publiced, lambda{ where(public: 2) }
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }
scope :find_by_ids,lambda{|k| where(id:k)}
+ scope :no_jupyter, -> { where(is_jupyter: false) }
after_create :send_tiding
#同步到trustie
@@ -103,6 +104,19 @@ class Shixun < ApplicationRecord
shixun_info.try(:evaluate_script)
end
+ def fork_reason
+ case shixun_info.try(:fork_reason)
+ when 'Shixun'
+ '实训内容升级'
+ when 'Course'
+ '课堂教学使用'
+ when 'Subject'
+ '实践课程使用'
+ else
+ shixun_info.try(:fork_reason)
+ end
+ end
+
def fork_identifier
self.fork_from.nil? ? "--" : fork_shixuns.first&.identifier
end
diff --git a/app/models/shixun_info.rb b/app/models/shixun_info.rb
index 321b4c44a..7f7aa364e 100644
--- a/app/models/shixun_info.rb
+++ b/app/models/shixun_info.rb
@@ -1,6 +1,7 @@
class ShixunInfo < ApplicationRecord
belongs_to :shixun
validates_uniqueness_of :shixun_id
+ validates_length_of :fork_reason, maximum: 60
after_commit :create_diff_record
private
diff --git a/app/models/sub_discipline.rb b/app/models/sub_discipline.rb
new file mode 100644
index 000000000..724a734f8
--- /dev/null
+++ b/app/models/sub_discipline.rb
@@ -0,0 +1,9 @@
+class SubDiscipline < ApplicationRecord
+ belongs_to :discipline
+ has_many :tag_disciplines, dependent: :destroy
+ has_one :hack
+
+ has_many :shixun_tag_disciplines, -> { where("shixun = 1") }, class_name: "TagDiscipline"
+ has_many :subject_tag_disciplines, -> { where("subject = 1") }, class_name: "TagDiscipline"
+ has_many :question_tag_disciplines, -> { where("question = 1") }, class_name: "TagDiscipline"
+end
diff --git a/app/models/tag_discipline.rb b/app/models/tag_discipline.rb
new file mode 100644
index 000000000..6be032a58
--- /dev/null
+++ b/app/models/tag_discipline.rb
@@ -0,0 +1,11 @@
+class TagDiscipline < ApplicationRecord
+ belongs_to :sub_discipline
+ belongs_to :user, optional: true
+ has_many :tag_discipline_containers, dependent: :destroy
+
+ validates_presence_of :name
+
+ def discipline
+ sub_discipline&.discipline
+ end
+end
diff --git a/app/models/tag_discipline_container.rb b/app/models/tag_discipline_container.rb
new file mode 100644
index 000000000..585182bbf
--- /dev/null
+++ b/app/models/tag_discipline_container.rb
@@ -0,0 +1,5 @@
+class TagDisciplineContainer < ApplicationRecord
+ belongs_to :tag_discipline
+
+ belongs_to :container, polymorphic: true, optional: true
+end
diff --git a/app/models/teacher_course_group.rb b/app/models/teacher_course_group.rb
index fbf9849ac..769026366 100644
--- a/app/models/teacher_course_group.rb
+++ b/app/models/teacher_course_group.rb
@@ -8,6 +8,8 @@ class TeacherCourseGroup < ApplicationRecord
scope :find_teacher_group_ids, lambda { |ids| where(course_group_id: ids) unless ids.blank?}
scope :get_user_groups,lambda {|ids| where(user_id:ids)}
+ validates_uniqueness_of :course_group_id, scope: :course_member_id
+
def course_members
self.course_group.course_members
end
diff --git a/app/models/user.rb b/app/models/user.rb
index a9b2f0b3a..d6c264e15 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -153,6 +153,10 @@ class User < ApplicationRecord
has_many :hacks, dependent: :destroy
has_many :hack_user_lastest_codes, dependent: :destroy
+ # 题库
+ has_many :item_banks, dependent: :destroy
+ has_many :item_baskets, -> { order("item_baskets.position ASC") }, dependent: :destroy
+
# Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) }
diff --git a/app/queries/admins/shixun_query.rb b/app/queries/admins/shixun_query.rb
index 0f8523599..29e087332 100644
--- a/app/queries/admins/shixun_query.rb
+++ b/app/queries/admins/shixun_query.rb
@@ -13,25 +13,24 @@ class Admins::ShixunQuery < ApplicationQuery
all_shixuns = Shixun.all
status =
case params[:status]
- when "editing" then [0]
- when "pending" then [1]
- when "processed" then [2]
- when "closed" then [3]
- else
- [0,1,2,3]
+ when "editing" then {status: 0}
+ when "processed" then {status: 2, public: 0}
+ when "pending" then {public: 1}
+ when "publiced" then {public: 2}
+ when "closed" then {status: 3}
end
- public =
- case params[:public]
- when "editing" then [0]
- when "pending" then [1]
- when "processed" then [2]
- else
- [0,1,2]
- end
+ all_shixuns = all_shixuns.where(status) if status.present?
- all_shixuns = all_shixuns.where(status: status) if status.present?
- all_shixuns = all_shixuns.where(public: public) if public.present?
+ if params[:fork_status].present?
+ all_shixuns = all_shixuns.where.not(fork_from: nil)
+ case params[:fork_status]
+ when 'Shixun', 'Course', 'Subject'
+ all_shixuns = all_shixuns.joins(:shixun_info).where(shixun_infos: {fork_reason: params[:fork_status]})
+ when 'Other'
+ all_shixuns = all_shixuns.joins(:shixun_info).where("fork_reason is null or fork_reason not in ('Shixun', 'Course', 'Subject')")
+ end
+ end
if params[:tag].present?
all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i)
diff --git a/app/queries/admins/shixun_settings_query.rb b/app/queries/admins/shixun_settings_query.rb
index 377e7bf60..1e45952bf 100644
--- a/app/queries/admins/shixun_settings_query.rb
+++ b/app/queries/admins/shixun_settings_query.rb
@@ -15,16 +15,15 @@ class Admins::ShixunSettingsQuery < ApplicationQuery
all_shixuns = all_shixuns.where(id: params[:id]) if params[:id].present?
status =
- case params[:status]
- when "editing" then [0]
- when "pending" then [1]
- when "processed" then [2]
- when "closed" then [3]
- else
- [0,1,2,3]
- end
-
- all_shixuns = all_shixuns.where(status: status) if status.present?
+ case params[:status]
+ when "editing" then {status: 0}
+ when "processed" then {status: 2, public: 0}
+ when "pending" then {public: 1}
+ when "publiced" then {public: 2}
+ when "closed" then {status: 3}
+ end
+
+ all_shixuns = all_shixuns.where(status) if status.present?
if params[:tag].present?
all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i)
diff --git a/app/queries/examination_bank_query.rb b/app/queries/examination_bank_query.rb
new file mode 100644
index 000000000..c4cb7dee3
--- /dev/null
+++ b/app/queries/examination_bank_query.rb
@@ -0,0 +1,32 @@
+class ExaminationBankQuery < ApplicationQuery
+ include CustomSortable
+ attr_reader :params
+
+ sort_columns :updated_at, default_by: :updated_at, default_direction: :desc, default_table: 'examination_banks'
+
+ def initialize(params)
+ @params = params
+ end
+
+ def call
+ if params[:public].to_i == 1
+ exams = ExaminationBank.where(public: 1)
+ elsif params[:public].to_i == 0
+ exams = ExaminationBank.where(user_id: User.current.id)
+ end
+
+ if params[:tag_discipline_id].present?
+ exams = exams.joins(:tag_discipline_containers).where(tag_discipline_containers: {tag_discipline_id: params[:tag_discipline_id]})
+ elsif params[:sub_discipline_id].present?
+ exams = exams.where(sub_discipline_id: params[:sub_discipline_id])
+ elsif params[:discipline_id].present?
+ exams = exams.joins(:sub_discipline).where(sub_disciplines: {discipline_id: params[:discipline_id]})
+ end
+
+ exams = exams.where(difficulty: params[:difficulty].to_i) if params[:difficulty].present?
+
+ exams = exams.where("name like ?", "%#{params[:keyword].strip}%") if params[:keyword].present?
+
+ custom_sort(exams, params[:sort_by], params[:sort_direction])
+ end
+end
\ No newline at end of file
diff --git a/app/queries/item_bank_query.rb b/app/queries/item_bank_query.rb
new file mode 100644
index 000000000..ecd52184c
--- /dev/null
+++ b/app/queries/item_bank_query.rb
@@ -0,0 +1,37 @@
+class ItemBankQuery < ApplicationQuery
+ include CustomSortable
+ attr_reader :params
+
+ sort_columns :updated_at, default_by: :updated_at, default_direction: :desc, default_table: 'item_banks'
+
+ def initialize(params)
+ @params = params
+ end
+
+ def call
+ if params[:public].to_i == 1
+ items = ItemBank.where(public: 1)
+ elsif params[:public].to_i == 0
+ items = ItemBank.where(user_id: User.current.id)
+ end
+
+ if params[:tag_discipline_id].present?
+ items = items.joins(:tag_discipline_containers).where(tag_discipline_containers: {tag_discipline_id: params[:tag_discipline_id]})
+ elsif params[:sub_discipline_id].present?
+ items = items.where(sub_discipline_id: params[:sub_discipline_id])
+ elsif params[:discipline_id].present?
+ items = items.joins(:sub_discipline).where(sub_disciplines: {discipline_id: params[:discipline_id]})
+ end
+
+ if params[:oj_status].present? && params[:item_type] == "PROGRAM"
+ items = items.joins("join hacks on hacks.id=item_banks.container_id and item_banks.container_type='Hack'").where(hacks: {status: params[:oj_status]})
+ end
+
+ items = items.where(item_type: params[:item_type]) if params[:item_type].present?
+ items = items.where(difficulty: params[:difficulty].to_i) if params[:difficulty].present?
+
+ items = items.where("name like ?", "%#{params[:keyword].strip}%") if params[:keyword].present?
+
+ custom_sort(items, params[:sort_by], params[:sort_direction])
+ end
+end
\ No newline at end of file
diff --git a/app/services/admins/identity_auths/agree_apply_service.rb b/app/services/admins/identity_auths/agree_apply_service.rb
index d75a6d7db..4528debb4 100644
--- a/app/services/admins/identity_auths/agree_apply_service.rb
+++ b/app/services/admins/identity_auths/agree_apply_service.rb
@@ -10,7 +10,6 @@ class Admins::IdentityAuths::AgreeApplyService < ApplicationService
ActiveRecord::Base.transaction do
apply.update!(status: 1)
user.update!(authentication: true)
-
RewardGradeService.call(user, container_id: user.id, container_type: 'Authentication', score: 500)
deal_tiding!
diff --git a/app/services/admins/import_discipline_service.rb b/app/services/admins/import_discipline_service.rb
new file mode 100644
index 000000000..bd284b6af
--- /dev/null
+++ b/app/services/admins/import_discipline_service.rb
@@ -0,0 +1,52 @@
+class Admins::ImportDisciplineService < ApplicationService
+ Error = Class.new(StandardError)
+
+ attr_reader :file, :result
+
+ def initialize(file)
+ @file = file
+ @result = { success: 0, fail: [] }
+ end
+
+ def call
+ raise Error, '文件不存在' if file.blank?
+
+ excel = Admins::ImportDisciplineExcel.new(file)
+ excel.read_each(&method(:save_discipline))
+
+ result
+ rescue ApplicationImport::Error => ex
+ raise Error, ex.message
+ end
+
+ private
+
+ def save_discipline(data)
+ count = 0
+ discipline_name = data.discipline_name.to_s.strip
+ sub_discipline_name = data.sub_discipline_name.to_s.strip
+
+ return unless discipline_name.present?
+ discipline = Discipline.find_by(name: discipline_name)
+ if discipline.blank?
+ discipline = Discipline.create!(name: discipline_name)
+ count += 1
+ end
+
+ if sub_discipline_name.present?
+ sub_discipline = SubDiscipline.find_by(name: discipline_name, discipline: discipline)
+ if sub_discipline.blank?
+ SubDiscipline.create!(name: sub_discipline_name, discipline: discipline)
+ count += 1
+ end
+ end
+
+ result[:success] += count
+ rescue Exception => ex
+ fail_data = data.as_json
+ fail_data[:data] = fail_data.values.join(',')
+ fail_data[:message] = ex.message
+
+ result[:fail] << fail_data
+ end
+end
\ No newline at end of file
diff --git a/app/services/admins/professional_auths/agree_apply_service.rb b/app/services/admins/professional_auths/agree_apply_service.rb
index 1ca2da2fc..3d723412b 100644
--- a/app/services/admins/professional_auths/agree_apply_service.rb
+++ b/app/services/admins/professional_auths/agree_apply_service.rb
@@ -10,7 +10,7 @@ class Admins::ProfessionalAuths::AgreeApplyService < ApplicationService
ActiveRecord::Base.transaction do
apply.update!(status: 1)
user.update!(professional_certification: true)
-
+ user.update!(is_shixun_marker: true) if user.is_teacher?
RewardGradeService.call(user, container_id: user.id, container_type: 'Professional', score: 500)
deal_tiding!
diff --git a/app/services/admins/update_user_service.rb b/app/services/admins/update_user_service.rb
index 41b5065d0..6b1c0c857 100644
--- a/app/services/admins/update_user_service.rb
+++ b/app/services/admins/update_user_service.rb
@@ -25,6 +25,7 @@ class Admins::UpdateUserService < ApplicationService
ActiveRecord::Base.transaction do
user.save!
user.user_extension.save!
+ user.update!(is_shixun_marker: true) if user.is_certification_teacher
update_gitlab_password if params[:password].present?
end
@@ -36,7 +37,7 @@ class Admins::UpdateUserService < ApplicationService
def user_attributes
params.slice(*%i[lastname nickname mail phone admin business is_test
- professional_certification authentication])
+ professional_certification authentication is_shixun_marker])
end
def user_extension_attributes
diff --git a/app/services/concerns/elasticsearch_able.rb b/app/services/concerns/elasticsearch_able.rb
index 015aac29b..6caf37f8f 100644
--- a/app/services/concerns/elasticsearch_able.rb
+++ b/app/services/concerns/elasticsearch_able.rb
@@ -9,7 +9,7 @@ module ElasticsearchAble
highlight: highlight_options,
body_options: body_options,
page: page,
- per_page: per_page
+ per_page: 20
}
end
@@ -37,7 +37,7 @@ module ElasticsearchAble
def per_page
per_page = params[:per_page].to_s.strip.presence || params[:limit].to_s.strip.presence
- per_page.to_i <= 0 ? 20 : per_page.to_i
+ per_page.to_i <= 0 || per_page.to_i > 20 ? 20 : per_page.to_i
end
def page
diff --git a/app/services/examination_banks/save_examination_bank_service.rb b/app/services/examination_banks/save_examination_bank_service.rb
new file mode 100644
index 000000000..1db165785
--- /dev/null
+++ b/app/services/examination_banks/save_examination_bank_service.rb
@@ -0,0 +1,30 @@
+class ExaminationBanks::SaveExaminationBankService < ApplicationService
+ attr_reader :exam, :params
+
+ def initialize(exam, params)
+ @exam = exam
+ @params = params
+ end
+
+ def call
+ ExaminationBanks::SaveExamForm.new(params).validate!
+
+ exam.name = params[:name].to_s.strip
+ exam.difficulty = params[:difficulty]
+ exam.duration = params[:duration].present? ? params[:duration].to_i : nil
+ exam.sub_discipline_id = params[:sub_discipline_id]
+ exam.save!
+
+ # 知识点的创建
+ new_tag_discipline_ids = params[:tag_discipline_id] || []
+ old_tag_discipline_ids = exam.tag_discipline_containers.pluck(:tag_discipline_id)
+ delete_tag_discipline_ids = old_tag_discipline_ids - new_tag_discipline_ids
+ create_tag_discipline_ids = new_tag_discipline_ids - old_tag_discipline_ids
+ exam.tag_discipline_containers.where(tag_discipline_id: delete_tag_discipline_ids).destroy_all
+ create_tag_discipline_ids.each do |tag_id|
+ exam.tag_discipline_containers << TagDisciplineContainer.new(tag_discipline_id: tag_id)
+ end
+
+ exam
+ end
+end
\ No newline at end of file
diff --git a/app/services/git_service.rb b/app/services/git_service.rb
index 544e830a4..7867d063e 100644
--- a/app/services/git_service.rb
+++ b/app/services/git_service.rb
@@ -6,7 +6,7 @@ class GitService
class << self
- ['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', 'file_content', 'commits'].each do |method|
+ ['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', 'file_content', 'commits', 'add_tree', 'delete_file'].each do |method|
define_method method do |params|
post(method, params)
end
diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb
index 487a79bfe..c70535e17 100644
--- a/app/services/homeworks_service.rb
+++ b/app/services/homeworks_service.rb
@@ -305,13 +305,20 @@ class HomeworksService
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
- if work.work_status == 0
- is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time)
- if is_complete || (myshixun.created_at < setting_time.end_time && (!homework.allow_late || setting_time.end_time >= Time.now))
- work.work_status = 1
- elsif homework.allow_late && myshixun.created_at < homework.late_time
- work.work_status = 2
- end
+ is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time)
+
+ # if work.work_status == 0
+ # if is_complete || (myshixun.created_at < setting_time.end_time && (!homework.allow_late || setting_time.end_time >= Time.now))
+ # work.work_status = 1
+ # elsif homework.allow_late && myshixun.created_at < homework.late_time
+ # work.work_status = 2
+ # end
+ # end
+
+ if !homework.allow_late || is_complete
+ work.work_status = 1
+ elsif myshixun.created_at < homework.late_time
+ work.work_status = 2
end
if work.work_status != 0
diff --git a/app/services/item_banks/save_item_service.rb b/app/services/item_banks/save_item_service.rb
new file mode 100644
index 000000000..764a4812d
--- /dev/null
+++ b/app/services/item_banks/save_item_service.rb
@@ -0,0 +1,58 @@
+class ItemBanks::SaveItemService < ApplicationService
+ attr_reader :item, :params
+
+ def initialize(item, params)
+ @item = item
+ @params = params
+ end
+
+ def call
+ new_record = item.new_record?
+ raise("不能更改题型") if !new_record && item.item_type != params[:item_type]
+ ItemBanks::SaveItemForm.new(params).validate!
+
+ ActiveRecord::Base.transaction do
+ item.item_type = params[:item_type] if new_record
+ item.difficulty = params[:difficulty]
+ item.sub_discipline_id = params[:sub_discipline_id]
+ item.name = params[:name].to_s.strip
+ item.save!
+
+ analysis = item.item_analysis || ItemAnalysis.new(item_bank_id: item.id)
+ analysis.analysis = params[:analysis].blank? ? nil : params[:analysis].strip
+ analysis.save
+
+ # 知识点的创建
+ new_tag_discipline_ids = params[:tag_discipline_id]
+ old_tag_discipline_ids = item.tag_discipline_containers.pluck(:tag_discipline_id)
+ delete_tag_discipline_ids = old_tag_discipline_ids - new_tag_discipline_ids
+ create_tag_discipline_ids = new_tag_discipline_ids - old_tag_discipline_ids
+ item.tag_discipline_containers.where(tag_discipline_id: delete_tag_discipline_ids).destroy_all
+ create_tag_discipline_ids.each do |tag_id|
+ item.tag_discipline_containers << TagDisciplineContainer.new(tag_discipline_id: tag_id)
+ end
+
+ # 选项的创建
+ if %W(SINGLE MULTIPLE JUDGMENT).include?(item.item_type)
+ old_choices = item.item_choices
+ new_choices = params[:choices]
+
+ new_choices.each_with_index do |choice, index|
+ choice_item = old_choices[index] || ItemChoice.new(item_bank_id: item.id)
+ choice_item.choice_text = choice[:choice_text]
+ choice_item.is_answer = choice[:is_answer]
+ choice_item.save!
+ end
+
+ if old_choices.length > new_choices.length
+ old_choices[new_choices.length..(old_choices.length-1)].each do |old_choice|
+ old_choice.destroy
+ end
+ end
+
+ end
+ end
+
+ item
+ end
+end
\ No newline at end of file
diff --git a/app/services/item_baskets/save_item_basket_service.rb b/app/services/item_baskets/save_item_basket_service.rb
new file mode 100644
index 000000000..cf6d3738b
--- /dev/null
+++ b/app/services/item_baskets/save_item_basket_service.rb
@@ -0,0 +1,47 @@
+class ItemBaskets::SaveItemBasketService < ApplicationService
+ attr_reader :user, :params
+
+ def initialize(user, params)
+ @user = user
+ @params = params
+ end
+
+ def call
+ raise("请选择试题") if params[:item_ids].blank?
+
+ # 只能选用公共题库或是自己的题库
+ items = ItemBank.where(public: 1).or(ItemBank.where(user_id: user.id))
+
+ # 已选到过试题篮的不重复选用
+ item_ids = params[:item_ids] - user.item_baskets.pluck(:item_bank_id)
+ items.where(id: item_ids).each do |item|
+ new_item = ItemBasket.new(user_id: user.id, item_bank_id: item.id, item_type: item.item_type)
+ new_item.score = item_score item.item_type
+ new_item.position = item_position item.item_type
+ new_item.save!
+ end
+ end
+
+ private
+
+ def item_score item_type
+ if user.item_baskets.where(item_type: item_type).last.present?
+ score = user.item_baskets.where(item_type: item_type).last.score
+ else
+ score =
+ case item_type
+ when "SINGLE", "MULTIPLE", "JUDGMENT"
+ 5
+ when "PROGRAM"
+ 10
+ else
+ 5
+ end
+ end
+ score
+ end
+
+ def item_position item_type
+ user.item_baskets.where(item_type: item_type).last&.position.to_i + 1
+ end
+end
\ No newline at end of file
diff --git a/app/services/jupyter_service.rb b/app/services/jupyter_service.rb
index 2d43a0987..bbe0330bb 100644
--- a/app/services/jupyter_service.rb
+++ b/app/services/jupyter_service.rb
@@ -8,7 +8,8 @@ module JupyterService
uri = "#{shixun_tomcat}/bridge/jupyter/get"
tpiID = "tpm#{shixun.id}"
mount = shixun.data_sets.present?
- params = {tpiID: tpiID, identifier: shixun.identifier, needMount: mount, gitUrl: '',
+ gitUrl = "#{edu_setting('git_address_domain')}/#{shixun.repo_path}"
+ params = {tpiID: tpiID, identifier: shixun.identifier, needMount: mount, gitUrl: gitUrl,
:containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"}
logger.info "test_juypter: uri->#{uri}, params->#{params}"
diff --git a/app/services/private_messages/create_service.rb b/app/services/private_messages/create_service.rb
index 88f3a084f..89365c4a7 100644
--- a/app/services/private_messages/create_service.rb
+++ b/app/services/private_messages/create_service.rb
@@ -30,6 +30,6 @@ class PrivateMessages::CreateService < ApplicationService
def validate!
raise Error, '内容不能为空' if content.blank?
- raise Error, '内容太长' if content.size > 255
+ raise Error, '内容太长' if content.size > 500
end
end
\ No newline at end of file
diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb
index f5af69179..32488a7c3 100644
--- a/app/services/shixun_search_service.rb
+++ b/app/services/shixun_search_service.rb
@@ -33,6 +33,10 @@ class ShixunSearchService < ApplicationService
@shixuns = status == "published" ? @shixuns.where(status: 2) : @shixuns.where(status: [0, 1])
end
+ if params[:no_jupyter]
+ @shixuns = @shixuns.where(is_jupyter: 0)
+ end
+
## 筛选 难度
if params[:diff].present? && params[:diff].to_i != 0
@shixuns = @shixuns.where(trainee: params[:diff])
@@ -49,12 +53,16 @@ class ShixunSearchService < ApplicationService
includes: [ :shixun_info, :challenges, :subjects, user: { user_extension: :school } ]
}
model_options.merge!(where: { id: @shixuns.pluck(:id) })
- model_options.merge!(order: {"myshixuns_count" => sort_str})
+ model_options.merge!(order: {sort_str => order_str})
model_options.merge!(default_options)
model_options
end
- def sort_str
+ def order_str
params[:order] || "desc"
end
+
+ def sort_str
+ params[:sort] || "myshixuns_count"
+ end
end
\ No newline at end of file
diff --git a/app/services/shixuns/create_shixun_service.rb b/app/services/shixuns/create_shixun_service.rb
index c85455901..2a66cf2fb 100644
--- a/app/services/shixuns/create_shixun_service.rb
+++ b/app/services/shixuns/create_shixun_service.rb
@@ -26,7 +26,14 @@ class CreateShixunService < ApplicationService
# 创建镜像
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id)
# 创建主服务配置
- ShixunServiceConfig.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id)
+ config_params =
+ if shixun.is_jupyter?
+ {shixun_id: shixun.id, mirror_repository_id: main_mirror.id, cpu_limit: 2,
+ memory_limit: 1024, lower_cpu_limit: 0.2, request_limit: 100}
+ else
+ {shixun_id: shixun.id, mirror_repository_id: main_mirror.id}
+ end
+ ShixunServiceConfig.create!(config_params)
# 创建子镜像相关数据(实训镜像关联表,子镜像服务配置)
sub_mirrors.each do |sub|
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => sub.id)
diff --git a/app/services/subjects/copy_subject_service.rb b/app/services/subjects/copy_subject_service.rb
index f44191fda..4715a8bad 100644
--- a/app/services/subjects/copy_subject_service.rb
+++ b/app/services/subjects/copy_subject_service.rb
@@ -79,7 +79,7 @@ class Subjects::CopySubjectService < ApplicationService
copy_shixun_service_configs_data!(shixun, to_shixun)
copy_challenges_data!(shixun, to_shixun)
copy_shixun_members_data!(to_shixun)
-
+ copy_jupyter_data_sets(shixun, to_shixun) if shixun.is_jupyter?
# 云上实验室
if laboratory
laboratory.laboratory_shixuns.create(shixun: to_shixun)
@@ -87,6 +87,25 @@ class Subjects::CopySubjectService < ApplicationService
to_shixun
end
+ # 复制jupyter的数据集
+ def copy_jupyter_data_sets(shixun, to_shixun)
+ return unless shixun.is_jupyter?
+ folder = EduSetting.get('shixun_folder')
+ raise "存储目录未定义" unless folder.present?
+ path = "#{folder}/#{to_shixun.identifier}"
+ FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path)
+ # 复制数据集
+ save_path = File.join(folder, shixun.identifier)
+ shixun.data_sets.each do |set|
+ new_date_set = Attachment.new
+ new_date_set.attributes = set.attributes.dup.except("id", "container_id", "disk_directory")
+ new_date_set.container_id = to_shixun.id
+ new_date_set.disk_directory = to_shixun.identifier
+ new_date_set.save!
+ FileUtils.cp("#{save_path}/#{set.relative_path_filename}", path)
+ end
+ end
+
# 创建实训长字段内容
def copy_shixun_info_data!(shixun, to_shixun)
to_shixun_info = ShixunInfo.new
diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb
index 279d147f4..b13b0ab1f 100644
--- a/app/services/users/shixun_service.rb
+++ b/app/services/users/shixun_service.rb
@@ -65,13 +65,18 @@ class Users::ShixunService
end
def manage_shixun_status_filter(relations)
- status = case params[:status]
- when 'editing' then 0
- when 'applying' then 1
- when 'published' then 2
- when 'closed' then 3
- end
- relations = relations.where(status: status) if status
+ if params[:status] == "publiced"
+ relations = relations.where(public: 2)
+ elsif params[:status] == "applying"
+ relations = relations.where(public: 1)
+ else
+ status = case params[:status]
+ when 'editing' then 0
+ when 'published' then 2
+ when 'closed' then 3
+ end
+ relations = relations.where(status: status) if status
+ end
relations
end
diff --git a/app/views/admins/disciplines/destroy.js.erb b/app/views/admins/disciplines/destroy.js.erb
new file mode 100644
index 000000000..ea9aedcd8
--- /dev/null
+++ b/app/views/admins/disciplines/destroy.js.erb
@@ -0,0 +1,2 @@
+$.notify({ message: '删除成功' });
+$(".discipline-item-<%= @discipline_id %>").remove();
\ No newline at end of file
diff --git a/app/views/admins/disciplines/edit.js.erb b/app/views/admins/disciplines/edit.js.erb
new file mode 100644
index 000000000..48c5b789f
--- /dev/null
+++ b/app/views/admins/disciplines/edit.js.erb
@@ -0,0 +1,2 @@
+$('.admin-modal-container').html("<%= j( render partial: 'admins/disciplines/shared/edit_discipline_modal', locals: { discipline: @discipline } ) %>");
+$('.modal.admin-edit-discipline-modal').modal('show');
\ No newline at end of file
diff --git a/app/views/admins/disciplines/index.html.erb b/app/views/admins/disciplines/index.html.erb
new file mode 100644
index 000000000..f4b116b93
--- /dev/null
+++ b/app/views/admins/disciplines/index.html.erb
@@ -0,0 +1,17 @@
+<% define_admin_breadcrumbs do %>
+ <% add_admin_breadcrumb('课程方向', admins_disciplines_path) %>
+<% end %>
+
+
+
+
+ <%= render(partial: 'admins/disciplines/shared/list') %>
+
+
+<%= render 'admins/disciplines/shared/create_discipline_modal' %>
+<%= render partial: 'admins/disciplines/shared/import_discipline_modal' %>
diff --git a/app/views/admins/disciplines/shared/_create_discipline_modal.html.erb b/app/views/admins/disciplines/shared/_create_discipline_modal.html.erb
new file mode 100644
index 000000000..7eb5d8985
--- /dev/null
+++ b/app/views/admins/disciplines/shared/_create_discipline_modal.html.erb
@@ -0,0 +1,28 @@
+
\ No newline at end of file
diff --git a/app/views/admins/disciplines/shared/_edit_discipline_modal.html.erb b/app/views/admins/disciplines/shared/_edit_discipline_modal.html.erb
new file mode 100644
index 000000000..ce511e27c
--- /dev/null
+++ b/app/views/admins/disciplines/shared/_edit_discipline_modal.html.erb
@@ -0,0 +1,23 @@
+
+
+
+
+
+ <%= simple_form_for([:admins, discipline], html: { class: 'admin-edit-discipline-form' }, defaults: { wrapper_html: { class: 'offset-md-1 col-md-10' } }) do |f| %>
+ <%= f.input :name, as: :string, label: '名称' %>
+
+
+ <% end %>
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/admins/disciplines/shared/_import_discipline_modal.html.erb b/app/views/admins/disciplines/shared/_import_discipline_modal.html.erb
new file mode 100644
index 000000000..de54fd758
--- /dev/null
+++ b/app/views/admins/disciplines/shared/_import_discipline_modal.html.erb
@@ -0,0 +1,30 @@
+
\ No newline at end of file
diff --git a/app/views/admins/disciplines/shared/_list.html.erb b/app/views/admins/disciplines/shared/_list.html.erb
new file mode 100644
index 000000000..343ff4851
--- /dev/null
+++ b/app/views/admins/disciplines/shared/_list.html.erb
@@ -0,0 +1,33 @@
+
+
+
+ 序号 |
+ 课程方向 |
+ 实践课程 |
+ 实训 |
+ 题库 |
+ 操作 |
+
+
+
+ <% if @disciplines.present? %>
+ <% @disciplines.each_with_index do |discipline, index| %>
+
+ <%= index + 1 %> |
+
+ <%= link_to discipline.name, admins_sub_disciplines_path(discipline_id: discipline), :title => discipline.name %>
+ |
+ <%= check_box_tag :subject,!discipline.subject,discipline.subject,remote:true,data:{id:discipline.id},class:"discipline-source-form" %> |
+ <%= check_box_tag :shixun,!discipline.shixun,discipline.shixun,remote:true,data:{id:discipline.id},class:"discipline-source-form" %> |
+ <%= check_box_tag :question,!discipline.question,discipline.question,remote:true,data:{id:discipline.id},class:"discipline-source-form" %> |
+
+ <%= link_to '编辑', edit_admins_discipline_path(discipline), remote: true, class: 'action' %>
+ <%= delete_link '删除', admins_discipline_path(discipline, element: ".discipline-item-#{discipline.id}"), class: 'delete-discipline-action' %>
+ |
+
+ <% end %>
+ <% else %>
+ <%= render 'admins/shared/no_data_for_table' %>
+ <% end %>
+
+
\ No newline at end of file
diff --git a/app/views/admins/disciplines/update.js.erb b/app/views/admins/disciplines/update.js.erb
new file mode 100644
index 000000000..c696c0a2a
--- /dev/null
+++ b/app/views/admins/disciplines/update.js.erb
@@ -0,0 +1,2 @@
+$('.modal.admin-edit-discipline-modal').modal("hide");
+$(".discipline-list-container").html("<%= j(render :partial => 'admins/disciplines/shared/list') %>");
\ No newline at end of file
diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb
index 4b84068e7..335e0d917 100644
--- a/app/views/admins/shared/_sidebar.html.erb
+++ b/app/views/admins/shared/_sidebar.html.erb
@@ -2,7 +2,7 @@