forked from GithubBackups/healthchecks
Display last notification in Integrations page.
This commit is contained in:
parent
c7a651c330
commit
2c04a42a57
@ -170,8 +170,14 @@ class Channel(models.Model):
|
||||
prio = int(prio)
|
||||
return user_key, prio, PO_PRIORITIES[prio]
|
||||
|
||||
def latest_notification(self):
|
||||
return Notification.objects.filter(channel=self).latest()
|
||||
|
||||
|
||||
class Notification(models.Model):
|
||||
class Meta:
|
||||
get_latest_by = "created"
|
||||
|
||||
owner = models.ForeignKey(Check)
|
||||
check_status = models.CharField(max_length=6)
|
||||
channel = models.ForeignKey(Channel)
|
||||
|
@ -5,6 +5,7 @@ from itertools import tee
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db.models import Count
|
||||
from django.http import HttpResponseBadRequest, HttpResponseForbidden
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils import timezone
|
||||
@ -266,6 +267,8 @@ def channels(request):
|
||||
return redirect("hc-channels")
|
||||
|
||||
channels = Channel.objects.filter(user=request.user).order_by("created")
|
||||
channels = channels.annotate(n_checks=Count("checks"))
|
||||
|
||||
num_checks = Check.objects.filter(user=request.user).count()
|
||||
|
||||
ctx = {
|
||||
|
@ -46,5 +46,6 @@ $(function() {
|
||||
return false;
|
||||
});
|
||||
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
});
|
@ -13,6 +13,7 @@
|
||||
<th>Type</th>
|
||||
<th>Value</th>
|
||||
<th>Assigned Checks</th>
|
||||
<th>Last Notification</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for ch in channels %}
|
||||
@ -47,9 +48,24 @@
|
||||
<a
|
||||
class="edit-checks"
|
||||
href="{% url 'hc-channel-checks' ch.code %}">
|
||||
{{ ch.checks.count }} of {{ num_checks }}
|
||||
{{ 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 }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user