From fd5139ed9b56b3122d73d397482ecd6fd8ffbe26 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Wed, 18 May 2016 20:25:35 +0200 Subject: Remove comments from code in place of oplogs --- web/js/nms-info-box.js | 101 +++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 74 deletions(-) (limited to 'web/js/nms-info-box.js') diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index b83ddd1..bad2960 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -22,7 +22,6 @@ * * General TODO: * - Fix broken stuff - * - Test comments * - 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 @@ -835,36 +834,27 @@ var switchCommentsPanel = function () { var domObj = document.createElement("div"); var comments = []; - var commentbox = document.createElement("div"); - commentbox.id = "commentbox"; - commentbox.className = "panel-body"; - commentbox.style.width = "100%"; - commentbox.innerHTML = '
'; - + var logs = nmsOplog.getSwitchLogs(this.sw); // We have data - if(!(!nmsData.comments || !nmsData.comments.comments)) { - this.commentsHash = nmsData.comments.hash; - - // We have data for this switch - if(nmsData.comments.comments[this.sw]) { - this.commentsHash = nmsData.comments.hash; - for (var c in nmsData.comments.comments[this.sw]["comments"]) { - var comment = nmsData.comments.comments[this.sw]["comments"][c]; - if (comment["state"] == "active" || comment["state"] == "persist" || comment["state"] == "inactive") { - comments.push(comment); - } - } - - if (comments.length > 0) { - var commenttable = nmsInfoBox._makeCommentTable(comments); - commenttable.id = "info-switch-comments-table"; - domObj.appendChild(commenttable); - } + var table = document.createElement("table"); + var tr; + var td1; + var td2; + var td3; + table.className = "table"; + table.classList.add("table"); + table.classList.add("table-condensed"); + for (var v in logs) { + tr = table.insertRow(-1); + tr.className = + td1 = tr.insertCell(0); + td2 = tr.insertCell(1); + td1.innerHTML = logs[v]['timestamp']; + td2.innerHTML = "[" + logs[v]['username'] + "] " + logs[v]['log']; + } + domObj.appendChild(table); - } - } - domObj.appendChild(commentbox); this._render(domObj); }; }; @@ -1023,51 +1013,17 @@ nmsInfoBox._makeTable = function(content, caption) { return table; }; -/* - * Create and return a table for comments. - * - * Input is an array of comments. - */ -nmsInfoBox._makeCommentTable = function(content) { - var table = document.createElement("table"); - table.className = "table"; - table.classList.add("table"); - table.classList.add("table-condensed"); - var cap = document.createElement("caption"); - cap.textContent = "Comments" - table.appendChild(cap); - for (var commentid in content) { - var tr; - var td1; - var td2; - var comment = content[commentid]; - var col; - if (comment["state"] == "active") - col = "danger"; - else if (comment["state"] == "inactive") - col = false; - else - col = "info"; - tr = table.insertRow(-1); - tr.id = "commentRow" + comment["id"]; - tr.className = col; - - td1 = tr.insertCell(0); - td1.style.whiteSpace = "nowrap"; - td1.style.width = "8em"; - td2 = tr.insertCell(1); - var txt = '
'; - txt += ''; - txt += ''; - txt += '
'; - td1.innerHTML = txt; - td2.innerHTML = comment["comment"]; - } - 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) > -1) { + return true; + } try { if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) { return true; @@ -1138,10 +1094,7 @@ nmsInfoBox._search = function() { if(id) { nmsMap.enableHighlights(); for(var sw in nmsData.switches.switches) { - if(sw.toLowerCase().indexOf(id) > -1) { - matches.push(sw); - nmsMap.setSwitchHighlight(sw,true); - } else if (nmsInfoBox._searchSmart(id,sw)) { + if (nmsInfoBox._searchSmart(id,sw)) { matches.push(sw); nmsMap.setSwitchHighlight(sw,true); } else { -- cgit v1.2.3