Skip to content

Commit

Permalink
成功搞定动态更新页面任务的展示
Browse files Browse the repository at this point in the history
  • Loading branch information
xsir317 committed Nov 22, 2014
1 parent 7f23705 commit 190c4b6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
12 changes: 12 additions & 0 deletions publisher/app/controllers/ProjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public function dopublish()
return Response::json(array("result"=>true,'msg' => '','tasks' => $task_ids));
}

public function queryStatus()
{
$ids = Input::get('sync_svr',array());
array_push($ids, intval(Input::get('upd_prj')));
$tasks = Tasks::whereIn("id",$ids)->get();
$return = array();
foreach ($tasks as $row) {
$return[$row->id] = $row->status;
}
return Response::json($return);
}

public function getSrclog()
{
//TODO 根据用户权限判断
Expand Down
2 changes: 2 additions & 0 deletions publisher/app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
Route::get('projects/publish',array('before' => 'auth', 'uses' => 'ProjectsController@publish'));
Route::get('projects/srclog',array('before' => 'auth', 'uses' => 'ProjectsController@getSrclog'));
Route::post('projects/dopublish',array('before' => 'auth', 'uses' => 'ProjectsController@dopublish'));
Route::post('projects/querystatus',array('before' => 'auth', 'uses' => 'ProjectsController@queryStatus'));

Route::any('servers/add',array('before' => 'auth', 'uses' => 'ServersController@addServers'));
Route::any('servers/edit',array('before' => 'auth', 'uses' => 'ServersController@editServers'));

Expand Down
88 changes: 81 additions & 7 deletions publisher/app/views/projects/publish.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
<tr><th>当前版本</th><td>{{{ $project->current_version }}}</td></tr>
<tr><th>备注</th><td>{{{ $project->comments }}}</td></tr>
<tr><th>操作</th>
<td>
<button class="uk-button" id="version_select">版本选择</button>&nbsp;已经选择版本:<span id="show_selected_version"></span>
<td style="line-height: 30px;">
<button class="uk-button" id="version_select">版本选择</button>
&nbsp;已经选择版本:<span id="show_selected_version">--</span>
&nbsp;更新情况:<span id="show_update_status">--</span>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -93,7 +95,7 @@
thisbtn.attr("disabled","disabled").html("载入中...");
//清理所有已经载入的页
lastlog = '';
version_log_box.html('');
version_log_box.empty();
load_log_data(function(){thisbtn.removeAttr("disabled").html("版本选择");});
});
Expand Down Expand Up @@ -170,14 +172,86 @@
{
//提交
$.post($("#publish_form").attr("action"),$("#publish_form").serialize(),function(_data){
//状态,提示信息
//设定项目update的任务号
//设定每个服务器更新的任务号
//启动轮询
if(!_data.result)
{
alert(_data.msg);
return false;
}
setTimeout(function(){update_task_status(_data.tasks);},3000);
},'json');
}
});
var update_task_status = function(_tasks){
var __tasks = _tasks;
$.post("/projects/querystatus",_tasks,function(_return){
var _done_tasks = new Array;
for(var _key in _return)
{
var _class = '';
switch(_return[_key])
{
case 'created':
continue;
case 'execute':
_class = 'uk-icon-spinner uk-icon-spin';
break;
case 'success':
_class = 'uk-icon-check-circle-o';
_done_tasks.push(parseInt(_key));
break;
case 'failed':
_class = 'uk-icon-times-circle-o';
_done_tasks.push(parseInt(_key));
break;
}
if(typeof(__tasks.upd_prj) != 'undefined' && __tasks.upd_prj == _key)
{
$("#show_update_status").empty().append($("<i>").attr('class', _class));
}
else
{
if(__tasks.sync_svr != 'undefined')
{
for(var __key in __tasks.sync_svr)
{
if(__tasks.sync_svr[__key] == _key)
{
$(".server_"+__key).find("td:eq(4)").empty().append($("<i>").attr('class', _class));
break;
}
}
}
}
}
console.log(_done_tasks);
console.log(__tasks);
if(typeof(__tasks.upd_prj) != 'undefined' && -1 != $.inArray(__tasks.upd_prj, _done_tasks))
{
delete __tasks.upd_prj;
}
if(typeof(__tasks.sync_svr) != 'undefined')
{
for(var __key in __tasks.sync_svr)
{
if( -1 != $.inArray(__tasks.sync_svr[__key], _done_tasks))
{
delete __tasks.sync_svr[__key];
}
}
if($.isEmptyObject(__tasks.sync_svr))
{
delete __tasks.sync_svr;
}
}
if(!$.isEmptyObject(__tasks))
{
console.log(__tasks);
setTimeout(function(){update_task_status(__tasks);},3000);
}
},'json');
}
//查询任务完成情况
</script>
@stop

0 comments on commit 190c4b6

Please sign in to comment.