Skip to content

Commit

Permalink
JS wasn't working as expected in Chrome so I made a few tweaks. #531
Browse files Browse the repository at this point in the history
  • Loading branch information
wilpig committed May 31, 2015
1 parent 707c842 commit e757ac2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions api/v1/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions assets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions cabnavigator.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,18 +521,19 @@ function BuildCabinet($rear=false){

$body.="\t</fieldset>\n";

$body.=' <fieldset name="sensors">
<legend>'.__("Environmental Sensors").'</legend>';
$body.=' <fieldset id="sensors">
<legend>'.__("Environmental Sensors").'</legend>
<div>';

foreach($SensorList as $Sensor){
$body.="\t\t<a href=\"devices.php?DeviceID=$Sensor->DeviceID\">$Sensor->Label</a><br>\n";
}

if($person->CanWrite($cab->AssignedTo)){
$body.="\n\t\t<br>\n\t\t<ul class=\"nav\"><a href=\"devices.php?action=new&CabinetID=$cab->CabinetID&DeviceType=Sensor\"><li>".__("Add Sensor")."</li></a></ul>\n";
$body.="\n\t\t<ul class=\"nav\"><a href=\"devices.php?action=new&CabinetID=$cab->CabinetID&DeviceType=Sensor\"><li>".__("Add Sensor")."</li></a></ul>\n";
}

$body.="\t</fieldset>\n";
$body.="\t\t</div>\n\t</fieldset>\n";


if ($person->CanWrite($cab->AssignedTo) || $person->SiteAdmin) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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('<br>Temp:&nbsp;'+data.sensor.Temperature+'&deg;&nbsp;&nbsp;Humidity:&nbsp;'+data.sensor.Humidity);
// When we add data to the box it grows so we need to adjust the bricks
$('#infopanel').masonry('layout');
$(link).after('<br>Temp:&nbsp;'+data.sensor.Temperature+'&deg;&nbsp;&nbsp;Humidity:&nbsp;'+data.sensor.Humidity+'<br>');
}else{
$(link).after('<br>'+data.message+'<br>');
}
// When we add data to the box it grows so we need to adjust the bricks
$('#infopanel').masonry('layout');
});
});
});
Expand Down

0 comments on commit e757ac2

Please sign in to comment.