2015-06-16 10:59:00 +00:00
|
|
|
$(function () {
|
2024-11-14 12:18:39 +00:00
|
|
|
var base = document.getElementById("base-url").getAttribute("href").slice(0, -1);
|
2024-03-26 15:28:47 +00:00
|
|
|
var favicon = document.querySelector('link[rel="icon"]');
|
2015-06-16 13:21:48 +00:00
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$(".rw .my-checks-name").click(function () {
|
2018-06-15 08:40:54 +00:00
|
|
|
var code = $(this).closest("tr.checks-row").attr("id");
|
2019-08-12 20:29:32 +00:00
|
|
|
var url = base + "/checks/" + code + "/name/";
|
2018-06-15 08:40:54 +00:00
|
|
|
|
|
|
|
$("#update-name-form").attr("action", url);
|
2016-12-23 18:19:06 +00:00
|
|
|
$("#update-name-input").val(this.dataset.name);
|
2023-06-14 12:06:37 +00:00
|
|
|
$("#update-slug-input").val(this.dataset.slug);
|
2020-03-09 08:16:39 +00:00
|
|
|
|
2024-11-14 12:18:39 +00:00
|
|
|
var tagsSelectize = document.getElementById("update-tags-input").selectize;
|
2020-03-05 13:49:42 +00:00
|
|
|
tagsSelectize.setValue(this.dataset.tags.split(" "));
|
2020-03-09 08:16:39 +00:00
|
|
|
|
2018-08-20 15:16:00 +00:00
|
|
|
$("#update-desc-input").val(this.dataset.desc);
|
2024-11-14 07:23:44 +00:00
|
|
|
$("#update-name-modal").modal("show");
|
2016-12-23 18:19:06 +00:00
|
|
|
$("#update-name-input").focus();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2018-06-11 09:40:20 +00:00
|
|
|
$(".integrations").tooltip({
|
|
|
|
container: "body",
|
2018-06-11 12:54:24 +00:00
|
|
|
selector: "span",
|
2024-11-14 07:23:44 +00:00
|
|
|
title: function () {
|
2018-06-11 09:40:20 +00:00
|
|
|
var idx = $(this).index();
|
|
|
|
return $("#ch-" + idx).data("title");
|
2024-11-14 07:23:44 +00:00
|
|
|
},
|
2018-06-11 09:40:20 +00:00
|
|
|
});
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$(".rw .integrations").on("click", "span", function () {
|
2018-06-10 20:19:25 +00:00
|
|
|
var isOff = $(this).toggleClass("off").hasClass("off");
|
2024-11-14 07:23:44 +00:00
|
|
|
var token = $("input[name=csrfmiddlewaretoken]").val();
|
2018-06-11 09:40:20 +00:00
|
|
|
|
|
|
|
var idx = $(this).index();
|
2018-06-15 08:40:54 +00:00
|
|
|
var checkCode = $(this).closest("tr.checks-row").attr("id");
|
2018-06-11 09:40:20 +00:00
|
|
|
var channelCode = $("#ch-" + idx).data("code");
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
var url =
|
2024-11-14 12:18:39 +00:00
|
|
|
base + "/checks/" + checkCode + "/channels/" + channelCode + "/enabled";
|
2018-06-11 09:40:20 +00:00
|
|
|
|
2018-06-10 20:19:25 +00:00
|
|
|
$.ajax({
|
2018-06-11 09:40:20 +00:00
|
|
|
url: url,
|
2018-06-10 20:19:25 +00:00
|
|
|
type: "post",
|
2024-11-14 07:23:44 +00:00
|
|
|
headers: { "X-CSRFToken": token },
|
|
|
|
data: { state: isOff ? "off" : "on" },
|
2018-06-10 20:19:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$(".last-ping").on("click", function () {
|
2018-06-11 09:02:00 +00:00
|
|
|
if (this.innerText == "Never") {
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-15 08:40:54 +00:00
|
|
|
var code = $(this).closest("tr.checks-row").attr("id");
|
2019-08-12 20:29:32 +00:00
|
|
|
var lastPingUrl = base + "/checks/" + code + "/last_ping/";
|
2022-03-16 11:51:26 +00:00
|
|
|
loadPingDetails(lastPingUrl);
|
2017-05-09 10:47:23 +00:00
|
|
|
|
2019-08-12 20:29:32 +00:00
|
|
|
var logUrl = base + "/checks/" + code + "/log/";
|
2018-06-15 07:52:38 +00:00
|
|
|
$("#ping-details-log").attr("href", logUrl);
|
|
|
|
|
2017-05-09 10:47:23 +00:00
|
|
|
return false;
|
|
|
|
});
|
2015-12-22 18:07:30 +00:00
|
|
|
|
2020-10-14 10:13:22 +00:00
|
|
|
$(".last-ping").tooltip({
|
|
|
|
selector: ".label-confirmation",
|
2024-11-14 07:23:44 +00:00
|
|
|
title: 'The word "confirm" was found in request body',
|
2020-10-14 10:13:22 +00:00
|
|
|
});
|
|
|
|
|
2024-01-22 13:20:09 +00:00
|
|
|
$("#my-checks-tags .btn").tooltip({
|
2024-11-14 07:23:44 +00:00
|
|
|
title: function () {
|
|
|
|
return this.getAttribute("data-tooltip");
|
|
|
|
},
|
2024-01-22 13:20:09 +00:00
|
|
|
});
|
|
|
|
|
2024-11-14 12:18:39 +00:00
|
|
|
function statusMatch(el, statuses) {
|
|
|
|
var statusClassList = el.querySelector(".status").classList;
|
|
|
|
// Go through currently active status filters, and, for each,
|
|
|
|
// check if the current check matches
|
|
|
|
for (const status of statuses) {
|
|
|
|
if (
|
|
|
|
status == "started" &&
|
|
|
|
el.querySelector(".spinner").classList.contains("started")
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (statusClassList.contains("ic-" + status)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-29 12:01:03 +00:00
|
|
|
function applyFilters() {
|
2023-05-09 07:14:30 +00:00
|
|
|
var url = new URL(window.location.href);
|
|
|
|
url.search = "";
|
2024-11-14 12:18:39 +00:00
|
|
|
|
|
|
|
// Checked tags
|
|
|
|
var checked = [];
|
2024-11-14 07:23:44 +00:00
|
|
|
$("#my-checks-tags .checked").each(function (index, el) {
|
2015-12-14 10:52:42 +00:00
|
|
|
checked.push(el.textContent);
|
2023-05-09 07:14:30 +00:00
|
|
|
url.searchParams.append("tag", el.textContent);
|
2015-12-14 10:52:42 +00:00
|
|
|
});
|
|
|
|
|
2024-11-14 12:18:39 +00:00
|
|
|
// Search string
|
2018-10-29 12:01:03 +00:00
|
|
|
var search = $("#search").val().toLowerCase();
|
|
|
|
if (search) {
|
2023-05-09 07:14:30 +00:00
|
|
|
url.searchParams.append("search", search);
|
2018-10-29 12:01:03 +00:00
|
|
|
}
|
|
|
|
|
2024-11-14 12:18:39 +00:00
|
|
|
// Status filters
|
2024-11-14 07:23:44 +00:00
|
|
|
var statuses = [];
|
|
|
|
$(".filter-btn:visible").each(function (index, el) {
|
|
|
|
statuses.push(el.dataset.value);
|
|
|
|
url.searchParams.append("status", el.dataset.value);
|
|
|
|
});
|
|
|
|
|
2018-10-12 09:52:48 +00:00
|
|
|
// Update hash
|
|
|
|
if (window.history && window.history.replaceState) {
|
2023-05-09 07:14:30 +00:00
|
|
|
window.history.replaceState({}, "", url.toString());
|
2018-10-12 09:52:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-09 07:14:30 +00:00
|
|
|
// Update sort links
|
|
|
|
document.querySelectorAll("a[data-sort-value]").forEach((a) => {
|
|
|
|
url.searchParams.set("sort", a.dataset.sortValue);
|
|
|
|
a.setAttribute("href", url.toString());
|
|
|
|
});
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
if (checked.length == 0 && !search && statuses.length == 0) {
|
2024-11-15 10:11:18 +00:00
|
|
|
// No checked tags, no search string, no status filters: show all
|
2015-12-14 10:52:42 +00:00
|
|
|
$("#checks-table tr.checks-row").show();
|
2024-11-15 10:11:18 +00:00
|
|
|
var numVisible = $("#checks-table tr.checks-row").length;
|
|
|
|
} else {
|
|
|
|
var numVisible = 0;
|
|
|
|
function applySingle(index, element) {
|
|
|
|
var nameData = element.querySelector(".my-checks-name").dataset;
|
|
|
|
if (search) {
|
|
|
|
var parts = [nameData.name, nameData.slug, element.id];
|
|
|
|
var haystack = parts.join("\n").toLowerCase();
|
|
|
|
if (haystack.indexOf(search) == -1) {
|
|
|
|
$(element).hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-12-14 10:52:42 +00:00
|
|
|
|
2024-11-15 10:11:18 +00:00
|
|
|
if (checked.length) {
|
|
|
|
var tags = nameData.tags.split(" ");
|
|
|
|
for (var i = 0, checkedTag; (checkedTag = checked[i]); i++) {
|
|
|
|
if (tags.indexOf(checkedTag) == -1) {
|
|
|
|
$(element).hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-12-14 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
2024-11-15 10:11:18 +00:00
|
|
|
if (statuses.length) {
|
|
|
|
if (!statusMatch(element, statuses)) {
|
2018-10-29 12:01:03 +00:00
|
|
|
$(element).hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-15 10:11:18 +00:00
|
|
|
$(element).show();
|
|
|
|
numVisible += 1;
|
2024-11-14 07:23:44 +00:00
|
|
|
}
|
|
|
|
|
2024-11-15 10:11:18 +00:00
|
|
|
// For each row, see if it needs to be shown or hidden
|
|
|
|
$("#checks-table tr.checks-row").each(applySingle);
|
2015-12-14 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
2024-11-15 10:11:18 +00:00
|
|
|
$("#checks-table").toggle(numVisible > 0);
|
|
|
|
$("#no-checks").toggle(numVisible == 0);
|
2018-10-29 12:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// User clicks on tags: apply filters
|
2024-11-14 07:23:44 +00:00
|
|
|
$("#my-checks-tags div").click(function () {
|
|
|
|
$(this).toggleClass("checked");
|
2018-10-29 12:01:03 +00:00
|
|
|
applyFilters();
|
2015-12-14 10:52:42 +00:00
|
|
|
});
|
|
|
|
|
2018-10-29 12:01:03 +00:00
|
|
|
// User changes the search string: apply filters
|
|
|
|
$("#search").keyup(applyFilters);
|
|
|
|
|
2024-09-30 07:29:30 +00:00
|
|
|
function switchUrlFormat(format) {
|
|
|
|
var url = new URL(window.location.href);
|
|
|
|
url.searchParams.delete("urls");
|
|
|
|
url.searchParams.append("urls", format);
|
|
|
|
window.location.href = url.toString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$("#to-uuid").click((e) => switchUrlFormat("uuid"));
|
|
|
|
$("#to-slug").click((e) => switchUrlFormat("slug"));
|
2024-09-30 07:29:30 +00:00
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$(".show-log").click(function (e) {
|
2018-06-15 08:40:54 +00:00
|
|
|
var code = $(this).closest("tr.checks-row").attr("id");
|
2019-08-12 20:29:32 +00:00
|
|
|
var url = base + "/checks/" + code + "/details/";
|
2018-06-15 08:40:54 +00:00
|
|
|
window.location = url;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2020-04-20 14:09:48 +00:00
|
|
|
$(".pause").tooltip({
|
|
|
|
title: "Pause this check?<br />Click again to confirm.",
|
|
|
|
trigger: "manual",
|
2024-11-14 07:23:44 +00:00
|
|
|
html: true,
|
2020-04-20 14:09:48 +00:00
|
|
|
});
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$(".pause").click(function () {
|
2020-04-20 14:09:48 +00:00
|
|
|
var btn = $(this);
|
|
|
|
|
|
|
|
// First click: show a confirmation tooltip
|
|
|
|
if (!btn.hasClass("confirm")) {
|
|
|
|
btn.addClass("confirm").tooltip("show");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second click: update UI and pause the check
|
|
|
|
btn.removeClass("confirm").tooltip("hide");
|
|
|
|
var code = btn.closest("tr.checks-row").attr("id");
|
2021-02-03 08:44:35 +00:00
|
|
|
$("#" + code + " span.status").attr("class", "status ic-paused");
|
2020-01-21 09:57:17 +00:00
|
|
|
|
|
|
|
var url = base + "/checks/" + code + "/pause/";
|
2024-11-14 07:23:44 +00:00
|
|
|
var token = $("input[name=csrfmiddlewaretoken]").val();
|
2020-01-21 09:57:17 +00:00
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: "post",
|
2024-11-14 07:23:44 +00:00
|
|
|
headers: { "X-CSRFToken": token },
|
2020-01-21 09:57:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$(".pause").mouseleave(function () {
|
2020-04-20 14:09:48 +00:00
|
|
|
$(this).removeClass("confirm").tooltip("hide");
|
|
|
|
});
|
|
|
|
|
2018-02-24 22:00:37 +00:00
|
|
|
$('[data-toggle="tooltip"]').tooltip({
|
2018-05-25 17:20:58 +00:00
|
|
|
html: true,
|
2018-06-11 08:31:28 +00:00
|
|
|
container: "body",
|
2024-11-14 07:23:44 +00:00
|
|
|
title: function () {
|
2018-02-24 22:00:37 +00:00
|
|
|
var cssClasses = this.getAttribute("class");
|
2021-02-03 08:44:35 +00:00
|
|
|
if (cssClasses.indexOf("ic-new") > -1)
|
2018-02-24 22:00:37 +00:00
|
|
|
return "New. Has never received a ping.";
|
2021-02-03 08:44:35 +00:00
|
|
|
if (cssClasses.indexOf("ic-paused") > -1)
|
2018-02-24 22:00:37 +00:00
|
|
|
return "Monitoring paused. Ping to resume.";
|
2018-05-25 17:20:58 +00:00
|
|
|
|
|
|
|
if (cssClasses.indexOf("sort-name") > -1)
|
|
|
|
return "Sort by name<br />(but failed always first)";
|
|
|
|
|
|
|
|
if (cssClasses.indexOf("sort-last-ping") > -1)
|
|
|
|
return "Sort by last ping<br />(but failed always first)";
|
2024-11-14 07:23:44 +00:00
|
|
|
},
|
2018-02-24 22:00:37 +00:00
|
|
|
});
|
2016-08-01 18:57:11 +00:00
|
|
|
|
2018-08-17 17:53:50 +00:00
|
|
|
// Schedule refresh to run every 3s when tab is visible and user
|
|
|
|
// is active, every 60s otherwise
|
2018-02-26 10:10:56 +00:00
|
|
|
var lastStatus = {};
|
2020-06-25 13:44:25 +00:00
|
|
|
var lastStarted = {};
|
2018-02-26 10:10:56 +00:00
|
|
|
var lastPing = {};
|
2018-11-29 13:00:01 +00:00
|
|
|
var statusUrl = $("#checks-table").data("status-url");
|
|
|
|
function refreshStatus() {
|
2018-02-26 10:10:56 +00:00
|
|
|
$.ajax({
|
2018-11-29 13:00:01 +00:00
|
|
|
url: statusUrl,
|
2018-02-26 10:10:56 +00:00
|
|
|
dataType: "json",
|
|
|
|
timeout: 2000,
|
2024-11-14 07:23:44 +00:00
|
|
|
success: function (data) {
|
2024-11-14 09:57:30 +00:00
|
|
|
var statusChanged = false;
|
2024-11-14 07:23:44 +00:00
|
|
|
for (var i = 0, el; (el = data.details[i]); i++) {
|
2018-02-26 10:10:56 +00:00
|
|
|
if (lastStatus[el.code] != el.status) {
|
|
|
|
lastStatus[el.code] = el.status;
|
2024-11-14 07:23:44 +00:00
|
|
|
$("#" + el.code + " span.status").attr(
|
|
|
|
"class",
|
|
|
|
"status ic-" + el.status,
|
|
|
|
);
|
2024-11-14 09:57:30 +00:00
|
|
|
statusChanged = true;
|
2018-02-26 10:10:56 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 13:44:25 +00:00
|
|
|
if (lastStarted[el.code] != el.started) {
|
|
|
|
lastStarted[el.code] = el.started;
|
2024-11-14 07:23:44 +00:00
|
|
|
$("#" + el.code + " .spinner").toggleClass(
|
|
|
|
"started",
|
|
|
|
el.started,
|
|
|
|
);
|
2024-11-14 09:57:30 +00:00
|
|
|
statusChanged = true;
|
2020-06-25 13:44:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 10:10:56 +00:00
|
|
|
if (lastPing[el.code] != el.last_ping) {
|
|
|
|
lastPing[el.code] = el.last_ping;
|
2022-06-27 07:05:32 +00:00
|
|
|
$("#" + el.code + " .last-ping").html(el.last_ping);
|
2018-02-26 10:10:56 +00:00
|
|
|
}
|
2018-02-24 22:00:37 +00:00
|
|
|
}
|
2018-02-26 10:10:56 +00:00
|
|
|
|
2024-11-14 09:57:30 +00:00
|
|
|
// If there were status updates and we have active status filters
|
|
|
|
// then we need to reapply filters now:
|
|
|
|
if (statusChanged && $(".filter-btn:visible").length) {
|
2024-11-14 07:23:44 +00:00
|
|
|
applyFilters();
|
|
|
|
}
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$("#my-checks-tags > div.btn").each(function (a) {
|
2024-01-22 13:20:09 +00:00
|
|
|
tag = this.innerText;
|
|
|
|
this.setAttribute("data-tooltip", data.tags[tag][1]);
|
|
|
|
var status = data.tags[tag][0];
|
|
|
|
if (lastStatus[tag] != status) {
|
|
|
|
$(this).removeClass("up grace down").addClass(status);
|
|
|
|
lastStatus[tag] = status;
|
|
|
|
}
|
2018-02-26 10:10:56 +00:00
|
|
|
});
|
2018-06-04 19:31:12 +00:00
|
|
|
|
|
|
|
if (document.title != data.title) {
|
|
|
|
document.title = data.title;
|
2024-11-14 12:18:39 +00:00
|
|
|
var downPostfix = data.title.includes("down") ? "_down" : "";
|
2024-03-26 15:28:47 +00:00
|
|
|
favicon.href = `${base}/static/img/favicon${downPostfix}.svg`;
|
2018-06-04 19:31:12 +00:00
|
|
|
}
|
2024-11-14 07:23:44 +00:00
|
|
|
},
|
2018-02-24 22:00:37 +00:00
|
|
|
});
|
2018-11-29 13:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Schedule regular status updates:
|
|
|
|
if (statusUrl) {
|
|
|
|
adaptiveSetInterval(refreshStatus);
|
|
|
|
}
|
2018-02-25 23:36:59 +00:00
|
|
|
|
2020-03-05 13:49:42 +00:00
|
|
|
// Configure Selectize for entering tags
|
2020-03-09 08:16:39 +00:00
|
|
|
function divToOption() {
|
2024-11-14 07:23:44 +00:00
|
|
|
return { value: this.textContent };
|
2020-03-09 08:16:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 13:49:42 +00:00
|
|
|
$("#update-tags-input").selectize({
|
|
|
|
create: true,
|
|
|
|
createOnBlur: true,
|
2022-06-29 08:14:49 +00:00
|
|
|
selectOnTab: false,
|
2020-03-05 13:49:42 +00:00
|
|
|
delimiter: " ",
|
|
|
|
labelField: "value",
|
|
|
|
searchField: ["value"],
|
|
|
|
hideSelected: true,
|
2020-03-09 08:16:39 +00:00
|
|
|
highlight: false,
|
2024-11-14 07:23:44 +00:00
|
|
|
options: $("#my-checks-tags div").map(divToOption).get(),
|
2020-03-05 13:49:42 +00:00
|
|
|
});
|
|
|
|
|
2024-11-14 07:23:44 +00:00
|
|
|
$(".my-checks-url").tooltip({ container: "body", title: "Click to copy" });
|
|
|
|
$(".my-checks-url").click(function (e) {
|
2022-12-15 09:39:58 +00:00
|
|
|
if (window.getSelection().toString()) {
|
|
|
|
// do nothing, selection not empty
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
navigator.clipboard.writeText(this.textContent);
|
|
|
|
$(".tooltip-inner").text("Copied!");
|
|
|
|
});
|
2024-11-14 07:23:44 +00:00
|
|
|
|
|
|
|
$("#check-filters button[title]").tooltip();
|
|
|
|
|
|
|
|
$("#filters li a").click(function () {
|
|
|
|
var v = this.dataset.value;
|
|
|
|
$("#check-filters button[data-value=" + v + "]").toggle();
|
|
|
|
applyFilters();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".filter-btn").click(function () {
|
|
|
|
$(this).hide();
|
|
|
|
applyFilters();
|
|
|
|
});
|
2024-11-14 07:23:44 +00:00
|
|
|
});
|