aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/nms-info-box.js
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2016-05-18 20:25:35 +0200
committerKristian Lyngstol <kristian@bohemians.org>2016-05-18 20:25:35 +0200
commitfd5139ed9b56b3122d73d397482ecd6fd8ffbe26 (patch)
tree24d3e639f1e3bd46c299f72dee61b5fb89035f11 /web/js/nms-info-box.js
parent69fe67df43cd17c47c03f3fe750d2478c3f2b8cc (diff)
Remove comments from code in place of oplogs
Diffstat (limited to 'web/js/nms-info-box.js')
-rw-r--r--web/js/nms-info-box.js101
1 files changed, 27 insertions, 74 deletions
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 = '<div class="input-group"><input type="text" class="form-control" placeholder="Comment" id="' + this.sw + '-comment"><span class=\"input-group-btn\"><button class="btn btn-default" onclick="addComment(\'' + this.sw + '\',document.getElementById(\'' + this.sw + '-comment\').value); document.getElementById(\'' + this.sw + '-comment\').value = \'\'; document.getElementById(\'' + this.sw + '-comment\').placeholder = \'Comment added. Wait for next refresh.\';">Add comment</button></span></div>';
-
+ 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 = '<div class="btn-group" role="group" aria-label="..."><button type="button" class="btn btn-xs btn-default" data-trigger="focus" data-toggle="popover" title="Info" data-content="Comment added ' + comment["time"] + " by user " + comment["username"] + ' and listed as ' + comment["state"] + '"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></button>';
- txt += '<button type="button" class="btn btn-xs btn-danger" data-trigger="focus" data-toggle="tooltip" title="Mark as deleted" onclick="commentDelete(' + comment["id"] + ');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>';
- txt += '<button type="button" class="btn btn-xs btn-success" data-trigger="focus" data-toggle="tooltip" title="Mark as inactive/fixed" onclick="commentInactive(' + comment["id"] + ');"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button>';
- txt += '<button type="button" class="btn btn-xs btn-info" data-trigger="focus" data-toggle="tooltip" title="Mark as persistent" onclick="commentPersist(' + comment["id"] + ');"><span class="glyphicon glyphicon-star" aria-hidden="true"></span></button></div>';
- 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 {