ajax刷新

This commit is contained in:
huang 2017-02-28 17:22:00 +08:00
parent 5740204301
commit be1b507354
5 changed files with 32 additions and 7 deletions

View File

@ -901,7 +901,20 @@ class ProjectsController < ApplicationController
begin begin
res = uri_exec uri, params res = uri_exec uri, params
# 任务开启成功后创建一条留言提示,并发布 # 任务开启成功后创建一条留言提示,并发布
@training_task.update_attribute(:status, 2) # @training_task.update_attribute(:status, 2)
# 轮询获取
for i in 0..10 do
sleep(10)
status = TrainingTask.where(:id => @training_task.id).first.try(:status)
if (status == 1 || status == 0)
@training_task.status = status
break
if i == 120
break
end
end
end
return return
rescue Exception => e rescue Exception => e
puts e puts e
@ -948,7 +961,7 @@ class ProjectsController < ApplicationController
def training_task_status def training_task_status
status = params[:status].to_i status = params[:status].to_i
task_id = params[:taskId] task_id = params[:taskId]
message = Base64.decode64(params[:msg]) message = Base64.decode64(params[:msg]) unless params[:msg].blank?
begin begin
@training_task = TrainingTask.find(task_id) @training_task = TrainingTask.find(task_id)
# 如果已经执行成功过,则不重复执行 # 如果已经执行成功过,则不重复执行

View File

@ -1,3 +1,4 @@
<% project = Project.find(project_id) %>
<% unless activity.author.nil? %> <% unless activity.author.nil? %>
<div class="container-big mt10" id="user_activity_<%= user_activity_id%>"> <div class="container-big mt10" id="user_activity_<%= user_activity_id%>">
<div class="pr"> <div class="pr">
@ -11,7 +12,7 @@
TO TO
<%= link_to activity.project.name.to_s+" | 实训任务", project_training_tasks_path(activity.project), :class => "newsBlue ml15"%> <%= link_to activity.project.name.to_s+" | 实训任务", project_training_tasks_path(activity.project), :class => "newsBlue ml15"%>
</div> </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"> <div class="homepagePostSetting">
<ul> <ul>
<li class="homepagePostSettingIcon"> <li class="homepagePostSettingIcon">
@ -46,7 +47,7 @@
<div class="mb10" style="font-weight:normal;"> <div class="mb10" style="font-weight:normal;">
<%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
</div> </div>
<% if @project.is_child_training_project? %> <% if project.is_child_training_project? %>
<div id="training_project_task_status_<%= activity.id %>"> <div id="training_project_task_status_<%= activity.id %>">
<%= render :partial => "training_tasks/action_status", :locals => {:activity => activity} %> <%= render :partial => "training_tasks/action_status", :locals => {:activity => activity} %>
</div> </div>

View File

@ -42,7 +42,9 @@
<%= render :partial => 'projects/act_issues', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %> <%= render :partial => 'projects/act_issues', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %>
<% when "TrainingTask" %> <% 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)) %> <% 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} %> <%= render :partial => 'projects/act_training_tasks', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %>
</div>
<% end %> <% end %>
<!--message--> <!--message-->
<% when "Message" %> <% when "Message" %>

View File

@ -1,2 +1,3 @@
$("#training_project_task_status_<%= @training_task.id %>").html('<%= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>'); $("#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_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}) %>');

View File

@ -6,11 +6,19 @@
<span class="task-display-span alert-blue mt10">当前任务正在后台测评中,稍后将显示您的任务完成情况......</span> <span class="task-display-span alert-blue mt10">当前任务正在后台测评中,稍后将显示您的任务完成情况......</span>
<% else %> <% else %>
<% if User.current.member_of?(@project) && @project.is_child_training_project? %> <% 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 %>
<% end %> <% end %>
</div> </div>
<script>
function training_task_submmit(){
$("#training_tasl_commit").html("<span class='task-display-span alert-blue mt10'>当前任务正在后台测评中,稍后将显示您的任务完成情况......</span>")
}
</script>