Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions openwisp_ipam/static/openwisp-ipam/js/subnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
fetchedPages = [],
busy = false,
nextPageUrl = '/api/v1/subnet/' + current_subnet + '/hosts/',
searchQuery = '',
lastRenderedPage = 0; //1 based indexing (0 -> no page rendered)
function addressListItem(addr) {
var id = normalizeIP(addr.address);
Expand All @@ -58,6 +59,42 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
});
return div;
}
function validateIp(ip_address, callback) {
if (ip_address === '') {
callback(true);
return;
}
$.ajax({
type: 'GET',
url: '/api/v1/subnet/' + current_subnet + '/hosts/?start=' + ip_address,
success: function (res) {
callback(res.results[0].address === ip_address);
},
error: function (error) {
callback(false);
throw error;
},
});
}
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/subnet/' + current_subnet + '/hosts/?start=' + searchQuery;
$('#subnet-visual').empty();
fetchedPages = [];
lastRenderedPage = 0;
busy = false;
onUpdate();
}
} else {
$("#invalid-address").show();
}
});
}
function appendPage() {
$('.subnet-visual').append(pageContainer(fetchedPages[lastRenderedPage]));
if (lastRenderedPage >= renderedPages) {
Expand Down Expand Up @@ -117,6 +154,9 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
}
}
}
$("#goto-button").on("click", function () {
goTo();
});
$('.subnet-visual').scroll(onUpdate);
onUpdate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ <h2>{% trans 'Network Hierarchical View' %}</h2>
<div id="graph"></div>

<h3>{% trans 'Subnet Visual Display' %}</h3>
<section class="subnet-visual{% if original.subnet.version == 6 %} ipv6{% endif %}">
<div>
<form onsubmit="return false">
<input id="goto-input" onkeypress="return event.keyCode != 13;" placeholder="Jump to" />
<input id="goto-button" type="button" value="Go" />
</form>
<ul id="invalid-address" class="errorlist" style="display:none;">
<li>Address not valid for subnet</li>
</ul>
</div>
<section id="subnet-visual" class="subnet-visual{% if original.subnet.version == 6 %} ipv6{% endif %}">
</section>
{% endif %}
{% endblock %}
Expand All @@ -37,6 +46,12 @@ <h3>{% trans 'Subnet Visual Display' %}</h3>
{{ block.super }}
{% if original and not is_popup %}
<script type="text/javascript">
document.querySelector("#goto-input").addEventListener("keyup", function (event) {
event.preventDefault();
if (event.key == "Enter") {
document.querySelector("#goto-button").click();
}
});
Comment thread
purhan marked this conversation as resolved.
var current_subnet = '{{ original.pk }}';
var IpAddUrl = '{% url ipaddress_add_url %}'
var IpChangeUrl = '{% url ipaddress_change_url "1234" %}'
Expand Down