diff --git a/openwisp_ipam/static/openwisp-ipam/css/admin.css b/openwisp_ipam/static/openwisp-ipam/css/admin.css index ecde0f1..72f5803 100644 --- a/openwisp_ipam/static/openwisp-ipam/css/admin.css +++ b/openwisp_ipam/static/openwisp-ipam/css/admin.css @@ -41,7 +41,6 @@ section.subnet-visual { background: rgba(149, 10, 10, 1); border: 1px solid rgba(0, 0, 0, 0.4); } - .subnet-visual .page { display: inline; } diff --git a/openwisp_ipam/static/openwisp-ipam/js/subnet.js b/openwisp_ipam/static/openwisp-ipam/js/subnet.js index 4807c07..47a27e3 100644 --- a/openwisp_ipam/static/openwisp-ipam/js/subnet.js +++ b/openwisp_ipam/static/openwisp-ipam/js/subnet.js @@ -56,6 +56,7 @@ function initHostsInfiniteScroll( var id = normalizeIP(addr.address); if (addr.used) { var uuid = ip_uuid[addr.address]; + var id_attr = 'id="addr_' + id + '"'; //note 1234 was passed as a dummy to be later on replaced in the script return ( '' + + '" ' + + id_attr + + ' onclick="return showAddAnotherPopup(this);">' + addr.address + "" ); @@ -111,20 +114,38 @@ function initHostsInfiniteScroll( function goTo() { var input = $("#goto-input").val().toLowerCase().trim(); validateIp(input, function (isValid) { - if (isValid) { - $("#invalid-address").hide(); - if (input !== searchQuery) { - searchQuery = input; - nextPageUrl = - "/api/v1/ipam/subnet/" + current_subnet + "/hosts/?start=" + searchQuery; - $("#subnet-visual").empty(); - fetchedPages = []; - lastRenderedPage = 0; - busy = false; - onUpdate(); - } - } else { + if (!isValid) { $("#invalid-address").show(); + return; + } + $("#invalid-address").hide(); + var id = normalizeIP(input); + var target = $("#addr_" + id); + if (target.length) { + // IP is already on the page + $("#subnet-visual").animate( + { + scrollTop: + target.offset().top - + $("#subnet-visual").offset().top + + $("#subnet-visual").scrollTop(), + }, + 500, + ); + target.css("background-color", "yellow"); + setTimeout(function () { + target.css("background-color", ""); + }, 500); + } else { + // IP not on page, re-fetch + searchQuery = input; + nextPageUrl = + "/api/v1/ipam/subnet/" + current_subnet + "/hosts/?start=" + searchQuery; + $("#subnet-visual").empty(); + fetchedPages = []; + lastRenderedPage = 0; + busy = false; + onUpdate(); } }); }