实训api改进及一些提醒

This commit is contained in:
huang 2017-02-21 14:34:17 +08:00
parent d21350b754
commit f59243ab9f
11 changed files with 103 additions and 35 deletions

View File

@ -767,6 +767,14 @@ class ProjectsController < ApplicationController
end
end
def add_script
if @project.update_attribute(:script, params[:project_script])
@notice = "脚本添加成功"
else
@notice = "脚本添加失败"
end
end
def modules
@project.enabled_module_names = params[:enabled_module_names]
flash[:notice] = l(:notice_successful_update)
@ -809,24 +817,33 @@ class ProjectsController < ApplicationController
def training_project_execute
jobName = "#{@project.id}"
pipeLine = Base64.encode64(@project.script)
params = {:jobName => "#{jobName}", :pipeLine => "#{pipeLine}"}
uri = URI.parse("http://106.75.33.219:9999/jenkins-exec/api/createJob")
begin
respond_message = uri_exec uri, params
@project.update_attribute(:training_status, 1) if respond_message.message
return
rescue
@message = "failure"
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
end
def training_task_execute
positon = params[:positon].to_i
def training_project_update
jobName = "#{@project.id}"
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
end
def task_execute
taskId = params[:training_task_id]
jobName = @project.job_name
jobName = @project.forked_from_project_id
params = {:jobName => "#{jobName}", :taskId => "#{taskId}"}
uri = URI.parse("http://106.75.33.219:9999/jenkins-exec/api/buildJob")
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
begin
task = TrainingTask.find(taskId)
respond_message = uri_exec uri, params
@ -839,8 +856,18 @@ class ProjectsController < ApplicationController
end
def uri_exec uri, params
res = Net::HTTP.post_form(uri, params)
res.body
Net::HTTP.post_form(uri, {jobName: '222e', pipeLine: base64}).body
res = Net::HTTP.post_form(uri, params).body
end
# 需要传Jobname项目IDTask ID, Stage
def training_task_status
task_id = params[:task_id]
stage = params[:stage].to_i
training_task = TrainingTask.find(task_id)
training_task.update_attribute(:status => stage)
end
# 资源库fork弹框

View File

@ -59,7 +59,7 @@ class TrainingTasksController < ApplicationController
def index
# 顶部导航
@project_menu_type = 11
@training_tasks = TrainingTask.where(:project_id => @project.id).order('updated_at desc')
@training_tasks = TrainingTask.where(:project_id => @project.id).order('position desc')
@training_tasks_count = @training_tasks.count
@limit = 10
@is_remote = true

View File

@ -15,7 +15,7 @@
</div>
<!--加入、退出、关注项目-->
<% if !@project.is_child_training_project? %>
<% if true %>
<div class="fr clear mr15">
<ul><span id="join_in_project_applied"><%= render :partial => "projects/applied_status" %></span></ul>
</div>

View File

@ -36,7 +36,7 @@
<!--项目fork-->
<li class="mr5 fl">
<!--实训项目条件1、modules中选中了实训任务 2、不是fork的项目-->
<% if !@project.enabled_modules.where("name = 'training_tasks'").empty? && @project.forked_from_project_id.nil? %>
<% if @project.is_training_project? %>
<%= link_to "开始实训", forked_pop_project_path(@project, :task => true), :class => "sy_btn_green fr", :remote => true %>
<% else %>
<%= link_to "<span class='vl_fork'></span>".html_safe+"Fork", forked_pop_project_path(@project),

View File

@ -0,0 +1 @@
$("#training_project_exec_tip").html('<%= escape_javascript( render :partial => 'projects/settings/training_project_exec_tip') %>');

View File

@ -1,23 +1,47 @@
<div class="alert alert-orange ml15 mr15 mb10"><p>提示文字</p></div>
<div id="training_project_exec_tip">
<%= render :partial => "projects/settings/training_project_exec_tip" %>
</div>
<div class=" sy_new_tchbox clear ">
<a href="#" class="fr sy_btn_green mb10">开启实训</a>
<div id="training_project_filter_tip">
<%= render :partial => "projects/settings/training_projects_filter_tip" %>
</div>
<div id="training_project_filter_tip">
</div>
<div class="cl"></div>
<div class="clear">
<textarea style="width:746px; height:300px;border: 1px solid #c8c8c8; padding:5px;margin-bottom: 5px;" placeholder="请输入脚本"></textarea>
<a href="javascript:void(0)" class="fr btn btn-grey">取消</a>
<a href="javascript:void(0)" class="fr btn btn-blue mr5">确定</a>
<%= form_tag(url_for(:controller => 'projects', :action => 'add_script', :project_id => @project.id), :id => 'project_script_form', :method => "post", :remote => true) do %>
<textarea id="project_script" name="project_script" style="width:746px; height:300px;border: 1px solid #c8c8c8; padding:5px;margin-bottom: 5px;" placeholder="请输入脚本"><%= @project.script %></textarea>
<span id ="project_script_tip" class="c_red" style="display: none">内容不能为空</span>
<a href="javascript:void(0)" class="fr btn btn-grey">取消</a>
<a href="javascript:void(0)" class="fr btn btn-blue mr5" onclick="project_script_commit()">确定</a>
<% end %>
</div>
</div>
<script>
function regex_pr_comment()
{
var comment = $.trim($("#project_script").val());
if(comment.length == 0)
{
$("#project_script_tip").show();
return false;
}
else
{
$("#project_script_tip").hide();
return true;
}
}
<textarea>
node()
{
stage "first"
def args = "command=fileExists"
def response = httpRequest acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_FORM', httpMode: 'POST', requestBody: args, url: "http://localhost:8080/jenkins-exec/pipeline/call?taskId=${taskId}"
println('Status: '+response.status)
println('Response: '+response.content)
}
</textarea>
//提交pull request_comment
function project_script_commit()
{
if(regex_pr_comment())
{
$("#project_script_form").submit();
}
}
</script>

View File

@ -0,0 +1,3 @@
<% if @notice %>
<div class="alert alert-orange ml15 mr15 mb10"><p><%= @notice %></p></div>
<% end %>

View File

@ -0,0 +1,5 @@
<% 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 %>

View File

@ -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') %>');

View File

@ -29,7 +29,9 @@
<a href="javascript:void(0);" class="fl mt2"><%= activity.journals.count %></a>
<% end %>
</td>
<td><a href="javascript:void(0);" class="btn btn-blue">提交评测</a></td>
<td>
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "btn btn-blue", :remote => true %>
</td>
</tr>
<% end %>

View File

@ -906,12 +906,15 @@ RedmineApp::Application.routes.draw do
match 'user_watcherlist', :to => 'projects#watcherlist', :via => :get, :as => "watcherlist"
#end
post 'add_script'
post 'modules'
post 'archive'
post 'unarchive'
post 'close'
post 'reopen'
get 'training_project_execute'
get 'training_project_update'
get 'task_execute'
get 'forked_pop'
get 'delete_member_pop', :to => 'projects#delete_member_pop', :via => :get, :as => "delete_member_pop"
get 'search_public_orgs_not_in_project'
@ -922,6 +925,7 @@ RedmineApp::Application.routes.draw do
collection do
get 'project_home'
match 'join_project', :via => [:get, :post]
match 'training_task_status', :via => [:get, :post]
end
#by young