diff options
-rw-r--r-- | web/nms.gathering.org/nms2/index.html | 2 | ||||
-rw-r--r-- | web/nms.gathering.org/nms2/js/nms-map-handlers.js | 10 | ||||
-rw-r--r-- | web/nms.gathering.org/nms2/js/nms.js | 56 | ||||
-rwxr-xr-x | web/nms.gathering.org/port-state.pl | 10 | ||||
-rwxr-xr-x | web/nms.gathering.org/switch-comment.pl | 25 |
5 files changed, 95 insertions, 8 deletions
diff --git a/web/nms.gathering.org/nms2/index.html b/web/nms.gathering.org/nms2/index.html index b86207c..0204d06 100644 --- a/web/nms.gathering.org/nms2/index.html +++ b/web/nms.gathering.org/nms2/index.html @@ -135,6 +135,7 @@ <button class="btn" onclick="document.getElementById('nowPickerBox').style.display = 'none';">Cancel</button> </div> </div> + <div style="position: fixed; z-index: 120;"> <div id="info-switch-parent" class="panel panel-default" style="display: none; backgroun:silver; position: fixed; z-index: 120;"> <div class="panel-heading"><h3 class="panel-title" id="info-switch-title"></h3></div> @@ -144,6 +145,7 @@ </div> </div> </div> + </div> <div id="aboutBox" class="panel panel-default" style="display: none; position: fixed; z-index: 100;"> <div class="panel-heading"><h3 class="panel-title">Welcome to NMS <button type="button" class="close" aria-labe="Close" onclick="document.getElementById('aboutBox').style.display = 'none';" style="float: right;"><span aria-hidden="true">×</span></button></h3></div> diff --git a/web/nms.gathering.org/nms2/js/nms-map-handlers.js b/web/nms.gathering.org/nms2/js/nms-map-handlers.js index db54837..763e482 100644 --- a/web/nms.gathering.org/nms2/js/nms-map-handlers.js +++ b/web/nms.gathering.org/nms2/js/nms-map-handlers.js @@ -225,10 +225,10 @@ function randomizeColors() function discoInit() { setNightMode(true); - setLegend(1,"blue","0"); - setLegend(5,"red", "1"); - setLegend(4,"yellow","2"); - setLegend(3,"green", "3"); - setLegend(2,"white","4"); + setLegend(1,"blue","Y"); + setLegend(2,"red", "M"); + setLegend(3,"yellow","C"); + setLegend(4,"green", "A"); + setLegend(5,"white","!"); } diff --git a/web/nms.gathering.org/nms2/js/nms.js b/web/nms.gathering.org/nms2/js/nms.js index 134bb98..95a682e 100644 --- a/web/nms.gathering.org/nms2/js/nms.js +++ b/web/nms.gathering.org/nms2/js/nms.js @@ -320,8 +320,14 @@ function hideSwitch() { var swtop = document.getElementById("info-switch-parent"); var switchele = document.getElementById("info-switch-table"); + var comments = document.getElementById("info-switch-comments-table"); if (switchele != undefined) switchele.parentNode.removeChild(switchele); + if (comments != undefined) + comments.parentNode.removeChild(comments); + commentbox = document.getElementById("commentbox"); + if (commentbox != undefined) + commentbox.parentNode.removeChild(commentbox); swtop.style.display = 'none'; nms.switch_showing = ""; } @@ -455,8 +461,44 @@ function switchInfo(x) td2.innerHTML = sw["management"]["poll_frequency"]; tr.appendChild(td1); tr.appendChild(td2); switchele.appendChild(tr); - + + comments = document.createElement("table"); + comments.id = "info-switch-comments-table"; + comments.border = "1"; + comments.className = "table col-md-6"; + var cap = document.createElement("caption"); + cap.innerText = "Comments"; + comments.appendChild(cap); + + tr = document.createElement("tr"); td1 = document.createElement("th"); td2 = document.createElement("th"); + td3 = document.createElement("th"); + td1.innerText = "Time"; + td2.innerText = "User"; + td3.innerText = "Comment"; + tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); comments.appendChild(tr); + var has_comment = false; + for (var c in sw["comments"]) { + var comment = sw["comments"][c]; + has_comment = true; + if (comment["state"] == "active" || comment["state"] == "persist") { + tr = document.createElement("tr"); td1 = document.createElement("td"); td2 = document.createElement("td"); + td3 = document.createElement("td"); + td1.innerText = epochToString(comment["time"]) + " "; + td2.innerText = comment["username"] + " "; + td3.innerText = comment['comment']; + tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); comments.appendChild(tr); + } + } + swpanel.appendChild(switchele); + if (has_comment) { + swpanel.appendChild(comments); + } + var commentbox = document.createElement("div"); + commentbox.id = "commentbox"; + console.log("x : " + x); + commentbox.innerHTML = '<input type="text" placeholder="Comment" id="' + x + '-comment"><button onclick="addComment(\'' + x + '\',document.getElementById(\'' + x + '-comment\').value); document.getElementById(\'' + x + '-comment\').value = \'added. Wait for it....\';">Add comment</button>'; + swpanel.appendChild(commentbox); swtop.style.display = 'block'; } @@ -545,6 +587,18 @@ function updatePing() }); } +function addComment(sw,comment) { + var myData = { + switch:sw, + comment:comment}; + console.log(myData); + $.ajax({ + type: "POST", + url: "/switch-comment.pl", + dataType: "text", + data:myData + }); +} /* * Update nms.switches_now and nms.switches_then */ diff --git a/web/nms.gathering.org/port-state.pl b/web/nms.gathering.org/port-state.pl index ee0fb2c..83e15f1 100755 --- a/web/nms.gathering.org/port-state.pl +++ b/web/nms.gathering.org/port-state.pl @@ -37,7 +37,7 @@ while (my $ref = $q->fetchrow_hashref()) { } #print Dumper(%json); -my $q2 = $dbh->prepare('select switch,sysname,placement,zorder,ip,switchtype,poll_frequency,community,last_updated from switches natural join placements'); +my $q2 = $dbh->prepare('select switch,sysname,placement,ip,switchtype,poll_frequency,community,last_updated from switches natural join placements'); my $q3 = $dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $when . ' order by switch,time desc'); $q2->execute(); @@ -54,7 +54,6 @@ while (my $ref = $q2->fetchrow_hashref()) { $json{'switches'}{$ref->{'sysname'}}{'placement'}{'y'} = $y2; $json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2; $json{'switches'}{$ref->{'sysname'}}{'placement'}{'height'} = $y1 - $y2; - $json{'switches'}{$ref->{'sysname'}}{'placement'}{'zorder'} = $ref->{'zorder'}; } $q3->execute(); while (my $ref = $q3->fetchrow_hashref()) { @@ -74,5 +73,12 @@ my $q5 = $dbh->prepare ('select ' . $now . ' as time;'); $q5->execute(); $json{'time'} = $q5->fetchrow_hashref()->{'time'}; +my $q6 = $dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,state,username,id,comment from switch_comments natural join switches order by time desc'); +$q6->execute(); +while (my $ref = $q6->fetchrow_hashref()) { + push @{$json{'switches'}{$ref->{'sysname'}}{'comments'}},$ref; +} + +$json{'username'} = $cgi->remote_user(); print $cgi->header(-type=>'text/json; charset=utf-8'); print JSON::XS::encode_json(\%json); diff --git a/web/nms.gathering.org/switch-comment.pl b/web/nms.gathering.org/switch-comment.pl new file mode 100755 index 0000000..262d625 --- /dev/null +++ b/web/nms.gathering.org/switch-comment.pl @@ -0,0 +1,25 @@ +#! /usr/bin/perl +use CGI qw(fatalsToBrowser); +use DBI; +use lib '../../include'; +use utf8; +use nms; +use strict; +use warnings; +use Data::Dumper; + +my $cgi = CGI->new; + +my $dbh = nms::db_connect(); + +my $data = $dbh->quote($cgi->param('comment') || die ); +my $switch = $dbh->quote($cgi->param('switch') || die ); +my $user = $dbh->quote($cgi->remote_user() || "undefined"); + + +my $q = $dbh->prepare("INSERT INTO switch_comments (time,username,switch,comment) values (now(),$user,(select switch from switches where sysname = $switch limit 1),$data)"); +$q->execute(); + +print $cgi->header(-type=>'text/json; charset=utf-8'); +print "{ 'state': 'ok' }"; + |