diff --git a/hc/front/tests/test_status.py b/hc/front/tests/test_status.py new file mode 100644 index 00000000..5dd3e4ec --- /dev/null +++ b/hc/front/tests/test_status.py @@ -0,0 +1,23 @@ +from hc.api.models import Check +from hc.test import BaseTestCase + + +class MyChecksTestCase(BaseTestCase): + + def setUp(self): + super(MyChecksTestCase, self).setUp() + self.check = Check(user=self.alice, name="Alice Was Here") + self.check.tags = "foo" + self.check.save() + + def test_it_works(self): + self.client.login(username="alice@example.org", password="password") + r = self.client.get("/checks/status/") + doc = r.json() + + self.assertEqual(doc["tags"]["foo"], "up") + + detail = doc["details"][0] + self.assertEqual(detail["code"], str(self.check.code)) + self.assertEqual(detail["status"], "new") + self.assertIn("Never", detail["last_ping"]) diff --git a/static/css/my_checks_mobile.css b/static/css/my_checks_mobile.css index 8ae13ccb..95a82d79 100644 --- a/static/css/my_checks_mobile.css +++ b/static/css/my_checks_mobile.css @@ -36,4 +36,24 @@ #checks-list th { width: 100px; +} + +#checks-list .label { + text-transform: uppercase; +} + +.label-new, .label-paused { + background-color: #777777; +} + +.label-up { + background-color: #22bc66; +} + +.label-grace { + background-color: #f0ad4e; +} + +.label-down { + background-color: #d9534f; } \ No newline at end of file diff --git a/static/js/checks.js b/static/js/checks.js index 1817242f..b1c0fc02 100644 --- a/static/js/checks.js +++ b/static/js/checks.js @@ -258,21 +258,36 @@ $(function () { }); // Auto-refresh + var lastStatus = {}; + var lastPing = {}; function refresh() { - $.getJSON("/checks/status/", function(data) { - for(var i=0, el; el=data.details[i]; i++) { - var elId = "#check-desktop-" + el.code; - $(elId + " .indicator-cell span").attr("class", "status icon-" + el.status); - $(elId + " .last-ping-cell").html(el.last_ping); - $(elId + " .li-pause-check").toggleClass("disabled", el.status == "paused"); - } - - $("#my-checks-tags button").each(function(a) { - var status = data.tags[this.innerText]; - if (status) { - this.setAttribute("class", "btn btn-xs " + status); + $.ajax({ + url: "/checks/status/", + dataType: "json", + timeout: 2000, + success: function(data) { + for(var i=0, el; el=data.details[i]; i++) { + if (lastStatus[el.code] != el.status) { + lastStatus[el.code] = el.status; + $("#si-" + el.code).attr("class", "status icon-" + el.status); + $("#sl-" + el.code).attr("class", "label label-" + el.status).text(el.status); + $("#pause-li-" + el.code).toggleClass("disabled", el.status == "paused"); + } + + if (lastPing[el.code] != el.last_ping) { + lastPing[el.code] = el.last_ping; + $("#lpd-" + el.code).html(el.last_ping); + $("#lpm-" + el.code).html(el.last_ping); + } } - }); + + $("#my-checks-tags button").each(function(a) { + var status = data.tags[this.innerText]; + if (status) { + this.setAttribute("class", "btn btn-xs " + status); + } + }); + } }); } diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html index ce279073..dad611ec 100644 --- a/templates/front/my_checks_desktop.html +++ b/templates/front/my_checks_desktop.html @@ -28,12 +28,12 @@