Merge branch 'dev_raining' of https://git.trustie.net/jacknudt/trustieforge into dev_raining

Conflicts:
	db/schema.rb
This commit is contained in:
daiao 2017-02-20 14:09:59 +08:00
commit c115fad8a1
22 changed files with 150 additions and 126 deletions

View File

@ -806,26 +806,34 @@ class ProjectsController < ApplicationController
end
def training_project_execute
user_name = @project.owner.try(:login)
jobName = "#{user_name}_#{@project.id}"
jobName = "#{@project.id}"
pipeLine = Base64.encode64(@project.script)
params = {}
params["jobName"] = "#{jobName}"
params["pipeLine"] = "#{pipeLine}"
params = {:jobName => "#{jobName}", :pipeLine => "#{pipeLine}"}
uri = URI.parse("http://106.75.33.219:9999/jenkins-exec/api/createJob")
uri_exec uri, params
# 返回成功信息job名存到数据库
begin
respond_message = uri_exec uri, params
@project.update_attribute(:training_status, 1) if respond_message.message
return
rescue
@message = "failure"
end
end
def training_task_execute
positon = params[:positon].to_i
taskId = params[:training_task_id]
jobName = @project.job_name
params = {}
params["jobName"] = "#{jobName}"
params["pipeLine"] = "#{pipeLine}"
uri = URI.parse("http://106.75.33.219:9999/jenkins-exec/api/createJob")
uri_exec uri, params
# 返回job执行信息哪一步成功错误原因
params = {:jobName => "#{jobName}", :taskId => "#{taskId}"}
uri = URI.parse("http://106.75.33.219:9999/jenkins-exec/api/buildJob")
begin
task = TrainingTask.find(taskId)
respond_message = uri_exec uri, params
# status 标注第几步已完成0表示未完成
task.update_attribute(:status, position)
return
rescue
@message = "失败,请联系系统管理员"
end
end
def uri_exec uri, params
@ -835,7 +843,7 @@ class ProjectsController < ApplicationController
# 资源库fork弹框
def forked_pop
@type = params[:type]
@task = params[:task]
respond_to do |format|
format.js
end

View File

@ -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]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :export_rep_static, :training_task_execute]
# 连接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]
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :training_task_execute]
# 版本库新增权限
# before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ]
accept_rss_auth :revisions
@ -132,7 +132,7 @@ class RepositoriesController < ApplicationController
# send_file "/path/to/file.zip"
end
# 开启实训项目
# 开启实训项目,学生会fork一个项目并自动发送任务
def training_task_execute
@project = Project.find(params[:id])
@repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab")
@ -163,17 +163,22 @@ class RepositoriesController < ApplicationController
end
end
def publish_training_tasks project, new_training_project
original_task = TrainingTask.where(:project_id => project.id, :position => 1)
# 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 = params[:training_task][:subject]
training_task.description = params[:training_task][:description]
training_task.tracker_id = params[:training_task][:tracker_id]
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)}
format.html{redirect_to project_training_tasks_url(:project_id => new_training_project.id)}
end
else
raise "create task failed"
end
end
@ -216,19 +221,20 @@ class RepositoriesController < ApplicationController
project.members << m
project.project_infos << project_info
copy_repository(project, gproject)
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_create)
if params[:continue]
attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
redirect_to new_project_url(attrs, :course => '0')
else
redirect_to project_path(project)
end
}
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
format.js
end
# respond_to do |format|
# format.html {
# flash[:notice] = l(:notice_successful_create)
# if params[:continue]
# attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
# redirect_to new_project_url(attrs, :course => '0')
# else
# redirect_to project_path(project)
# end
# }
# format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
# format.js
# end
return project
else
respond_to do |format|
format.html { render :action => 'forked', :layout => 'base_projects'}

View File

@ -2,13 +2,14 @@
class TrainingTasksController < ApplicationController
layout 'base_projects'
before_filter :find_project, :only => [:index, :new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete]
before_filter :allow_manager, :only => []
before_filter :allow_members, :only => [:new, :create]
before_filter :build_new_task_from_params, :only => [:new, :create, :update_form]
before_filter :find_training_task, :only => [:show, :edit, :update, :add_journal, :complete_training_task]
# before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :find_project, :only => [:index, :new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete]
# before_filter :authorize, :except => [:index, :show]
# before_filter :authorize, :except => [:new, :index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply, :issue_commits, :commit_for_issue, :issue_commit_delete]

View File

