{% extends 'ftp_deploy/base.html' %}

{% block content %}

    
    <div class="row">
        <div class="col-sm-6"><h3>{{service.repo_name}}</h3></div>
        <div class="col-sm-6">
            <div class="pull-right">
            	<a href="{% url 'ftpdeploy_dashboard' %}" class="btn btn-default">Dashboard</a>
            	<a href="{% url 'ftpdeploy_service_edit' service.pk %}" class="btn btn-primary"><i class="fa fa-cog"></i> </a>
                <a href="{% url 'ftpdeploy_service_delete' service.pk %}" class="btn btn-danger"><i class="fa fa-minus"></i></a>
            </div>
        </div>
    </div>
    <span class="clearfix"></span>

    {{request.POST.submit}}
    <hr>
    <div class="row">
        <div class="col-sm-8">
			<h3 style="display: inline;">Statistics</h3>
            <ul class="list-unstyled">
                <li>
                    <small>
                    POST Hook: 
                    {% if service.repo_hook %}
                        <i class="fa fa-check c-ok"></i>
                    {% else %}
                        <b>{{service.hook_url}}</b> 
                        <a href="{% url 'ftpdeploy_bb_api' service.pk %}" id="add_hook"><i class="fa fa-times c-remove"></i> Add hook</a> 
                    {% endif %}
                    </small>
                </li>    
                <li><small>Branch: <b>{{service.repo_branch}}</b></small></li>
                <li><small>Number of Deploys: <span class="label label-success"><b>{{service.deploys}}</b></span> </small></li>
                {% if service.fail_deploys %}
                    <li><small>Fail Deploys: <span class="label label-danger"><b>{{service.fail_deploys}}</b></span></small></li>
                {% endif %}
                {% if service.skipped_deploys %}
                    <li><small>Skipped Deploys: <span class="label label-warning"><b>{{service.skipped_deploys}}</b></span></small></li>
                {% endif %}
                <li><small>Last Deploy User: <b>{{service.latest_log_user}}</b></small></li>
                <li><small>Last Deploy Date: <b>{{service.latest_log_date}}</b></small></li>
            </ul>
            
        </div>
        <div class="col-sm-4">
        	<h2 style="display: inline;">Status</h2>
    			{% if service.status %}
    			    <a href="{% url 'ftpdeploy_service_status' service.pk %}" id="service-manage-status"><i class="fa fa-check c-ok"></i></a>
				    <p><small>Last Check: {{service.updated}}</small></p>
    			{% else %}
    			    <a href="{% url 'ftpdeploy_service_status' service.pk %}" id="service-manage-status"><i class="fa fa-times c-remove"></i></a>
    			    <p><small>{{service.status_message|safe}}</small></p>
    			{% endif %}
        	<span class="clearfix"></span>
        	
        </div>
    </div>
	<br>
    {% if fail_logs %}
        <div class="row">
        	<div class="col-sm-12">
        		<div id="fail-deploys">
                    <h3>Fail Deploys</h3>
                    <table class="table table-hover">
                        <thead>
                          <tr>
                            <th>Date</th>
                            <th>Commits</th>
                            <th>User</th>
                            <th>Restorable</th>
                            <th>Status</th>
                            <th>
                                <a href="{% url 'ftpdeploy_service_restore' service.pk %}" class="btn btn-success btn-xs pull-right" id="restore-init">Restore Deploys</a>
                            </th>
                          </tr>
                        </thead>
                        <tbody id="log-list">
                                {% for log in fail_logs %}
                                <tr>
                                    <td>{{log.created}}</td>
                                    <td>
                                        {% for commits in log.commits_info %}
                                            <small>'{{commits.0}}' ({{commits.1}})</small> <br>
                                            <small>{{commits.2}}</small> <br>
                                        {% endfor %}
                                    </td>
                                    <td>{{log.user}}</td>
                                    <td>
                                        {% if log.payload %}
                                            <i class="fa fa-check c-ok"></i>
                                        {% else %}
                                            <i class="fa fa-times c-remove"></i>
                                        {% endif %}
                                    </td>
                                    <td>
                                        <i class="fa fa-times c-remove"  data-toggle="tooltip" data-placement="left" title="{{log.status_message}}"></i>
                                    </td>
                                    <td>
                                        <a href="#" class="btn btn-warning btn-xs pull-right log-skip">Skip</a>
                                        <a href="{% url 'ftpdeploy_log_skip' log.pk %}#" class="btn btn-warning btn-xs pull-right log-skip-confirm" style="display: none;">Confirm</a>
                                    </td>
                                </tr>
                                {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>

        </div>
        <div class="row">
            <div class="col-sm-12">
                <div id="fail-restore-progress" style="display: none;">
                    <h5>Restoring...</h5>
                    <div class="progress progress-striped active">
                      <div class="progress-bar"  role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                        <span class="sr-only">45% Complete</span>
                      </div>
                    </div>
                </div>
            </div>
        </div>
        <hr><br>
    {% endif %}
    <div class="row">
    	<div class="col-sm-12">
    		<h3>Recent Deploys</h3>
    		<table class="table table-hover">
                <thead>
                  <tr>
                    <th>Service</th>
                    <th>Branch</th>
                    <th>Date</th>
                    <th>Commits</th>
                    <th>User</th>
                    <th>Status</th>
                  </tr>
                </thead>
                <tbody id="log-list">
                    {% include "ftp_deploy/log/list.html" with logs=recent_logs %}
                </tbody>
            </table>
    	</div>
    </div>

{% endblock content %}

