Created
March 11, 2018 12:39
-
-
Save drweaver/efd81aa8ad86192a8b7e974a04af9741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html ng-app="surveillance"> | |
<head> | |
<link rel="icon" type="image/png" href="favicon.png" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> | |
<script> | |
angular.module('surveillance', []) | |
.controller('CamListController', ['$scope', function($scope) { | |
$scope.cams = [ | |
{name:'Garage', path:'garagecam'}, | |
{name:'Lounge', path:'loungecam'}, | |
{name:'Garden', path:'gardencam'} | |
]; | |
$scope.pageVisible = true; | |
window.document.addEventListener("visibilitychange", function(e) { | |
if( window.document.visibilityState == 'hidden' ) { | |
$scope.pageVisible = false; | |
} | |
if( window.document.visibilityState == 'visible' ) { | |
$scope.pageVisible = true; | |
} | |
$scope.$apply(); | |
}); | |
}]) | |
.controller('CamController', ['$scope', '$http', '$rootScope', function($scope, $http, $rootScope) { | |
$scope.status = 'loading...'; | |
$scope.setCam = function(cam) { | |
$scope.cam = cam; | |
console.log($scope.cam.path); | |
$scope.getDetection('status'); | |
}; | |
$scope.getDetection = function(action){ | |
$http.get('/'+$scope.cam.path+'control/0/detection/'+action).then(function(response) { | |
$scope.status = response.data.split(" ").pop().toLowerCase(); | |
}, function(response) { | |
console.log('error: '+response); | |
$scope.status = 'unknown'; | |
}); | |
}; | |
$scope.expanded = false; | |
$scope.hideMe = false; | |
$scope.expandToggle = function() { | |
$scope.expanded = !$scope.expanded; | |
$rootScope.$broadcast($scope.expanded?'showCam':'showAllCams', $scope.cam.path); | |
}; | |
$scope.$on('showAllCams', function(event, args) { | |
$scope.hideMe = false; | |
}); | |
$scope.$on('showCam', function(event, args) { | |
$scope.hideMe = args != $scope.cam.path; | |
}); | |
$scope.counter=0; | |
$scope.incrementCounter = function() { | |
$scope.counter++; | |
}; | |
}]); | |
</script> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="page-header"> | |
<h1>Surveillance</h1> | |
</div> | |
<div class="row" ng-controller="CamListController"> | |
<div ng-hide="hideMe" class="{{expanded?'col-sm-12':'col-sm-6'}}" ng-repeat="item in cams" ng-controller="CamController" ng-init="setCam(item)"> | |
<div class="thumbnail"> | |
<img class="img-responsive" ng-src="/{{item.path}}/?c={{counter}}" ng-click="expandToggle()" ng-if="pageVisible"/> | |
<div class="caption"> | |
<h3> | |
{{item.name}} | |
<div class="btn-group" role="group"> | |
<button type="button" class="btn btn-default btn-sm" ng-click="getDetection('start')"> | |
<span class="glyphicon glyphicon-play" aria-hidden="true"></span> | |
</button> | |
<button type="button" class="btn btn-default btn-sm" ng-click="getDetection('pause')"> | |
<span class="glyphicon glyphicon-pause" aria-hidden="true"></span> | |
</button> | |
</div> | |
<span class="badge">{{status}}</span> | |
<button type="button" class="btn btn-default btn-sm hidden-xs" ng-click="expandToggle()"> | |
<span class="glyphicon glyphicon-resize-{{expanded ? 'small' : 'full'}}" aria-hidden="true"></span> | |
</button> | |
<button type="button" class="btn btn-default btn-sm" ng-click="incrementCounter()"> | |
<span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> | |
</button> | |
</h3> | |
</div> <!-- caption --> | |
</div> <!-- thumbnail --> | |
</div> <!-- col --> | |
</div> <!-- row --> | |
</div> <!-- container --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment