From 2a68f56a3adc0e92bd1ed768900101b7aa067c7c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 3 Sep 2023 19:56:20 +0200 Subject: [PATCH 1/4] Add UI-related antigravity changes Signed-off-by: DL6ER --- groups-adlists.lp => groups-lists.lp | 15 ++++++++---- scripts/pi-hole/js/groups-adlists.js | 35 +++++++++++++++++++++------- scripts/pi-hole/lua/sidebar.lp | 10 ++++---- 3 files changed, 42 insertions(+), 18 deletions(-) rename groups-adlists.lp => groups-lists.lp (84%) diff --git a/groups-adlists.lp b/groups-lists.lp similarity index 84% rename from groups-adlists.lp rename to groups-lists.lp index 953dedf4b..8b212791f 100644 --- a/groups-adlists.lp +++ b/groups-lists.lp @@ -12,7 +12,7 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r') @@ -22,7 +22,7 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')

- Add a new adlist + Add a new subscribed list

@@ -45,7 +45,14 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')
  • Multiple adlists can be added by separating each unique URL with a space
  • Click on the icon in the first column to get additional information about your lists. The icons correspond to the health of the list.
  • - + @@ -55,7 +62,7 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')

    - List of adlists + List of subscribed lists

    diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index 8889d4987..8bffae22b 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -13,7 +13,8 @@ var GETDict = {}; $(function () { GETDict = utils.parseQueryString(); - $("#btnAdd").on("click", addAdlist); + $("#btnAddAllow").on("click", { type: "allow" }, addAdlist); + $("#btnAddBlock").on("click", { type: "block" }, addAdlist); utils.setBsSelectDefaults(); initTable(); @@ -59,7 +60,9 @@ function format(data) { // Compile extra info for displaying return ( "" + - '
    Health status of this list:' + + '
    Type of this list:' + + data.type + + 'list
    Health status of this list:' + statusText + '
    This list was added to Pi-hole  ' + utils.datetimeRelative(data.date_added) + @@ -170,9 +173,22 @@ function initTable() { break; } + // Add red minus sign icon if data["type"] is "block" + // Add green plus sign icon if data["type"] is "allow" + let status = + ""; + if (data.type === "block") { + status = ""; + } else if (data.type === "allow") { + status = ""; + } + $("td:eq(1)", row).addClass("list-status-" + statusCode); $("td:eq(1)", row).html( - "" + "" + + status ); if (data.address.startsWith("file://")) { @@ -480,17 +496,18 @@ function delItems(ids) { }); } -function addAdlist() { +function addAdlist(event) { + const type = event.data.type; const address = utils.escapeHtml($("#new_address").val()); const comment = utils.escapeHtml($("#new_comment").val()); utils.disableAll(); - utils.showAlert("info", "", "Adding adlist...", address); + utils.showAlert("info", "", "Adding subscribed " + type + "list...", address); if (address.length === 0) { // enable the ui elements again utils.enableAll(); - utils.showAlert("warning", "", "Warning", "Please specify an adlist address"); + utils.showAlert("warning", "", "Warning", "Please specify " + type + "list address"); return; } @@ -498,10 +515,10 @@ function addAdlist() { url: "/api/lists", method: "post", dataType: "json", - data: JSON.stringify({ address: address, comment: comment }), + data: JSON.stringify({ address: address, comment: comment, type: type }), success: function () { utils.enableAll(); - utils.showAlert("success", "fas fa-plus", "Successfully added list", address); + utils.showAlert("success", "fas fa-plus", "Successfully added " + type + "list", address); table.ajax.reload(null, false); table.rows().deselect(); @@ -511,7 +528,7 @@ function addAdlist() { error: function (data, exception) { apiFailure(data); utils.enableAll(); - utils.showAlert("error", "", "Error while adding new list", data.responseText); + utils.showAlert("error", "", "Error while adding new " + type + "list", data.responseText); console.log(exception); // eslint-disable-line no-console }, }); diff --git a/scripts/pi-hole/lua/sidebar.lp b/scripts/pi-hole/lua/sidebar.lp index 4087c2882..7f7166352 100644 --- a/scripts/pi-hole/lua/sidebar.lp +++ b/scripts/pi-hole/lua/sidebar.lp @@ -66,12 +66,12 @@ - From 3a9144d3b7ae36958418f94b20f0bef48888d1df Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 13 Sep 2023 17:01:07 +0200 Subject: [PATCH 2/4] Always show regex ID when available Signed-off-by: DL6ER --- scripts/pi-hole/js/queries.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 1b95f8e4e..4be813863 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -83,8 +83,7 @@ function parseQueryStatus(data) { buttontext, icon = null, colorClass = false, - isCNAME = false, - regexLink = false; + isCNAME = false; switch (data.status) { case "GRAVITY": colorClass = "text-red"; @@ -111,7 +110,6 @@ function parseQueryStatus(data) { colorClass = "text-red"; icon = "fa-solid fa-ban"; fieldtext = "Blocked (regex)"; - regexLink = data.regex_id > 0; buttontext = ''; break; @@ -152,7 +150,6 @@ function parseQueryStatus(data) { colorClass = "text-red"; icon = "fa-solid fa-ban"; fieldtext = "Blocked (regex denied, CNAME)"; - regexLink = data.regex_id > 0; buttontext = ''; isCNAME = true; @@ -160,7 +157,7 @@ function parseQueryStatus(data) { case "DENYLIST_CNAME": colorClass = "text-red"; icon = "fa-solid fa-ban"; - fieldtext = "Blocked (exact diened, CNAME)"; + fieldtext = "Blocked (exact denied, CNAME)"; buttontext = ''; isCNAME = true; @@ -198,13 +195,16 @@ function parseQueryStatus(data) { buttontext = ""; } + var matchText = + colorClass === "text-green" ? "allowed" : colorClass === "text-red" ? "blocked" : "matched"; + return { fieldtext: fieldtext, buttontext: buttontext, colorClass: colorClass, icon: icon, isCNAME: isCNAME, - regexLink: regexLink, + matchText: matchText, }; } @@ -248,14 +248,15 @@ function formatInfo(data) { var regexInfo = "", cnameInfo = ""; - if (queryStatus.regexLink) { + if (data.regex_id !== null && data.regex_id > -1) { var regexLink = 'Regex ID ' + + '" target="_blank">regex ID ' + data.regex_id + ""; - regexInfo = divStart + "Query was blocked by: " + regexLink + ""; + regexInfo = + divStart + "Query was " + queryStatus.matchText + " by " + regexLink + ""; } if (queryStatus.isCNAME) { From 60ed8d2352fce23bb91cd9e91c2d6e5c4b8b6be1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 27 Sep 2023 21:31:03 +0200 Subject: [PATCH 3/4] Ensure type is transmitted when editing lists Signed-off-by: DL6ER --- scripts/pi-hole/js/groups-adlists.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index 8bffae22b..e2d0c47b1 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -534,7 +534,8 @@ function addAdlist(event) { }); } -function editAdlist() { +function editAdlist(event) { + const type = event.data.type; const elem = $(this).attr("id"); const tr = $(this).closest("tr"); const address = tr.attr("data-id"); @@ -584,6 +585,7 @@ function editAdlist() { groups: groups, comment: comment, enabled: enabled, + type: type, }), success: function () { utils.enableAll(); From 7daf75044a23b1b243544a631b30d01ae4773e99 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 27 Sep 2023 19:13:22 -0300 Subject: [PATCH 4/4] Passing the type using the `data-type` attribute Fix the "Cannot read properties of undefined" error: - The `function editAdlist(event)` wasn't receiving any arguments, because every call to this function is not passing arguments, so `event` was undefined. Using `data-type` attribute to pass the value and avoid the error. Signed-off-by: RD WebDesign --- scripts/pi-hole/js/groups-adlists.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js index e2d0c47b1..84ff709c2 100644 --- a/scripts/pi-hole/js/groups-adlists.js +++ b/scripts/pi-hole/js/groups-adlists.js @@ -146,6 +146,7 @@ function initTable() { rowCallback: function (row, data) { var dataId = utils.hexEncode(data.address); $(row).attr("data-id", dataId); + $(row).attr("data-type", data.type); var statusCode = 0, statusIcon; @@ -534,10 +535,10 @@ function addAdlist(event) { }); } -function editAdlist(event) { - const type = event.data.type; +function editAdlist() { const elem = $(this).attr("id"); const tr = $(this).closest("tr"); + const type = tr.attr("data-type"); const address = tr.attr("data-id"); const status = tr.find("#enabled_" + address).is(":checked"); const comment = utils.escapeHtml(tr.find("#comment_" + address).val());