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

{% set page_title = 'Build ' + spkg.name + ' ' + job.version + ' on ' + job.architecture %}

{% block body_header %}
<h3 class="title is-3">Build {{spkg.name}} {{job.version}} on {{job.architecture}}</h3>
{% endblock %}

{% block breadcrumbs %}
<nav class="pt-3" aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="{{ url_for('portal.repo_index', repo_name=spkg.repo.name) }}">Packages in {{spkg.repo.name}}</a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ url_for('packages.src_package_details', repo_name=spkg.repo.name, suite_name=suite_name, name=spkg.name) }}">{{spkg.name}}</a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ url_for('packages.builds_list', name=spkg.name, page=1) }}">Builds</a>
        </li>
        <li class="breadcrumb-item">
            {{suite_name}}
        </li>
        <li class="breadcrumb-item active" aria-current="page">
            {{spkg.name}} {{job.version}} on {{job.architecture}}
        </li>
    </ol>
</nav>
{% endblock %}

{% block body %}

<b>ID:</b> {{job.uuid}}<br/>
<br/>
<b>Created:</b> {{humanized_timediff(job.time_created)}}<br/>
<b>Assigned:</b> {{humanized_timediff(job.time_assigned)}}<br/>
{% if job.time_finished %}<b>Finished:</b> {{humanized_timediff(job.time_finished)}}<br/>{% endif %}
{% if worker %}
<b>Worker:</b> {{worker.name}}<br/>
{% endif %}

