实训项目一些ajax控制
This commit is contained in:
parent
96aa9b7261
commit
eeba0c362d
|
@ -29,7 +29,7 @@ class ProjectsController < ApplicationController
|
|||
menu_item :share, :only => :share
|
||||
|
||||
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,
|
||||
:view_homework_attaches,:join_project, :project_home, :training_execute]
|
||||
:view_homework_attaches,:join_project, :project_home, :training_execute, :training_task_status]
|
||||
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
|
||||
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
|
||||
before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar]
|
||||
|
@ -848,19 +848,21 @@ class ProjectsController < ApplicationController
|
|||
@notice = "重新开启实训成功"
|
||||
end
|
||||
|
||||
# TrainintTask.status 0:评测中 1:评测成功 2:评测惊醒中
|
||||
def task_execute
|
||||
taskId = params[:training_task_id]
|
||||
jobName = @project.forked_from_project_id
|
||||
params = {:jobName => "#{jobName}", :taskId => "#{taskId}"}
|
||||
uri = URI.parse("http://123.59.135.74: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 = "失败,请联系系统管理员"
|
||||
@training_task = TrainingTask.find(taskId)
|
||||
if @training_task.status == 0
|
||||
params = {:jobName => "#{jobName}", :taskId => "#{taskId}"}
|
||||
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
|
||||
begin
|
||||
respond_message = uri_exec uri, params
|
||||
@training_task.update_attribute(:status, 2)
|
||||
return
|
||||
rescue
|
||||
@message = "失败,请联系系统管理员"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -889,7 +891,7 @@ class ProjectsController < ApplicationController
|
|||
forked_count = @project.forked_count.to_i + 1
|
||||
@project.update_attributes(:forked_count => forked_count)
|
||||
# 发布实训任务,只发布实训任务的第一个
|
||||
publish_training_tasks(@project, new_training_project)
|
||||
publish_training_tasks(@project.id, new_training_project.id, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -898,39 +900,38 @@ class ProjectsController < ApplicationController
|
|||
# 需要传Task ID
|
||||
# 判断任务是否完成
|
||||
# 如果完成则发送下一个任务直到任务结束
|
||||
# status 1 成功,2 失败
|
||||
# TrainingTask.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)
|
||||
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
|
||||
|
||||
@training_task = TrainingTask.find(task_id)
|
||||
original_project_id = Project.find(@training_task.project_id).try(:forked_from_project_id)
|
||||
original_project = Project.find(original_project_id)
|
||||
original_tasks_count = original_project.training_tasks.count
|
||||
position = @training_task.try(:position) + 1
|
||||
# 测试,默认成功
|
||||
if position <= original_tasks_count
|
||||
# 继续下一个任务
|
||||
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))
|
||||
publish_training_tasks original_project_id, @training_task.project_id, position
|
||||
@training_task.update_attribute(:status, 1)
|
||||
end
|
||||
end
|
||||
|
||||
# 实训开启成功后,发布第一个任务
|
||||
# REDO:失败后提醒用户,及相关处理
|
||||
def publish_training_tasks original_project, new_training_project
|
||||
original_task = TrainingTask.where(:project_id => original_project.id, :position => 1).first
|
||||
def publish_training_tasks original_project_id, new_training_project_id, position
|
||||
original_task = TrainingTask.where(:project_id => original_project_id, :position => position).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.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)}
|
||||
format.html{redirect_to project_training_tasks_url(:project_id => new_training_project_id)}
|
||||
end
|
||||
else
|
||||
raise "create task failed"
|
||||
|
@ -952,7 +953,7 @@ class ProjectsController < ApplicationController
|
|||
project.forked_from_project_id = tproject.id
|
||||
project.enabled_module_names = tproject.enabled_module_names
|
||||
if project.save
|
||||
project.update_attribute(:training_status,1)
|
||||
project.update_attribute(:training_status,2)
|
||||
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?
|
||||
|
@ -975,6 +976,21 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 判断用户是否已经fork过该项目
|
||||
def has_forked?(project, user)
|
||||
projects = Project.where("user_id =?", user)
|
||||
projects.map(&:forked_from_project_id).detect{|s| s == @project.id}.nil? ? true : false
|
||||
end
|
||||
|
||||
def copy_repository(project, gproject)
|
||||
repository = Repository.factory('Git')
|
||||
repository.project_id = project.id
|
||||
repository.type = 'Repository::Gitlab'
|
||||
repository.url = gproject.name
|
||||
repository.identifier = gproject.name
|
||||
repository = repository.save
|
||||
end
|
||||
|
||||
# 资源库fork弹框
|
||||
def forked_pop
|
||||
respond_to do |format|
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$("#task_action_status_<%= @training_task.id %>").html('<%= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>');
|
|
@ -0,0 +1 @@
|
|||
$("#task_action_status_<%= @training_task.id %>").html('<%= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>');
|
|
@ -0,0 +1,8 @@
|
|||
<% activity = activity.nil? ? local_assigns[:activity] : activity %>
|
||||
<% if activity.status == 1 %>
|
||||
<a class="btn btn-grey">评测通过</a>
|
||||
<% elsif activity.status == 2 %>
|
||||
<a class="btn btn-blue">评测中</a>
|
||||
<% else %>
|
||||
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "btn btn-blue", :remote => true %>
|
||||
<% end %>
|
|
@ -1,10 +1,10 @@
|
|||
<% unless activity.author.nil? %>
|
||||
<tr id="user_activity_<%= user_activity_id %>">
|
||||
<td>
|
||||
<% if activity.status == 0 %>
|
||||
<div class="issues_ciricons fl ml15 mt5"><i class="icon-flag fb " style="color:#49a547; font-size:15px;"></i></div>
|
||||
<% elsif activity.status == 1 %>
|
||||
<% if activity.status == 1 %>
|
||||
<div class="issues_ciricons fl ml15"><span class="issues_ciricons_02 "></span></div>
|
||||
<% else %>
|
||||
<div class="issues_ciricons fl ml15 mt5"><i class="icon-flag fb " style="color:#49a547; font-size:15px;"></i></div>
|
||||
<% end %>
|
||||
<div class=" fl ml5">
|
||||
<div class="issues_list_titlebox clear">
|
||||
|
@ -29,11 +29,13 @@
|
|||
<a href="javascript:void(0);" class="fl mt2"><%= activity.journals.count %></a>
|
||||
<% end %>
|
||||
</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 %>
|
||||
<td>
|
||||
<% if @project.is_child_training_project? %>
|
||||
<div id="task_action_status_<%= activity.id %>">
|
||||
<%= render :partial => 'action_status', :locals => {:activity => activity} %>
|
||||
</div>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
|
|
Loading…
Reference in New Issue