Merge branch 'develop' of https://git.trustie.net/jacknudt/trustieforge into develop
This commit is contained in:
commit
abcaf33a17
|
@ -853,8 +853,10 @@ class ProjectsController < ApplicationController
|
|||
params = {jobName: jobName, pipeLine: pipeLine}
|
||||
res = uri_exec uri, params
|
||||
training_project_notice res
|
||||
if res['code'] == 0
|
||||
@project.update_attribute(:training_status, 1)
|
||||
end
|
||||
end
|
||||
|
||||
def training_project_update
|
||||
jobName = "#{@project.id}"
|
||||
|
@ -863,8 +865,10 @@ class ProjectsController < ApplicationController
|
|||
params = {jobName: jobName, pipeLine: pipeLine}
|
||||
res = uri_exec uri, params
|
||||
training_project_notice res
|
||||
if res['code'] == 0
|
||||
@project.update_attribute(:training_status, 1)
|
||||
end
|
||||
end
|
||||
|
||||
def training_project_notice res
|
||||
if res['code'] == 0
|
||||
|
@ -891,18 +895,30 @@ class ProjectsController < ApplicationController
|
|||
gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
gitUrl = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ rep_identify + "."+"git"
|
||||
gitUrl = Base64.encode64(gitUrl)
|
||||
|
||||
if @training_task.status == 0
|
||||
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}"}
|
||||
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
|
||||
begin
|
||||
res = uri_exec uri, params
|
||||
# 任务开启成功后创建一条留言提示,并发布
|
||||
@training_task.update_attribute(:status, 2)
|
||||
return
|
||||
# 轮询获取
|
||||
for i in 0..60 do
|
||||
sleep(1)
|
||||
result = TrainingTask.where(:id => @training_task.id).first.try(:result)
|
||||
if (result != 0)
|
||||
break
|
||||
end
|
||||
end
|
||||
# @training_task = TrainingTask.find(@training_task.id)
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'TrainingTask','Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def uri_exec uri, params
|
||||
|
@ -931,7 +947,7 @@ class ProjectsController < ApplicationController
|
|||
forked_count = @project.forked_count.to_i + 1
|
||||
@project.update_attributes(:forked_count => forked_count)
|
||||
# 发布实训任务,只发布实训任务的第一个
|
||||
publish_training_tasks(@project.id, new_training_project.id, 1)
|
||||
publish_training_tasks(@project.id, new_training_project.id, 1, @project.user_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -944,7 +960,7 @@ class ProjectsController < ApplicationController
|
|||
def training_task_status
|
||||
status = params[:status].to_i
|
||||
task_id = params[:taskId]
|
||||
message = Base64.decode64(params[:msg])
|
||||
message = Base64.decode64(params[:msg]) unless params[:msg].blank?
|
||||
begin
|
||||
@training_task = TrainingTask.find(task_id)
|
||||
# 如果已经执行成功过,则不重复执行
|
||||
|
@ -961,11 +977,12 @@ class ProjectsController < ApplicationController
|
|||
ActiveRecord::Base.transaction do
|
||||
if position < original_tasks_count
|
||||
# 继续发布下一个任务
|
||||
publish_training_tasks original_project_id, @training_task.project_id, position + 1
|
||||
publish_training_tasks original_project_id, @training_task.project_id, position + 1, original_project.user_id
|
||||
end
|
||||
@training_task.update_attribute(:status, 1)
|
||||
@training_task.update_attribute(:result, 1)
|
||||
# 创建一条回复提醒
|
||||
content = (position == original_tasks_count) ? "恭喜您,您已经完成了实训项目的所有任务" : "恭喜您,您已经完成了本任务"
|
||||
content = (position == original_tasks_count) ? "恭喜您,您已经完成了实训项目的所有任务" : "恭喜您,您已经完成了本任务,请继续下一任务"
|
||||
add_training_task_journal(content, original_project.user_id)
|
||||
end
|
||||
else
|
||||
|
@ -973,6 +990,7 @@ class ProjectsController < ApplicationController
|
|||
add_training_task_journal(content, original_project.user_id)
|
||||
# 失败的时候可以继续提交
|
||||
@training_task.update_attribute(:status, 0)
|
||||
@training_task.update_attribute(:result, 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -989,7 +1007,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
# 实训开启成功后,发布第一个任务
|
||||
# REDO:失败后提醒用户,及相关处理
|
||||
def publish_training_tasks original_project_id, new_training_project_id, position
|
||||
def publish_training_tasks original_project_id, new_training_project_id, position, user_id
|
||||
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]))
|
||||
|
@ -998,13 +1016,12 @@ class ProjectsController < ApplicationController
|
|||
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_url(new_training_project_id)}
|
||||
end
|
||||
else
|
||||
raise "create task failed"
|
||||
begin
|
||||
training_task.save
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# 复制项目
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<% project = Project.find(project_id) %>
|
||||
<% unless activity.author.nil? %>
|
||||
<div class="container-big mt10" id="user_activity_<%= user_activity_id%>">
|
||||
<div class="pr">
|
||||
|
@ -11,7 +12,7 @@
|
|||
TO
|
||||
<%= link_to activity.project.name.to_s+" | 实训任务", project_training_tasks_path(activity.project), :class => "newsBlue ml15"%>
|
||||
</div>
|
||||
<% if !@project.is_child_training_project? && User.current.logged? && (is_project_manager?(User.current.id, project_id) || activity.author_id == User.current.id) %>
|
||||
<% if !project.is_child_training_project? && User.current.logged? && (is_project_manager?(User.current.id, project_id) || activity.author_id == User.current.id) %>
|
||||
<div class="homepagePostSetting">
|
||||
<ul>
|
||||
<li class="homepagePostSettingIcon">
|
||||
|
@ -46,7 +47,7 @@
|
|||
<div class="mb10" style="font-weight:normal;">
|
||||
<%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
|
||||
</div>
|
||||
<% if @project.is_child_training_project? %>
|
||||
<% if project.is_child_training_project? %>
|
||||
<div id="training_project_task_status_<%= activity.id %>">
|
||||
<%= render :partial => "training_tasks/action_status", :locals => {:activity => activity} %>
|
||||
</div>
|
||||
|
|
|
@ -42,14 +42,16 @@
|
|||
<%= render :partial => 'projects/act_issues', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %>
|
||||
<% when "TrainingTask" %>
|
||||
<% if User.current.admin? || is_project_manager?(User.current.id, @project.id) || is_project_manager?(User.current, @project.try(:forked_from_project_id)) %>
|
||||
<div id="project_show_training_task_<%= @project.id %>">
|
||||
<%= render :partial => 'projects/act_training_tasks', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %>
|
||||
</div>
|
||||
<% end %>
|
||||
<!--message-->
|
||||
<% when "Message" %>
|
||||
<%= render :partial => 'projects/act_messages', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :is_course => 1, :is_board => 0} %>
|
||||
<!--Attachment -->
|
||||
<% when "Attachment" %>
|
||||
<%= render :partial => 'projects/project_attachment', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id } %>
|
||||
<%#= render :partial => 'projects/project_attachment', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id } %>
|
||||
<% when "Commit" %>
|
||||
<%= render :partial => 'projects/project_commit', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :identifier => get_rep_identifier_by_project(@project) } %>
|
||||
<% end %>
|
||||
|
|
|
@ -34,8 +34,9 @@
|
|||
</ul>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
||||
<div id="project_act_show_<%= @project.id %>">
|
||||
<%= render :partial => "project_activities", :locals => {:forge_acts => @events_pages, :page => 0, :type => @type} %>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
autoUrl('project_description_code');
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
$("#training_project_task_status_<%= @training_task.id %>").html('<%= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>');
|
||||
$("#training_task_details").html('<%= escape_javascript( render :partial => 'training_tasks/training_task_details', :locals => {:activity => @training_task, :project_id => @project.id}) %>');
|
||||
//$("#training_project_task_status_<%#= @training_task.id %>").html('<%#= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>');
|
||||
//$("#training_task_details").html('<%#= escape_javascript( render :partial => 'training_tasks/training_task_details', :locals => {:activity => @training_task, :project_id => @project.id}) %>');
|
||||
//$("#project_show_training_task_<%#= @training_task.project_id %>").html('<%#= escape_javascript( render :partial => 'projects/act_training_tasks', :locals => {:activity => @training_task, :user_activity_id => @training_task.id, :project_id => @training_task.project_id}) %>');
|
||||
$("#project_act_show_<%= @project.id %>").html('<%= escape_javascript( render :partial => 'projects/project_activities', :locals => {:forge_acts => @events_pages, :page => 0, :type => @type}) %>');
|
|
@ -1 +1 @@
|
|||
$("#task_action_status_<%= @training_task.id %>").html('<%= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>');
|
||||
alert("test");
|
|
@ -6,11 +6,19 @@
|
|||
<span class="task-display-span alert-blue mt10">当前任务正在后台测评中,稍后将显示您的任务完成情况......</span>
|
||||
<% else %>
|
||||
<% if User.current.member_of?(@project) && @project.is_child_training_project? %>
|
||||
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "task-display-span bBlue mt10", :remote => true %>
|
||||
<div id="training_tasl_commit">
|
||||
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "task-display-span bBlue mt10", :onclick => "training_task_submmit();", :remote => true %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function training_task_submmit(){
|
||||
$("#training_tasl_commit").html("<span class='task-display-span alert-blue mt10'>当前任务正在后台测评中,稍后将显示您的任务完成情况......</span>")
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -32,9 +32,7 @@
|
|||
<%= render :partial => 'task_attachments', :locals => {:training_task => @training_task} %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div id="training_project_task_status_<%= @training_task.id %>">
|
||||
<%= render :partial => "training_tasks/action_status", :locals => {:activity => @training_task} %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
class HomeworkBankMigration < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :homework_commons, :homework_bank_id, :integer
|
||||
add_column :homework_commons, :is_update, :boolean, :default => false
|
||||
|
||||
count =Course.all.count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
Course.page(i).per(30).each do |course|
|
||||
if course.is_delete == 0
|
||||
course.homework_commons.each do |homework|
|
||||
unless homework.user.homework_banks.select("name").to_s.include?(homework.name)
|
||||
homework_bank = HomeworkBank.create(:user_id => homework.user_id, :name => homework.name, :description => homework.description, :homework_type => homework.homework_type,
|
||||
:quotes => 1, :is_public => course.is_public, :applicable_syllabus => course.syllabus.title, :homework_common_id => homework.id, :created_at => homework.created_at)
|
||||
if homework.homework_type == 2 && homework.homework_detail_programing
|
||||
homework_bank.update_attributes(:language => homework.homework_detail_programing.language, :standard_code => homework.homework_detail_programing.standard_code)
|
||||
homework.homework_tests.each do |test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
input: test.input,
|
||||
output: test.output,
|
||||
test_type: true
|
||||
)
|
||||
end
|
||||
homework.homework_samples.each do |test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
input: test.input,
|
||||
output: test.output,
|
||||
test_type: false
|
||||
)
|
||||
end
|
||||
elsif homework.homework_type == 3 && homework.homework_detail_group
|
||||
homework_bank.update_attributes(:min_num => homework.homework_detail_group.min_num, :max_num => homework.homework_detail_group.max_num, :base_on_project => homework.homework_detail_group.base_on_project)
|
||||
end
|
||||
homework.update_column('homework_bank_id', homework_bank.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# add_column :homework_commons, :homework_bank_id, :integer
|
||||
# add_column :homework_commons, :is_update, :boolean, :default => false
|
||||
#
|
||||
# count =Course.all.count / 30 + 2
|
||||
# transaction do
|
||||
# for i in 1 ... count do i
|
||||
# Course.page(i).per(30).each do |course|
|
||||
# if course.is_delete == 0
|
||||
# course.homework_commons.each do |homework|
|
||||
# unless homework.user.homework_banks.select("name").to_s.include?(homework.name)
|
||||
# homework_bank = HomeworkBank.create(:user_id => homework.user_id, :name => homework.name, :description => homework.description, :homework_type => homework.homework_type,
|
||||
# :quotes => 1, :is_public => course.is_public, :applicable_syllabus => course.syllabus.title, :homework_common_id => homework.id, :created_at => homework.created_at)
|
||||
# if homework.homework_type == 2 && homework.homework_detail_programing
|
||||
# homework_bank.update_attributes(:language => homework.homework_detail_programing.language, :standard_code => homework.homework_detail_programing.standard_code)
|
||||
# homework.homework_tests.each do |test|
|
||||
# homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
# input: test.input,
|
||||
# output: test.output,
|
||||
# test_type: true
|
||||
# )
|
||||
# end
|
||||
# homework.homework_samples.each do |test|
|
||||
# homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
# input: test.input,
|
||||
# output: test.output,
|
||||
# test_type: false
|
||||
# )
|
||||
# end
|
||||
# elsif homework.homework_type == 3 && homework.homework_detail_group
|
||||
# homework_bank.update_attributes(:min_num => homework.homework_detail_group.min_num, :max_num => homework.homework_detail_group.max_num, :base_on_project => homework.homework_detail_group.base_on_project)
|
||||
# end
|
||||
# homework.update_column('homework_bank_id', homework_bank.id)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddResultToTrainingTask < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :training_tasks, :result, :integer, :default => 0
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue