<div class="panel panel-default">
    <div class="panel-body">
        <ul class="nav">
            <h5><strong><i class="glyphicon glyphicon-hand-down"></i> 以下为当前正在执行的项目进度</strong></h5>
            <hr>
        </ul>
    </div>
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th class="w10p">项目名</th>
                <th>进度</th>
                <th class="w13p">开始时间</th>
                <th class="w20p">操作</th>
            </tr>
            </thead>
            <tbody>
           		
            </tbody>
        </table>
    </div>
    <div class="panel-footer">
    </div>
</div>
<script type="text/javascript">
	
	var taskId = ""
	var projectId = ""
	var task = {
		getTask: function (){
			$.ajax({
		        type: "POST",
		        cache: false,
		        url: "/task/getExcutingTask",
		        data:"task_id=" + taskId + "&project_id=" + projectId,
		        dataType: 'json',
		        success: function (response) {
		        	projectId = ""
		        	taskId = ""
		            if(response.code == 0) {
						Common.errorBox("#failedBox", response.message)
					} else {
						var html = ""
						var name = ""
						var isSuccess = ""
						var percentage = ""
						var finish
						var doing

						for (var j in response.data.project) {
							projectId += "," + response.data.project[j]['project_id'];
						}
						projectId = projectId.substring(1)
						
						for (var i in response.data.task) {
							taskId += "," + response.data.task[i]['task_id']
							name = response.data.project[response.data.task[i]['project_id']]['name']
							if (response.data.result[response.data.task[i]['task_id']]['result'] == "1") {
								isSuccess = "progress-bar-success"
							} else {
								isSuccess = "progress-bar-danger"
							}

							finish = parseInt(response.data.result[response.data.task[i]['task_id']]['finish']);
							doing = parseInt(response.data.result[response.data.task[i]['task_id']]['doing']);
							percentage = Math.ceil(finish/(finish+doing)*100)
							 
							html += '<tr>\
						                <td class="center">' + name + '</td>\
						                <td>\
						                    <div class="progress" style="margin-bottom: 0; height: 14px">\
						                        <div class="progress-bar ' + isSuccess + ' progress-bar-striped active" role="progressbar"\
						                             aria-valuenow="45"\
						                             aria-valuemin="0"\
						                             aria-valuemax="100"\
						                             style="min-width: 2em; width: ' + percentage + '%">\
						                            <div style="font-size:10px;line-height:14px;">' + percentage + '%</div>\
						                        </div>\
						                    </div>\
						                </td>\
						                <td class="center">\
						                    <label class="text-info">' + response.data.task[i]['create_time'] + '</label>\
						                </td>\
						                <td class="center">\
						                    <a name="info" class="glyphicon glyphicon-align-justify" href="/publish/taskLog?task_id=' + response.data.task[i]['task_id'] + '">节点进度</a>\
						                </td>\
						            </tr>'
						}
						taskId = taskId.substring(1)
						$('tbody').html(html)
						setTimeout(function(){
							task.getTask()
						}, 1000)
						
					}
		        },
				error: function(){
					Common.errorBox("#failedBox", "ajax请求出错")
				},
		    });
		}
	}
	
	task.getTask()
</script>