实训项目一些调整,api和结构
This commit is contained in:
parent
f7e59c782c
commit
96aa9b7261
|
@ -815,16 +815,29 @@ class ProjectsController < ApplicationController
|
|||
redirect_to admin_projects_url(:status => params[:status])
|
||||
end
|
||||
|
||||
# 弹框提醒:
|
||||
# 自己不能参加自己的实训项目
|
||||
# 没有建立版本库的项目不能开启实训
|
||||
# 已经实训过直接跳入
|
||||
#
|
||||
def training_chiled_project_exec
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# training_status: 默认为0; 1代表实训项目; 2:代表实训子项目
|
||||
def training_project_execute
|
||||
jobName = "#{@project.id}"
|
||||
pipeLine = "#{Base64.encode64(@project.script)}"
|
||||
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob")
|
||||
res = Net::HTTP.post_form(uri, {jobName: jobName, pipeLine: pipeLine}).body
|
||||
if res.code == 0
|
||||
@project.update_attribute(:training_status, 1)
|
||||
else
|
||||
flash[:notice] = "启动失败"
|
||||
end
|
||||
# if res.code == 0
|
||||
@project.update_attribute(:training_status, 1)
|
||||
@notice = "实训开启成功"
|
||||
# else
|
||||
# flash[:notice] = "启动失败"
|
||||
# end
|
||||
end
|
||||
|
||||
def training_project_update
|
||||
|
@ -832,11 +845,7 @@ class ProjectsController < ApplicationController
|
|||
pipeLine = "#{Base64.encode64(@project.script)}"
|
||||
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/updateJob")
|
||||
res = Net::HTTP.post_form(uri, {jobName: jobName, pipeLine: pipeLine}).body
|
||||
if res.code == 0
|
||||
@project.update_attribute(:training_status, 1)
|
||||
else
|
||||
flash[:notice] = "启动失败"
|
||||
end
|
||||
@notice = "重新开启实训成功"
|
||||
end
|
||||
|
||||
def task_execute
|
||||
|
@ -856,18 +865,114 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def uri_exec uri, params
|
||||
Net::HTTP.post_form(uri, {jobName: '222e', pipeLine: base64}).body
|
||||
|
||||
res = Net::HTTP.post_form(uri, params).body
|
||||
end
|
||||
|
||||
# 需要传Jobname(项目ID),Task ID, Stage
|
||||
# 开启实训项目,学生会fork一个项目并自动发送任务
|
||||
def training_project_extend
|
||||
@project = Project.find(params[:id])
|
||||
@repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab")
|
||||
# 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项
|
||||
unless has_forked?(@project, User.current)
|
||||
project = project_from_current_project(@project.id, User.current.id)
|
||||
redirect_to project_path(project)
|
||||
else
|
||||
ActiveRecord::Base.transaction do
|
||||
g = Gitlab.client
|
||||
if User.current.gid.nil?
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
s.sync_user(User.current)
|
||||
end
|
||||
gproject = g.fork(@project.gpid, User.current.gid)
|
||||
if gproject
|
||||
new_training_project = copy_project_and_module(@project, gproject)
|
||||
forked_count = @project.forked_count.to_i + 1
|
||||
@project.update_attributes(:forked_count => forked_count)
|
||||
# 发布实训任务,只发布实训任务的第一个
|
||||
publish_training_tasks(@project, new_training_project)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 需要传Task ID
|
||||
# 判断任务是否完成
|
||||
# 如果完成则发送下一个任务直到任务结束
|
||||
# status 1 成功,2 失败
|
||||
def training_task_status
|
||||
status = params[:status].to_i
|
||||
task_id = params[:task_id]
|
||||
stage = params[:stage].to_i
|
||||
training_task = TrainingTask.find(task_id)
|
||||
training_task.update_attribute(:status => stage)
|
||||
origianl_project = Project.find(training_task.project_id)
|
||||
original_tasks_count = origianl_project.training_tasks.count
|
||||
position = training_task.try(:position) + 1
|
||||
if status == 1 && position <= original_tasks_count
|
||||
position = training_task.position + 1
|
||||
|
||||
# 继续下一个任务
|
||||
TrainingTask.where(:project_id => origianl_project.id, :position => position)
|
||||
publish_training_tasks original_project, new_training_project
|
||||
training_task.update_attribute(:status, training_task.try(:position))
|
||||
end
|
||||
end
|
||||
|
||||
# 实训开启成功后,发布第一个任务
|
||||
# REDO:失败后提醒用户,及相关处理
|
||||
def publish_training_tasks original_project, new_training_project
|
||||
original_task = TrainingTask.where(:project_id => original_project.id, :position => 1).first
|
||||
training_task = TrainingTask.new
|
||||
training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads]))
|
||||
training_task.subject = original_task.subject
|
||||
training_task.description = original_task.description
|
||||
training_task.position = original_task.position
|
||||
training_task.project_id = new_training_project.id
|
||||
training_task.author_id = User.current.id
|
||||
if training_task.save
|
||||
respond_to do |format|
|
||||
format.html{redirect_to project_training_tasks_url(:project_id => new_training_project.id)}
|
||||
end
|
||||
else
|
||||
raise "create task failed"
|
||||
end
|
||||
end
|
||||
|
||||
# 复制项目
|
||||
def copy_project_and_module tproject, gproject
|
||||
project = Project.new
|
||||
project.name = tproject.name
|
||||
project.is_public = tproject.is_public
|
||||
project.status = tproject.status
|
||||
project.description = tproject.description
|
||||
project.hidden_repo = tproject.hidden_repo
|
||||
project.user_id = User.current.id
|
||||
project.project_type = 0
|
||||
project.project_new_type = tproject.project_new_type
|
||||
project.gpid = gproject.id
|
||||
project.forked_from_project_id = tproject.id
|
||||
project.enabled_module_names = tproject.enabled_module_names
|
||||
if project.save
|
||||
project.update_attribute(:training_status,1)
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => User.current, :roles => [r])
|
||||
if ProjectScore.where("project_id=?", project.id).first.nil?
|
||||
ProjectScore.create(:project_id => project.id, :score => false)
|
||||
end
|
||||
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id)
|
||||
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id)
|
||||
Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
|
||||
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0)
|
||||
Rails.logger.debug "ProjectStatus created: #{project_status.to_json}"
|
||||
project.members << m
|
||||
project.project_infos << project_info
|
||||
copy_repository(project, gproject)
|
||||
return project
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'forked', :layout => 'base_projects'}
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 资源库fork弹框
|
||||
|
|
|
@ -35,12 +35,12 @@ class RepositoriesController < ApplicationController
|
|||
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats, :quality_analysis]
|
||||
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
||||
|
||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :export_rep_static, :training_task_execute]
|
||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend]
|
||||
# 连接gitlab
|
||||
# before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff]
|
||||
|
||||
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :training_task_execute]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :training_project_extend]
|
||||
# 版本库新增权限
|
||||
# before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ]
|
||||
accept_rss_auth :revisions
|
||||
|
@ -133,7 +133,7 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
# 开启实训项目,学生会fork一个项目并自动发送任务
|
||||
def training_task_execute
|
||||
def training_project_extend
|
||||
@project = Project.find(params[:id])
|
||||
@repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab")
|
||||
# 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项
|
||||
|
|
|
@ -544,7 +544,7 @@ module ProjectsHelper
|
|||
result = "manage_versions"
|
||||
elsif user.allowed_to?(:manage_repository, @project)
|
||||
result = "manage_repository"
|
||||
elsif is_project_manager?(user.id, @project.id)
|
||||
elsif @project.is_training_project?
|
||||
result = "training_task"
|
||||
end
|
||||
result
|
||||
|
|
|
@ -225,12 +225,12 @@ class Project < ActiveRecord::Base
|
|||
|
||||
# 判断项目是否为实训项目
|
||||
def is_training_project?
|
||||
(self.enabled_modules.where("name = 'training_tasks'").empty? && self.training_status == 0) ? false : true
|
||||
(self.enabled_modules.where("name = 'training_tasks'").empty? && self.training_status == 1) ? false : true
|
||||
end
|
||||
|
||||
# 判断项目是否为开启实训的项目(eg:学生开启实训)
|
||||
def is_child_training_project?
|
||||
self.training_status == 1 ? true :false
|
||||
self.training_status == 2 ? true :false
|
||||
end
|
||||
|
||||
def new_course
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</div>
|
||||
|
||||
<!--加入、退出、关注项目-->
|
||||
<% if true %>
|
||||
<% if !@project.is_child_training_project? %>
|
||||
<div class="fr clear mr15">
|
||||
<ul><span id="join_in_project_applied"><%= render :partial => "projects/applied_status" %></span></ul>
|
||||
</div>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<li class="mr5 fl">
|
||||
<!--实训项目条件:1、modules中选中了实训任务 2、不是fork的项目-->
|
||||
<% if @project.is_training_project? %>
|
||||
<%= link_to "开始实训", forked_pop_project_path(@project, :task => true), :class => "sy_btn_green fr", :remote => true %>
|
||||
<%= link_to "开始实训", training_chiled_project_exec_project_path(@project), :class => "sy_btn_green fr", :remote => true %>
|
||||
<% else %>
|
||||
<%= link_to "<span class='vl_fork'></span>".html_safe+"Fork", forked_pop_project_path(@project),
|
||||
:class=>"pro_new_topbtn_left fl", :remote => true %>
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<div style="width:460px;">
|
||||
<div class="sy_popup_top">
|
||||
<h3 class="fl">提示</h3>
|
||||
<a href="javascript:void(0);" class="sy_icons_close fr" onclick="hideModal()"></a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="sy_popup_con" style="width:380px;">
|
||||
<ul class="sy_popup_add" >
|
||||
<%# 实训项目和非实训项目,@type为true的时候为实训 %>
|
||||
<% if User.current.id == @project.user_id %>
|
||||
<li class="center mb30" style="line-height:20px">
|
||||
很抱歉,您不能在自己的实训项目中启动训练
|
||||
</li>
|
||||
<% else %>
|
||||
<% if @project.gpid.blank? %>
|
||||
<li class="center mb30" style="line-height:20px">
|
||||
该项目还没有创建版本库,暂时不支持实训
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="center mb5" style="line-height:20px">
|
||||
<% if has_forked_cur_project(@project) %>
|
||||
您已经实训过该项目,点击“确定”将会跳转到您的实训项目主页,请问您是否继续?
|
||||
<% elsif @project.training_tasks.count == 0 %>
|
||||
该项目还没有创建实训任务,暂时不支持开启实训
|
||||
<% else %>
|
||||
实训将在后台为您创建一个新的同名项目,并为您推送第一个任务,请问您是否继续?
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="mt10">
|
||||
<label class="mr27"> </label>
|
||||
<a href="javascript:void(0);" class="sy_btn_grey fl " onclick="hideModal()">取 消</a>
|
||||
<%= link_to "确 定", {:controller => 'projects', :action => 'training_project_extend'}, :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
|
@ -1 +1,2 @@
|
|||
$("#training_project_exec_tip").html('<%= escape_javascript( render :partial => 'projects/settings/training_project_exec_tip') %>');
|
||||
$("#training_project_exec_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_project_exec_tip') %>');
|
||||
$("#training_project_filter_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_projects_filter_tip') %>');
|
|
@ -19,7 +19,7 @@
|
|||
<% if User.current.allowed_to?(:manage_repository, @project) %>
|
||||
<li><a href="javascript:void(0)" id="pro_st_tb_6" class="<%= show_memu == 'manage_repository' ? 'active' : ''%>" onclick="project_setting(6);">版本库</a></li>
|
||||
<% end %>
|
||||
<% if User.current.admin? %>
|
||||
<% if @project.is_training_project? %>
|
||||
<li><a href="javascript:void(0)" id="pro_st_tb_7" class="<%= show_memu == 'trainig_task' ? 'active' : ''%>" onclick="project_setting(7);">实训任务</a></li>
|
||||
<% end %>
|
||||
<!--<li id="pro_st_tb_7" class="pro_st_normaltab" onclick="project_setting(7);">活动(时间跟踪)</li>-->
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<% if @project.training_status == 1 %>
|
||||
<%= link_to "重启实训", training_project_update_project_path, :class => "fr sy_btn_green mb10", :remote => true %>
|
||||
<% else %>
|
||||
<%= link_to "开启实训", training_project_execute_project_path, :class => "fr sy_btn_green mb10", :remote => true %>
|
||||
<% unless @project.script.blank? %>
|
||||
<% if @project.training_status == 1 %>
|
||||
<%= link_to "重启实训", training_project_update_project_path, :class => "fr sy_btn_green mb10", :remote => true %>
|
||||
<% else %>
|
||||
<%= link_to "开启实训", training_project_execute_project_path, :class => "fr sy_btn_green mb10", :remote => true %>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -0,0 +1,3 @@
|
|||
var htmlvalue = "<%= escape_javascript(render :partial => 'projects/training_child_project_exec') %>";
|
||||
pop_box_new(htmlvalue,460,316);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$("#training_project_exec_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_project_exec_tip') %>');
|
||||
$("#training_project_filter_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_projects_filter_tip') %>');
|
|
@ -7,60 +7,31 @@
|
|||
<div class="sy_popup_con" style="width:380px;">
|
||||
<ul class="sy_popup_add" >
|
||||
<%# 实训项目和非实训项目,@type为true的时候为实训 %>
|
||||
<% if @project.is_training_project? %>
|
||||
<% if User.current.id == @project.user_id %>
|
||||
<li class="center mb30" style="line-height:20px">
|
||||
很抱歉,您不能在自己的实训项目中启动训练
|
||||
</li>
|
||||
<% else %>
|
||||
<% if @project.gpid.blank? %>
|
||||
<li class="center mb30" style="line-height:20px">
|
||||
该项目还没有创建版本库,暂时不支持实训
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="center mb5" style="line-height:20px">
|
||||
<% if has_forked_cur_project(@project) %>
|
||||
您已经实训过该项目,点击“确定”将会跳转到您的实训项目主页,请问您是否继续?
|
||||
<% else %>
|
||||
实训将在后台为您创建一个新的同名项目,并为您推送第一个任务,请问您是否继续?
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="mt10">
|
||||
<label class="mr27"> </label>
|
||||
<a href="javascript:void(0);" class="sy_btn_grey fl " onclick="hideModal()">取 消</a>
|
||||
<%= link_to "确 定", {:controller => 'repositories', :action => 'training_task_execute'}, :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if User.current.id == @project.user_id %>
|
||||
<li class="center mb30" style="line-height:20px">
|
||||
自己不能Fork自己创建的项目
|
||||
</li>
|
||||
<% else %>
|
||||
<% if User.current.id == @project.user_id %>
|
||||
<% if @project.gpid.blank? %>
|
||||
<li class="center mb30" style="line-height:20px">
|
||||
自己不能Fork自己创建的项目
|
||||
该项目还没有创建版本库,暂时不能Fork
|
||||
</li>
|
||||
<% else %>
|
||||
<% if @project.gpid.blank? %>
|
||||
<li class="center mb30" style="line-height:20px">
|
||||
该项目还没有创建版本库,暂时不能Fork
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="center mb5" style="line-height:20px">
|
||||
<% if has_forked_cur_project(@project) %>
|
||||
您已经Fork过该项目,点击“确定”将会跳入您Fork的项目主页,请问是否继续?
|
||||
<% else %>
|
||||
Fork将在后台执行<br>平台将为您创建一个新的同名项目和版本库,请问是否继续?
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="mt10">
|
||||
<label class="mr27"> </label>
|
||||
<a href="javascript:void(0);" class="sy_btn_grey fl " onclick="hideModal()">取 消</a>
|
||||
<%= link_to "确 定", {:controller => 'repositories', :action => 'forked'}, :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<li class="center mb5" style="line-height:20px">
|
||||
<% if has_forked_cur_project(@project) %>
|
||||
您已经Fork过该项目,点击“确定”将会跳入您Fork的项目主页,请问是否继续?
|
||||
<% else %>
|
||||
Fork将在后台执行<br>平台将为您创建一个新的同名项目和版本库,请问是否继续?
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="mt10">
|
||||
<label class="mr27"> </label>
|
||||
<a href="javascript:void(0);" class="sy_btn_grey fl " onclick="hideModal()">取 消</a>
|
||||
<%= link_to "确 定", {:controller => 'repositories', :action => 'forked'}, :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
|
@ -29,9 +29,11 @@
|
|||
<a href="javascript:void(0);" class="fl mt2"><%= activity.journals.count %></a>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "btn btn-blue", :remote => true %>
|
||||
</td>
|
||||
<% if @project.is_child_training_project? %>
|
||||
<td>
|
||||
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "btn btn-blue", :remote => true %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -914,8 +914,10 @@ RedmineApp::Application.routes.draw do
|
|||
post 'reopen'
|
||||
get 'training_project_execute'
|
||||
get 'training_project_update'
|
||||
get 'training_project_extend'
|
||||
get 'task_execute'
|
||||
get 'forked_pop'
|
||||
get 'training_chiled_project_exec'
|
||||
get 'delete_member_pop', :to => 'projects#delete_member_pop', :via => :get, :as => "delete_member_pop"
|
||||
get 'search_public_orgs_not_in_project'
|
||||
match 'copy', :via => [:get, :post]
|
||||
|
|
Loading…
Reference in New Issue