{% extends "base.html" %}
{% block content %}
<h2 class="sub-header">{{ pipeline.name }}</h2>

<div class='row top-buffer col-md-12'>
<button id="hide_btn" name="button2id" class="btn btn-primary" title="Job details">Toggle job details</button>
<form class="form-horizontal" style="display:none;" method='POST' action='{{ url_for('pipeline', pipeline_id=pipeline.id) }}'>
<fieldset>

<legend>Job details</legend>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Parent ID</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.parent_id }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Name</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.name }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Description</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.description }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">DRMAA ID</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.drmaa_id }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Status</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.status }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

<!-- Textarea -->
<div class="form-group">
  <label class="col-sm-1 control-label" for="textarea">Job command</label>
  <div class="col-sm-7">                     
    <textarea class="form-control" rows="10" id="textarea" name="job_command">{{ pipeline.job_command }}</textarea>
  </div>
</div>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Error</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.error }}" class="form-control input-md" readonly="readonly">
  </div>
</div>


<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Is unique</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.is_unique }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Unique key</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.unique_key }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	
 
<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Is group job</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.is_group_job }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	
	
 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Max parallel nr</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.max_parallel_nr }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	

 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Max nr of restarts</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.max_nr_of_restarts }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	

 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Current run</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.current_run }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	

 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Start date</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.start_date }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	
	
 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">End date</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.end_date }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	 

 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Delete time</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.delete_time }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	 
	
<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Who create</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.who_create }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Who update</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.who_update }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	

<div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Create date</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.create_date }}" class="form-control input-md" readonly="readonly">
  </div>
</div>
	
 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Executer</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.executer }}" class="form-control input-md" readonly="readonly">
  </div>
</div>

 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Start submit date</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.start_submit_date }}" class="form-control input-md" readonly="readonly">
  </div>
</div>	
 
 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">End submit date</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.end_submit_date }}" class="form-control input-md" readonly="readonly">
  </div>
</div>
	
 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">Start run date</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.start_run_date }}" class="form-control input-md" readonly="readonly">
  </div>
</div> 

 <div class="form-group">
  <label class="col-sm-1 control-label" for="textinput">End run date</label>  
  <div class="col-sm-7">
  <input id="textinput" name="textinput" type="text" placeholder="{{ pipeline.end_run_date }}" class="form-control input-md" readonly="readonly">
  </div>
</div> 	
 

<div class="form-group">
  <label class="col-sm-1 control-label" for="button1id">Actions</label>
  <div class="col-sm-8">
    <button id="button_save" name="button_save" class="btn btn-primary" title="Save" type="submit">Save</button>
    <a href="{{ url_for('restart', pipeline_id=pipeline.id, stay_on_page=1)}}" onclick="return confirm('Do you really want ro restart job {{ pipeline.id }}?')"><button id="button1id" name="button1id" class="btn btn-primary" title="Restart job">Restart</button></a>
    <a href="{{ url_for('restart_recursive', pipeline_id=pipeline.id, stay_on_page=1)}}" onclick="return confirm('Do you really want to recursively restart job {{ pipeline.id }}?')"><button id="button2id" name="button2id" class="btn btn-primary" title="Restart job recursively">Restart Recursive</button></a>
    <a href="{{ url_for('cancel', pipeline_id=pipeline.id, stay_on_page=1)}}" onclick="return confirm('Do you really want to cancel job {{ pipeline.id }}?')"><button id="button2id" name="button2id" class="btn btn-danger" title="Cancel job">Cancel</button></a>
			<a href="{{ url_for('delete', pipeline_id=pipeline.id, stay_on_page=1)}}" onclick="return confirm('Do you really want to finish job {{ pipeline.id }}?')"><button id="button2id" name="button2id" class="btn btn-danger" title="Finish job">Finish</button></a>
  </div>
</div>

</fieldset>
</form>
</div>

{% if not is_group_job %}
<div id="log_files_row" class="row top-buffer col-md-12">
	<button id="hide_log_btn" name="button2id" class="btn btn-danger" title="Log file">Toggle LOG files</button>
	<div id="name" class="row top-buffer">
		<div id="log_files" class="col-sm-12" style="display:none">
			<div id="out_row" class="row top_buffer col-sm-12">
				<h4>STDOUT file:</h4>
				<div id="out_file" class="col-sm-6" style="background-color:#87CEFA; border-radius: 10px;">
				{{ out_log | safe}}
				</div>
			</div>
			<div id="error_row" class="row top-buffer col-sm-12">
				<h4>STDERR file:</h4>
				<div id="error_file" class="col-sm-6" style="background-color:#FFB6C1; border-radius: 10px;">
				{{ error_log | safe}}
				</div>
			</div>
		</div>
	</div>
