diff --git a/hc/front/templatetags/hc_extras.py b/hc/front/templatetags/hc_extras.py index e1da352d..3c2c0fbc 100644 --- a/hc/front/templatetags/hc_extras.py +++ b/hc/front/templatetags/hc_extras.py @@ -73,3 +73,11 @@ def sortchecks(checks, key): @register.filter def trunc(s): return s[:150] + + +@register.filter +def num_down_title(num_down): + if num_down: + return "%d down – %s" % (num_down, settings.SITE_NAME) + else: + return settings.SITE_NAME diff --git a/hc/front/views.py b/hc/front/views.py index 89313c06..3fc212f2 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -24,7 +24,7 @@ from hc.front.forms import (AddWebhookForm, NameTagsForm, TimeoutForm, AddUrlForm, AddEmailForm, AddOpsGenieForm, CronForm, AddSmsForm) from hc.front.schemas import telegram_callback -from hc.front.templatetags.hc_extras import sortchecks +from hc.front.templatetags.hc_extras import num_down_title, sortchecks from hc.lib import jsonschema from pytz import all_timezones from pytz.exceptions import UnknownTimeZoneError @@ -35,9 +35,10 @@ VALID_SORT_VALUES = ("name", "-name", "last_ping", "-last_ping", "created") def _tags_statuses(checks): - tags, down, grace = {}, {}, {} + tags, down, grace, num_down = {}, {}, {}, 0 for check in checks: if check.get_status() == "down": + num_down += 1 for tag in check.tags_list(): down[tag] = "down" elif check.in_grace_period(): @@ -49,7 +50,7 @@ def _tags_statuses(checks): tags.update(grace) tags.update(down) - return tags + return tags, num_down @login_required @@ -61,12 +62,14 @@ def my_checks(request): checks = list(Check.objects.filter(user=request.team.user)) sortchecks(checks, request.profile.sort) - pairs = list(_tags_statuses(checks).items()) + tags_statuses, num_down = _tags_statuses(checks) + pairs = list(tags_statuses.items()) pairs.sort(key=lambda pair: pair[0].lower()) ctx = { "page": "checks", "checks": checks, + "num_down": num_down, "now": timezone.now(), "tags": pairs, "ping_endpoint": settings.PING_ENDPOINT, @@ -93,7 +96,12 @@ def status(request): "last_ping": render_to_string("front/last_ping_cell.html", ctx) }) - return JsonResponse({"details": details, "tags": _tags_statuses(checks)}) + tags_statuses, num_down = _tags_statuses(checks) + return JsonResponse({ + "details": details, + "tags": tags_statuses, + "title": num_down_title(num_down) + }) def _welcome_check(request): diff --git a/static/js/checks.js b/static/js/checks.js index 01c7dd50..2974ef68 100644 --- a/static/js/checks.js +++ b/static/js/checks.js @@ -297,6 +297,11 @@ $(function () { this.setAttribute("class", "btn btn-xs " + status); } }); + + if (document.title != data.title) { + document.title = data.title; + } + } }); } diff --git a/templates/front/my_checks.html b/templates/front/my_checks.html index 02e8d11d..30b6daea 100644 --- a/templates/front/my_checks.html +++ b/templates/front/my_checks.html @@ -1,8 +1,7 @@ {% extends "base.html" %} {% load compress staticfiles hc_extras %} -{% block title %}My Checks - {% site_name %}{% endblock %} - +{% block title %}{{ num_down|num_down_title }}{% endblock %} {% block content %}