2023-05-10 12:38:13 +00:00
|
|
|
function expandAll() {
|
2024-02-20 12:07:05 +00:00
|
|
|
$('.group-heading').each(function () {
|
|
|
|
let style = $(this).attr("style")
|
|
|
|
// display only elements that are currently visible
|
|
|
|
if (style === "display: none;") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
$(this).next().addClass('show')
|
|
|
|
});
|
2023-05-10 12:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function collapseAll() {
|
|
|
|
$('.collapse').removeClass('show');
|
|
|
|
}
|
|
|
|
|
2024-04-22 13:02:10 +00:00
|
|
|
function showByID(id) {
|
|
|
|
if (!id) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let parent = $("#" + id).parent();
|
|
|
|
if (!parent) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let target = $("#" + parent.attr("data-bs-target"));
|
|
|
|
if (target.length > 0) {
|
|
|
|
target.addClass('show');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-10 12:38:13 +00:00
|
|
|
function toggleByID(id) {
|
2023-07-03 12:59:52 +00:00
|
|
|
if (id) {
|
|
|
|
let el = $("#" + id);
|
|
|
|
if (el.length > 0) {
|
|
|
|
el.click();
|
|
|
|
}
|
2023-05-10 12:38:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-20 11:31:41 +00:00
|
|
|
function debounce(func, delay) {
|
|
|
|
let timer;
|
2024-02-20 12:07:05 +00:00
|
|
|
return function (...args) {
|
2024-02-20 11:31:41 +00:00
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
func.apply(this, args);
|
|
|
|
}, delay);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
$('#search').on("keyup", debounce(search, 500));
|
2024-02-20 11:31:41 +00:00
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
// search shows or hides groups&rules that satisfy the search phrase.
|
|
|
|
// case-insensitive, respects GET param `search`.
|
|
|
|
function search() {
|
2024-02-20 11:31:41 +00:00
|
|
|
$(".rule").show();
|
2024-02-20 12:07:05 +00:00
|
|
|
|
|
|
|
let groupHeader = $(".group-heading")
|
|
|
|
let searchPhrase = $("#search").val().toLowerCase()
|
|
|
|
if (searchPhrase.length === 0) {
|
|
|
|
groupHeader.show()
|
|
|
|
setParamURL('search', '')
|
2024-02-20 11:31:41 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
$(".rule-table").removeClass('show');
|
|
|
|
groupHeader.hide()
|
|
|
|
|
|
|
|
searchPhrase = searchPhrase.toLowerCase()
|
|
|
|
filterRuleByName(searchPhrase);
|
|
|
|
filterRuleByLabels(searchPhrase);
|
|
|
|
filterGroupsByName(searchPhrase);
|
2024-02-20 11:31:41 +00:00
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
setParamURL('search', searchPhrase)
|
2024-02-20 11:31:41 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
function setParamURL(key, value) {
|
|
|
|
let url = new URL(location.href)
|
|
|
|
url.searchParams.set(key, value);
|
2024-04-22 13:02:10 +00:00
|
|
|
window.history.replaceState(null, null, `?${url.searchParams.toString()}${url.hash}`);
|
2024-02-20 12:07:05 +00:00
|
|
|
}
|
2024-02-20 11:31:41 +00:00
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
function getParamURL(key) {
|
|
|
|
let url = new URL(location.href)
|
|
|
|
return url.searchParams.get(key)
|
2024-02-20 11:31:41 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
function filterGroupsByName(searchPhrase) {
|
|
|
|
$(".group-heading").each(function () {
|
|
|
|
const groupName = $(this).attr('data-group-name').toLowerCase();
|
|
|
|
const hasValue = groupName.indexOf(searchPhrase) >= 0
|
2024-02-20 11:31:41 +00:00
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
if (!hasValue) {
|
|
|
|
return
|
|
|
|
}
|
2024-02-20 11:31:41 +00:00
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
const target = $(this).attr("data-bs-target");
|
|
|
|
$(`div[id="${target}"] .rule`).show();
|
|
|
|
$(this).show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterRuleByName(searchPhrase) {
|
|
|
|
$(".rule").each(function () {
|
|
|
|
const ruleName = $(this).attr("data-rule-name").toLowerCase();
|
|
|
|
const hasValue = ruleName.indexOf(searchPhrase) >= 0
|
|
|
|
if (!hasValue) {
|
2024-02-20 11:31:41 +00:00
|
|
|
$(this).hide();
|
2024-02-20 12:07:05 +00:00
|
|
|
return
|
2024-02-20 11:31:41 +00:00
|
|
|
}
|
2024-02-20 12:07:05 +00:00
|
|
|
|
|
|
|
const target = $(this).attr('data-bs-target')
|
|
|
|
$(`#rules-${target}`).addClass('show');
|
|
|
|
$(`div[data-bs-target='rules-${target}']`).show();
|
|
|
|
$(this).show();
|
|
|
|
});
|
2024-02-20 11:31:41 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
function filterRuleByLabels(searchPhrase) {
|
|
|
|
$(".rule").each(function () {
|
|
|
|
const matches = $(".label", this).filter(function () {
|
|
|
|
const label = $(this).text().toLowerCase();
|
|
|
|
return label.indexOf(searchPhrase) >= 0;
|
|
|
|
}).length;
|
2024-02-20 11:31:41 +00:00
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
if (matches > 0) {
|
|
|
|
const target = $(this).attr('data-bs-target')
|
2024-02-20 11:31:41 +00:00
|
|
|
$(`#rules-${target}`).addClass('show');
|
|
|
|
$(`div[data-bs-target='rules-${target}']`).show();
|
|
|
|
$(this).show();
|
|
|
|
}
|
2024-02-20 12:07:05 +00:00
|
|
|
});
|
2024-02-20 11:31:41 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 12:38:13 +00:00
|
|
|
$(document).ready(function () {
|
|
|
|
$(".group-heading a").click(function (e) {
|
|
|
|
e.stopPropagation(); // prevent collapse logic on link click
|
|
|
|
let target = $(this).attr('href');
|
|
|
|
if (target.length > 0) {
|
|
|
|
toggleByID(target.substr(1));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".group-heading").click(function (e) {
|
|
|
|
let target = $(this).attr('data-bs-target');
|
|
|
|
let el = $("#" + target);
|
|
|
|
new bootstrap.Collapse(el, {
|
|
|
|
toggle: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-02-20 12:07:05 +00:00
|
|
|
// update search element with value from URL, if any
|
|
|
|
let searchPhrase = getParamURL('search')
|
|
|
|
$("#search").val(searchPhrase)
|
|
|
|
|
|
|
|
// apply filtering by search phrase
|
|
|
|
search()
|
|
|
|
|
2023-05-10 12:38:13 +00:00
|
|
|
let hash = window.location.hash.substr(1);
|
2024-04-22 13:02:10 +00:00
|
|
|
showByID(hash);
|
2023-05-10 12:38:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
$('[data-bs-toggle="tooltip"]').tooltip();
|
2023-07-03 12:59:52 +00:00
|
|
|
});
|