diff --git a/hc/front/views.py b/hc/front/views.py index 1fb886fc..c82e0fff 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -208,6 +208,9 @@ def update_name(request, code): check.tags = form.cleaned_data["tags"] check.save() + if request.META.get("HTTP_REFERER", "").endswith("/log/"): + return redirect("hc-log", code) + return redirect("hc-checks") @@ -241,6 +244,10 @@ def update_timeout(request, code): check.alert_after = check.get_alert_after() check.save() + + if request.META.get("HTTP_REFERER", "").endswith("/log/"): + return redirect("hc-log", code) + return redirect("hc-checks") @@ -298,6 +305,9 @@ def pause(request, code): check.status = "paused" check.save() + if request.META.get("HTTP_REFERER", "").endswith("/log/"): + return redirect("hc-log", code) + return redirect("hc-checks") @@ -340,6 +350,7 @@ def log(request, code): channels = list(channels.order_by("created")) ctx = { + "page": "log", "check": check, "ping_endpoint": settings.PING_ENDPOINT, "channels": channels, diff --git a/static/css/base.css b/static/css/base.css index c2725cf8..51bf3d8a 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -52,7 +52,7 @@ body { font-size: small; } -.page-checks .container-fluid { +.page-checks .container-fluid, .page-log .container-fluid { /* Fluid below 1320px, but max width capped to 1320px ... */ max-width: 1320px; } diff --git a/static/css/log.css b/static/css/log.css index 2e4f6f9d..865e16cb 100644 --- a/static/css/log.css +++ b/static/css/log.css @@ -23,6 +23,10 @@ border-radius: 3px; } +.details-block .copy-btn { + width: 90px; +} + .details-block code { display: block; padding: 8px; @@ -30,6 +34,9 @@ background: #f5f5f5; } +.details-block form { + display: inline; +} #details-status td { padding: 8px; @@ -73,6 +80,10 @@ content: " "; } +#log-container { + overflow: hidden; +} + #log { visibility: hidden; font-size: 13px; diff --git a/static/js/checks.js b/static/js/checks.js index 09fc07c9..d7c0afdf 100644 --- a/static/js/checks.js +++ b/static/js/checks.js @@ -13,166 +13,6 @@ $(function () { return false; }); - var MINUTE = {name: "minute", nsecs: 60}; - var HOUR = {name: "hour", nsecs: MINUTE.nsecs * 60}; - var DAY = {name: "day", nsecs: HOUR.nsecs * 24}; - var WEEK = {name: "week", nsecs: DAY.nsecs * 7}; - var UNITS = [WEEK, DAY, HOUR, MINUTE]; - - var secsToText = function(total) { - var remainingSeconds = Math.floor(total); - var result = ""; - for (var i=0, unit; unit=UNITS[i]; i++) { - if (unit === WEEK && remainingSeconds % unit.nsecs != 0) { - // Say "8 days" instead of "1 week 1 day" - continue - } - - var count = Math.floor(remainingSeconds / unit.nsecs); - remainingSeconds = remainingSeconds % unit.nsecs; - - if (count == 1) { - result += "1 " + unit.name + " "; - } - - if (count > 1) { - result += count + " " + unit.name + "s "; - } - } - - return result; - } - - var periodSlider = document.getElementById("period-slider"); - noUiSlider.create(periodSlider, { - start: [20], - connect: "lower", - range: { - 'min': [60, 60], - '33%': [3600, 3600], - '66%': [86400, 86400], - '83%': [604800, 604800], - 'max': 2592000, - }, - pips: { - mode: 'values', - values: [60, 1800, 3600, 43200, 86400, 604800, 2592000], - density: 4, - format: { - to: secsToText, - from: function() {} - } - } - }); - - periodSlider.noUiSlider.on("update", function(a, b, value) { - var rounded = Math.round(value); - $("#period-slider-value").text(secsToText(rounded)); - $("#update-timeout-timeout").val(rounded); - }); - - var graceSlider = document.getElementById("grace-slider"); - noUiSlider.create(graceSlider, { - start: [20], - connect: "lower", - range: { - 'min': [60, 60], - '33%': [3600, 3600], - '66%': [86400, 86400], - '83%': [604800, 604800], - 'max': 2592000, - }, - pips: { - mode: 'values', - values: [60, 1800, 3600, 43200, 86400, 604800, 2592000], - density: 4, - format: { - to: secsToText, - from: function() {} - } - } - }); - - graceSlider.noUiSlider.on("update", function(a, b, value) { - var rounded = Math.round(value); - $("#grace-slider-value").text(secsToText(rounded)); - $("#update-timeout-grace").val(rounded); - }); - - function showSimple() { - $("#update-timeout-form").show(); - $("#update-cron-form").hide(); - } - - function showCron() { - $("#update-timeout-form").hide(); - $("#update-cron-form").show(); - } - - var currentPreviewHash = ""; - function updateCronPreview() { - var schedule = $("#schedule").val(); - var tz = $("#tz").val(); - var hash = schedule + tz; - - // Don't try preview with empty values, or if values have not changed - if (!schedule || !tz || hash == currentPreviewHash) - return; - - // OK, we're good - currentPreviewHash = hash; - $("#cron-preview-title").text("Updating..."); - - var token = $('input[name=csrfmiddlewaretoken]').val(); - $.ajax({ - url: "/checks/cron_preview/", - type: "post", - headers: {"X-CSRFToken": token}, - data: {schedule: schedule, tz: tz}, - success: function(data) { - if (hash != currentPreviewHash) { - return; // ignore stale results - } - - $("#cron-preview" ).html(data); - var haveError = $("#invalid-arguments").size() > 0; - $("#update-cron-submit").prop("disabled", haveError); - } - }); - } - - $(".timeout-grace").click(function() { - var code = $(this).closest("tr.checks-row").attr("id"); - var url = "/checks/" + code + "/timeout/"; - - $("#update-timeout-form").attr("action", url); - $("#update-cron-form").attr("action", url); - - // Simple - periodSlider.noUiSlider.set(this.dataset.timeout); - graceSlider.noUiSlider.set(this.dataset.grace); - - // Cron - currentPreviewHash = ""; - $("#cron-preview").html("

Updating...

"); - $("#schedule").val(this.dataset.schedule); - document.getElementById("tz").selectize.setValue(this.dataset.tz); - var minutes = parseInt(this.dataset.grace / 60); - $("#update-timeout-grace-cron").val(minutes); - updateCronPreview(); - - this.dataset.kind == "simple" ? showSimple() : showCron(); - $('#update-timeout-modal').modal({"show":true, "backdrop":"static"}); - return false; - }); - - // Wire up events for Timeout/Cron forms - $(".kind-simple").click(showSimple); - $(".kind-cron").click(showCron); - - $("#schedule").on("keyup", updateCronPreview); - $("#tz").selectize({onChange: updateCronPreview}); - $(".check-menu-remove").click(function() { var code = $(this).closest("tr.checks-row").attr("id"); var url = "/checks/" + code + "/remove/"; diff --git a/static/js/log.js b/static/js/log.js index 84dd33cc..27bfd5c8 100644 --- a/static/js/log.js +++ b/static/js/log.js @@ -1,4 +1,48 @@ $(function () { + $("#edit-name").click(function() { + $('#update-name-modal').modal("show"); + $("#update-name-input").focus(); + + return false; + }); + + $("#pause").click(function(e) { + $("#pause-form").submit(); + return false; + }); + + $("#ping-now").click(function(e) { + var button = this; + $.get(this.dataset.url, function() { + button.textContent = "Success!"; + }); + }); + + $("#ping-now").mouseout(function(e) { + setTimeout(function() { + e.target.textContent = "Ping Now!"; + }, 300); + }); + + + // Copy to clipboard + var clipboard = new Clipboard('button.copy-btn'); + $("button.copy-btn").mouseout(function(e) { + setTimeout(function() { + e.target.textContent = e.target.dataset.label; + }, 300); + }); + + clipboard.on('success', function(e) { + e.trigger.textContent = "Copied!"; + e.clearSelection(); + }); + + clipboard.on('error', function(e) { + var text = e.trigger.getAttribute("data-clipboard-text"); + prompt("Press Ctrl+C to select:", text) + }); + $("#log tr.ok").on("click", function() { $("#ping-details-body").text("Updating..."); $('#ping-details-modal').modal("show"); diff --git a/static/js/update-timeout-modal.js b/static/js/update-timeout-modal.js new file mode 100644 index 00000000..0934bbbb --- /dev/null +++ b/static/js/update-timeout-modal.js @@ -0,0 +1,192 @@ +$(function () { + $(".timeout-grace").click(function() { + var code = $(this).closest("tr.checks-row").attr("id"); + if (!code) { + code = this.dataset.code; + } + + var url = "/checks/" + code + "/timeout/"; + + $("#update-timeout-form").attr("action", url); + $("#update-cron-form").attr("action", url); + + // Simple + periodSlider.noUiSlider.set(this.dataset.timeout); + graceSlider.noUiSlider.set(this.dataset.grace); + + // Cron + currentPreviewHash = ""; + $("#cron-preview").html("

Updating...

"); + $("#schedule").val(this.dataset.schedule); + document.getElementById("tz").selectize.setValue(this.dataset.tz); + var minutes = parseInt(this.dataset.grace / 60); + $("#update-timeout-grace-cron").val(minutes); + updateCronPreview(); + + this.dataset.kind == "simple" ? showSimple() : showCron(); + $('#update-timeout-modal').modal({"show":true, "backdrop":"static"}); + return false; + }); + + function init(code, kind, timeout, grace, schedule, tz) { + var url = "/checks/" + code + "/timeout/"; + + $("#update-timeout-form").attr("action", url); + $("#update-cron-form").attr("action", url); + + // Simple + periodSlider.noUiSlider.set(timeout); + graceSlider.noUiSlider.set(grace); + + // Cron + currentPreviewHash = ""; + $("#cron-preview").html("

Updating...

"); + $("#schedule").val(schedule); + document.getElementById("tz").selectize.setValue(tz); + var minutes = parseInt(grace / 60); + $("#update-timeout-grace-cron").val(minutes); + updateCronPreview(); + + kind == "simple" ? showSimple() : showCron(); + $('#update-timeout-modal').modal({"show":true, "backdrop":"static"}); + return false; + + } + + + var MINUTE = {name: "minute", nsecs: 60}; + var HOUR = {name: "hour", nsecs: MINUTE.nsecs * 60}; + var DAY = {name: "day", nsecs: HOUR.nsecs * 24}; + var WEEK = {name: "week", nsecs: DAY.nsecs * 7}; + var UNITS = [WEEK, DAY, HOUR, MINUTE]; + + var secsToText = function(total) { + var remainingSeconds = Math.floor(total); + var result = ""; + for (var i=0, unit; unit=UNITS[i]; i++) { + if (unit === WEEK && remainingSeconds % unit.nsecs != 0) { + // Say "8 days" instead of "1 week 1 day" + continue + } + + var count = Math.floor(remainingSeconds / unit.nsecs); + remainingSeconds = remainingSeconds % unit.nsecs; + + if (count == 1) { + result += "1 " + unit.name + " "; + } + + if (count > 1) { + result += count + " " + unit.name + "s "; + } + } + + return result; + } + + var periodSlider = document.getElementById("period-slider"); + noUiSlider.create(periodSlider, { + start: [20], + connect: "lower", + range: { + 'min': [60, 60], + '33%': [3600, 3600], + '66%': [86400, 86400], + '83%': [604800, 604800], + 'max': 2592000, + }, + pips: { + mode: 'values', + values: [60, 1800, 3600, 43200, 86400, 604800, 2592000], + density: 4, + format: { + to: secsToText, + from: function() {} + } + } + }); + + periodSlider.noUiSlider.on("update", function(a, b, value) { + var rounded = Math.round(value); + $("#period-slider-value").text(secsToText(rounded)); + $("#update-timeout-timeout").val(rounded); + }); + + var graceSlider = document.getElementById("grace-slider"); + noUiSlider.create(graceSlider, { + start: [20], + connect: "lower", + range: { + 'min': [60, 60], + '33%': [3600, 3600], + '66%': [86400, 86400], + '83%': [604800, 604800], + 'max': 2592000, + }, + pips: { + mode: 'values', + values: [60, 1800, 3600, 43200, 86400, 604800, 2592000], + density: 4, + format: { + to: secsToText, + from: function() {} + } + } + }); + + graceSlider.noUiSlider.on("update", function(a, b, value) { + var rounded = Math.round(value); + $("#grace-slider-value").text(secsToText(rounded)); + $("#update-timeout-grace").val(rounded); + }); + + function showSimple() { + $("#update-timeout-form").show(); + $("#update-cron-form").hide(); + } + + function showCron() { + $("#update-timeout-form").hide(); + $("#update-cron-form").show(); + } + + var currentPreviewHash = ""; + function updateCronPreview() { + var schedule = $("#schedule").val(); + var tz = $("#tz").val(); + var hash = schedule + tz; + + // Don't try preview with empty values, or if values have not changed + if (!schedule || !tz || hash == currentPreviewHash) + return; + + // OK, we're good + currentPreviewHash = hash; + $("#cron-preview-title").text("Updating..."); + + var token = $('input[name=csrfmiddlewaretoken]').val(); + $.ajax({ + url: "/checks/cron_preview/", + type: "post", + headers: {"X-CSRFToken": token}, + data: {schedule: schedule, tz: tz}, + success: function(data) { + if (hash != currentPreviewHash) { + return; // ignore stale results + } + + $("#cron-preview" ).html(data); + var haveError = $("#invalid-arguments").size() > 0; + $("#update-cron-submit").prop("disabled", haveError); + } + }); + } + + // Wire up events for Timeout/Cron forms + $(".kind-simple").click(showSimple); + $(".kind-cron").click(showCron); + + $("#schedule").on("keyup", updateCronPreview); + $("#tz").selectize({onChange: updateCronPreview}); + +}); diff --git a/templates/base.html b/templates/base.html index 23d26005..d16a5bc1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -45,7 +45,7 @@