From 843eb800602be8cbc432382d19d33c5872b7a2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 19 Aug 2017 18:25:52 -0700 Subject: [PATCH] Add button to toggle annotation visibility If user make annotation hidden by default, then render a button that allows to show it per label --- assets/static/alerts.js | 1 + assets/static/templates.js | 3 ++- assets/static/ui.js | 22 ++++++++++++++++++++++ assets/templates/alertgroup.html | 31 +++++++++++++++++++++---------- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/assets/static/alerts.js b/assets/static/alerts.js index 830afe7e2..1ed950ea9 100644 --- a/assets/static/alerts.js +++ b/assets/static/alerts.js @@ -33,6 +33,7 @@ AlertGroup.prototype.Added = function() { var elem = $("#" + this.id); ui.setupGroupTooltips(elem); ui.setupGroupLinkHover(elem); + ui.setupGroupAnnotationToggles(elem); }; AlertGroup.prototype.Update = function() { diff --git a/assets/static/templates.js b/assets/static/templates.js index ddaedaab3..9012b87d9 100644 --- a/assets/static/templates.js +++ b/assets/static/templates.js @@ -36,8 +36,9 @@ var templates = {}, silenceFormFatal: "#silence-form-fatal", silenceFormLoading: "#silence-form-loading", - // label button + // alert partials buttonLabel: "#label-button-filter", + alertAnnotation: "#alert-annotation", // alert group alertGroup: "#alert-group", diff --git a/assets/static/ui.js b/assets/static/ui.js index 2849a75a3..c12a2a2b5 100644 --- a/assets/static/ui.js +++ b/assets/static/ui.js @@ -75,6 +75,28 @@ function setupGroupTooltips(groupElem) { }); } +function setupGroupAnnotationToggles(groupElem) { + $(groupElem).on("click", "[data-toggle=toggle-hidden-annotation]", function() { + var alert = $(this).parent(); + var icon = $(this).find("i.fa"); + var showingHidden = icon.hasClass("fa-search-minus"); + if (showingHidden) { + // we're currently showing hidden annotations, so the action is to hide them + icon.removeClass("fa-search-minus").addClass("fa-search-plus"); + $.each(alert.find(".hidden-annotation"), function(i, annotation){ + $(annotation).addClass("hidden"); + }); + } else { + // we're currently hiding hidden annotations, so the action is to show them + icon.removeClass("fa-search-plus").addClass("fa-search-minus"); + $.each(alert.find(".hidden-annotation"), function(i, annotation){ + $(annotation).removeClass("hidden"); + }); + } + }); +} + exports.setupModal = setupModal; exports.setupGroupTooltips = setupGroupTooltips; exports.setupGroupLinkHover = setupGroupLinkHover; +exports.setupGroupAnnotationToggles = setupGroupAnnotationToggles; diff --git a/assets/templates/alertgroup.html b/assets/templates/alertgroup.html index e7e31bcc2..a5a0faa1b 100644 --- a/assets/templates/alertgroup.html +++ b/assets/templates/alertgroup.html @@ -27,20 +27,20 @@ + +