135135 width : 300px ;
136136 font-size : 14px ;
137137 }
138-
139- .search-box button {
140- padding : 8px 16px ;
141- background : # 0066cc ;
142- color : white;
143- border : none;
144- border-radius : 4px ;
145- margin-left : 8px ;
146- cursor : pointer;
147- }
148-
149- .search-box button : hover {
150- background : # 0052a3 ;
151- }
152138 </ style >
153139</ head >
154140< body >
@@ -199,12 +185,10 @@ <h1>Compliance Dashboard</h1>
199185 {{end}}
200186 </ div >
201187
202- < form class ="search-box " method ="get ">
203- < input type ="text " name ="search " placeholder ="Search by hostname or user... " value ="{{.Search}} ">
204- {{if .Status}}< input type ="hidden " name ="status " value ="{{.Status}} "> {{end}}
205- < button type ="submit "> Search</ button >
188+ < div class ="search-box ">
189+ < input type ="text " id ="searchInput " placeholder ="Search by hostname or user... " value ="{{.Search}} ">
206190 {{if .Search}}< a href ="? " style ="margin-left: 10px; "> Clear</ a > {{end}}
207- </ form >
191+ </ div >
208192
209193 < div class ="filters ">
210194 < a href ="? " class ="{{if not .Status}}active{{end}} "> All</ a >
@@ -259,5 +243,60 @@ <h1>Compliance Dashboard</h1>
259243 {{if .HasNext}}< a href ="?page={{add .Page 1}}{{if .Search}}&search={{.Search}}{{end}}{{if .Status}}&status={{.Status}}{{end}} "> Next →</ a > {{end}}
260244 </ div >
261245 {{end}}
246+
247+ < script >
248+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
249+ const searchInput = document . getElementById ( 'searchInput' ) ;
250+ const table = document . querySelector ( 'table' ) ;
251+
252+ if ( searchInput && table ) {
253+ const tbody = table . querySelector ( 'tbody' ) ;
254+ const rows = tbody ? Array . from ( tbody . querySelectorAll ( 'tr' ) ) : [ ] ;
255+
256+ searchInput . addEventListener ( 'input' , function ( ) {
257+ const searchTerm = this . value . toLowerCase ( ) ;
258+
259+ rows . forEach ( row => {
260+ const hostname = row . cells [ 0 ] ? row . cells [ 0 ] . textContent . toLowerCase ( ) : '' ;
261+ const user = row . cells [ 1 ] ? row . cells [ 1 ] . textContent . toLowerCase ( ) : '' ;
262+
263+ if ( hostname . includes ( searchTerm ) || user . includes ( searchTerm ) ) {
264+ row . style . display = '' ;
265+ } else {
266+ row . style . display = 'none' ;
267+ }
268+ } ) ;
269+
270+ // Update visible count
271+ const visibleRows = rows . filter ( row => row . style . display !== 'none' ) ;
272+ updateEmptyState ( visibleRows . length === 0 , searchTerm !== '' ) ;
273+ } ) ;
274+
275+ // Function to show/hide empty state
276+ function updateEmptyState ( isEmpty , hasSearch ) {
277+ let emptyState = document . querySelector ( '.empty' ) ;
278+
279+ if ( isEmpty ) {
280+ if ( ! emptyState ) {
281+ emptyState = document . createElement ( 'div' ) ;
282+ emptyState . className = 'empty' ;
283+ emptyState . innerHTML = '<p>No devices found.</p>' +
284+ ( hasSearch ? '<p>Try adjusting your search terms.</p>' : '' ) ;
285+ table . parentNode . insertBefore ( emptyState , table . nextSibling ) ;
286+ } else {
287+ emptyState . innerHTML = '<p>No devices found.</p>' +
288+ ( hasSearch ? '<p>Try adjusting your search terms.</p>' : '' ) ;
289+ }
290+ table . style . display = 'none' ;
291+ } else {
292+ if ( emptyState ) {
293+ emptyState . style . display = 'none' ;
294+ }
295+ table . style . display = '' ;
296+ }
297+ }
298+ }
299+ } ) ;
300+ </ script >
262301</ body >
263302</ html >
0 commit comments