@@ -35,6 +35,7 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
3535 fetchedPages = [ ] ,
3636 busy = false ,
3737 nextPageUrl = '/api/v1/subnet/' + current_subnet + '/hosts/' ,
38+ searchQuery = '' ,
3839 lastRenderedPage = 0 ; //1 based indexing (0 -> no page rendered)
3940 function addressListItem ( addr ) {
4041 var id = normalizeIP ( addr . address ) ;
@@ -58,6 +59,41 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
5859 } ) ;
5960 return div ;
6061 }
62+ async function validateIp ( ip_address ) {
63+ if ( ip_address === '' ) return true ;
64+ var isValid = false ;
65+ await $ . ajax ( {
66+ type : 'GET' ,
67+ url : '/api/v1/subnet/' + current_subnet + '/hosts/?start=' + ip_address ,
68+ success : function ( res ) {
69+ isValid = ( res . results [ 0 ] . address == ip_address ) ;
70+ } ,
71+ error : function ( error ) {
72+ busy = false ;
73+ throw error ;
74+ } ,
75+ } ) ;
76+ return isValid ;
77+ }
78+ function goTo ( ) {
79+ var input = $ ( "#goto-input" ) . val ( ) . toLowerCase ( ) . trim ( ) ;
80+ validateIp ( input ) . then ( isValid => {
81+ if ( isValid ) {
82+ $ ( "#invalid-address" ) . hide ( ) ;
83+ if ( input !== searchQuery ) {
84+ searchQuery = input ;
85+ nextPageUrl = '/api/v1/subnet/' + current_subnet + '/hosts/?start=' + searchQuery ;
86+ $ ( '#subnet-visual' ) . empty ( ) ;
87+ fetchedPages = [ ] ;
88+ lastRenderedPage = 0 ;
89+ busy = false ;
90+ onUpdate ( ) ;
91+ }
92+ } else {
93+ $ ( "#invalid-address" ) . show ( ) ;
94+ }
95+ } ) ;
96+ }
6197 function appendPage ( ) {
6298 $ ( '.subnet-visual' ) . append ( pageContainer ( fetchedPages [ lastRenderedPage ] ) ) ;
6399 if ( lastRenderedPage >= renderedPages ) {
@@ -117,6 +153,9 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
117153 }
118154 }
119155 }
156+ $ ( "#goto-button" ) . on ( "click" , function ( ) {
157+ goTo ( ) ;
158+ } ) ;
120159 $ ( '.subnet-visual' ) . scroll ( onUpdate ) ;
121160 onUpdate ( ) ;
122161}
0 commit comments