#*
 * Copyright 2012 LinkedIn Corp.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
*#

<!DOCTYPE html> 
<html>
	<head lang="en">

#parse("azkaban/webapp/servlet/velocity/style2.vm")
#parse("azkaban/webapp/servlet/velocity/javascript.vm")

		<script type="text/javascript" src="${context}/js/azkaban.nav.js"></script>
		<script type="text/javascript" src="${context}/js/d3.v3.min.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban.date.utils.js"></script>
		<script type="text/javascript" src="${context}/js/azkaban.jobhistory.view.js"></script>
		<script type="text/javascript">
			var contextURL = "${context}";
			var currentTime = ${currentTime};
			var timezone = "${timezone}";
			var errorMessage = null;
			var successMessage = null;
			
			var projectId = "$projectId";
			var projectName = "$projectName";
			var jobName = "$jobid";
			var dataSeries = $dataSeries;
		</script>
		<style>
			.axis path,
			.axis line {
			  fill: none;
			  stroke: #000;
			  shape-rendering: crispEdges;
			}
			
			.x.axis path {
			  display: none;
			}
			
			.line {
			  fill: none;
			  stroke: steelblue;
			  stroke-width: 1.5px;
			}
		</style>
	</head>
	<body>

#set ($current_page="all")
#parse ("azkaban/webapp/servlet/velocity/nav2.vm")

		<div class="container">

#if ($errorMsg)
			<div class="panel panel-danger">
				<div class="panel-heading">Error</div>
				<div class="panel-body">
					$errorMsg
				</div>
			</div>
#else
	#if ($error_message != "null")
			<div class="alert alert-danger">$error_message</div>
	#elseif ($success_message != "null")
			<div class="alert alert-success">$success_message</div>
	#end

	## Alert message

			<div class="alert alert-dismissable alert-messaging" id="messaging">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				<p id="messaging-message"></p>
			</div>
	
	## Page header

			<div class="page-header">
				<h1>
					<a href="${context}/manager?project=${project.name}">$project.name</a> / 
					<a href="${context}/manager?project=${project.name}&flow=${flowid}">$flowid</a>
				</h1>
			</div>

			<div class="row">
				<div class="col-lg-8">
	
	## Breadcrumb

					<ol class="breadcrumb">
						<li><a href="${context}/manager?project=${project.name}"><strong>Project</strong> $project.name</a></li>
						<li><a href="${context}/manager?project=${project.name}&flow=${flowid}"><strong>Flow</strong> $flowid</a></li>
						<li><a href="${context}/manager?project=${project.name}&flow=${flowid}&job=${jobid}"><strong>Job</strong> $jobid</a></li>
					</ol>
			
	#set ($job_page="history")
	#parse ("azkaban/webapp/servlet/velocity/jobnav.vm")
				
					<div class="panel panel-default">
						<div class="panel-heading">Job History</div>
						<div class="panel-body">
							<div id="timeGraph"></div>
						</div>

						<table id="all-jobs" class="table table-striped table-bordered">
							<thead>
								<tr>
									<th class="execid">Execution Id</th>
									<th class="jobid">Job</th>
									<th class="flowid">Flow</th>
									<th class="date">Start Time</th>
									<th class="date">End Time</th>
									<th class="elapse">Elapse</th>		
									<th class="status">Status</th>
									<th class="logs">Logs</th>
								</tr>
							</thead>
							<tbody>
	#if ($history)
		#foreach ($job in $history)
								<tr>
									<td class="first">
			#if ($job.attempt > 0)
										<a href="${context}/executor?execid=${job.execId}">${job.execId}.${job.attempt}</a>
			#else
										<a href="${context}/executor?execid=${job.execId}">${job.execId}</a>
			#end
									</td>
									<td>
										<a href="${context}/manager?project=${projectName}&flow=${job.flowId}&job=${jobid}">${jobid}</a>
									</td>
									<td>
										<a href="${context}/manager?project=${projectName}&flow=${job.flowId}">${job.flowId}</a>
									</td>
									<td>$utils.formatDate(${job.startTime})</td>
									<td>$utils.formatDate(${job.endTime})</td>
									<td>$utils.formatDuration(${job.startTime}, ${job.endTime})</td>
									<td>
										<div class="status ${job.status}">
											$utils.formatStatus(${job.status})
										</div>
									</td>
									<td class="logLink">
										<a href="${context}/executor?execid=${job.execId}&job=${jobid}&attempt=${job.attempt}">Logs</a>
									</td>
								</tr>
		#end
	#else
								<tr>
									<td colspan="8">No history</td>
								</tr>
	#end
							</tbody>
						</table>
					</div>

					<ul class="pagination" id="pageSelection">
						<li id="previous" class="first"><a href="${context}/manager?project=${projectId}&job=${jobid}&history&page=${previous.page}&size=${previous.size}"><span class="arrow">&larr;</span>Previous</a></li>
						<li id="page1" #if($page1.selected) class="selected" #elseif ($page1.disabled) class="disabled" #end><a href="${context}/manager?project=${projectName}&job=${jobid}&history&page=${page1.nextPage}&size=${page1.size}">${page1.page}</a></li>
						<li id="page2" #if($page2.selected) class="selected" #elseif ($page2.disabled) class="disabled" #end><a href="${context}/manager?project=${projectName}&job=${jobid}&history&page=${page2.nextPage}&size=${page2.size}">${page2.page}</a></li>
						<li id="page3" #if($page3.selected) class="selected" #elseif ($page3.disabled) class="disabled" #end><a href="${context}/manager?project=${projectName}&job=${jobid}&history&page=${page3.nextPage}&size=${page3.size}">${page3.page}</a></li>
						<li id="page4" #if($page4.selected) class="selected" #elseif ($page4.disabled) class="disabled" #end><a href="${context}/manager?project=${projectName}&job=${jobid}&history&page=${page4.nextPage}&size=${page4.size}">${page4.page}</a></li>
						<li id="page5" #if($page5.selected) class="selected" #elseif ($page5.disabled) class="disabled" #end><a href="${context}/manager?project=${projectName}&job=${jobid}&history&page=${page5.nextPage}&size=${page5.size}">${page5.page}</a></li>
						<li id="next"><a href="${context}/manager?project=${projectName}&job=${jobid}&history&page=${next.page}&size=${next.size}">Next<span class="arrow">&rarr;</span></a></li>
					</ul>

				</div><!-- /col-lg-8 -->
				<div class="col-lg-4">
	#parse ("azkaban/webapp/servlet/velocity/jobsidebar.vm")
				</div><!-- /col-lg-4 -->
			</div><!-- /row -->

#end
#parse ("azkaban/webapp/servlet/velocity/footer.vm")
		</div>
	</body>
</html>
