diff --git a/hc/front/templatetags/hc_extras.py b/hc/front/templatetags/hc_extras.py
index b312d803..e1da352d 100644
--- a/hc/front/templatetags/hc_extras.py
+++ b/hc/front/templatetags/hc_extras.py
@@ -48,8 +48,14 @@ def last_ping_key(check):
return check.last_ping.isoformat() if check.last_ping else "9999"
+def not_down_key(check):
+ return check.get_status() != "down"
+
+
@register.filter
def sortchecks(checks, key):
+ """Sort the list of checks in-place by given key, then by status=down. """
+
if key == "created":
checks.sort(key=lambda check: check.created)
elif key.endswith("name"):
@@ -57,6 +63,10 @@ def sortchecks(checks, key):
elif key.endswith("last_ping"):
checks.sort(key=last_ping_key, reverse=key.startswith("-"))
+ # Move failed checks to the beginning. Sorts in python are stable
+ # so this does not mess up the previous sort.
+ checks.sort(key=not_down_key)
+
return checks
diff --git a/hc/front/views.py b/hc/front/views.py
index 8c5976ae..27204d11 100644
--- a/hc/front/views.py
+++ b/hc/front/views.py
@@ -24,6 +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.lib import jsonschema
from pytz import all_timezones
from pytz.exceptions import UnknownTimeZoneError
@@ -58,6 +59,7 @@ def my_checks(request):
request.profile.save()
checks = list(Check.objects.filter(user=request.team.user))
+ sortchecks(checks, request.profile.sort)
pairs = list(_tags_statuses(checks).items())
pairs.sort(key=lambda pair: pair[0].lower())
diff --git a/static/js/checks.js b/static/js/checks.js
index f790b6e9..01c7dd50 100644
--- a/static/js/checks.js
+++ b/static/js/checks.js
@@ -192,6 +192,7 @@ $(function () {
return false;
});
+ // Filtering by tags
$("#my-checks-tags button").click(function() {
// .active has not been updated yet by bootstrap code,
// so cannot use it
@@ -238,12 +239,19 @@ $(function () {
});
$('[data-toggle="tooltip"]').tooltip({
+ html: true,
title: function() {
var cssClasses = this.getAttribute("class");
if (cssClasses.indexOf("icon-new") > -1)
return "New. Has never received a ping.";
if (cssClasses.indexOf("icon-paused") > -1)
return "Monitoring paused. Ping to resume.";
+
+ if (cssClasses.indexOf("sort-name") > -1)
+ return "Sort by name
(but failed always first)";
+
+ if (cssClasses.indexOf("sort-last-ping") > -1)
+ return "Sort by last ping
(but failed always first)";
}
});
diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html
index dc7f0c77..b4a6d0fc 100644
--- a/templates/front/my_checks_desktop.html
+++ b/templates/front/my_checks_desktop.html
@@ -4,11 +4,17 @@