{% extends "layout.html" %}
{% block sidebar %}
{% if not suite %}
{% include "cupboard/sidebar.html" %}
{% else %}
{% include [suite + "-sidebar.html", "generic/sidebar.html"] %}
{% endif %}
{% endblock %}
{% from "run_util.html" import display_publish_result_code %}
{% block page_title %}Merge Proposal Status - {{ proposal.url }}{% endblock %}
{% block body %}
<div class="section" id="merge-proposal-status">
<h1>Merge Proposal Status</h1>

<ul>
	<li>URL: <a href="{{ proposal.url }}">{{ proposal.url }}</a></li>
{% if proposal.package %}
<li>Package: <a href="/cupboard/pkg/{{ proposal.package }}">{{ proposal.package }}</a></li>
{% endif %}
<li>Status:
{% if is_admin and proposal.status in ('closed', 'abandoned', 'applied', 'rejected') %}
<select id="status" name='status' onchange="submit_status(this.value)">
  <option value="closed"{% if proposal.status == 'closed' %} selected="true"{% endif %}>Closed</option>
  <option value="abandoned"{% if proposal.status == 'abandoned' %} selected="true"{% endif %}>Abandoned</option>
  <option value="rejected"{% if proposal.status == 'rejected' %} selected="true"{% endif %}>Rejected</option>
  <option value="applied"{% if proposal.status == 'applied' %} selected="true"{% endif %}>Applied</option>
</select>
<script>
function submit_status(status) {
console.log("Changing of merge proposal {{ proposal.url }} to " + status);
$.post('/api/merge-proposal', {'status': status, 'url': {{ proposal.url|tojson }}});
}
</script>
{% elif proposal.status == 'merged' %}
Merged{% if proposal.merged_at %} at {{ format_timestamp(proposal.merged_at) }}{% endif %}{% if proposal.merged_by %} by {{ proposal.merged_by }}{% endif %}
{% else %}
{{ proposal.status }}
{% endif %}
</li>
{% if proposal.suite %}
<li><a href="/{{ proposal.suite }}/pkg/{{ proposal.package }}">Run Details</a></li>
{% endif %}

<h2>State changes</h2>

<ul>
	{% for publish in publishes %}
	<li>{{ format_timestamp(publish.timestamp) }}: {{ display_publish_result_code(publish.result_code) }}: {% if '\n' in publish.description %}<pre>{{ publish.description }}</pre>{% else %}{{ publish.description }}{% endif %}</li>
	{% endfor %}
</ul>

{% endblock %}
