Difference between revisions of "Widget:Pamela"

From Whitespace (Hackerspace Gent)
Jump to: navigation, search
(further styling)
 
(34 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<includeonly>
+
<noinclude>
<div id="pamelaWidget">Loading <a href='http://0x20.be/Pamela'>Pamela</a>...</div>
+
<div>
 +
  <div id="openbanner">[http://0x20.be/pam <span style="color:white">The space is open!</span>]</div>
 +
</div>
 +
{{#widget:Pamela}}</noinclude><includeonly>
 +
<div id="pamelaWidget">Loading <a href='/Pamela'>Pamela</a>...</div>
 
<script type="text/javascript">
 
<script type="text/javascript">
 
var xmlHttp = null;
 
var xmlHttp = null;
Line 6: Line 10:
 
function LoadPamelaCountWidget()
 
function LoadPamelaCountWidget()
 
{
 
{
     var Url = window.location.protocol + "//0x20.be/pam/macs";
+
     var Url = "/pam/data";
  
 
     xmlHttp = new XMLHttpRequest();
 
     xmlHttp = new XMLHttpRequest();
Line 18: Line 22:
 
function ProcessRequest()
 
function ProcessRequest()
 
{
 
{
     var macs, i;
+
     var data, i;
 +
    var pamTalkPeople = ['is nobody', 'is one person', 'are two people', 'are three people', 'are four people', 'are five people'];
 +
    var pamTalkMachines = ['are no machines', 'is one machine', 'are two machines', 'are three machines', 'are four machines', 'are five machines'];
  
 
     if ( !(xmlHttp.readyState == 4 && xmlHttp.status == 200))
 
     if ( !(xmlHttp.readyState == 4 && xmlHttp.status == 200))
Line 25: Line 31:
 
         return;
 
         return;
  
     var macs = eval ( "(" + xmlHttp.responseText + ")" );
+
     var data = eval ( "(" + xmlHttp.responseText + ")" );
 +
 
 
     var people = [];
 
     var people = [];
 
     var services = [];
 
     var services = [];
 +
    var entities = [];
  
     for (i = macs.length -1; i >= 0; i--) {
+
     for (i = data.length -1; i >= 0; i--) {
         if (macs[i].indexOf('(') != -1) {
+
         if (data[i].indexOf('(') != -1) {
             services.push('<span style="color:darkgray">' + macs[i] + '</span>');
+
             services.push('<span style="color:darkgray">' + data[i] + '</span>');
 
         }
 
         }
         else if ( macs[i].split( ':' ).length == 6 ) {
+
         else if (data[i].split( ':' ).length == 6) {
             people.push(macs[i]);
+
             entities.push(data[i]);
 
         }
 
         }
 +
// Hack please remove once the pamela db has been fixed
 +
        else if (data[i] == 'the cable guy') {
 +
            services.push('<span style="color:darkgray">' + data[i] + '</span>');
 +
        }
 +
// End of code to remove
 
         else {
 
         else {
             people.unshift(macs[i]);
+
             people.unshift('<a href="/' + data[i] + '">' + data[i] + '</a>');
 
         }
 
         }
 
     }
 
     }
  
 
     document.getElementById('openbanner').style.display = people.length > 0 ? 'block' : 'none';
 
     document.getElementById('openbanner').style.display = people.length > 0 ? 'block' : 'none';
     document.getElementById( "pamelaWidget" ).innerHTML = "According to <a href='" + window.location.protocol + "//0x20.be/Pamela'>Pamela</a> there are " + macs.length + " devices active in the space: " + people.concat(services).join( ", " );
+
 
 +
     if ( data.length > 0 ) {
 +
var msg = "";
 +
 
 +
        // Dealing with unknown entities
 +
        if ( entities.length > 0 ) {
 +
      msg = msg + "<p>";
 +
      msg = msg + "<span style='color:red;'>WARNING:</span>";
 +
      msg = msg + "<span style='color:darkred;'>According to <a href='/Pamela'>Pamela</a> there ";             
 +
      if ( entities.length == 1 ) {
 +
          msg = msg + "is 1 unknown entity";
 +
              }
 +
              else {
 +
                  msg = msg + "are " + entities.length + " unknown entities";
 +
              }
 +
              msg = msg + " present in Whitespace!!! >> " +  entities.join(", " ) + " <<";
 +
      msg = msg + "</p>";
 +
      msg = msg + "<p>";
 +
              msg = msg + "Furthermore <a href='/Pamela'>Pamela</a> says there ";
 +
}
 +
        else {
 +
      msg = msg + "<p>";
 +
              msg = msg + "According to <a href='/Pamela'>Pamela</a> there "
 +
}
 +
 
 +
        // Dealing with people
 +
if ( people.length > 5 ) {
 +
      msg = msg + " are " + people.length + " people";
 +
}
 +
        else {
 +
      msg = msg + pamTalkPeople[people.length];
 +
}
 +
msg = msg  + " in the space";
 +
        if ( people.length > 0 ) {
 +
              msg = msg + ", namely: " + people.join(", " );
 +
        }
 +
 
 +
        // Dealing with machines
 +
        msg = msg + " and there "
 +
if ( services.length > 5 ) {
 +
              msg = msg + " are " + services.length + " machines";
 +
}
 +
        else {
 +
      msg = msg + pamTalkMachines[services.length];
 +
}
 +
msg = msg + " active";
 +
if ( services.length > 0 ) {
 +
              msg = msg + ", namely: " + services.join(", " );
 +
}
 +
msg = msg + ".";
 +
        msg = msg + "</p>";
 +
    }
 +
    else {
 +
        var msg = "<p><span style='color:red; font-weight: bold;'>THE WORLD EXPLODED!!!</span> ";
 +
        msg = msg + "<span style='color:darkred'>According to <a href='/Pamela'>Pamela</a> there's no man or machine left alive!!!</span></p>";
 +
    }
 +
 
 +
    document.getElementById( "pamelaWidget" ).innerHTML = msg;
 
}
 
}
  

Latest revision as of 01:13, 8 March 2013

Loading Pamela...