1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- angular.module('camotion')
- .controller('CamerasController', ['$scope', 'CamerasService', '$timeout',
- function($scope, CamerasService, $timeout) {
-
- $scope.cameras = [];
- $scope.images = {};
- $scope.interval = 1000;
-
- $scope.playPause = function(camera)
- {
- if ($scope.isPlaying(camera)) {
- $scope.pause(camera);
- }
- else {
- $scope.play(camera);
- }
- };
-
- $scope.play = function(camera)
- {
- if (!$scope.isPlaying(camera)) {
- $scope.images[camera.Id] = {
- image: null,
- timerId: 0
- };
- $scope.updateCamera(camera);
- }
- };
-
- $scope.pause = function(camera)
- {
- if ($scope.isPlaying(camera)) {
- $scope.images[camera.Id] = null;
- }
- };
-
- $scope.isPlaying = function(camera)
- {
- return $scope.images[camera.Id] != null;
- };
-
- $scope.updateCamera = function(camera)
- {
- if ($scope.isPlaying(camera)) {
- CamerasService.getImage({camera_id: camera.Id})
- .then(function (image) {
- if ($scope.isPlaying(camera)) {
- $scope.images[camera.Id] = {
- image: image.Image,
- timerId: $timeout(function () {
- $scope.updateCamera(camera);
- }, $scope.interval)
- }
- }
- }, function (error) {
- $scope.pause(camera);
- });
- }
- };
-
- CamerasService.getAll({}).then(function(cameras)
- {
- $scope.images = {};
- $scope.cameras = cameras.Data;
- for (var i = 0; i < $scope.cameras.length; ++i) {
- var camera = angular.copy($scope.cameras[i]);
- $scope.play(camera);
- }
- });
-
- $scope.$on('$destroy', function(){
- $scope.images = {};
- });
- }]);
|