Merge branch 'develop' of https://bdgit.trustie.net/hushasha/bigdata into develop
This commit is contained in:
commit
f6f3960ba4
|
|
@ -107,12 +107,15 @@ class CoursesController < ApplicationController
|
|||
def sync_students
|
||||
school_id = User.find(@course.tea_id).try(:user_extensions).try(:school_id)
|
||||
@import_attachments = Attachment.where(:container_id => @course.id, :container_type => "ImportStudent")
|
||||
@had_import_count = 0
|
||||
@list_count = 0
|
||||
if @import_attachments.present?
|
||||
@import_attachments.each do |attachment|
|
||||
path = attachment.disk_directory
|
||||
name = attachment.disk_filename
|
||||
if name.split(".").last == "xls" || name.split(".").last == "xlsx"
|
||||
lists = readData("files/#{path}/#{name}")
|
||||
@list_count += lists.count
|
||||
lists.each do |list|
|
||||
logger.info("#{list[0]}---#{list[1]}")
|
||||
user = User.find_by_sql("SELECT u.* FROM `users` u, `user_extensions` ue where u.id = ue.user_id and CONCAT(u.lastname,u.firstname) ='#{list[1]}' and ue.school_id='#{school_id}' and ue.student_id='#{list[0]}'").first
|
||||
|
|
@ -122,10 +125,10 @@ class CoursesController < ApplicationController
|
|||
members << Member.new(:role_ids => [10], :user_id => user.id)
|
||||
@course.members << members
|
||||
StudentsForCourse.create(:student_id => user.id, :course_id => @course.id)
|
||||
@had_import_count += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@members = @course.members.joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id asc").select{|m| m.roles.to_s.include?("Student")}
|
||||
|
|
|
|||
|
|
@ -543,8 +543,11 @@ update
|
|||
# token值解密
|
||||
# gitlab_token = aes_dicrypt("priEn3UwXfJs3Pmy", token)
|
||||
@zip_path = Gitlab.endpoint.to_s + "/projects/" + @shixun.gpid.to_s + "/repository/archive?&private_token=" + token
|
||||
|
||||
login = User.find_by_mail("educoder@163.com").try(:login)
|
||||
if @shixun.fork_from.present?
|
||||
login = User.find_by_mail("eduforge@163.com").try(:login)
|
||||
else
|
||||
login = User.find_by_mail("educoder@163.com").try(:login)
|
||||
end
|
||||
gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
@repos_url = git_shixun_url(@shixun, login)
|
||||
# @repos_url = gitlab_address.to_s+"/" + @creator + "/" + @repository.identifier+"."+"git"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class ShixunsController < ApplicationController
|
|||
def statistics_students
|
||||
|
||||
end
|
||||
|
||||
# push代码的时候会触发gitlab hook
|
||||
def ghook
|
||||
# shixun_modify_status_without_publish(@shixun, 1)
|
||||
|
|
@ -221,7 +222,7 @@ class ShixunsController < ApplicationController
|
|||
ShixunMember.create!(:user_id => member, :shixun_id => @shixun.id, :role => 2)
|
||||
u = s.g.add_team_member(@shixun.gpid, gid, 40) # 3代表角色master
|
||||
if u.blank?
|
||||
raise("同步Gitlab数据错误")
|
||||
raise("同步Gitlab数据失败")
|
||||
end
|
||||
end
|
||||
@collaborators = @shixun.collaborators
|
||||
|
|
@ -486,6 +487,7 @@ class ShixunsController < ApplicationController
|
|||
#@shixun.major_id = params[:major_id]
|
||||
@shixun.trainee = params[:trainee]
|
||||
@shixun.webssh = params[:webssh].to_i
|
||||
@shixun.can_copy = params[:can_copy].to_i
|
||||
@shixun.identifier = identifier
|
||||
# if params[:course_id]
|
||||
# params[:course_id].each do |course_id|
|
||||
|
|
@ -514,9 +516,9 @@ class ShixunsController < ApplicationController
|
|||
s = Trustie::Gitlab::Sync.new
|
||||
gproject = s.create_shixun(@shixun, repository)
|
||||
raise "版本库创建失败" if @shixun.gpid.blank? # 若和gitlab没同步成功,则抛出异常
|
||||
g = Gitlab.client
|
||||
hook_url = Setting.protocol + "://" + Setting.host_name + "/shixuns/#{@shixun.identifier}" + "/ghook"
|
||||
g.add_project_hook(@shixun.gpid, hook_url)
|
||||
# g = Gitlab.client
|
||||
# hook_url = Setting.protocol + "://" + Setting.host_name + "/shixuns/#{@shixun.identifier}" + "/ghook"
|
||||
# g.add_project_hook(@shixun.gpid, hook_url)
|
||||
redirect_to shixun_path @shixun, notice: l(:notice_successful_create)
|
||||
rescue Exception => e
|
||||
respond_to do |format|
|
||||
|
|
@ -528,6 +530,119 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def copy
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
new_shixun = Shixun.new
|
||||
new_shixun.attributes = @shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier", "homepage_show")
|
||||
new_shixun.user_id = User.current.id
|
||||
new_shixun.identifier = generate_identifier
|
||||
new_shixun.status = 0
|
||||
new_shixun.fork_from = @shixun.id
|
||||
new_shixun.save!
|
||||
# 同步复制版本库,先fork再修改版本库名
|
||||
# eduforge用户作为版本库的创建者
|
||||
repository = Repository.new
|
||||
repository.shixun = new_shixun
|
||||
repository.type = 'Repository::Gitlab'
|
||||
repository.identifier = new_shixun.identifier.downcase
|
||||
repository.project_id = -1
|
||||
repository.save!
|
||||
g = Gitlab.client
|
||||
user_gid = User.find_by_mail("eduforge@163.com").try(:gid)
|
||||
gshixun = g.fork(@shixun.gpid, user_gid)
|
||||
raise "版本库创建失败" if gshixun.try(:id).blank?
|
||||
gshixun = g.edit_project(gshixun.id, new_shixun.identifier, new_shixun.identifier)
|
||||
raise "版本库创建失败" if (gshixun.try(:name) != new_shixun.identifier || gshixun.try(:path) != new_shixun.identifier)
|
||||
new_shixun.update_column(:gpid, gshixun.id)
|
||||
|
||||
# 同步复制合作者,合作者加入到gitlab
|
||||
@shixun.shixun_members.each do |shixun_member|
|
||||
if ShixunMember.where(:shixun_id => new_shixun.try(:id), :user_id => shixun_member.user_id).blank?
|
||||
ShixunMember.create!(:user_id => shixun_member.try(:user_id), :shixun_id => new_shixun.try(:id),
|
||||
:role => (shixun_member.try(:user_id) == User.current.id ? 1 : 2))
|
||||
end
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
gid = User.find(shixun_member.user_id).try(:gid)
|
||||
u = s.g.add_team_member(gshixun.id, gid, 40) # 3代表角色master
|
||||
if u.blank?
|
||||
raise("同步Gitlab数据失败")
|
||||
end
|
||||
end
|
||||
# 同步复制关卡
|
||||
if @shixun.challenges.present?
|
||||
@shixun.challenges.each do |challenge|
|
||||
new_challenge = Challenge.new
|
||||
new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id")
|
||||
new_challenge.user_id = User.current.id
|
||||
new_challenge.shixun_id = new_shixun.id
|
||||
new_challenge.save!
|
||||
if challenge.st == 0 # 评测题
|
||||
# 同步测试集
|
||||
if challenge.test_sets.present?
|
||||
challenge.test_sets.each do |test_set|
|
||||
new_test_set = TestSet.new
|
||||
new_test_set.attributes = test_set.attributes.dup.except("id","challenge_id")
|
||||
new_test_set.challenge_id = new_challenge.id
|
||||
new_test_set.save!
|
||||
end
|
||||
end
|
||||
# 同步关卡标签
|
||||
challenge_tags = ChallengeTag.where("challenge_id =? and challenge_choose_id is null", challenge.id)
|
||||
if challenge_tags.present?
|
||||
challenge_tags.each do |challenge_tag|
|
||||
ChallengeTag.create!(:challenge_id => new_challenge.id, :name => challenge_tag.try(:name))
|
||||
end
|
||||
end
|
||||
elsif challenge.st == 1 # 选择题
|
||||
if challenge.challenge_chooses.present?
|
||||
challenge.challenge_chooses.each do |challenge_choose|
|
||||
new_challenge_choose = ChallengeChoose.new
|
||||
new_challenge_choose.attributes = challenge_choose.attributes.dup.except("id","challenge_id")
|
||||
new_challenge_choose.challenge_id = new_challenge.id
|
||||
new_challenge_choose.save!
|
||||
# 每一题的选项
|
||||
if challenge_choose.challenge_questions.present?
|
||||
challenge_choose.challenge_questions.each do |challenge_question|
|
||||
new_challenge_question = ChallengeQuestion.new
|
||||
new_challenge_question.attributes = challenge_question.attributes.dup.except("id","challenge_choose_id")
|
||||
new_challenge_question.challenge_choose_id = new_challenge_choose.id
|
||||
new_challenge_question.save!
|
||||
end
|
||||
end
|
||||
# 每一题的知识标签
|
||||
st_challenge_tags = ChallengeTag.where(:challenge_id => challenge.id, :challenge_choose_id => challenge_choose.id)
|
||||
if st_challenge_tags.present?
|
||||
st_challenge_tags.each do |st_challenge_tag|
|
||||
ChallengeTag.create!(:challenge_id => new_challenge.id, :name => st_challenge_tag.try(:name), :challenge_choose_id => new_challenge_choose.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# 中间层创建测试集
|
||||
shixun_tomcat = Redmine::Configuration['shixun_tomcat']
|
||||
gameInfo = new_shixun.gameInfo
|
||||
uri ="#{shixun_tomcat}/bridge/game/publishGame"
|
||||
params = {gameInfo:gameInfo}
|
||||
res = uri_exec uri, params
|
||||
if res && res['code'].to_i != 0
|
||||
raise("实训云平台繁忙(繁忙等级:90)")
|
||||
end
|
||||
flash[:notice] = "实训复制成功"
|
||||
redirect_to shixun_challenges_path(new_shixun)
|
||||
rescue Exception => e
|
||||
logger.info("copy shixun failed ##{e.message}")
|
||||
flash[:notice] = "#{e.message}"
|
||||
g.delete_project(gshixun.id) if gshixun.try(:id).present? # 异常后,如果已经创建了版本库需要删除该版本库
|
||||
redirect_to shixun_challenges_path(@shixun)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.html{redirect_to shixun_challenges_path(@shixun)}
|
||||
|
|
@ -560,6 +675,7 @@ class ShixunsController < ApplicationController
|
|||
@shixun.language = params[:language]
|
||||
@shixun.trainee = params[:trainee]
|
||||
@shixun.webssh = params[:webssh].to_i
|
||||
@shixun.can_copy = params[:can_copy].to_i
|
||||
# if params[:course_id]
|
||||
# @shixun.shixun_major_courses.destroy_all
|
||||
# params[:course_id].each do |course_id|
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
class Shixun < ActiveRecord::Base
|
||||
attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication,
|
||||
:myshixun_count, :propaedeutics, :trainee, :major_id, :homepage_show, :webssh, :hidden
|
||||
:myshixun_count, :propaedeutics, :trainee, :major_id, :homepage_show, :webssh, :hidden, :fork_from, :can_copy
|
||||
|
||||
has_many :users, :through => :shixun_members
|
||||
has_many :shixun_members, :dependent => :destroy
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
<script src="/javascripts/jquery.datetimepicker.js" type="text/javascript"></script>
|
||||
<div class="task-popup" style="width:450px;">
|
||||
<div class="task-popup-title clearfix">
|
||||
<h3 class="fl color-grey">上传文件</h3>
|
||||
<a href="javascript:void(0);" onclick="$('#datetimepicker_mask').datetimepicker('destroy');" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a>
|
||||
</div>
|
||||
<div class="task-popup-content clear">
|
||||
<div class="ml15">
|
||||
本次新加入<%= @had_import_count %>个学生,还有<%= @list_count - @had_import_count %>个学生没有加入
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,2 +1,6 @@
|
|||
$("#setting_teacher_list").hide();
|
||||
$("#setting_student_list").html("<%= j(render :partial => 'courses/settings/all_student_list') %>").show();
|
||||
$("#setting_student_list").html("<%= j(render :partial => 'courses/settings/all_student_list') %>").show();
|
||||
<% if @had_import_count > 0 %>
|
||||
var htmlvalue = '<%= escape_javascript(render :partial => 'courses/settings/import_students_result', :locals => {:course => @course}) %>';
|
||||
pop_box_new(htmlvalue, 440, 490);
|
||||
<% end %>
|
||||
|
|
@ -102,6 +102,13 @@
|
|||
<label style="top:6px" class="color-grey" for="websh">(勾选则给学员的实践任务提供命令行窗口,否则不提供)</label>
|
||||
</span>
|
||||
</li>
|
||||
<li class="clearfix mb15">
|
||||
<label class="panel-form-label fl">复制 </label>
|
||||
<span class="fl mr20">
|
||||
<input type="checkbox" <%= @shixun.can_copy ? 'checked' : "" %> name="can_copy" value="1" id="can_copy" class="ml5 mr5 magic-checkbox" >
|
||||
<label style="top:6px" class="color-grey" for="can_copy">(勾选则给实训合作者提供复制实训功能,否则不提供)</label>
|
||||
</span>
|
||||
</li>
|
||||
<li class="clearfix">
|
||||
<a href="javascript:void(0)" class="task-btn task-btn-blue fr" onclick="submit_new_project();">提交</a>
|
||||
<%= link_to "取消", shixuns_path, :class => "task-btn fr mr10" %>
|
||||
|
|
|
|||
|
|
@ -50,7 +50,13 @@
|
|||
<label style="top:6px" class="color-grey" for="webssh">(勾选则给学员的实践任务提供命令行窗口,否则不提供)</label>
|
||||
</span>
|
||||
</li>
|
||||
|
||||
<li class="clearfix mb15">
|
||||
<label class="panel-form-label fl">复制 </label>
|
||||
<span class="fl mr20">
|
||||
<input type="checkbox" <%= @shixun.can_copy ? 'checked' : "" %> name="can_copy" value="<%= @shixun.can_copy ? 1 : 0 %>" id="can_copy" class="ml5 mr5 magic-checkbox" >
|
||||
<label style="top:6px" class="color-grey" for="can_copy">(勾选则给实训合作者提供复制实训功能,否则不提供)</label>
|
||||
</span>
|
||||
</li>
|
||||
<li class="clearfix">
|
||||
<a href="javascript:void(0)" class="task-btn task-btn-green fr " onclick="submit_edit_shixun(<%= @shixun.id %>);">保存</a>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,13 @@
|
|||
<!--<%#= @shixun.language %>-->
|
||||
<!--</div>-->
|
||||
</li>
|
||||
<li class="clearfix mb15">
|
||||
<label class="panel-form-label fl">复制 </label>
|
||||
<span class="fl mr20">
|
||||
<input type="checkbox" <%= @shixun.can_copy ? 'checked' : "" %> name="can_copy" value="<%= @shixun.can_copy ? 1 : 0 %>" id="can_copy" disabled="disabled" class="ml5 mr5 magic-checkbox" >
|
||||
<label style="top:6px" class="color-grey" for="can_copy">(勾选则给实训合作者提供复制实训功能,否则不提供)</label>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -29,15 +29,16 @@
|
|||
<%= link_to "继续实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15 ", :id => "shixun_operation", :remote => true %>
|
||||
<% end %>
|
||||
<%= link_to '发送至', search_user_courses_shixun_path(@shixun), :remote => true, :class => "fr shixun-task-btn task-btn-green mr15" %>
|
||||
<%# if User.current.manager_of_shixun?(@shixun) %>
|
||||
<%#= link_to "复制", copy_shixun_path(@shixun), :class => "fr shixun-task-btn task-btn-green mr15", :target => "_blank" %>
|
||||
<%# end %>
|
||||
<% elsif @shixun.status == 3 %>
|
||||
<% unless myshixun.blank? %>
|
||||
<%= link_to "继续实战", operation_shixun_path(@shixun, :myshixun_id => myshixun.try(:id)), :class => "fr shixun-task-btn task-btn-orange mr15 ", :id => "shixun_operation", :remote => true %>
|
||||
<% end %>
|
||||
<a href="javascript:void(0);" class="fr shixun-task-ban-btn mr15">已关闭</a>
|
||||
<% end %>
|
||||
<% if @shixun.can_copy && User.current.manager_of_shixun?(@shixun) %>
|
||||
<%#= link_to "复制", copy_shixun_path(@shixun), :class => "fr shixun-task-btn task-btn-green mr15" %>
|
||||
<a href="javascript:void(0);" onclick="op_confirm_box_loading('<%= copy_shixun_path(@shixun) %>', '复制将在后台执行</br>平台将为你创建一个新的同名实训和内容,请问是否继续?');" class = "fr shixun-task-btn task-btn-green mr15">复制</a>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
<% unless User.current.manager_of_shixun?(@shixun) %>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class AddForkFromToShixuns < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :shixuns, :fork_from, :integer
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddCanCopyToShixuns < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :shixuns, :can_copy, :boolean, :default => true
|
||||
end
|
||||
end
|
||||
|
|
@ -85,8 +85,8 @@ class Gitlab::Client
|
|||
# public (optional) - if true same as setting visibility_level = 20
|
||||
# visibility_level (optional)
|
||||
|
||||
def edit_project(id, visibility_level, default_branch)
|
||||
put("/projects/#{id}", :body => {:visibility_level => visibility_level, :default_branch => default_branch})
|
||||
def edit_project(id, name, path)
|
||||
put("/projects/#{id}", :body => {:name => name, :path => path})
|
||||
end
|
||||
|
||||
# Deletes a project.
|
||||
|
|
|
|||
|
|
@ -253,6 +253,13 @@ function op_confirm_box(url, str){
|
|||
pop_box_new(htmlvalue, 578, 205);
|
||||
}
|
||||
|
||||
function op_confirm_box_loading(url, str){
|
||||
var htmlvalue = '<div class="task-popup" style="width:578px;"><div class="task-popup-title clearfix"><h3 class="fl color-grey">提示</h3><a href="javascript:void(0);" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a></div>'+
|
||||
'<div class="task-popup-content"><p class="task-popup-text-center font-16">' + str + '</p></div><div class="task-popup-submit clearfix"><a href="javascript:void(0);" onclick="hideModal();" class="task-btn fl">取消</a>'+
|
||||
'<a href="'+ url +'" class="task-btn task-btn-blue fr" onclick="hideModal();$(\'.loading_all\').show();">确定</a></div></div>';
|
||||
pop_box_new(htmlvalue, 578, 205);
|
||||
}
|
||||
|
||||
// 两个按钮 点击确认跳转, 提示信息有两行
|
||||
function s_op_confirm_box(url, str){
|
||||
var htmlvalue = '<div class="task-popup" style="width:480px;"><div class="task-popup-title clearfix"><h3 class="fl color-grey">提示</h3><a href="javascript:void(0);" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a></div>'+
|
||||
|
|
|
|||
Loading…
Reference in New Issue