Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 1 | angular.module('bmcApp').controller('sensorController', [ |
| 2 | '$scope', '$http', '$location', 'dbusWebsocketService', |
| 3 | function($scope, $http, $location, dbusWebsocketService) { |
| 4 | $scope.smartTablePageSize = 10; |
| 5 | $scope.next_id = 0; |
| 6 | dbusWebsocketService.start('/xyz/openbmc_project/sensors', function(evt) { |
| 7 | var obj = JSON.parse(evt.data); |
Ed Tanous | 4d92cbf | 2017-06-22 15:41:02 -0700 | [diff] [blame] | 8 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 9 | $scope.$apply(function() { |
| 10 | for (var sensor_name in obj) { |
| 11 | var found = false; |
| 12 | for (var sensor_index in $scope.rowCollection) { |
| 13 | var sensor_object = $scope.rowCollection[sensor_index]; |
| 14 | if (sensor_object.name === sensor_name) { |
| 15 | sensor_object.value = obj[sensor_name]; |
| 16 | found = true; |
| 17 | break; |
| 18 | } |
| 19 | } |
| 20 | if (!found) { |
| 21 | console.log(sensor_name + ' -> ' + obj[sensor_name]); |
| 22 | $scope.next_id = $scope.next_id + 1; |
Ed Tanous | 5fceeb4 | 2017-06-28 09:43:09 -0700 | [diff] [blame] | 23 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 24 | $scope.rowCollection.push({ |
| 25 | id : $scope.next_id, |
| 26 | name : sensor_name, |
| 27 | value : obj[sensor_name], |
Ed Tanous | 5fceeb4 | 2017-06-28 09:43:09 -0700 | [diff] [blame] | 28 | }); |
| 29 | } |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 30 | }; |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | $scope.rowCollection = []; |
| 35 | |
| 36 | } |
| 37 | ]); |