diff --git a/app/assets/javascripts/admins/projects/index.js b/app/assets/javascripts/admins/projects/index.js deleted file mode 100644 index 534a065ca..000000000 --- a/app/assets/javascripts/admins/projects/index.js +++ /dev/null @@ -1,11 +0,0 @@ -$(document).on('turbolinks:load', function () { - if ($('body.admins-projects-index-page').length > 0) { - var $form = $('.search-form'); - - // 清空 - $form.on('click', '.clear-btn', function () { - $form.find('input[name="search"]').val(''); - $form.find('input[type="submit"]').trigger('click'); - }); - } -}); diff --git a/app/assets/javascripts/admins/shixun_modify_records/index.js b/app/assets/javascripts/admins/shixun_modify_records/index.js deleted file mode 100644 index 13b348b04..000000000 --- a/app/assets/javascripts/admins/shixun_modify_records/index.js +++ /dev/null @@ -1,12 +0,0 @@ -$(document).on('turbolinks:load', function () { - if ($('body.admins-shixun-modify-records-index-page').length > 0) { - var $form = $('.search-form'); - - // 清空 - $form.on('click', '.clear-btn', function () { - $form.find('select[name="date"]').val('weekly'); - $form.find('input[name="user_name"]').val(''); - $form.find('input[type="submit"]').trigger('click'); - }); - } -}); diff --git a/app/assets/stylesheets/admins/diff.scss b/app/assets/stylesheets/admins/diff.scss deleted file mode 100644 index 34944ae4c..000000000 --- a/app/assets/stylesheets/admins/diff.scss +++ /dev/null @@ -1,14 +0,0 @@ -.diff{overflow:auto;} -.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0 1rem;display:table;width:100%;} -.diff del, .diff ins{display:block;text-decoration:none;} -.diff li{padding:0; display:table-row;margin: 0;height:1em;} -.diff li.ins{background:#dfd; color:#080} -.diff li.del{background:#fee; color:#b00} -.diff li:hover{background:#ffc} - -/* try 'whitespace:pre;' if you don't want lines to wrap */ -.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;} -.diff del strong{font-weight:normal;background:#fcc;} -.diff ins strong{font-weight:normal;background:#9f9;} -.diff li.diff-comment { display: none; } -.diff li.diff-block-info { background: none repeat scroll 0 0 gray; } \ No newline at end of file diff --git a/app/assets/stylesheets/admins/shixun_feedback_messages.scss b/app/assets/stylesheets/admins/shixun_feedback_messages.scss deleted file mode 100644 index 92b92c01c..000000000 --- a/app/assets/stylesheets/admins/shixun_feedback_messages.scss +++ /dev/null @@ -1,7 +0,0 @@ -.admins-shixun-feedback-messages-index-page { - .content-img { - img { - height: 60px; - } - } -} \ No newline at end of file diff --git a/app/controllers/admins/shixun_modify_records_controller.rb b/app/controllers/admins/shixun_modify_records_controller.rb deleted file mode 100644 index 43d9a4a16..000000000 --- a/app/controllers/admins/shixun_modify_records_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Admins::ShixunModifyRecordsController < Admins::BaseController - - def index - records = Admins::ShixunModifyRecordQuery.call(params) - - @records = paginate records.includes(:diff_record_content) - end - -end diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb deleted file mode 100644 index 707255866..000000000 --- a/app/controllers/colleges_controller.rb +++ /dev/null @@ -1,175 +0,0 @@ -class CollegesController < ApplicationController - include PaginateHelper - - # layout 'college' - - before_action :require_login - before_action :check_college_present! - before_action :check_manage_permission! - - helper_method :current_school, :current_college - - def statistics - # 教师、学生总数 - count_statistic = UserExtension.where(school_id: current_school.id) - .select('SUM(IF(identity=0, 1, 0)) AS teachers_count, SUM(IF(identity=1, 1, 0)) AS students_count').first - @teachers_count = count_statistic['teachers_count'] - @students_count = count_statistic['students_count'] - - # 课堂总数 - @courses_count = Course.where(school_id: current_school.id, is_delete: 0).where.not(id: 1309).count - # 实训总数 - @shixuns_count = Shixun.visible.joins('left join user_extensions on user_extensions.user_id = shixuns.user_id') - .where(user_extensions: { school_id: current_school.id }).count - render json: { teachers_count: @teachers_count, students_count: @students_count, courses_count: @courses_count, shixuns_count: @shixuns_count, school: current_school.name } - end - - def shixun_time - time_sum = Game.joins('left join user_extensions on user_extensions.user_id = games.user_id') - .where(user_extensions: { school_id: current_school.id }).sum(:cost_time) - shixun_time_sum = (time_sum / (24 * 60 * 60.0)).ceil - - render json: { shixun_time: shixun_time_sum } - end - - def shixun_report_count - shixun_report_count = StudentWork.where(work_status: [1, 2]).where('myshixun_id != 0') - .joins('left join user_extensions on user_extensions.user_id = student_works.user_id') - .where(user_extensions: { school_id: current_school.id }).count - render json: { shixun_report_count: shixun_report_count } - end - - def teachers - @teachers = User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count, - (SELECT count(c.id) FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.user_id=users.id AND m.role in (1,2,3) and c.school_id = #{current_school.id} AND c.is_delete = 0) as course_count - FROM `users`, user_extensions ue where ue.school_id=#{current_school.id} and users.id=ue.user_id and ue.identity=0 ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10") - # ).order("publish_shixun_count desc, experience desc").limit(10) - # @teacher_count = UserExtension.where(school_id: current_school.id) - # .select('SUM(IF(identity=0, 1, 0)) AS teachers_count').first.teachers_count - @teachers = - @teachers.map do |teacher| - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{current_school.id}") - course_count = course_ids.size - homeworks = HomeworkCommon.where(:homework_type => 4, :course_id => course_ids.map(&:id)) - un_shixun_work_count = homeworks.where("publish_time > '#{Time.now}' or publish_time is null").count - shixun_work_count = homeworks.size - un_shixun_work_count - student_count = StudentsForCourse.where(:course_id => course_ids.map(&:id)).count - myshixun_ids = StudentWork.select("myshixun_id").where("homework_common_id in (#{homeworks.map(&:id).join(',').strip == "" ? -1 : homeworks.map(&:id).join(',')}) and myshixun_id is not null") - complete_myshixun = Myshixun.select("id").where(:status => 1, :id => myshixun_ids.map(&:myshixun_id)).size - all_myshixun = Myshixun.select("id").where(:id => myshixun_ids.map(&:myshixun_id)).size - complete_rate = all_myshixun == 0 ? 0 : ((complete_myshixun * 100) / all_myshixun).try(:round, 2).to_f - real_name = teacher.show_real_name - teacher = teacher.attributes.dup.merge({ - real_name: real_name, - course_count: course_count, - shixun_work_count: shixun_work_count, - un_shixun_work_count: un_shixun_work_count, - student_count: student_count, - complete_rate: complete_rate - }).to_json - JSON.parse(teacher) - end - end - - def shixun_chart_data - shixun_ids = HomeworkCommonsShixun.joins(homework_common: :course).where(courses: {school_id: current_school.id, is_delete: 0}).where('courses.id != 1309').pluck('distinct shixun_id') - shixun_count_map = ShixunTagRepertoire.joins(:tag_repertoire).where(shixun_id: shixun_ids).group('tag_repertoires.name').order('count_shixun_id desc').count(:shixun_id) - - names = [] - data = [] - shixun_count_map.each do |name, count| - break if names.size == 9 - - names << name - data << { value: count, name: name } - end - - if shixun_count_map.keys.size > 9 - other_count = shixun_count_map.values[9..-1].reduce(:+) - names << 'Others' - data << { name: 'Others', value: other_count } - end - - render json: { names: names, data: data } - end - - # 在线课堂 - def course_statistics - courses = Course.where(school_id: current_school.id, is_delete: 0).where.not(id: 1309) - - @course_count = courses.size - courses = courses.left_joins(practice_homeworks: { student_works: { myshixun: :games } }) - .select('courses.id, courses.name, courses.is_end, IFNULL(sum(games.evaluate_count), 0) evaluating_count') - .group('courses.id').order('is_end asc, evaluating_count desc') - - @courses = paginate courses - - course_ids = @courses.map(&:id) - @student_count = StudentsForCourse.where(course_id: course_ids).group(:course_id).count - @shixun_work_count = HomeworkCommon.where(homework_type: 4, course_id: course_ids).group(:course_id).count - @attachment_count = Attachment.where(container_id: course_ids, container_type: 'Course').group(:container_id).count - @message_count = Message.joins(:board).where(boards: { parent_id: 0, course_id: course_ids }).group('boards.course_id').count - @active_time = CourseActivity.where(course_id: course_ids).group(:course_id).maximum(:created_at) - @exercise_count = Exercise.where(course_id: course_ids).group(:course_id).count - @poll_count = Poll.where(course_id: course_ids).group(:course_id).count - @other_work_count = HomeworkCommon.where(homework_type: [1,3], course_id: course_ids).group(:course_id).count - end - - # 学生实训 - def student_shixun - # @student_count = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id, identity: 1 }).count - @students = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id, identity: 1 }).includes(:user_extension).order('experience desc').limit(10) - - student_ids = @students.map(&:id) - @shixun_count = Myshixun.where(user_id: student_ids).group(:user_id).count - @study_shixun_count = Myshixun.where(user_id: student_ids, status: 0).group(:user_id).count - end - - def student_hot_evaluations - games = Game.joins(:myshixun).joins('join shixun_tag_repertoires str on str.shixun_id = myshixuns.shixun_id') - games = games.joins('join tag_repertoires tr on tr.id = str.tag_repertoire_id') - games = games.joins("join user_extensions ue on ue.user_id = myshixuns.user_id and ue.school_id = #{current_school.id}") - evaluate_count_map = games.group('tr.name').reorder('sum_games_evaluate_count desc').limit(10).sum('games.evaluate_count') - - render json: { names: evaluate_count_map.keys, values: evaluate_count_map.values } - end - - private - - def require_login - return if User.current.logged? - - redirect_to "/login?back_url=#{CGI::escape(request.fullpath)}" - end - - def check_college_present! - return if current_college.present? - - redirect_to '/404' - end - - def check_manage_permission! - return if can_manage_college? - - redirect_to '/403' - end - - def can_manage_college? - return true if current_user.admin_or_business? # 超级管理员|运营 - return true if current_college.is_a?(Department) && current_college.member?(current_user) # 部门管理员 - return true if current_user.is_teacher? && current_user.school_id == current_school.id # 学校老师 - # return true if current_school.customers.exists? && current_user.partner&.partner_customers&.exists?(customer_id: current_school.customer_id) - - false - end - - def current_school - current_college.is_a?(School) ? current_college : current_college.school - end - - def current_college - @_current_college ||= begin - Department.find_by(identifier: params[:id]) || School.find_by(id: params[:id]) - end - end -end \ No newline at end of file diff --git a/app/controllers/concerns/laboratory_helper.rb b/app/controllers/concerns/laboratory_helper.rb deleted file mode 100644 index e03273d68..000000000 --- a/app/controllers/concerns/laboratory_helper.rb +++ /dev/null @@ -1,32 +0,0 @@ -module LaboratoryHelper - extend ActiveSupport::Concern - - included do - before_action :setup_laboratory - - helper_method :current_laboratory - helper_method :default_setting - helper_method :default_yun_session - end - - def current_laboratory - @_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1)) - end - - def default_laboratory - @_default_laboratory ||= Laboratory.find(1) - end - - def default_setting - @_default_setting ||= LaboratorySetting.find_by(laboratory_id: 1) - end - - def setup_laboratory - Laboratory.current = current_laboratory - end - - def default_yun_session - laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1)) - @_default_yun_session = "#{laboratory.try(:identifier).split('.').first}_user_id" - end -end \ No newline at end of file diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb deleted file mode 100644 index 104851676..000000000 --- a/app/controllers/item_banks_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -class LibrariesController < ApplicationController - include PaginateHelper - - def index - default_sort('updated_at', 'desc') - - @items = ItemBankQuery.call(params) - @items = paginate courses.includes(:school, :students, :attachments, :homework_commons, teacher: :user_extension) - end - - def create - - end -end \ No newline at end of file diff --git a/app/controllers/jupyters_controller.rb b/app/controllers/jupyters_controller.rb deleted file mode 100644 index 96ebf3452..000000000 --- a/app/controllers/jupyters_controller.rb +++ /dev/null @@ -1,46 +0,0 @@ - -class JupytersController < ApplicationController - include JupyterService - - before_action :shixun, only: [:open, :open1, :test, :save] - - def save_with_tpi - myshixun = Myshixun.find_by(identifier: params[:identifier]) - jupyter_save_with_game(myshixun, params[:jupyter_port]) - render json: {status: 0} - end - - def save_with_tpm - shixun = Shixun.find_by(identifier: params[:identifier]) - jupyter_save_with_shixun(shixun, params[:jupyter_port]) - render json: {status: 0} - end - - def get_info_with_tpi - myshixun = Myshixun.find_by(identifier: params[:identifier]) - url = jupyter_url_with_game(myshixun) - port = jupyter_port_with_game(myshixun) - render json: {status: 0, url: url, port: port} - end - - def get_info_with_tpm - shixun = Shixun.find_by(identifier: params[:identifier]) - url = jupyter_url_with_shixun(shixun) - port = jupyter_port_with_shixun(shixun) - render json: {status: 0, url: url, port: port} - end - - def reset_with_tpi - myshixun = Myshixun.find_by(identifier: params[:identifier]) - info = jupyter_tpi_reset(myshixun) - render json: {status: 0, url: info[:url], port: info[:port]} - end - - def reset_with_tpm - shixun = Shixun.find_by(identifier: params[:identifier]) - info = jupyter_tpm_reset(shixun) - render json: {status: 0, url: info[:url], port: info[:port]} - end - - -end \ No newline at end of file diff --git a/app/helpers/admins/base_helper.rb b/app/helpers/admins/base_helper.rb deleted file mode 100644 index 95e54db46..000000000 --- a/app/helpers/admins/base_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Admins::BaseHelper - include ManageBackHelper -end \ No newline at end of file diff --git a/app/helpers/admins/competition_prize_users_helper.rb b/app/helpers/admins/competition_prize_users_helper.rb deleted file mode 100644 index 0fa338341..000000000 --- a/app/helpers/admins/competition_prize_users_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Admins::CompetitionPrizeUsersHelper - def display_auth_state(flag, other = false, success: nil, normal: nil, error: nil) - success ||= ''.html_safe - normal ||= '--' - error ||= ''.html_safe - - return success if flag - other ? normal : error - end -end \ No newline at end of file diff --git a/app/models/item_analysis.rb b/app/models/item_analysis.rb deleted file mode 100644 index 8f6e71302..000000000 --- a/app/models/item_analysis.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ItemAnalysis < ApplicationRecord - belongs_to :item_bank -end diff --git a/app/models/item_bank.rb b/app/models/item_bank.rb deleted file mode 100644 index 8078a55e0..000000000 --- a/app/models/item_bank.rb +++ /dev/null @@ -1,11 +0,0 @@ -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 } - - belongs_to :user - - has_one :item_analysis, dependent: :destroy - has_many :item_choices, dependent: :destroy - has_many :item_baskets, dependent: :destroy -end diff --git a/app/models/item_basket.rb b/app/models/item_basket.rb deleted file mode 100644 index d736d9bc0..000000000 --- a/app/models/item_basket.rb +++ /dev/null @@ -1,4 +0,0 @@ -class ItemBasket < ApplicationRecord - belongs_to :item_bank - belongs_to :user -end diff --git a/app/models/item_choice.rb b/app/models/item_choice.rb deleted file mode 100644 index ccc35698e..000000000 --- a/app/models/item_choice.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ItemChoice < ApplicationRecord - belongs_to :item_bank -end diff --git a/app/queries/admins/shixun_modify_record_query.rb b/app/queries/admins/shixun_modify_record_query.rb deleted file mode 100644 index 227e2f4c2..000000000 --- a/app/queries/admins/shixun_modify_record_query.rb +++ /dev/null @@ -1,33 +0,0 @@ -class Admins::ShixunModifyRecordQuery < ApplicationQuery - attr_reader :params - - def initialize(params) - @params = params - end - - def call - if params[:user_name].blank? || params[:date].blank? - records = DiffRecord.none - else - records = DiffRecord.joins(:user).where("concat(users.lastname, users.firstname) like ?", "%#{params[:user_name].strip}%") - if time_range.present? - records = records.where(created_at: time_range) - end - end - records.order("diff_records.created_at desc") - end - - private - - def time_range - @_time_range ||= begin - case params[:date] - when 'weekly' then 1.weeks.ago..Time.now - when 'monthly' then 1.months.ago..Time.now - when 'quarterly' then 3.months.ago..Time.now - when 'yearly' then 1.years.ago..Time.now - else '' - end - end - end -end diff --git a/app/services/jupyter_service.rb b/app/services/jupyter_service.rb deleted file mode 100644 index 0f5af6cb8..000000000 --- a/app/services/jupyter_service.rb +++ /dev/null @@ -1,195 +0,0 @@ -#coding=utf-8 - -module JupyterService - - def _open_shixun_jupyter(shixun) - if shixun.is_jupyter? - shixun_tomcat = edu_setting('cloud_bridge') - uri = "#{shixun_tomcat}/bridge/jupyter/get" - tpiID = "tpm#{shixun.id}" - mount = shixun.data_sets.present? - params = {tpiID: tpiID, identifier: shixun.identifier, needMount: mount, - :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"} - - logger.info "test_juypter: uri->#{uri}, params->#{params}" - res = uri_post uri, params - if res && res['code'].to_i != 0 - raise("实训云平台繁忙(繁忙等级:99)") - end - - logger.info "test_juypter: #{res}" - - @shixun_jupyter_port = res['port'] - - "#{jupyter_service(res['port'])}/notebooks/data/workspace/myshixun_#{tpiID}/01.ipynb" - end - end - - def jupyter_url_with_shixun(shixun) - #打开tpm - juypter接口 - _open_shixun_jupyter(shixun) - end - - def jupyter_port_with_shixun(shixun) - if @shixun_jupyter_port.to_i <=0 - _open_shixun_jupyter(shixun) - end - @shixun_jupyter_port - end - - - def _open_game_jupyter(myshixun) - ## 打开tpi - shixun = myshixun.shixun - - if shixun.is_jupyter? - shixun_tomcat = edu_setting('cloud_bridge') - uri = "#{shixun_tomcat}/bridge/jupyter/get" - - tpiID = myshixun.id - mount = myshixun.shixun.data_sets.present? - params = {tpiID: tpiID, identifier: shixun.identifier, myshixunIdentifier: myshixun.identifier, needMount: mount, - :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"} - res = uri_post uri, params - - logger.info "test_juypter: #{res}" - - if res && res['code'].to_i != 0 - raise("实训云平台繁忙(繁忙等级:99)") - end - - @game_jupyter_port = res['port'] - - repo_save_path = myshixun.repo_save_path - - "#{jupyter_service(res['port'])}/notebooks/data/workspace/myshixun_#{tpiID}/#{repo_save_path}/01.ipynb" - end - end - - - def jupyter_url_with_game(myshixun) - _open_game_jupyter(myshixun) - end - - def jupyter_port_with_game(myshixun) - if @game_jupyter_port.to_i <=0 - _open_game_jupyter(myshixun) - end - @game_jupyter_port - end - - def jupyter_save_with_shixun(shixun,jupyter_port) - author_name = current_user.real_name - author_email = current_user.git_mail - message = "User submitted" - - tpiID = "tpm#{shixun.id}" - - src_url = "#{jupyter_service(jupyter_port)}/nbconvert/notebook/data/workspace/myshixun_#{tpiID}/01.ipynb?download=true" - - response = Faraday.get(src_url) - - if response.status.to_i != 200 - raise("获取文件内容失败:#{response.status}") - end - - content = response.body.force_encoding('utf-8') - - c = GitService.update_file(repo_path: shixun.repo_path, - file_path: "01.ipynb", - message: message, - content: content, - author_name: author_name, - author_email: author_email) - - return c.size - end - - def jupyter_save_with_game(myshixun,jupyter_port) - author_name = current_user.real_name - author_email = current_user.git_mail - message = "User submitted" - - tpiID = myshixun.id - - repo_save_path = myshixun.repo_save_path - src_url = "#{jupyter_service(jupyter_port)}/nbconvert/notebook/data/workspace/myshixun_#{tpiID}/#{repo_save_path}/01.ipynb?download=true" - response = Faraday.get(src_url) - - if response.status.to_i != 200 - raise("获取文件内容失败:#{response.status}") - end - - content = response.body.force_encoding('utf-8') - - c = GitService.update_file(repo_path: myshixun.repo_path, - file_path: "01.ipynb", - message: message, - content: content, - author_name: author_name, - author_email: author_email) - - return c.size - end - - - ##重置jupyter环境 - def jupyter_tpi_reset(myshixun) - jupyter_delete_tpi(myshixun) - url = jupyter_url_with_game(myshixun) - port = jupyter_port_with_game(myshixun) - {url: url, port: port} - end - - ## 重置tpm环境 - def jupyter_tpm_reset(shixun) - jupyter_delete_tpm(shixun) - - url = jupyter_url_with_shixun(shixun) - port = jupyter_port_with_shixun(shixun) - - {url: url, port: port} - end - - - - # 删除pod - def jupyter_delete_tpi(myshixun) - myshixun_id = myshixun.id - digest = myshixun.identifier + edu_setting('bridge_secret_key') - digest_key = Digest::SHA1.hexdigest("#{digest}") - begin - shixun_tomcat = edu_setting('cloud_bridge') - uri = "#{shixun_tomcat}/bridge/jupyter/delete" - Rails.logger.info("#{current_user} => cloese_jupyter digest is #{digest}") - params = {:tpiID => myshixun_id, :digestKey => digest_key, :identifier => myshixun.identifier} - res = uri_post uri, params - if res && res['code'].to_i != 0 - raise("实训云平台繁忙(繁忙等级:110)") - end - end - end - - - def jupyter_delete_tpm(shixun) - tpiID = "tpm#{shixun.id}" - digest = shixun.identifier + edu_setting('bridge_secret_key') - digest_key = Digest::SHA1.hexdigest("#{digest}") - begin - shixun_tomcat = edu_setting('cloud_bridge') - uri = "#{shixun_tomcat}/bridge/jupyter/delete" - Rails.logger.info("#{current_user} => cloese_jupyter digest is #{digest}") - params = {:tpiID => tpiID, :digestKey => digest_key, :identifier => shixun.identifier} - res = uri_post uri, params - if res && res['code'].to_i != 0 - raise("实训云平台繁忙(繁忙等级:110)") - end - end - end - - def jupyter_service jupyter_port - edu_setting('jupyter_service').gsub("PORT", jupyter_port) - end - - -end diff --git a/app/services/shixuns/create_shixun_service.rb b/app/services/shixuns/create_shixun_service.rb deleted file mode 100644 index c85455901..000000000 --- a/app/services/shixuns/create_shixun_service.rb +++ /dev/null @@ -1,115 +0,0 @@ -class CreateShixunService < ApplicationService - attr_reader :user, :params, :permit_params - - def initialize(user, permit_params, params) - @user = user - @params = params - @permit_params = permit_params - end - - def call - shixun = Shixun.new(permit_params) - identifier = Util::UUID.generate_identifier(Shixun, 8) - shixun.identifier= identifier - shixun.user_id = user.id - main_mirror = MirrorRepository.find params[:main_type] - sub_mirrors = MirrorRepository.where(id: params[:sub_type]) - begin - ActiveRecord::Base.transaction do - shixun.save! - # 获取脚本内容 - shixun_script = get_shixun_script(shixun, main_mirror, sub_mirrors) - # 创建额外信息 - ShixunInfo.create!(shixun_id: shixun.id, evaluate_script: shixun_script, description: params[:description]) - # 创建合作者 - shixun.shixun_members.create!(user_id: user.id, role: 1) - # 创建镜像 - ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id) - # 创建主服务配置 - ShixunServiceConfig.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id) - # 创建子镜像相关数据(实训镜像关联表,子镜像服务配置) - sub_mirrors.each do |sub| - ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => sub.id) - # 实训子镜像服务配置 - name = sub.name #查看镜像是否有名称,如果没有名称就不用服务配置 - ShixunServiceConfig.create!(:shixun_id => shixun.id, :mirror_repository_id => sub.id) if name.present? - end - # 创建版本库 - repo_path = repo_namespace(user.login, shixun.identifier) - GitService.add_repository(repo_path: repo_path) - shixun.update_column(:repo_name, repo_path.split(".")[0]) - # 如果是云上实验室,创建相关记录 - if !Laboratory.current.main_site? - Laboratory.current.laboratory_shixuns.create!(shixun: shixun, ownership: true) - end - # 如果是jupyter,先创建一个目录,为了挂载(因为后续数据集,开启Pod后环境在没销毁前,你上传数据集是挂载不上目录的,因此要先创建目录,方便中间层挂载) - if shixun.is_jupyter? - folder = EduSetting.get('shixun_folder') - path = "#{folder}/#{identifier}" - FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path) - end - return shixun - end - rescue => e - Rails.logger.error("shixun_create_error: #{e.message}") - raise("创建实训失败!") - end - end - - private - - def get_shixun_script shixun, main_mirror, sub_mirrors - if !shixun.is_jupyter? - mirror = main_mirror.mirror_scripts - if main_mirror.blank? - modify_shixun_script shixun, mirror.first&.(:script) - else - sub_name = sub_mirrors.pluck(:type_name) - if main_mirror.type_name == "Java" && sub_name.include?("Mysql") - mirror.last.try(:script) - else - shixun_script = mirror.first&.script - modify_shixun_script shixun, shixun_script - end - end - end - end - - def modify_shixun_script shixun, script - if script.present? - source_class_name = [] - challenge_program_name = [] - shixun.challenges.map(&:exec_path).each do |exec_path| - challenge_program_name << "\"#{exec_path}\"" - if shixun.main_mirror_name == "Java" - if exec_path.nil? || exec_path.split("src/")[1].nil? - source = "\"\"" - else - source = "\"#{exec_path.split("src/")[1].split(".java")[0]}\"" - end - logger.info("----source: #{source}") - source_class_name << source.gsub("/", ".") if source.present? - elsif shixun.main_mirror_name.try(:first) == "C#" - if exec_path.nil? || exec_path.split(".")[1].nil? - source = "\"\"" - else - source = "\"#{exec_path.split(".")[0]}.exe\"" - end - source_class_name << source if source.present? - end - end - script = if script.include?("sourceClassName") && script.include?("challengeProgramName") - script.gsub(/challengeProgramNames=\(.*\)/,"challengeProgramNames=\(#{challenge_program_name.reject(&:blank?).join(" ")}\)").gsub(/sourceClassNames=\(.*\)/, "sourceClassNames=\(#{source_class_name.reject(&:blank?).join(" ")}\)") - else - script.gsub(/challengeProgramNames=\(.*\)/,"challengeProgramNames=\(#{challenge_program_name.reject(&:blank?).join(" ")}\)").gsub(/sourceClassNames=\(.*\)/, "sourceClassNames=\(#{challenge_program_name.reject(&:blank?).join(" ")}\)") - end - end - return script - end - - # 版本库目录空间 - def repo_namespace(user, shixun_identifier) - "#{user}/#{shixun_identifier}.git" - end - -end diff --git a/app/views/admins/shixun_modify_records/index.html.erb b/app/views/admins/shixun_modify_records/index.html.erb deleted file mode 100644 index cecba30cb..000000000 --- a/app/views/admins/shixun_modify_records/index.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<% define_admin_breadcrumbs do %> - <% add_admin_breadcrumb('实训修改记录') %> -<% end %> - -