From f70f65f7466a480a45a8260b35887cb7ed36b466 Mon Sep 17 00:00:00 2001 From: Ole Mathias Heggem Date: Sat, 25 Mar 2017 15:04:04 +0100 Subject: Added a basic search results page and search on tags --- web/js/nms-info-box.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ web/js/nms-search.js | 32 ++++++++++++++++++++++---------- 2 files changed, 72 insertions(+), 10 deletions(-) (limited to 'web/js') diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index 2cc6fc4..6e3f31c 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -76,6 +76,16 @@ var nmsInfoBox = nmsInfoBox || { } } }, + { + 'id': 'searchResults', + 'title': 'Search Results', + 'views': { + 'initial': { + 'name': 'Search Results', + 'panels': ['searchResults'] + } + } + }, { 'id': 'inventoryListing', 'title': 'Inventory listing', @@ -723,6 +733,46 @@ var searchHelpPanel = function() { }; nmsInfoBox.addPanelType("searchHelp",searchHelpPanel); + +/* + * Panel type: Search Results + * + * Show the search results + * + */ +var searchResultsPanel = function() { + var searchPage = 0; + nmsInfoPanel.call(this,"searchResults"); + this.refresh = function(reason) { + var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'}); + var switches = nmsSearch.matches.sort(collator.compare); + if(switches.length <= 0) { + var x = document.createElement("div"); + var c = document.createElement("p"); + c.innerText = "No results :("; + x.appendChild(c); + this._render(x) + } + + else { + var table = document.createElement('table'); + table.className = "table table-condensed"; + table.id = "searchResults-table" + for (var sw in switches) { + var row = table.insertRow(sw); + var cell1 = row.insertCell(0); + var cell2 = row.insertCell(1); + var cell3 = row.insertCell(2); + cell1.innerHTML = ""+switches[sw]+ ''; + cell2.innerHTML = nmsData.switches["switches"][switches[sw]].distro_name; + cell3.innerHTML = handlers[0].getInfo(switches[sw]).why; + } + this._render(table); + } + }; +}; +nmsInfoBox.addPanelType("searchResults",searchResultsPanel); + /* * Panel type: Add switch * diff --git a/web/js/nms-search.js b/web/js/nms-search.js index 1167b51..7528a82 100644 --- a/web/js/nms-search.js +++ b/web/js/nms-search.js @@ -15,6 +15,8 @@ nmsSearch.helpText = [ 'IP search: Start typing an IP and any switch with that IP registered either as management IP or part of its subnet will be identified', 'SNMP search: Type anything found in the "sysDescr" SNMP OID to hilight a switch matching that. Practical examples include version numbers for firmware (e.g.: "JUNOS 12." vs "JUNOS 14.").']; +nmsSearch.matches = []; + /* * Test if the search expression "id" matches the switch "sw" * @@ -80,6 +82,13 @@ nmsSearch.searchTest = function(id, sw) { return true; } } catch (e) {} + try { + for (var x in nmsData.switches.switches[sw]['tags']) { + if(re.test(nmsData.switches.switches[sw]['tags'][x])){ + return true; + } + } + } catch (e) {} try { for (var x in nmsData.snmp.snmp[sw].misc.entPhysicalSerialNum) { if (nmsData.snmp.snmp[sw].misc.entPhysicalSerialNum[x] == null) { @@ -126,7 +135,7 @@ nmsSearch._disableTimer = function() { nmsSearch.search = function() { var el = document.getElementById("searchbox"); var id = false; - var matches = []; + nmsSearch.matches = []; if (el) { id = el.value.toLowerCase(); } @@ -134,7 +143,7 @@ nmsSearch.search = function() { nmsMap.enableHighlights(); for(var sw in nmsData.switches.switches) { if (nmsSearch.searchTest(id,sw)) { - matches.push(sw); + nmsSearch.matches.push(sw); nmsMap.setSwitchHighlight(sw,true); } else { nmsMap.setSwitchHighlight(sw,false); @@ -145,22 +154,25 @@ nmsSearch.search = function() { nmsSearch._disableTimer(); nmsMap.disableHighlights(); } - if(matches.length == 1) { - document.getElementById("searchbox-submit").classList.add("btn-primary"); - document.getElementById("searchbox").dataset.match = matches[0]; - } else { + if(nmsSearch.matches.length == 0) { document.getElementById("searchbox-submit").classList.remove("btn-primary"); document.getElementById("searchbox").dataset.match = ''; } }; +nmsSearch.runSearch = function() { + if(nmsSearch.matches.length == 1) { + nmsInfoBox.showWindow("switchInfo",nmsSearch.matches[0]); + } + else { + nmsInfoBox.showWindow('searchResults',nmsSearch.matches.length); + } +}; + nmsSearch._searchKeyListener = function(e) { switch (e.keyCode) { case 13: - var sw = document.getElementById("searchbox").dataset.match; - if(sw != '') { - nmsInfoBox.showWindow("switchInfo",sw); - } + nmsSearch.runSearch(); break; case 27: nmsSearch.reset(); -- cgit v1.2.3 From 10f6ab7d5b9f5c9abcdfcd66104b24c3ff47133c Mon Sep 17 00:00:00 2001 From: Ole Mathias Heggem Date: Thu, 20 Apr 2017 03:50:48 +0200 Subject: No search-box at zero results, the search button change color on 0 (white) , 1 (green) and multiple (blue) hits --- web/js/nms-info-box.js | 36 +++++++++++++----------------------- web/js/nms-search.js | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 25 deletions(-) (limited to 'web/js') diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index cd84ec0..66b81b9 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -746,30 +746,20 @@ var searchResultsPanel = function() { this.refresh = function(reason) { var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'}); var switches = nmsSearch.matches.sort(collator.compare); - if(switches.length <= 0) { - var x = document.createElement("div"); - var c = document.createElement("p"); - c.innerText = "No results :("; - x.appendChild(c); - this._render(x) + var table = document.createElement('table'); + table.className = "table table-condensed"; + table.id = "searchResults-table" + for (var sw in switches) { + var row = table.insertRow(sw); + var cell1 = row.insertCell(0); + var cell2 = row.insertCell(1); + var cell3 = row.insertCell(2); + cell1.innerHTML = ""+switches[sw]+ ''; + cell2.innerHTML = nmsData.switches["switches"][switches[sw]].distro_name; + cell3.innerHTML = handlers[0].getInfo(switches[sw]).why; + } + this._render(table); } - - else { - var table = document.createElement('table'); - table.className = "table table-condensed"; - table.id = "searchResults-table" - for (var sw in switches) { - var row = table.insertRow(sw); - var cell1 = row.insertCell(0); - var cell2 = row.insertCell(1); - var cell3 = row.insertCell(2); - cell1.innerHTML = ""+switches[sw]+ ''; - cell2.innerHTML = nmsData.switches["switches"][switches[sw]].distro_name; - cell3.innerHTML = handlers[0].getInfo(switches[sw]).why; - } - this._render(table); - } - }; }; nmsInfoBox.addPanelType("searchResults",searchResultsPanel); diff --git a/web/js/nms-search.js b/web/js/nms-search.js index 41e5397..0726bb4 100644 --- a/web/js/nms-search.js +++ b/web/js/nms-search.js @@ -171,18 +171,31 @@ nmsSearch.search = function() { nmsMap.disableHighlights(); } if(nmsSearch.matches.length == 0) { + document.getElementById("searchbox-submit").classList.remove("btn-success"); + document.getElementById("searchbox-submit").classList.remove("btn-primary"); + } + else if(nmsSearch.matches.length == 1) { + document.getElementById("searchbox-submit").classList.add("btn-success"); document.getElementById("searchbox-submit").classList.remove("btn-primary"); - document.getElementById("searchbox").dataset.match = ''; } + else { + document.getElementById("searchbox-submit").classList.add("btn-primary"); + document.getElementById("searchbox-submit").classList.remove("btn-success"); + } + }; nmsSearch.runSearch = function() { if(nmsSearch.matches.length == 1) { nmsInfoBox.showWindow("switchInfo",nmsSearch.matches[0]); } - else { + else if(nmsSearch.matches.length > 1) { nmsInfoBox.showWindow('searchResults',nmsSearch.matches.length); } + else { + document.getElementById("searchbox-submit").classList.remove("btn-primary"); + document.getElementById("searchbox").dataset.match = ''; + } }; nmsSearch._searchKeyListener = function(e) { -- cgit v1.2.3