<b>Status:</b>
{% if job.status == JobStatus.WAITING %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <i class="fa fa-hourglass-start" aria-hidden="true"></i>
  </span> Waiting
{% elif job.status == JobStatus.DEPWAIT %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <i class="fa fa-puzzle-piece" aria-hidden="true"></i>
  </span> Waiting for dependency
{% elif job.status == JobStatus.SCHEDULED %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <i class="fa fa-circle-notch fa-spin" aria-hidden="true"></i>
  </span> Scheduled
{% elif job.status == JobStatus.RUNNING %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <i class="fa fa-cog fa-spin" aria-hidden="true"></i>
  </span> Running
{% elif job.status == JobStatus.DONE %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <i class="fa fa-check" aria-hidden="true"></i>
  </span> Done
{% elif job.status == JobStatus.STARVING %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <i class="fa fa-clock-o" aria-hidden="true"></i>
  </span> Starving
{% elif job.status == JobStatus.TERMINATED %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <i class="fa fa-skull" aria-hidden="true"></i>
  </span> Terminated
{% endif %}
<br/>

{% if job.result != JobResult.UNKNOWN %}
<br/>
<h3 class="subtitle is-3">Result</h3>
<p>
{% if job.result == JobResult.SUCCESS_PENDING %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <font class="fa fa-check-circle" aria-hidden="true" color="green"></font>
    <i class="fa fa-clock" aria-hidden="true"></i>
  </span> Successful (pending)
{% elif job.result == JobResult.FAILURE_PENDING %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <font class="fa fa-times-circle" aria-hidden="true" color="red"></font>
    <i class="fa fa-clock" aria-hidden="true"></i>
  </span> Failed (pending)
{% elif job.result == JobResult.SUCCESS %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <font class="fa fa-check-circle" aria-hidden="true" color="green"></font>
  </span> Success
{% elif job.result == JobResult.FAILURE %}
  <span style="font-size: 20px; line-height: 1.5em;">
    <font class="fa fa-times-circle" aria-hidden="true" color="red"></font>
  </span> Failed
{% elif job.result == JobResult.FAILURE_DEPENDENCY %}
  <span style="font-size: 20px; line-height: 1.5em;">
      <font class="fa fa-diagram-project" aria-hidden="true" color="purple"></font>
  </span> Dependency issue
{% endif %}
</p>
{% endif %}

<br/>
<h3 class="subtitle is-3 mb-2">Details</h3>
<p>
<b>Repository:</b> {{spkg.repo.name}}<br/>
<b>Suite:</b> {{suite_name}}<br/>
<b>Maintainer:</b> {{spkg.maintainer.replace('@', '[at]')}}<br/>
{% if spkg.uploaders %}<b>Uploaders:</b> {{'; '.join(spkg.uploaders).replace('@', '[at]')}}<br/>{% endif %}
<b>Version:</b> {{job.version}}<br/>
<b>Architecture:</b> <span class="badge badge-pill badge-secondary"><i class="fas fa-cog"></i> {{job.architecture}}</span><br/>
</p>

{% if dep_issues %}
<h3 class="subtitle is-3 mt-4 mb-1">Dependency Issues</h3>

<div class="column is-6">
{% for issue in dep_issues %}
  {% if issue.missing %}
    <div class="card">
        <header class="card-header">
            <p class="card-header-title">
            Missing dependencies ({{issue.package_name}} {{issue.package_version}})
            </p>
            <div class="card-header-icon">
            <span class="icon">
                <i class="fas fa-question" aria-hidden="true"></i>
            </span>
            </div>
        </header>
        <div class="card-content py-3">
            <div class="content">
                <ul>
                    {% for m in issue.missing %}
                    <li>
                    <h5 class="subtitle mb-1">
                      {{ link_for_bin_package_id(spkg.repo.name, suite_name, m.unsat_dependency)|safe }}
                      <small><i class="fas fa-microchip"></i> {{m.architecture}}</small>
                    </h5>
                    <p class="mb-1"><b>Required by:</b> {{m.package_name}}<br/>
                    {% if m.package_version %}<b>Version:</b> {{m.package_version}}<br/>{% endif %}
                    </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>
  {% endif %}

  {% if issue.conflicts %}
    <div class="card">
        <header class="card-header">
            <p class="card-header-title">
            Conflicts in the dependency chain ({{issue.package_name}} {{issue.package_version}})
            </p>
            <div class="card-header-icon">
            <span class="icon">
                <i class="fas fa-bomb" aria-hidden="true"></i>
            </span>
            </div>
        </header>
        <div class="card-content py-3">
            <div class="content">
                {% for c in conflicts %}
                    <h4 class="subtitle mb-3">{{c.pkg1.package_name}} <span class="has-text-weight-light">vs.</span> {{c.pkg2.package_name}}</h4>
                    <div class="card has-background-white-ter">
                        <div class="card-content">

                        {% set pkg1_type_html = '' %}
                        {% if c.pkg1.package_type == PackageType.SOURCE %}
                        {% set pkg1_type_html = '<i class="fas fa-drafting-compass"></i>' %}
                        {% elif c.pkg1.package_type == PackageType.BINARY %}
                        {% set pkg1_type_html = '<i class="fas fa-cube"></i>' %}
                        {% endif %}

                        {% set pkg2_type_html = '' %}
                        {% if c.pkg2.package_type == PackageType.SOURCE %}
                        {% set pkg2_type_html = '<i class="fas fa-drafting-compass"></i>' %}
                        {% elif c.pkg2.package_type == PackageType.BINARY %}
                        {% set pkg2_type_html = '<i class="fas fa-cube"></i>' %}
                        {% endif %}

                        <!-- Package 1-->
                        <h5 class="subtitle mb-2">Package 1: {{c.pkg1.package_name}} {{c.pkg1.package_version}}&nbsp;&nbsp;{{ pkg1_type_html | safe }}</h5>
                        {% if c.pkg1.unsat_conflict %}
                        <span><b>Conflict:</b> {{c.pkg1.unsat_conflict}}</span>
                        {% endif %}

                        <ul class="mt-1">
                        {% for d in c.depchain1 %}
                            <li>
                                <b>{{d.package_name}} {{d.package_version}}</b> {% if d.package_type == PackageType.SOURCE %}<small><i class="fas fa-drafting-compass"></i></small>{% endif %}<br/>
                                <p class="mb-1 text-secondary"><b>Depends:</b> {{d.depends}}</p>
                            </li>
                        {% endfor %}
                        </ul>

                        <!-- Package 2-->
                        <h5 class="subtitle mb-2">Package 2: {{c.pkg2.package_name}} {{c.pkg2.package_version}}&nbsp;&nbsp;{{ pkg2_type_html | safe }}</h5>
                        {% if c.pkg2.unsat_conflict %}
                        <span><b>Conflict:</b> {{c.pkg2.unsat_conflict}}</span>
                        {% endif %}

                        <ul class="mt-1">
                        {% for d in c.depchain2 %}
                            <li>
                                <b>{{d.package_name}} {{d.package_version}}</b> {% if d.package_type == PackageType.SOURCE %}<small><i class="fas fa-drafting-compass"></i></small>{% endif %}<br/>
                                <p class="mb-1 text-secondary"><b>Depends:</b> {{d.depends}}</p>
                            </li>
                        {% endfor %}
                        </ul>
                    </div>
                    </div>
                {% endfor %}
            </div>
        </div>
      </div>
  {% endif %}

{% endfor %}
</div>
{% endif %}

{% if log_viewer_url %}
<br/>
<p><a class="button is-info" href="{{log_viewer_url}}" target="_blank" role="button">View Full Log</a></p>
{% else %}
<br/>
{% if job.status == JobStatus.DONE %}
  <h6 class="subtitle is-6"><i class="fa-solid fa-circle-exclamation"></i>&nbsp;Log data is not accessible.</h6>
{% else %}
  <h3 class="subtitle is-3 mb-2">Log Excerpt</h3>
  <div class="columns">
    <div class="column is-half">
      <div class="container">
        <pre><code>{{job.latest_log_excerpt if job.latest_log_excerpt else '...'}}</code></pre>
      </div>
    </div>
  </div>
{%endif %}
{%endif %}

{% endblock %}
