diff --git a/api/v1/index.php b/api/v1/index.php index 87d6095ad..d5b0655b5 100644 --- a/api/v1/index.php +++ b/api/v1/index.php @@ -419,7 +419,7 @@ function authenticate(\Slim\Route $route) { $response['errorcode']=404; $response['message']=__("Device not found"); }else{ - $reading=$dev->GetSensorReading(); + $reading=$dev->GetSensorReading(false); if(!$reading){ $response['error']=true; $response['errorcode']=404; @@ -431,7 +431,7 @@ function authenticate(\Slim\Route $route) { } } - echoResponse($response['errorcode'],$response); + echoResponse(200,$response); }); // this is messy as all hell and i'm still thinking about how to do it better diff --git a/assets.inc.php b/assets.inc.php index 91d357ca7..9072a0511 100644 --- a/assets.inc.php +++ b/assets.inc.php @@ -3183,9 +3183,9 @@ static function UpdateSensors($CabinetID=null){ return true; } - function GetSensorReading(){ + function GetSensorReading($filterrights=true){ global $dbh; - if(!$this->getDevice()){ + if(!$this->getDevice($filterrights)){ return false; } // If this isn't a sensor device or doesn't have a template we can't have readings from it diff --git a/cabnavigator.php b/cabnavigator.php index 62f4f8d1d..05d487472 100644 --- a/cabnavigator.php +++ b/cabnavigator.php @@ -521,18 +521,19 @@ function BuildCabinet($rear=false){ $body.="\t\n"; - $body.='
- '.__("Environmental Sensors").''; + $body.='
+ '.__("Environmental Sensors").' +
'; foreach($SensorList as $Sensor){ $body.="\t\tDeviceID\">$Sensor->Label
\n"; } if($person->CanWrite($cab->AssignedTo)){ - $body.="\n\t\t
\n\t\t\n"; + $body.="\n\t\t\n"; } - $body.="\t
\n"; + $body.="\t\t\n\t
\n"; if ($person->CanWrite($cab->AssignedTo) || $person->SiteAdmin) { @@ -644,6 +645,7 @@ function BuildCabinet($rear=false){ if($("#legend *").length==1){$("#legend").hide();} if($("#keylock div").text().trim()==""){$("#keylock").hide();} if($("#cabnotes div").text().trim()==""){$("#cabnotes").hide();} + if($("#sensors div").text().trim()==""){$("#sensors").hide();} $("#verifyaudit").click(function(e){ e.preventDefault(); @@ -808,14 +810,16 @@ function flippyfloppy(){ $('#cabnotes > div').html($('#cabnotes > div').text()); // Add sensor data to the page - $('fieldset[name=sensors] a:not([href$=Sensor])').each(function(){ + $('#sensors a:not([href$=Sensor])').each(function(){ var link=this; $.get('api/v1/device/'+link.href.split('=').pop()+'/getsensorreadings',function(data){ if(!data.error){ - $(link).after('
Temp: '+data.sensor.Temperature+'°  Humidity: '+data.sensor.Humidity); - // When we add data to the box it grows so we need to adjust the bricks - $('#infopanel').masonry('layout'); + $(link).after('
Temp: '+data.sensor.Temperature+'°  Humidity: '+data.sensor.Humidity+'
'); + }else{ + $(link).after('
'+data.message+'
'); } + // When we add data to the box it grows so we need to adjust the bricks + $('#infopanel').masonry('layout'); }); }); });