<div>
	<br><br><br>
	<div class='ui container'>
	 	<h1>Bull Ops: 
			<div class="ui inline dropdown">
				<div class="text">
					<%=req.params.queue?req.params.queue:'queue'%>
				</div>
				<i class="dropdown icon"></i>
				<div class="menu">
					<a class="item" href='/bull/queue'>
						queue
					</a>
					<a class="item" href='/bull/crawler'>
						crawler
					</a>
				</div>
			</div>
		</h1>
		<div class="ui pointing secondary menu">
	 		<a class="item" href='/bull/<%=req.params.queue%>'>Overview</a>
	 		<a class="item" href='/bull/<%=req.params.queue%>/active'>Active</a>
	 		<a class="item" href='/bull/<%=req.params.queue%>/inactive'>Inactive</a>
	 		<a class="item" href='/bull/<%=req.params.queue%>/delayed'>Delayed</a>
	 		<a class="item" href='/bull/<%=req.params.queue%>/failed'>Failed</a>
	 		<a class="item" href='/bull/<%=req.params.queue%>/complete'>Complete</a>
	 	</div>
		<h3>Items in queue - <%=state%></h3>
		<table class="ui celled structured table" style="display: block;overflow-x:scroll;">
			<thead>
				<tr>
					<th>ID</th>
					<th class="single line">Name</th>
					<th class="single line">Title</th>
					<th>Progress</th>
					<!-- <th>Currency</th> -->
					<!-- <th>State</th> -->
					<th>Timestamp</th>
					<th>Processed On</th>
					<th>Finished On</th>
					<th>Retry</th>
					<th>Delete</th>
					<th>Recreate</th>
					
				</tr>
			</thead>
			<tbody>
				<%jobs.forEach(function(job){%>
					<tr>
						<td><a href="" class='job_id' data-id='<%=job.id%>'><%=job.id%></a></td>

						<td>
							<%if(job.name){%>
							<%-job.name.substring(0,150)%>
							<%}%>
						</td>
						<td>
							<%if(job.data.title){%>
							<%-job.data.title.substring(0,150)%>
							<%}%>
						</td>
						<td><%=job.progress%></td>
						<!-- <td><%=job.state%></td> -->
						<!-- <td></td> -->
						<td><%=job.timestamp%></td>
						<td><%=job.processedOn%></td>
						<td><%=job.finishedOn%></td>
						<td class="center aligned">
							<button class="<%-state!='failed'?'disabled':''%> circular green ui icon button retry_job" data-id='<%=job.id%>'>
								<i class="icon refresh"></i>
							</button>
						</td>
						<td class="center aligned">
							<button class="circular red ui icon button delete_job" data-id='<%=job.id%>'>
								<i class="icon delete"></i>
							</button>
						</td>
						<td class="center aligned">
							<a class="circular green ui icon button" href='/bull/<%=req.params.queue%>/job/<%=job.id%>/recreate'>
								<i class="icon plus"></i>
							</a>
						</td>
						
					</tr>
					<tr id='json_<%=job.id%>' style='display: none;'>
						<td colspan='8'>
							 <pre><%=JSON.stringify(job,null,4)%> </pre>
						</td>
					</tr>
				<%})%>
			</tbody>
		</table>
			
			
	</div>
	<br><br><br>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		$('.job_id').click(function(e){
			e.preventDefault();
			var job_id=$(this).attr('data-id');
			$('#json_'+job_id).toggle();
		});
		$('.retry_job').click(function(){
			var button = this;
			$(button).addClass('loading');
			var job_id=$(this).attr('data-id');
			// var job_id='';
			$.post("/bull/<%=req.params.queue%>/retry", {job_id: job_id}, function(result,status){
				console.log('result = '+result);
				console.log('status = '+status);// this runs only on sucess
				if(status=='success'){
					$(button).removeClass('loading');
					$(button).addClass('disabled');
				}
			});
			
		})
		$('.delete_job').click(function(){
			var button = this;
			$(button).addClass('loading');
			var job_id=$(this).attr('data-id');
			// var job_id='';
			var r = confirm("Delete this permanently ?");
			if (r == true) {
				$.post("/bull/<%=req.params.queue%>/delete", {job_id: job_id}, function(result,status){
				console.log('result = '+result);
				console.log('status = '+status);// this runs only on sucess
				if(status=='success'){
					$(button).removeClass('loading');
					$(button).addClass('disabled');
				}
			});
			} else {
				$(button).removeClass('loading');
			}
			
		})
		var path = window.location.pathname;
		$('a[href="'+path+'"]').addClass('active');
		$('.dropdown').dropdown();
	});
</script>