TPI开启任务模块
This commit is contained in:
parent
c1a8682ac2
commit
622b7a4979
|
@ -20,8 +20,35 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# copy_shixun:复制一个新的实训模块包括版本库
|
||||
# publish_challenges:自动创建第一个Challenge
|
||||
def shixun_exec
|
||||
monitor_filter
|
||||
if @had_exec == true || User.current.id == @shixun.user_id
|
||||
render_403
|
||||
end
|
||||
repository = @shixun.repository
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
g = Gitlab.client
|
||||
if User.current.gid.nil?
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
s.sync_user(User.current)
|
||||
end
|
||||
gshixun = g.fork(@shixun.gpid, User.current.gid)
|
||||
new_shixun = copy_shixun(@shixun, gshixun)
|
||||
publish_challenges(@shixun.id, new_shixun.id, position = 1)
|
||||
respond_to do |format|
|
||||
format.html{redirect_to shixun_path(new_shixun)}
|
||||
end
|
||||
rescue Exception => e
|
||||
respond_to do |format|
|
||||
format.html{
|
||||
flash[:notice] = l(:notice_shixun_failed_exec)+ ":" + e.message
|
||||
redirect_to shixun_path(@shixun)}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
|
@ -156,6 +183,41 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def publish_challenges original_shixun_id, new_shixun_id, position
|
||||
original_challenge = Challenge.where(:shixun_id => original_shixun_id, :position => position).first
|
||||
challenge = Challenge.create(:subject => original_challenge.subject, :description => original_challenge.description,
|
||||
:position => 1, :shixun_id => new_shixun_id, :user_id => User.current.id)
|
||||
end
|
||||
|
||||
# 复制项目
|
||||
# gshixun --> gitlab project
|
||||
def copy_shixun tpm_shixun, gshixun
|
||||
shixun = Shixun.new
|
||||
shixun.name = tpm_shixun.name
|
||||
shixun.description = tpm_shixun.description
|
||||
shixun.is_public = tpm_shixun.is_public
|
||||
shixun.parent_id = tpm_shixun.id
|
||||
shixun.user_id = User.current.id
|
||||
shixun.gpid = gshixun.id
|
||||
shixun.forked_form = tpm_shixun.id
|
||||
shixun.status = 2
|
||||
if shixun.save
|
||||
m = ShixunMember.new(:user_id => User.current.id, :role => 1)
|
||||
shixun.shixun_members << m
|
||||
copy_shixun_repository(shixun, gshixun)
|
||||
return shixun
|
||||
end
|
||||
end
|
||||
|
||||
def copy_shixun_repository(shixun, gshixun)
|
||||
repository = Repository.factory('Git')
|
||||
repository.shixun_id = shixun.id
|
||||
repository.type = 'Repository::Gitlab'
|
||||
repository.url = gshixun.name
|
||||
repository.identifier = gshixun.name
|
||||
repository = repository.save
|
||||
end
|
||||
|
||||
def uri_exec uri, params
|
||||
res = Net::HTTP.post_form(uri, params).body
|
||||
res = JSON.parse(res)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
module ShixunsHelper
|
||||
|
||||
def tpi_allow_show shixun
|
||||
(shixun.tpm? && User.current.logged? && User.current.id != shixun.user_id)
|
||||
end
|
||||
|
||||
#显示项目配置菜单
|
||||
def show_project_memu user
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# status 控制实训的状态,0:未开启;1: 已开启
|
||||
# status 控制实训的状态,0:未开启;1: 已开启(TPM) 2: 子项目(TPI)
|
||||
class Shixun < ActiveRecord::Base
|
||||
attr_accessible :description, :is_public, :name, :parent_id, :changeset_num, :forked_form, :status
|
||||
attr_accessible :description, :is_public, :name, :parent_id, :changeset_num, :forked_form, :status, :user_id, :gpid, :forked_count
|
||||
|
||||
has_many :users, :through => :shixun_members
|
||||
has_many :shixun_members
|
||||
|
@ -13,7 +13,11 @@ class Shixun < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def tpi?
|
||||
(!self.parent_id.nil? && !self.forked_form.nil?) ? true : false
|
||||
(!self.parent_id.nil? && !self.forked_form.nil? && self.status == 2) ? true : false
|
||||
end
|
||||
|
||||
def tpm?
|
||||
(self.parent_id.nil? && self.status == 1) ? true : false
|
||||
end
|
||||
|
||||
def owner
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
<li class="mt10">
|
||||
<label class="mr27"> </label>
|
||||
<a href="javascript:void(0);" class="sy_btn_grey fl " onclick="hideModal()">取 消</a>
|
||||
<% if @had_exec %>
|
||||
<% if @had_exec == true %>
|
||||
<%= link_to "确 定", project_path(@tpm), :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<% else %>
|
||||
<%= link_to "确 定", {:controller => 'shixuns', :action => 'shixun_exec'}, :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<%= link_to "确 定", shixun_exec_shixun_path(@shixun), :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
|
|
|
@ -11,6 +11,18 @@
|
|||
<%=link_to @shixun.name, shixun_path(@shixun), :class => "pro_new_username break_word" %>
|
||||
</div>
|
||||
|
||||
<% if tpi_allow_show(@shixun) %>
|
||||
<div class="fr clear mr15">
|
||||
<ul>
|
||||
<span id="join_in_project_applied">
|
||||
<li class="mr5 fl">
|
||||
<%= link_to "开始实训", shixun_monitor_shixun_path(@shixun), :class => "sy_btn_green fr", :remote => true %>
|
||||
</li>
|
||||
</span>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="cl"></div>
|
||||
<% unless @shixun.parent_id %>
|
||||
<div class="fl pro_new_name ml15 clear mt5">
|
||||
|
@ -39,20 +51,20 @@
|
|||
<li id="project_menu_05">
|
||||
<%= link_to (1 > 0 ? "#{l(:project_module_repository)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k 99999}</span>".html_safe : "#{l(:project_module_repository)}"),
|
||||
({:controller => 'repositories', :action => 'shixun_show', :id => @shixun, :repository_id => shixun_repository(@shixun).try(:identifier)}),
|
||||
:class => "pro_new_proname", :title => "#{99999}" %></li>
|
||||
:class => "pro_new_proname", :title => "#{99999}" %></li>
|
||||
<% end %>
|
||||
<li id="project_menu_010">
|
||||
<%= link_to "#{l(:button_configure)}", settings_shixun_path(@shixun), :class => "pro_new_proname" %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--新版项目头部结束-->
|
||||
<script>
|
||||
$(function(){
|
||||
<!--新版项目头部结束-->
|
||||
<script>
|
||||
$(function(){
|
||||
|
||||
$("#project_menu_0<%= @shixun_menu_type %>").addClass('pro_new_topnav_active');
|
||||
$("#project_menu_0<%= @shixun_menu_type %>").addClass('pro_new_topnav_active');
|
||||
|
||||
})
|
||||
</script>
|
||||
})
|
||||
</script>
|
|
@ -33,6 +33,7 @@ zh:
|
|||
notice_account_wrong_password: 密码错误
|
||||
name_can_be_empty: 可以不填写真实姓名[保密所需]
|
||||
notice_successful_create: 创建成功
|
||||
notice_shixun_failed_exec: 实训开启失败,错误信息如下
|
||||
notice_create_failed: 创建失败,请先完善个人信息
|
||||
notice_failed_create: 创建失败
|
||||
notice_successful_update: 更新成功
|
||||
|
|
|
@ -30,6 +30,8 @@ RedmineApp::Application.routes.draw do
|
|||
|
||||
resources :shixuns do
|
||||
member do
|
||||
get 'shixun_monitor'
|
||||
get 'shixun_exec'
|
||||
post 'add_script'
|
||||
get 'settings(/:tab)', :action => 'settings', :as => 'settings'
|
||||
get 'shixun_job_create'
|
||||
|
|
Loading…
Reference in New Issue