{% extends "base.html" %}
{% load compress humanize staticfiles hc_extras %}

{% block title %}Integrations - healthchecks.io{% endblock %}


{% block content %}
<div class="row">
<div class="col-sm-12">
    <table class="table channels-table">
        {% if channels %}
        <tr>
            <th>Type</th>
            <th>Value</th>
            <th>Assigned Checks</th>
            <th>Last Notification</th>
            <th></th>
        </tr>
        {% for ch in channels %}
        <tr class="channel-row">
            <td>
            {% if ch.kind == "email" %} Email {% endif %}
            {% if ch.kind == "webhook" %} Webhook {% endif %}
            {% if ch.kind == "slack" %} Slack {% endif %}
            {% if ch.kind == "hipchat" %} HipChat {% endif %}
            {% if ch.kind == "pd" %} PagerDuty {% endif %}
            {% if ch.kind == "po" %} Pushover {% endif %}
            {% if ch.kind == "victorops" %} VictorOps {% endif %}
            </td>
            <td class="value-cell">
                {% if ch.kind == "email" %}
                    <span class="preposition">to</span>
                    {{ ch.value }}
                    {% if not ch.email_verified %}
                        <span class="channel-unconfirmed">(unconfirmed)</span>
                    {% endif %}
                {% elif ch.kind == "pd" %}
                    <span class="preposition">API key</span>
                    {{ ch.value }}
                {% elif ch.kind == "victorops" %}
                    <span class="preposition">Post URL</span>
                    {{ ch.value }}
                {% elif ch.kind == "po" %}
                    <span class="preposition">user key</span>
                    {{ ch.po_value|first }}
                    ({{ ch.po_value|last }} priority)
                {% elif ch.kind == "webhook" %}
                    <table>
                        {% if ch.value_down %}
                        <tr>
                            <td class="preposition">down&nbsp;</td>
                            <td>{{ ch.value_down }}</td>
                        </tr>
                        {% endif %}
                        {% if ch.value_up %}
                        <tr>
                            <td class="preposition">up&nbsp;</td>
                            <td>{{ ch.value_up }}</td>
                        </tr>
                        {% endif %}
                    </table>
                {% else %}
                    {{ ch.value }}
                {% endif %}
            </td>
            <td class="channels-num-checks">
                <a
                    class="edit-checks"
                    href="{% url 'hc-channel-checks' ch.code %}">
                    {{ ch.n_checks }} of {{ num_checks }}
                </a>
            </td>
            <td>
            {% with n=ch.latest_notification %}
                {% if n %}
                    {% if n.error %}
                    <span class="text-danger" data-toggle="tooltip" title="{{ n.error }}">
                        <strong>Failed</strong>, {{ n.created|naturaltime }}
                    </span>
                    {% else %}
                    Delivered, {{ n.created|naturaltime }}
                    {% endif %}
                {% else %}
                Never
                {% endif %}
            {% endwith %}
            </td>
            <td>
                <button
                    data-name="{{ ch.value }}"
                    data-url="{% url 'hc-remove-channel' ch.code %}"
                    class="btn btn-sm btn-default channel-remove"
                    type="button">
                    <span class="glyphicon glyphicon-trash"></span>
                </button>
            </td>
            <td>

            </td>
        </tr>
        {% endfor %}
        {% endif %}
    </table>


    <h1 class="ai-title">Add More</h1>
    <ul class="add-integration">
        <li>
            <img src="{% static 'img/integrations/slack.png' %}"
                alt="Slack icon" />

            <h2>Slack</h2>
            <p>A messaging app for teams.</p>

            <a href="{% url 'hc-add-slack' %}" class="btn btn-primary">Add Integration</a>
        </li>
        <li>
            <img src="{% static 'img/integrations/email.png' %}"
                alt="Email icon" />

            <h2>Email</h2>
            <p>Get an email message when check goes up or down.</p>

            <a href="{% url 'hc-add-email' %}" class="btn btn-primary">Add Integration</a>
        </li>
        <li>
            <img src="{% static 'img/integrations/webhook.png' %}"
                alt="Webhook icon" />

            <h2>Webhook</h2>
            <p>Receive a HTTP callback when a check goes down.</p>

            <a href="{% url 'hc-add-webhook' %}" class="btn btn-primary">Add Integration</a>
        </li>
        <li>
            <img src="{% static 'img/integrations/pd.png' %}"
                alt="PagerDuty icon" />

            <h2>PagerDuty</h2>
            <p>On-call scheduling, alerting, and incident tracking.</p>

            <a href="{% url 'hc-add-pd' %}" class="btn btn-primary">Add Integration</a>
        </li>
        <li>
            <img src="{% static 'img/integrations/hipchat.png' %}"
                alt="HipChat icon" />

            <h2>HipChat</h2>
            <p>Group and private chat, file sharing, and integrations.</p>

            <a href="{% url 'hc-add-hipchat' %}" class="btn btn-primary">Add Integration</a>
        </li>
        <li>
            <img src="{% static 'img/integrations/victorops.png' %}"
                alt="VictorOps icon" />

            <h2>VictorOps</h2>
            <p>On-call scheduling, alerting, and incident tracking.</p>

            <a href="{% url 'hc-add-victorops' %}" class="btn btn-primary">Add Integration</a>
        </li>
        {% if enable_pushover %}
        <li>
            <img src="{% static 'img/integrations/pushover.png' %}"
                 alt="Pushover icon" />

            <h2>Pushover</h2>
            <p>Receive instant push notifications on your phone or tablet.</p>

            <a href="{% url 'hc-add-pushover' %}" class="btn btn-primary">Add Integration</a>
        </li>
        {% endif %}
    </ul>



</div>
</div>

<div id="checks-modal" class="modal">
    <div class="modal-dialog">
            <div class="modal-content">
                <h2>Email</h2>
                <p>Get an email message when check goes up or down</p>
            </div>
        </form>
    </div>
</div>

<div id="remove-channel-modal" class="modal">
    <div class="modal-dialog">
        <form id="remove-channel-form" method="post">
            {% csrf_token %}
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="remove-check-title">Remove Channel <span class="remove-channel-name"></span></h4>
                </div>
                <div class="modal-body">
                    <p>You are about to remove channel
                        <strong class="remove-channel-name">---</strong>.
                    </p>
                    <p>Once it's gone it's gone. But, if you change your
                    mind later, you can create a similar channel again.</p>
                    <p>Do you want to continue?</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger">Remove</button>
                </div>
            </div>
        </form>
    </div>
</div>

{% endblock %}

{% block scripts %}
{% compress js %}
<script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/channels.js' %}"></script>
{% endcompress %}
{% endblock %}
