@@ -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,42 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
5859 } ) ;
5960 return div ;
6061 }
62+ function validateIp ( ip_address , callback ) {
63+ if ( ip_address === '' ) {
64+ callback ( true ) ;
65+ return ;
66+ }
67+ $ . ajax ( {
68+ type : 'GET' ,
69+ url : '/api/v1/subnet/' + current_subnet + '/hosts/?start=' + ip_address ,
70+ success : function ( res ) {
71+ callback ( res . results [ 0 ] . address === ip_address ) ;
72+ } ,
73+ error : function ( error ) {
74+ callback ( false ) ;
75+ throw error ;
76+ } ,
77+ } ) ;
78+ }
79+ function goTo ( ) {
80+ var input = $ ( "#goto-input" ) . val ( ) . toLowerCase ( ) . trim ( ) ;
81+ validateIp ( input , function ( isValid ) {
82+ if ( isValid ) {
83+ $ ( "#invalid-address" ) . hide ( ) ;
84+ if ( input !== searchQuery ) {
85+ searchQuery = input ;
86+ nextPageUrl = '/api/v1/subnet/' + current_subnet + '/hosts/?start=' + searchQuery ;
87+ $ ( '#subnet-visual' ) . empty ( ) ;
88+ fetchedPages = [ ] ;
89+ lastRenderedPage = 0 ;
90+ busy = false ;
91+ onUpdate ( ) ;
92+ }
93+ } else {
94+ $ ( "#invalid-address" ) . show ( ) ;
95+ }
96+ } ) ;
97+ }
6198 function appendPage ( ) {
6299 $ ( '.subnet-visual' ) . append ( pageContainer ( fetchedPages [ lastRenderedPage ] ) ) ;
63100 if ( lastRenderedPage >= renderedPages ) {
@@ -117,6 +154,9 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
117154 }
118155 }
119156 }
157+ $ ( "#goto-button" ) . on ( "click" , function ( ) {
158+ goTo ( ) ;
159+ } ) ;
120160 $ ( '.subnet-visual' ) . scroll ( onUpdate ) ;
121161 onUpdate ( ) ;
122162}
0 commit comments