</div>
{% endif %}


{% if show_progress %}
<div id="name" class="row row_buffer">
	<!-- <span>{{ waiting }}, {{ running }}, {{ finished }}</span> -->
</div>
<h3 class="sub-header">Progress of this group</h3>
<div id="progress_bar" class="col-sm-6 row top_buffer">
	<div class="progress">
		<div class="progress-bar progress-bar-success" style="width: {{ finished }}%">
			<span>{{ num_finished }}/{{ num_total }}  ({{ finished }}%)  Finished </span>
		</div>
		<div class="progress-bar progress-bar-warning" style="width: {{ running }}%">
		</div>
		<div class="progress-bar progress-bar-danger" style="width: {{ failed }}%">
		</div>
		<div class="progress-bar progress-bar-info" style="width: {{ waiting }}%">
		</div>
	</div>	
</div>
{% endif %}

	
<div class="col-md-12 table-responsive">
<h4>Jobs in this group</h4>
<table id="pipeline_table" data-toggle="table" class="table table-striped" data-pagination="true" data-page-list="[50, 100, 1000, 2000]" data-smart-display=True data-page-size=50 data-search="true">
  <thead>
    <tr>
		<th data-sortable="true">ID</th>
		<th data-sortable="true">Name</th>
		<th>Description</th>
		<th data-sortable="true">Create date</th>
		<th>Executer</th>
		<th data-sortable="true">Status</th>
		<th>Action</th>
    </tr>
  </thead>
  <tbody>
  {% for member in members %}
    <tr>
		<td>{{ member.id }}.</td>
		<td><a href="{{ url_for('pipeline', pipeline_id=member.id)  }}">{{ member.name }}</a></td>
		<td>{{ member.description }}</td>
		<td>{{ member.create_date }}</td>
		<td>{{ member.executer }}</td>
		<td>
		{% if member.status == "FINISHED" %}
			<button class="btn btn-success btn-block">{{ member.status }}</button>
		{% elif member.status == "RUNNING" %}
			<button class="btn btn-warning btn-block">{{ member.status }}</button>
		{% elif member.status == "FAILED" %}
			<button class="btn btn-danger btn-block">{{ member.status }}</button>
		{% elif member.status == "SUSPENDED" %}
			<button class="btn btn-default btn-block">{{ member.status }}</button>
		{% elif member.status == "IDLE" %}
			<button class="btn btn-info btn-block">{{ member.status }}</button>
		{% else %}
		 <button class="btn btn-default btn-block">{{ member.status }}</button>
		{% endif %}
		</td>
		<td>
		<a href="{{ url_for('restart', pipeline_id=member.id, stay_on_page=pipeline.id)}}" onclick="return confirm('Do you really want ro restart job {{ member.id }}?')"><span class="glyphicon glyphicon-repeat" aria-hidden="false" data-toggle="tooltip" data-placement="top"  title='RESTART. Sets the job status to "IDLE" and stops it if it is running.'></span></a>
		<a href="{{ url_for('restart_recursive', pipeline_id=member.id, stay_on_page=pipeline.id)}}" onclick="return confirm('Do you really want to recursively restart job {{ member.id }}?')"><span class="glyphicon glyphicon-refresh" aria-hidden="true" data-toggle="tooltip" data-placement="top" title='RESTART RECURSIVE. Sets the job status to "IDLE" and stops it if it is running. Does the same to all jobs that depend directly or indirectly on this job'></span></a>
		<a href="{{ url_for('cancel', pipeline_id=member.id, stay_on_page=pipeline.id)}}" onclick="return confirm('Do you really want to cancel job {{ member.id }}?')"><span class="glyphicon glyphicon-remove" aria-hidden="true" data-toggle="tooltip" data-placement="top" title='CANCEL. Sets the status of this job to "CANCELLED" and stops the job if it is running'></span></a>
		<a href="{{ url_for('finish', pipeline_id=member.id, stay_on_page=pipeline.id)}}" onclick="return confirm('Do you really want to finish job {{ member.id }}?')"><span class="glyphicon glyphicon-stop" aria-hidden="true" data-toggle="tooltip" data-placement="top" title='FINISH. Sets the status of this job to "FINISHED". If the job is running, it does nothing.'></span></a>
		<a href="{{ url_for('delete', pipeline_id=member.id, stay_on_page=pipeline.id)}}" onclick="return confirm('Do you really want to delete job {{ member.id }}?')"><span class="glyphicon glyphicon-trash" aria-hidden="true" data-toggle="tooltip" data-placement="top"  title="DELETE. Deletes the job from the database."></span></a>
		</td>
    </tr>
    {% endfor %}
  </tbody>
</table>
</div>

{% endblock %}
