update spaceapi code for ajar/shut
[svn42.git] / raspberry-kiosk / kiosk.js
index cb3c3c4..da4df77 100644 (file)
@@ -1,6 +1,17 @@
+function min(a,b)
+{
+       if (a > b)
+               return b;
+       else
+               return a;
+}
+
 function writeGooglePlusEvents(data, elem)
 {
   var ghtml = "";
+  //var gplusimgwidth = parseInt($('<table class="gplusimg" />').css("width"));
+  var gplusimgwidth = 495;
+  var minimgwidth=78;
   for (var i=0; i< data.items.length; i++)
   {
     var item = data.items[i];
@@ -33,11 +44,33 @@ function writeGooglePlusEvents(data, elem)
     ghtml += '<img class="gplusactor" src="'+item.actor.image.url+'"/><p class="gplustimestamp">'+item.updated.substring(0,16).replace("T"," ")+'</p>';
     ghtml += '<p class="gplustxt">'+notetxt+'</p>';
     if (noteimgs.length>0)
-    {
+    { 
+      var bigimglimit;
       ghtml += '<table class="gplusimg" cellspacing="0"><tr>';
-      for (var ni=0; ni<noteimgs.length; ni++)
+      if (noteimgs.length > 3)
+      {
+              var gplusimgmaxwidth = gplusimgwidth - (minimgwidth * ((noteimgs.length -1) / 3));
+             bigimglimit = "max-height:"+(minimgwidth*3)+"px; max-width:"+gplusimgmaxwidth+"px;"
+             ghtml += '<td><img class="gplusimg" style="'+bigimglimit+'" src="'+noteimgs[0]+'"/></td>';
+             for (var ni=1; ni<noteimgs.length; ni+=3)
+             {
+                 ghtml += '<td>';
+                 var niimax = min(noteimgs.length, ni+3);
+                 for (var nii=ni; nii<niimax; nii++)
+                 {
+                       ghtml += '<img class="gplusimg" style="max-width:'+minimgwidth+'px; max-height:'+minimgwidth+'px;" src="'+noteimgs[nii]+'"/><br/>';
+                 }
+                 ghtml += '</td>';
+             }
+      }
+      else
       {
-        ghtml += '<td><img class="gplusimg" src="'+noteimgs[ni]+'"/></td>';
+             var gplusimgmaxwidth = gplusimgwidth / noteimgs.length;
+            bigimglimit = "max-width:"+gplusimgmaxwidth+"px;"
+             for (var ni=0; ni<noteimgs.length; ni++)
+            {
+               ghtml += '<td><img class="gplusimg" style="'+bigimglimit+'" src="'+noteimgs[ni]+'"/></td>';
+            }
       }
       ghtml += '</tr></table>';
     }
@@ -133,21 +166,58 @@ function writeAnwesenheitStatus(data)
   html='<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100"><tr><td style="width:100px;"><img style="float:left;" src="'+iconuri+'" height="100" width="100"/></td><td style="width:4px;"></td><td class="anwesenheitsstatus" style="background-color:'+statuscolor+'; ">'+data.status+'</td></tr></table>';
   document.getElementById('anwesenheit_status').innerHTML=html;
 
-  if (data.sensors)
+if (data.sensors)
   {
-    for (var s=0; s<data.sensors.length;s++)
+    if (data.sensors.temperature)
     {
-      $.each( data.sensors[s], function(stype, std){
-        $.each( std, function(swhere, svalue){
-           sensorstd+='<td class="sensorstatus"><b>'+stype+'</b><br/>'+swhere+': '+svalue+'</td>';
-        });
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Temperatur</b>';
+      $.each( data.sensors.temperature, function(s, sensorobj) {
+        sensorstd+='<br/>'+sensorobj.location+': '+sensorobj.value.toFixed(2)+sensorobj.unit;
       });
+      sensorstd+='</td>';
+    }
+    if (data.sensors.ext_illumination)
+    {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Licht</b>';
+      $.each( data.sensors.ext_illumination, function(s, sensorobj) {
+        sensorstd+='<br/>'+sensorobj.location+': '+sensorobj.value;
+      });
+      sensorstd+='</td>';
+    }
+    if (data.sensors.door_locked)
+    {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Eingangstür</b>';
+      $.each( data.sensors.door_locked, function(s, sensorobj)  {
+        var lockstatus="Auf";
+        if (sensorobj.value) { lockstatus = "Zu"; }
+        sensorstd+='<br/>'+sensorobj.location+': '+lockstatus;
+      });
+      sensorstd+='</td>';
+    }
+    if (data.sensors.ext_door_ajar)
+    {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Türkontakt</b>';
+      $.each( data.sensors.ext_door_ajar, function(s, sensorobj)  {
+        var lockstatus="Auf";
+        if (sensorobj.value) { lockstatus = "Zu"; }
+        sensorstd+='<br/>'+sensorobj.location+': '+lockstatus;
+      });
+      sensorstd+='</td>';
+    }
+    if (data.sensors.ext_dust)
+    {
+      sensorstd+='<td style="background-color:white; height:42px; text-align:center; vertical-align:middle; display:table-cell;"><b>Staub</b>';
+      $.each( data.sensors.ext_dust, function(s, sensorobj) {
+        sensorstd+='<br/>'+sensorobj.location+': '+sensorobj.value+sensorobj.unit+'</td>';
+      });
+      sensorstd+='</td>';
+
+    }    
+    if (sensorstd != "")
+    {
+      sensorshtml='<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>'+sensorstd+'</tr></table>';
+      document.getElementById('sensor_status').innerHTML=sensorshtml;
     }
-  }
-  if (sensorstd != "")
-  {
-    sensorshtml='<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>'+sensorstd+'</tr></table>';
-    document.getElementById('sensor_status').innerHTML=sensorshtml;
   }
 }