Browse Source

Display last notification in Integrations page.

pull/40/head
Pēteris Caune 9 years ago
parent
commit
2c04a42a57
4 changed files with 27 additions and 1 deletions
  1. +6
    -0
      hc/api/models.py
  2. +3
    -0
      hc/front/views.py
  3. +1
    -0
      static/js/channels.js
  4. +17
    -1
      templates/front/channels.html

+ 6
- 0
hc/api/models.py View File

@ -170,8 +170,14 @@ class Channel(models.Model):
prio = int(prio) prio = int(prio)
return user_key, prio, PO_PRIORITIES[prio] return user_key, prio, PO_PRIORITIES[prio]
def latest_notification(self):
return Notification.objects.filter(channel=self).latest()
class Notification(models.Model): class Notification(models.Model):
class Meta:
get_latest_by = "created"
owner = models.ForeignKey(Check) owner = models.ForeignKey(Check)
check_status = models.CharField(max_length=6) check_status = models.CharField(max_length=6)
channel = models.ForeignKey(Channel) channel = models.ForeignKey(Channel)


+ 3
- 0
hc/front/views.py View File

@ -5,6 +5,7 @@ from itertools import tee
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db.models import Count
from django.http import HttpResponseBadRequest, HttpResponseForbidden from django.http import HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone from django.utils import timezone
@ -266,6 +267,8 @@ def channels(request):
return redirect("hc-channels") return redirect("hc-channels")
channels = Channel.objects.filter(user=request.user).order_by("created") 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() num_checks = Check.objects.filter(user=request.user).count()
ctx = { ctx = {


+ 1
- 0
static/js/channels.js View File

@ -46,5 +46,6 @@ $(function() {
return false; return false;
}); });
$('[data-toggle="tooltip"]').tooltip();
}); });

+ 17
- 1
templates/front/channels.html View File

@ -13,6 +13,7 @@
<th>Type</th> <th>Type</th>
<th>Value</th> <th>Value</th>
<th>Assigned Checks</th> <th>Assigned Checks</th>
<th>Last Notification</th>
<th></th> <th></th>
</tr> </tr>
{% for ch in channels %} {% for ch in channels %}
@ -47,9 +48,24 @@
<a <a
class="edit-checks" class="edit-checks"
href="{% url 'hc-channel-checks' ch.code %}"> href="{% url 'hc-channel-checks' ch.code %}">
{{ ch.checks.count }} of {{ num_checks }}
{{ ch.n_checks }} of {{ num_checks }}
</a> </a>
</td> </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> <td>
<button <button
data-name="{{ ch.value }}" data-name="{{ ch.value }}"


Loading…
Cancel
Save