@ -5,7 +5,7 @@
<div class="cl"></div>
<div id="messageContent">
<div class="resources"><%= link_to image_tag(url_to_avatar(User.current),:class=>"fl mr10", :width => "50", :height => "50"), :alt => "用户头像" %>
<div class="resources " ><%= link_to image_tag(url_to_avatar(User.current),:class=>"fl mr10", :width => "50", :height => "50"), :alt => "用户头像" %>
<div class="fl" style="width:658px;">
<%= form_for('new_form',:url => leave_contest_message_path(@contest.id), :html =>{:id => "contest_feedback_new"}, :method => "post") do |f|%>
<%= render :partial => "users/jour_form", :locals => {:f => f, :object => @contest} %>

View File

@ -40,6 +40,9 @@
<li>
<a href="http://www.xtu.edu.cn/" target="_blank"><img src="images/footer_logo/p-xtu.png" width="210" height="40" alt="湘潭大学"></a>
</li>
<li>
<a href="http://www.copu.org.cn/" target="_blank"><img src="images/footer_logo/p-zgkyrj.png" width="210" height="40" alt="中国开源软件推进联盟"></a>
</li>
</ul>
<div class="cl"></div>
</div>

View File

@ -38,9 +38,8 @@
<li class="fl"><a href="http://www.webxmf.com/" target="_blank"><img src="/images/footer_logo/bee_logo.png" width="167" height="40" style="display: inline-block;" alt="web小蜜蜂" /></a></li>
</ul>
<div class="cl"></div>-->
<ul class="copyright">
<li class="fl mr10"><%= l(:label_rights_reserved)%></li>
<li class="fl"><a href="http://www.miibeian.gov.cn/" class="fl f_grey" target="_blank"><%= l(:label_license)%></a></li>
</ul>
<div class="copyright">
<p ><%= l(:label_rights_reserved)%><span class="mr10"></span><a href="http://www.miibeian.gov.cn/" class=" f_grey" target="_blank"><%= l(:label_license)%></a></p>
</div>
</ul>
</div><!--Footer end-->

View File

@ -38,8 +38,7 @@
<li class="fl"><a href="http://www.webxmf.com/" target="_blank"><img src="/images/footer_logo/bee_logo.png" width="167" height="40" style="display: inline-block;" alt="web小蜜蜂" /></a></li>
</ul>
<div class="cl"></div>
<ul class="copyright">
<li class="fl mr30"><%= l(:label_rights_reserved)%></li>
<li class="fl"><a href="http://www.miibeian.gov.cn/" class="fl f_grey" target="_blank"><%= l(:label_license)%></a></li>
</ul>
<div class="copyright">
<p ><%= l(:label_rights_reserved)%><span class="mr10"></span><a href="http://www.miibeian.gov.cn/" class=" f_grey" target="_blank"><%= l(:label_license)%></a></p>
</div>
</div><!--Footer end-->

View File

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

View File

@ -1,42 +1,42 @@
<div class="pro_new_prompt ml15 mr15 mb10"><p>问题跟踪模块与实训模块不能同时选择</p><p>一旦选定并保存后,将不能修改</p></div>
<ul class="pro_newsetting_con ml30 mb15">
<h2 class="pro_newsetting_title">请选择此项目可以使用的模块:</h2>
<%= form_for @project,:url => { :action => 'modules', :id => @project },:html => {:id => 'modules-form',:method => :post} do |f| %>
<% Redmine::AccessControl.available_project_modules.each do |m| %>
<li class="clear">
<%= check_box_tag('enabled_module_names[]', m, @project.module_enabled?(m), :class=>"fl mt8", :id => 'project_module_'+m.to_s ).html_safe -%>
<p class="fl ml5"><%= l_or_humanize(m, :prefix => "project_module_").html_safe %></p>
</li>
<% end %>
<li class="clear ">
<p class="fl ml5"><%= check_all_links('modules-form').html_safe %></p>
</li>
<% end %>
<li class="clear">
<a href="javascript:void(0);" class="sy_btn_blue mr15 fr" onclick="$('#modules-form').submit()"> <%= l(:button_save) %></a>
</li>
</ul>
<script>
$(function(){
if($("#project_module_issue_tracking").is(":checked")){
$("#project_module_training_tasks").attr('disabled', 'disabled')
}else if($("#project_module_training_tasks").is(":checked")){
$("#project_module_issue_tracking").attr('disabled', 'disabled');
}
$("#project_module_issue_tracking").on('click', function(){
if($("#project_module_issue_tracking").is(":checked")) {
$("#project_module_training_tasks").attr('disabled', 'disabled');
}else{
$("#project_module_training_tasks").removeAttr('disabled');
}
});
$("#project_module_training_tasks").on('click', function(){
if($("#project_module_training_tasks").is(":checked")){
$("#project_module_issue_tracking").attr('disabled', 'disabled');
}else {
$("#project_module_issue_tracking").removeAttr('disabled');
}
});
});
<ul class="pro_newsetting_con ml30 mb15">
<h2 class="pro_newsetting_title">请选择此项目可以使用的模块:</h2>
<%= form_for @project,:url => { :action => 'modules', :id => @project },:html => {:id => 'modules-form',:method => :post} do |f| %>
<% Redmine::AccessControl.available_project_modules.each do |m| %>
<li class="clear">
<%= check_box_tag('enabled_module_names[]', m, @project.module_enabled?(m), :class=>"fl mt8", :id => 'project_module_'+m.to_s ).html_safe -%>
<p class="fl ml5"><%= l_or_humanize(m, :prefix => "project_module_").html_safe %></p>
</li>
<% end %>
<li class="clear ">
<p class="fl ml5"><%= check_all_links('modules-form').html_safe %></p>
</li>
<% end %>
<li class="clear">
<a href="javascript:void(0);" class="sy_btn_blue mr15 fr" onclick="$('#modules-form').submit()"> <%= l(:button_save) %></a>
</li>
</ul>
<script>
$(function(){
if($("#project_module_issue_tracking").is(":checked")){
$("#project_module_training_tasks").attr('disabled', 'disabled')
}else if($("#project_module_training_tasks").is(":checked")){
$("#project_module_issue_tracking").attr('disabled', 'disabled');
}
$("#project_module_issue_tracking").on('click', function(){
if($("#project_module_issue_tracking").is(":checked")) {
$("#project_module_training_tasks").attr('disabled', 'disabled');
}else{
$("#project_module_training_tasks").removeAttr('disabled');
}
});
$("#project_module_training_tasks").on('click', function(){
if($("#project_module_training_tasks").is(":checked")){
$("#project_module_issue_tracking").attr('disabled', 'disabled');
}else {
$("#project_module_issue_tracking").removeAttr('disabled');
}
});
});
</script>

View File

@ -1,15 +1,26 @@
<h3>请输入脚本</h3>
<p><%= link_to "开启实训", training_project_execute_project_path(@project) %></p>
<textarea id="pull_request_comment" name="pull_request_comment" class="pullreques_reply_textarea" style="padding-left: 0px;"></textarea>
<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)
}
<div class="alert alert-orange ml15 mr15 mb10"><p>提示文字</p></div>
<div class=" sy_new_tchbox clear ">
<a href="#" class="fr sy_btn_green mb10">开启实训</a>
<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>
</div>
</div>
<h3>请输入脚本</h3>
<p><%= link_to "开启实训", training_project_execute_project_path(@project) %></p>
<textarea id="pull_request_comment" name="pull_request_comment" class="pullreques_reply_textarea" style="padding-left: 0px;"></textarea>
<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>

View File

@ -7,7 +7,7 @@
<div class="sy_popup_con" style="width:380px;">
<ul class="sy_popup_add" >
<%# 实训项目和非实训项目,@type为true的时候为实训 %>
<% if @type %>
<% if @task %>
<% if User.current.id == @project.user_id %>
<li class="center mb30" style="line-height:20px">
很抱歉,您不能在自己的实训项目中启动训练
@ -19,7 +19,7 @@
</li>
<% else %>
<li class="center mb5" style="line-height:20px">
<% if has_training_cur_project(@project) %>
<% if has_forked_cur_project(@project) %>
您已经实训过该项目,点击“确定”将会跳转到您的实训项目主页,请问您是否继续?
<% else %>
实训将在后台为您创建一个新的同名项目,并为您推送第一个任务,请问您是否继续?
@ -28,7 +28,7 @@
<li class="mt10">
<label class="mr27">&nbsp;</label>
<a href="javascript:void(0);" class="sy_btn_grey fl " onclick="hideModal()">取&nbsp;&nbsp;消</a>
<%= link_to "确 定", {:controller => 'projects', :action => 'training_task_execute'}, :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
<%= link_to "确 定", {:controller => 'repositories', :action => 'training_task_execute'}, :class => "sy_btn_blue fl ml20", :onclick => "hideModal();", :target => "_blank" %>
<div class="cl"></div>
</li>
<% end %>

View File

@ -1,10 +1 @@
<div class="project_r_h">
<div class="fl"><h2 class="project_h2_repository"><%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %></h2></div>
</div>
<%= form_for('forked',:url => {:controller => 'repositories', :action => 'forked'},:method => "post") do |f| %>
<input type="text" name="repo_name"/>
<button type="submit">确定</button>
<% end %>
<%= @project.id %>
<%= @repository.id %>
<%= User.current %>

View File

@ -1,4 +1,4 @@
<div class="resources" id="user_activity_<%= user_activity_id%>" style="<%= activity.private == 1? 'background-color:#cecece;':'' %>">
<div class="resources mb10" id="user_activity_<%= user_activity_id%>" style="<%= activity.private == 1? 'background-color:#cecece;':'' %>">
<div class="homepagePostBrief">
<div class="homepagePostPortrait">
<%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user), :alt => "用户头像" %>

View File

@ -13,10 +13,10 @@
</div>
<div class="cl"></div>
<div id="messageContent">
<div id="messageContent" >
<% unless is_current_user %>
<div class="resources mb10"><%= link_to image_tag(url_to_avatar(User.current),:class=>"fl mr10", :width => "50", :height => "50"), :alt => "用户头像" %>
<div class="fl" style="width:658px;">
<div class="fl" style="width:658px;" >
<%= form_for('new_form',:url => leave_user_message_path(@user.id), :html =>{:id => "user_feedback_new"}, :method => "post") do |f|%>
<%= render :partial => "jour_form", :locals => {:f => f, :object => @user} %>
<input id="private_flag" name="private" type="hidden" value="0"/>

View File

@ -1161,6 +1161,7 @@ RedmineApp::Application.routes.draw do
get 'projects/:id/repository/changes(/*path(.:ext))', :to => 'repositories#changes'
get 'projects/:id/repository/forked', :to => 'repositories#forked'
get 'projects/:id/repository/training_task_execute', :to => 'repositories#training_task_execute'
get 'projects/:id/repository/tree_head_message', :to => 'repositories#tree_head_message', :as => "tree_head_message"
get 'projects/:id/repository/export_rep_static', :to => 'repositories#export_rep_static'
get 'projects/:id/repository/project_archive', :to => 'repositories#project_archive', :as => 'project_archive'

View File

@ -1,6 +1,6 @@
class AddAuthorIdToTrainingTasks < ActiveRecord::Migration
def change
add_column :training_tasks, :author_id, :integer
add_column :training_tasks, :status, :integer, :limit => 1, :default => 1
add_column :training_tasks, :status, :integer, :limit => 1, :default => 0
end
end

View File

@ -1,5 +1,5 @@
class AddScriptToProject < ActiveRecord::Migration
def change
add_column :projects, :script, :text
end
end
class AddScriptToProject < ActiveRecord::Migration
def change
add_column :projects, :script, :text
end
end

View File

@ -1,5 +1,5 @@
class AddPositonToTrainingTask < ActiveRecord::Migration
def change
add_column :training_tasks, :position, :integer, :limit => 1
add_column :training_tasks, :position, :integer, :limit => 1, :default => 0
end
end

View File

@ -0,0 +1,5 @@
class AddTrainingStatusToProject < ActiveRecord::Migration
def change
add_column :projects, :training_status, :integer, :limit => 1, :default => 0
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -8,7 +8,7 @@
.courseRSide{ width:730px; background:#fff; padding:10px; margin-left: 10px; margin-bottom:10px;}
.wrap-big {width:980px; background:#fff; padding:10px; margin-bottom:10px;}
/*资源库*/
.resources {width:718px; background-color:#ffffff; padding:15px; border:1px solid #dddddd;float: right}
.resources {width:718px; background-color:#ffffff; padding:15px; border:1px solid #dddddd;float: right;}
.resourcesBanner {width:730px; height:40px; background-color:#eaeaea; margin-bottom:10px;}
.bannerName {background:#3b94d6; color:#ffffff; height:40px; line-height:40px; width:90px; text-align:center; font-weight:normal; vertical-align:middle; font-size: 16px; float:left;}
.resourcesSelect {width:30px; height:24px; float:right; position:relative; margin-top:-6px;}

View File

@ -433,7 +433,7 @@ a.topnav_login_box:hover {color:#a1ebff;}
.languageBox {width:55px; height:20px; margin-left:5px; outline:none; color:#666666; border:1px solid #d9d9d9;}
.departments{ width:855px; margin:5px auto;height:40px;line-height:40px;}
.departments li {height:40px; line-height:40px;}
.copyright{ width:375px; margin:0 auto;height:20px;line-height:20px;}
.copyright{ width:100%; text-align: center; }
a.f_grey {color:#666666;}
a.f_grey:hover {color:#000000;}
/*消息弹框*/