实训项目相关模块相关api的开发

This commit is contained in:
huang 2017-02-19 17:49:58 +08:00
parent 82c6799953
commit 8d1987567e
11 changed files with 136 additions and 164 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

@ -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

@ -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

@ -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 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

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20170219025424) do
ActiveRecord::Schema.define(:version => 20170219070127) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -305,18 +305,17 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
end
create_table "boards", :force => true do |t|
t.integer "project_id", :null => false
t.string "name", :default => "", :null => false
t.integer "project_id", :null => false
t.string "name", :default => "", :null => false
t.string "description"
t.integer "position", :default => 1
t.integer "topics_count", :default => 0, :null => false
t.integer "messages_count", :default => 0, :null => false
t.integer "position", :default => 1
t.integer "topics_count", :default => 0, :null => false
t.integer "messages_count", :default => 0, :null => false
t.integer "last_message_id"
t.integer "parent_id"
t.integer "course_id"
t.integer "org_subfield_id"
t.integer "contest_id"
t.integer "training_project_id"
end
add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id"
@ -714,8 +713,8 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
t.string "code"
t.integer "time"
t.string "extra"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "location"
t.string "term"
t.string "string"
@ -725,29 +724,28 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
t.string "class_period"
t.integer "school_id"
t.text "description"
t.integer "status", :default => 1
t.integer "attachmenttype", :default => 2
t.integer "status", :default => 1
t.integer "attachmenttype", :default => 2
t.integer "lft"
t.integer "rgt"
t.integer "is_public", :limit => 1, :default => 1
t.integer "inherit_members", :limit => 1, :default => 1
t.integer "open_student", :default => 0
t.integer "outline", :default => 0
t.integer "publish_resource", :default => 0
t.integer "is_delete", :default => 0
t.integer "is_public", :limit => 1, :default => 1
t.integer "inherit_members", :limit => 1, :default => 1
t.integer "open_student", :default => 0
t.integer "outline", :default => 0
t.integer "publish_resource", :default => 0
t.integer "is_delete", :default => 0
t.integer "end_time"
t.string "end_term"
t.integer "is_excellent", :default => 0
t.integer "excellent_option", :default => 0
t.integer "is_copy", :default => 0
t.integer "visits", :default => 0
t.integer "is_excellent", :default => 0
t.integer "excellent_option", :default => 0
t.integer "is_copy", :default => 0
t.integer "visits", :default => 0
t.integer "syllabus_id"
t.string "invite_code"
t.string "qrcode"
t.integer "qrcode_expiretime", :default => 0
t.integer "professional_level_id", :limit => 1
t.integer "invite_code_halt", :limit => 1, :default => 0
t.integer "os_allow", :default => 0
t.integer "qrcode_expiretime", :default => 0
t.integer "invite_code_halt", :limit => 1, :default => 0
t.integer "os_allow", :default => 0
end
add_index "courses", ["invite_code"], :name => "index_courses_on_invite_code", :unique => true
@ -822,9 +820,19 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "disciplines", :force => true do |t|
t.string "name"
t.integer "professional_level_id", :limit => 1
create_table "delayed_jobs_20161218", :id => false, :force => true do |t|
t.integer "id", :default => 0, :null => false
t.integer "priority", :default => 0, :null => false
t.integer "attempts", :default => 0, :null => false
t.text "handler", :null => false
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "discuss_demos", :force => true do |t|
@ -979,9 +987,8 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
t.integer "forge_act_id"
t.string "forge_act_type"
t.integer "org_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "training_project_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "forge_activities", ["forge_act_id"], :name => "index_forge_activities_on_forge_act_id"
@ -1683,12 +1690,9 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
end
create_table "professional_levels", :force => true do |t|
t.integer "level"
end
create_table "professions", :force => true do |t|
t.string "name"
t.integer "discipline_id", :limit => 1
t.string "level"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "project_infos", :force => true do |t|
@ -1701,19 +1705,18 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
create_table "project_scores", :force => true do |t|
t.string "project_id"
t.integer "score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "issue_num", :default => 0
t.integer "issue_journal_num", :default => 0
t.integer "news_num", :default => 0
t.integer "documents_num", :default => 0
t.integer "changeset_num", :default => 0
t.integer "board_message_num", :default => 0
t.integer "board_num", :default => 0
t.integer "attach_num", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "issue_num", :default => 0
t.integer "issue_journal_num", :default => 0
t.integer "news_num", :default => 0
t.integer "documents_num", :default => 0
t.integer "changeset_num", :default => 0
t.integer "board_message_num", :default => 0
t.integer "board_num", :default => 0
t.integer "attach_num", :default => 0
t.datetime "commit_time"
t.integer "pull_request_num", :default => 0
t.integer "training_project_id", :default => -1
t.integer "pull_request_num", :default => 0
end
create_table "project_statuses", :force => true do |t|
@ -1736,40 +1739,37 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
end
create_table "projects", :force => true do |t|
t.string "name", :default => "", :null => false
t.string "name", :default => "", :null => false
t.text "description"
t.string "homepage", :default => ""
t.boolean "is_public", :default => true, :null => false
t.string "homepage", :default => ""
t.boolean "is_public", :default => true, :null => false
t.integer "parent_id"
t.datetime "created_on"
t.datetime "updated_on"
t.string "identifier"
t.integer "status", :default => 1, :null => false
t.integer "status", :default => 1, :null => false
t.integer "lft"
t.integer "rgt"
t.boolean "inherit_members", :default => false, :null => false
t.boolean "inherit_members", :default => false, :null => false
t.integer "project_type"
t.boolean "hidden_repo", :default => false, :null => false
t.integer "attachmenttype", :default => 1
t.boolean "hidden_repo", :default => false, :null => false
t.integer "attachmenttype", :default => 1
t.integer "user_id"
t.integer "dts_test", :default => 0
t.string "enterprise_name"
t.integer "organization_id"
t.integer "project_new_type"
t.integer "gpid"
t.integer "forked_from_project_id"
t.integer "forked_count"
t.integer "publish_resource", :default => 0
t.integer "boards_count", :default => 0
t.integer "news_count", :default => 0
t.integer "acts_count", :default => 0
t.integer "journals_count", :default => 0
t.integer "boards_reply_count", :default => 0
t.integer "visits", :default => 0
t.integer "hot", :default => 0
t.integer "publish_resource", :default => 0
t.integer "visits", :default => 0
t.integer "hot", :default => 0
t.string "invite_code"
t.string "qrcode"
t.integer "qrcode_expiretime", :default => 0
t.integer "qrcode_expiretime", :default => 0
t.text "script"
t.integer "training_status", :limit => 1, :default => 0
end
add_index "projects", ["lft"], :name => "index_projects_on_lft"
@ -2163,8 +2163,8 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
t.string "title"
t.text "description"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "eng_name"
t.integer "syllabus_type"
t.integer "credit"
@ -2173,9 +2173,8 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
t.integer "practice_hours"
t.string "applicable_major"
t.string "pre_course"
t.integer "visits", :default => 0
t.integer "des_status", :default => 0
t.integer "professional_level_id", :limit => 1
t.integer "visits", :default => 0
t.integer "des_status", :default => 0
end
add_index "syllabuses", ["user_id"], :name => "index_syllabuses_on_user_id"
@ -2256,46 +2255,6 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
t.integer "fields_bits", :default => 0
end
create_table "trackers_training_projects", :id => false, :force => true do |t|
t.integer "training_project_id", :default => 0, :null => false
t.integer "tracker_id", :default => 0, :null => false
end
add_index "trackers_training_projects", ["training_project_id"], :name => "projects_trackers_training_project_id"
create_table "training_projects", :force => true do |t|
t.string "name", :limit => 30, :null => false
t.text "description"
t.string "homepage", :limit => 60
t.boolean "is_public", :default => true, :null => false
t.integer "parent_id"
t.integer "projects_count", :default => 0
t.string "identifier", :null => false
t.integer "status", :default => 1
t.integer "lft"
t.integer "rgt"
t.boolean "inherit_members", :default => false, :null => false
t.integer "project_type"
t.boolean "hidden_repo", :default => false, :null => false
t.integer "attachmenttype", :default => 1
t.integer "user_id"
t.integer "dts_test", :default => 0
t.string "enterprise_name"
t.integer "organization_id"
t.integer "project_new_type"
t.integer "gpid"
t.integer "forked_from_project_id"
t.integer "forked_count"
t.integer "publish_resource", :default => 0
t.integer "visits", :default => 0
t.integer "hot", :default => 0
t.string "invite_code"
t.string "qrcode"
t.integer "qrcode_expiretime", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "training_tasks", :force => true do |t|
t.integer "project_id"
t.integer "tracker_id"
@ -2304,7 +2263,8 @@ ActiveRecord::Schema.define(:version => 20170219025424) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "author_id"
t.integer "status", :limit => 1, :default => 1
t.integer "status", :limit => 1, :default => 0
t.integer "position", :limit => 1
end
create_table "user_actions", :force => true do |t|