diff options
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/nms-info-box.js | 143 | ||||
-rw-r--r-- | web/js/nms-oplog.js | 2 | ||||
-rw-r--r-- | web/js/nms-search.js | 144 | ||||
-rw-r--r-- | web/js/nms.js | 9 |
4 files changed, 152 insertions, 146 deletions
diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index 9133d7f..676197b 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -13,15 +13,12 @@ /* * * Currently broken or needs reimplementing: - * - Possibly: Comment CRUD, did not want to test writes on our "historic db copy" - * - Comments popover * - Handler unloading is not working correctly, and many are never removed * - SSH-management link, this should propably be a custom "view" of sorts * - inventoryListing window is partially broken when first opened. Since it's * both a window type and a panel with different modes it has some conflicts. * * General TODO: - * - Fix broken stuff * - Add external windows (timetravel, etc) * - Take a critical look at what methods/variables should be marked as "_" * - Currently argument is assumed to be a switch, this should not be the case @@ -176,8 +173,10 @@ nmsInfoBox.addPanelType = function (id, obj) { */ nmsInfoBox.hide = function() { this._sw = false; - this._windowHandler.hide(); - this._windowHandler.unloadWindow(); + if (this._windowHandler != undefined && this._windowHandler.hide != undefined) { + this._windowHandler.hide(); + this._windowHandler.unloadWindow(); + } }; /* @@ -590,13 +589,7 @@ var searchHelpPanel = function() { nmsInfoPanel.call(this,"searchHelp"); this.refresh = function(reason) { var x = document.createElement("div"); - var searchHelp = [ - "The search box can be used to identify switches in several ways. The simplest is by name.", - "If you are using the non-public version of Gondul, you can also perform smart searches.", - "Distro search: Type the name of a distro-switch and all access switches registered to that distro switch will also be hilighted.", - 'Active ports: Type "active>x", "active<x" or "active=x" to identify switch with "x" amount of active gigabit ethernet (ge) ports. E.g.: "active>30".', - '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.").']; + var searchHelp = nmsSearch.helpText; for (var a in searchHelp) { var c = document.createElement("p"); c.innerText = searchHelp[a]; @@ -704,7 +697,7 @@ var inventoryListingPanel = function() { for(var sw in nmsData.switches.switches) { var value = ''; if(this.filter != '') { - if(sw.toLowerCase().indexOf(this.filter) == -1 && !nmsInfoBox._searchSmart(this.filter,sw)) + if(sw.toLowerCase().indexOf(this.filter) == -1 && !nmsSearch.searchTest(this.filter,sw)) continue; } try { @@ -957,130 +950,6 @@ nmsInfoBox._makeTable = function(content, caption) { return table; }; -nmsInfoBox.searchSmart = function(id, sw) { - if (id == "") - return false; - return nmsInfoBox._searchSmart(id, sw); -} - -nmsInfoBox._searchSmart = function(id, sw) { - try { - if(sw.toLowerCase().indexOf(id.toLowerCase()) > -1) { - return true; - } - if (id[0] == "\"") { - if (("\"" + sw.toLowerCase() + "\"") == id.toLowerCase()) { - return true; - } else { - return false; - } - } - try { - if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) { - return true; - } - } catch (e) {} - try { - if (id.match("active")) { - var limit = id; - limit = limit.replace("active>",""); - limit = limit.replace("active<",""); - limit = limit.replace("active=",""); - var operator = id.replace("active","")[0]; - if (limit == parseInt(limit)) { - var ports = parseInt(nmsData.switchstate.switches[sw].ifs.ge.live); - limit = parseInt(limit); - if (operator == ">" ) { - if (ports > limit) { - return true; - } - } else if (operator == "<") { - if (ports < limit) { - return true; - } - } else if (operator == "=") { - if (ports == limit) { - return true; - } - } - } - } - } catch (e) {} - try { - if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) { - return true; - } - if (nmsData.smanagement.switches[sw].mgmt_v6_addr.match(id)) { - return true; - } - } catch (e) {} - try { - if (nmsData.smanagement.switches[sw].subnet4.match(id)) { - return true; - } - if (nmsData.smanagement.switches[sw].subnet6.match(id)) { - return true; - } - } catch (e) {} - if (nmsData.snmp.snmp[sw].misc.sysDescr[0].toLowerCase().match(id)) { - return true; - } - } catch (e) { - return false; - } - return false; -}; - -/* - * FIXME: Not sure this belongs here, it's really part of the "Core" ui, - * not just the infobox. - */ -nmsInfoBox._search = function() { - var el = document.getElementById("searchbox"); - var id = false; - var matches = []; - if (el) { - id = el.value.toLowerCase(); - } - if(id) { - nmsMap.enableHighlights(); - for(var sw in nmsData.switches.switches) { - if (nmsInfoBox._searchSmart(id,sw)) { - matches.push(sw); - nmsMap.setSwitchHighlight(sw,true); - } else { - nmsMap.setSwitchHighlight(sw,false); - } - } - } else { - nmsMap.disableHighlights(); - } - if(matches.length == 1) { - document.getElementById("searchbox-submit").classList.add("btn-primary"); - document.getElementById("searchbox").dataset.match = matches[0]; - } else { - document.getElementById("searchbox-submit").classList.remove("btn-primary"); - document.getElementById("searchbox").dataset.match = ''; - } -}; - -nmsInfoBox._searchKeyListener = function(e) { - switch (e.keyCode) { - case 13: - var sw = document.getElementById("searchbox").dataset.match; - if(sw != '') { - nmsInfoBox.showWindow("switchInfo",sw); - } - break; - case 27: - document.getElementById("searchbox").dataset.match = ''; - document.getElementById("searchbox").value = ''; - nmsInfoBox._search(); - nmsInfoBox.hide(); - break; - } -}; - nmsInfoBox._nullBlank = function(x) { if (x == null || x == false || x == undefined) return ""; diff --git a/web/js/nms-oplog.js b/web/js/nms-oplog.js index 5da7893..674b87a 100644 --- a/web/js/nms-oplog.js +++ b/web/js/nms-oplog.js @@ -39,7 +39,7 @@ nmsOplog.getSwitchLogs = function(sw) { var logs = []; for (var v in nmsData['oplog']['oplog']) { var log = nmsData['oplog']['oplog'][v]; - if (nmsInfoBox.searchSmart(log['systems'],sw)) { + if (nmsSearch.searchTest(log['systems'],sw)) { logs.push(log); } } diff --git a/web/js/nms-search.js b/web/js/nms-search.js new file mode 100644 index 0000000..7d4c9a6 --- /dev/null +++ b/web/js/nms-search.js @@ -0,0 +1,144 @@ +"use strict"; + +var nmsSearch = nmsSearch || { +}; + +nmsSearch.helpText = [ + "The search box can be used to identify switches in several ways. The simplest is by name.", + "Searching by name can be done by just entering text, or if you want to match \"foobar1\" but not \"foobar15\" you can enclose the name in quotation marks. E.g.: foobar1 matches foobar1 and foobar1123123123, while \"foobar1\" only matches exactly foobar1.", + "If you are using the non-public version of Gondul, you can also perform smart searches.", + "Distro search: Type the name of a distro-switch and all access switches registered to that distro switch will also be hilighted.", + 'Active ports: Type "active>x", "active<x" or "active=x" to identify switch with "x" amount of active gigabit ethernet (ge) ports. E.g.: "active>30".', + '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.").']; + +/* + * Test if the search expression "id" matches the switch "sw" + * + * Return true if it does. + */ +nmsSearch.searchTest = function(id, sw) { + try { + if(sw.toLowerCase().indexOf(id.toLowerCase()) > -1) { + return true; + } + if (id[0] == "\"") { + if (("\"" + sw.toLowerCase() + "\"") == id.toLowerCase()) { + return true; + } else { + return false; + } + } + try { + if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) { + return true; + } + } catch (e) {} + try { + if (id.match("active")) { + var limit = id; + limit = limit.replace("active>",""); + limit = limit.replace("active<",""); + limit = limit.replace("active=",""); + var operator = id.replace("active","")[0]; + if (limit == parseInt(limit)) { + var ports = parseInt(nmsData.switchstate.switches[sw].ifs.ge.live); + limit = parseInt(limit); + if (operator == ">" ) { + if (ports > limit) { + return true; + } + } else if (operator == "<") { + if (ports < limit) { + return true; + } + } else if (operator == "=") { + if (ports == limit) { + return true; + } + } + } + } + } catch (e) {} + try { + if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) { + return true; + } + if (nmsData.smanagement.switches[sw].mgmt_v6_addr.match(id)) { + return true; + } + } catch (e) {} + try { + if (nmsData.smanagement.switches[sw].subnet4.match(id)) { + return true; + } + if (nmsData.smanagement.switches[sw].subnet6.match(id)) { + return true; + } + } catch (e) {} + if (nmsData.snmp.snmp[sw].misc.sysDescr[0].toLowerCase().match(id)) { + return true; + } + } catch (e) { + return false; + } + return false; +}; + +nmsSearch.reset = function() { + var el = document.getElementById("searchbox"); + el.value = ""; + nmsSearch.search(); +} + +nmsSearch.search = function() { + var el = document.getElementById("searchbox"); + var id = false; + var matches = []; + if (el) { + id = el.value.toLowerCase(); + } + if(id) { + nmsMap.enableHighlights(); + for(var sw in nmsData.switches.switches) { + if (nmsSearch.searchTest(id,sw)) { + matches.push(sw); + nmsMap.setSwitchHighlight(sw,true); + } else { + nmsMap.setSwitchHighlight(sw,false); + } + } + } else { + nmsMap.disableHighlights(); + } + if(matches.length == 1) { + document.getElementById("searchbox-submit").classList.add("btn-primary"); + document.getElementById("searchbox").dataset.match = matches[0]; + } else { + document.getElementById("searchbox-submit").classList.remove("btn-primary"); + document.getElementById("searchbox").dataset.match = ''; + } +}; + +nmsSearch._searchKeyListener = function(e) { + switch (e.keyCode) { + case 13: + var sw = document.getElementById("searchbox").dataset.match; + if(sw != '') { + nmsInfoBox.showWindow("switchInfo",sw); + } + break; + case 27: + document.getElementById("searchbox").dataset.match = ''; + document.getElementById("searchbox").value = ''; + nmsInfoBox._search(); + nmsInfoBox.hide(); + break; + } +} + +nmsSearch.init = function() { + $("#searchbox").keyup(function(e) { + nmsSearch._searchKeyListener(e); + }); +} diff --git a/web/js/nms.js b/web/js/nms.js index 33be786..a91493f 100644 --- a/web/js/nms.js +++ b/web/js/nms.js @@ -560,7 +560,7 @@ function initNMS() { detectHandler(); nms.playback.play(); setupKeyhandler(); - setupSearchKeyHandler(); + nmsSearch.init(); } function detectHandler() { @@ -711,13 +711,6 @@ function setupKeyhandler() }); } -function setupSearchKeyHandler() -{ - $("#searchbox").keyup(function(e) { - nmsInfoBox._searchKeyListener(e); - }); -} - function getCookie(cname) { var name = cname + "="; |