Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
298224bc80
@ -0,0 +1,206 @@
|
||||
class Subjects::CopySubjectService < ApplicationService
|
||||
attr_reader :subject, :to_subject, :user_id, :laboratory
|
||||
|
||||
def initialize(subject, user_id, laboratory=nil)
|
||||
@subject = subject
|
||||
@user_id = user_id
|
||||
@laboratory = laboratory
|
||||
subject_params = subject.attributes.dup.except('id', 'copy_subject_id', 'user_id', 'homepage_show')
|
||||
@to_subject = Subject.new(subject_params)
|
||||
end
|
||||
|
||||
def call
|
||||
return if subject.blank?
|
||||
ActiveRecord::Base.transaction do
|
||||
copy_subject!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
# 复制实践课程表
|
||||
def copy_subject!
|
||||
to_subject.copy_subject_id = subject.id
|
||||
to_subject.user_id = user_id
|
||||
to_subject.save!
|
||||
|
||||
copy_stages_data!(subject, to_subject)
|
||||
copy_subject_members_data(to_subject)
|
||||
laboratory.laboratory_subjects.create(subject: to_subject) if laboratory
|
||||
end
|
||||
|
||||
# 复制章节需要的章节
|
||||
def copy_stages_data!(subject, to_subject)
|
||||
subject.stages.each do |stage|
|
||||
to_stage = to_subject.stages.new
|
||||
to_stage.attributes = stage.attributes.dup.except('id', 'subject_id', 'user_id')
|
||||
to_stage.user_id = user_id
|
||||
to_stage.save!
|
||||
|
||||
copy_stage_shixuns_data!(stage, to_stage)
|
||||
end
|
||||
end
|
||||
|
||||
# 创建实践课程关联实训表
|
||||
def copy_stage_shixuns_data!(stage, to_stage)
|
||||
stage.stage_shixuns.each do |stage_shixun|
|
||||
to_shixun = copy_shixun_data!(stage_shixun)
|
||||
to_stage_shixun = to_stage.stage_shixuns.new
|
||||
to_stage_shixun.attributes = stage_shixun.attributes.dup.except('id', 'subject_id', 'stage_id', 'shixun_id')
|
||||
to_stage_shixun.subject_id = to_stage.subject_id
|
||||
to_stage_shixun.shixun_id = to_shixun.id
|
||||
to_stage_shixun.save!
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# 复制实训数据
|
||||
def copy_shixun_data!(stage_shixun)
|
||||
shixun = stage_shixun.shixun
|
||||
to_shixun = Shixun.new
|
||||
to_shixun.attributes = shixun.attributes.dup.except('id', 'user_id', 'identifier', 'homepage_show',
|
||||
'use_scope', 'averge_star', 'myshixuns_count')
|
||||
to_shixun.user_id = user_id
|
||||
to_shixun.save!
|
||||
|
||||
copy_shixun_info_data!(shixun, to_shixun)
|
||||
copy_shixun_mirror_repositories_data!(shixun, to_shixun)
|
||||
copy_shixun_tag_repertoires_data!(shixun, to_shixun)
|
||||
copy_shixun_service_configs_data!(shixun, to_shixun)
|
||||
copy_challenges_data!(shixun, to_shixun)
|
||||
copy_shixun_members_data!(to_shixun)
|
||||
|
||||
# 云上实验室
|
||||
laboratory.laboratory_shixuns.create(shixun: to_shixun) if laboratory
|
||||
to_shixun
|
||||
end
|
||||
|
||||
# 创建实训长字段内容
|
||||
def copy_shixun_info_data!(shixun, to_shixun)
|
||||
to_shixun_info = ShixunInfo.new
|
||||
to_shixun_info.attributes = shixun.shixun_info.attributes.except('id', 'shixun_id')
|
||||
to_shixun_info.shixun_id = to_shixun.id
|
||||
to_shixun_info.save!
|
||||
end
|
||||
|
||||
# 创建实训镜像标签
|
||||
def copy_shixun_mirror_repositories_data!(shixun, to_shixun)
|
||||
shixun.shixun_mirror_repositories.each do |shixun_mirror_repository|
|
||||
to_shixun_mirror_repository = to_shixun.shixun_mirror_repositories.new
|
||||
to_shixun_mirror_repository.attributes = shixun_mirror_repository.attributes.dup.except('id', 'shixun_id')
|
||||
to_shixun_mirror_repository.shixun_id = to_shixun.id
|
||||
to_shixun_mirror_repository.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 创建实训tag标签
|
||||
def copy_shixun_tag_repertoires_data!(shixun, to_shixun)
|
||||
shixun.shixun_tag_repertoires.each do |shixun_tag_repertoire|
|
||||
to_shixun_tag_repertoire = to_shixun.shixun_tag_repertoires.new
|
||||
to_shixun_tag_repertoire.attributes = shixun_tag_repertoire.attributes.dup.except('id', 'shixun_id')
|
||||
to_shixun_tag_repertoire.shixun_id = to_shixun.id
|
||||
to_shixun_tag_repertoire.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 复制实训服务配置
|
||||
def copy_shixun_service_configs_data!(shixun, to_shixun)
|
||||
shixun.shixun_service_configs.each do |shixun_service_config|
|
||||
to_shixun_service_config = to_shixun.shixun_service_configs.new
|
||||
to_shixun_service_config.attributes = shixun_service_config.attributes.dup.except('id', 'shixun_id')
|
||||
to_shixun_service_config.shixun_id = to_shixun.id
|
||||
to_shixun_service_config.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 复制关卡信息
|
||||
def copy_challenges_data!(shixun, to_shixun)
|
||||
shixun.challenges.each do |challenge|
|
||||
to_challenge = to_shixun.challenges.new
|
||||
to_challenge.attributes = challenge.attributes.dup.except('id', 'shixun_id', 'praises_count', 'user_id', 'visits')
|
||||
to_challenge.user_id = user_id
|
||||
to_challenge.shixun_id = to_shixun.id
|
||||
to_challenge.save!
|
||||
|
||||
copy_challenge_answers_data!(challenge, to_challenge)
|
||||
copy_challenge_tags_data!(challenge, to_challenge)
|
||||
copy_test_sets_data!(challenge, to_challenge)
|
||||
copy_challenge_chooses_data!(challenge, to_challenge)
|
||||
end
|
||||
end
|
||||
|
||||
# 复制答案数据
|
||||
def copy_challenge_answers_data!(challenge, to_challenge)
|
||||
challenge.challenge_answers.each do |challenge_answer|
|
||||
to_challenge_answer = to_challenge.challenge_answers.new
|
||||
to_challenge_answer.attributes = challenge_answer.attributes.dup.except('id', 'challenge_id')
|
||||
to_challenge_answer.challenge_id = to_challenge.id
|
||||
to_challenge_answer.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 复制关卡标签数据
|
||||
def copy_challenge_tags_data!(challenge, to_challenge)
|
||||
challenge.challenge_tags.each do |challenge_tag|
|
||||
to_challenge_tag = to_challenge.challenge_tags.new
|
||||
to_challenge_tag.attributes = challenge_tag.attributes.dup.except('id', 'challenge_id')
|
||||
to_challenge_tag.challenge_id = to_challenge.id
|
||||
to_challenge_tag.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 复制测试集
|
||||
def copy_test_sets_data!(challenge, to_challenge)
|
||||
challenge.test_sets.each do |test_set|
|
||||
to_test_set = to_challenge.test_sets.new
|
||||
to_test_set.attributes = test_set.attributes.dup.except('id', 'challenge_id')
|
||||
to_test_set.challenge_id = to_challenge.id
|
||||
to_test_set.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 复制选择题关卡
|
||||
def copy_challenge_chooses_data!(challenge, to_challenge)
|
||||
challenge.challenge_chooses.each do |challenge_choose|
|
||||
to_challenge_choose = to_challenge.challenge_chooses.new
|
||||
to_challenge_choose.attributes = challenge_choose.attributes.dup.except('id', 'challenge_id')
|
||||
to_challenge_choose.challenge_id = to_challenge.id
|
||||
to_challenge_choose.save!
|
||||
|
||||
copy_challenge_questions_data!(challenge_choose, to_challenge_choose)
|
||||
copy_challenge_choose_tags_data!(challenge_choose, to_challenge_choose)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# 复制选择题问题
|
||||
def copy_challenge_questions_data!(challenge_choose, to_challenge_choose)
|
||||
challenge_choose.challenge_questions.each do |challenge_question|
|
||||
to_challenge_question = to_challenge_choose.challenge_questions.new
|
||||
to_challenge_question.attributes = challenge_question.attributes.dup.except('id', 'challenge_choose_id')
|
||||
to_challenge_question.challenge_choose_id = to_challenge_choose.id
|
||||
to_challenge_question.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 复制选择题标签
|
||||
def copy_challenge_choose_tags_data!(challenge_choose, to_challenge_choose)
|
||||
challenge_choose.challenge_tags.each do |challenge_tag|
|
||||
to_challenge_tag = to_challenge_choose.challenge_tags.new
|
||||
to_challenge_tag.attributes = challenge_tag.attributes.dup.except('id', 'challenge_choose_id')
|
||||
to_challenge_tag.challenge_choose_id = to_challenge_choose.id
|
||||
to_challenge_tag.save!
|
||||
end
|
||||
end
|
||||
|
||||
# 创建实训成员
|
||||
def copy_shixun_members_data!(to_shixun)
|
||||
to_shixun.shixun_members.create!(user_id: user_id, role: 1)
|
||||
end
|
||||
|
||||
# 创建课程成员
|
||||
def copy_subject_members_data(to_subject)
|
||||
to_subject.subject_members.create!(user_id: user_id, role: 1)
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
json.count @users.total_count
|
||||
json.users do
|
||||
json.array! @users.each do |user|
|
||||
json.extract! user, :id, :login, :real_name, :identity, :school_name, :hidden_phone
|
||||
end
|
||||
end
|
@ -0,0 +1,21 @@
|
||||
<% define_breadcrumbs do %>
|
||||
<% add_breadcrumb('用户列表') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container user-list-form">
|
||||
<%= form_tag(cooperative_users_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<div class="form-group mr-2">
|
||||
<label for="identity">职业:</label>
|
||||
<% identity_options = [['全部', ''], ['教师', 0], ['学生', 1], ['专业人士', 2]] %>
|
||||
<%= select_tag(:identity, options_for_select(identity_options), class: 'form-control') %>
|
||||
</div>
|
||||
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'ID/姓名/邮箱/手机号检索') %>
|
||||
<%= text_field_tag(:school_name, params[:school_name], class: 'form-control col-sm-2', placeholder: '学校/单位检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="box cooperative-list-container user-list-container">
|
||||
<%= render partial: 'cooperative/users/shared/list', locals: { users: @users } %>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
$('.user-list-container').html("<%= j(render partial: 'cooperative/users/shared/list', locals: { users: @users }) %>");
|
@ -0,0 +1,40 @@
|
||||
<table class="table table-hover user-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="10%" class="text-left">真实姓名</th>
|
||||
<th width="16%">邮件地址</th>
|
||||
<th width="10%">手机号码</th>
|
||||
<th width="18%">单位</th>
|
||||
<th width="10%">角色</th>
|
||||
<th width="14%"><%= sort_tag('创建于', name: 'created_on', path: cooperative_users_path) %></th>
|
||||
<th width="14%"><%= sort_tag('最后登录', name: 'last_login_on', path: cooperative_users_path) %></th>
|
||||
<th width="6%"><%= sort_tag('经验值', name: 'experience', path: cooperative_users_path) %></th>
|
||||
<th width="6%"><%= sort_tag('金币', name: 'grade', path: cooperative_users_path) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if users.present? %>
|
||||
<% users.each do |user| %>
|
||||
<tr class="user-item-<%= user.id %>">
|
||||
<td class="text-left">
|
||||
<%= link_to "/users/#{user.login}", target: '_blank' do %>
|
||||
<%= overflow_hidden_span user.real_name, width: 100 %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= overflow_hidden_span display_text(user.mail), width: 150 %></td>
|
||||
<td><%= overflow_hidden_span display_text(user.phone), width: 100 %></td>
|
||||
<td><%= overflow_hidden_span display_text(user.school_name), width: 150 %></td>
|
||||
<td><%= user.identity %></td>
|
||||
<td><%= display_text(user.created_on&.strftime('%Y-%m-%d %H:%M')) %></td>
|
||||
<td><%= display_text(user.last_login_on&.strftime('%Y-%m-%d %H:%M')) %></td>
|
||||
<td><%= user.experience.to_i %></td>
|
||||
<td class="grade-content"><%= user.grade.to_i %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'cooperative/shared/paginate', locals: { objects: users } %>
|
@ -0,0 +1,5 @@
|
||||
class AddLaboratoryIdToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_reference :users, :laboratory
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddCopyFromForSubjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :subjects, :copy_subject_id, :integer
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddLaboratoryIdToLibraries < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_reference :libraries, :laboratory
|
||||
end
|
||||
end
|
@ -0,0 +1,7 @@
|
||||
class TransferLaboratoryData < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
Course.where(laboratory_id: nil).update_all(laboratory_id: 1)
|
||||
Competition.where(laboratory_id: nil).update_all(laboratory_id: 1)
|
||||
Library.where(laboratory_id: nil).update_all(laboratory_id: 1)
|
||||
end
|
||||
end
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue