1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- angular.module('camotion')
- .controller('SensorsController', ['$scope', 'SensorsService', '$timeout',
- function($scope, SensorsService, $timeout) {
-
- $scope.values = {};
- $scope.interval = 1000;
-
- $scope.luTable = {
- columns: [
- {
- name: "Name",
- width: 3,
- getValue: function (item) {
- return item.Name;
- }
- },{
- name: "Description",
- width: 7,
- getValue: function (item) {
- return item.Description;
- }
- },{
- name: "Value",
- width: 2,
- getValue: function (item) {
- return $scope.values[item.Id].value.Value;
- }
- }
- ],
-
- getLoadPagePromise: function (page, perPage, query, promise) {
- return SensorsService.getAll({page: page, perPage: perPage, query: query}, promise);
- },
-
- onPageChanged: function()
- {
- for (var i in $scope.values) {
- $timeout.cancel($scope.values[i].timerId);
- }
- $scope.values = {};
- var items = $scope.luTable.luBasicTableScope.items.Data;
- for (i = 0; i < items.length; ++i) {
- var item = angular.copy(items[i]);
- $scope.values[item.Id] = {
- value: 0,
- timerId: 0
- };
- $scope.updateSensor(item);
- }
- }
- };
-
- $scope.updateSensor = function(sensor)
- {
- SensorsService.getValue({sensor_id: sensor.Id})
- .then(function(value) {
- if (typeof $scope.values[sensor.Id] != 'undefined') {
- $scope.values[sensor.Id] = {
- value: value,
- timerId: $timeout(function () {
- $scope.updateSensor(sensor);
- }, $scope.interval)
- }
- }
- });
- };
-
- $scope.$on('$destroy', function(){
- $scope.values = {};
- });
- }]);
|