diff options
| author | Ed Tanous <ed.tanous@intel.com> | 2017-06-28 09:43:09 -0700 |
|---|---|---|
| committer | Ed Tanous <ed.tanous@intel.com> | 2017-06-28 09:43:09 -0700 |
| commit | 5fceeb4563c08468e9623cef1e3d7f4de9373d2f (patch) | |
| tree | 6854993a288f126465e6bd3b089e7090aef7409e /static/js/sensorController.js | |
| parent | 7b4e3dae0477703143b8cb28b3a6abc9d4d0d83b (diff) | |
| download | bmcweb-5fceeb4563c08468e9623cef1e3d7f4de9373d2f.tar.gz bmcweb-5fceeb4563c08468e9623cef1e3d7f4de9373d2f.zip | |
update sensor page
Diffstat (limited to 'static/js/sensorController.js')
| -rw-r--r-- | static/js/sensorController.js | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/static/js/sensorController.js b/static/js/sensorController.js index 67c9d82..0fa9045 100644 --- a/static/js/sensorController.js +++ b/static/js/sensorController.js @@ -1,41 +1,54 @@ angular.module('bmcApp').controller('sensorController', [ '$scope', '$http', '$location', 'websocketService', function($scope, $http, $location, websocketService) { - $scope.sensor_values = {}; + $scope.smartTablePageSize = 10; + $scope.next_id = 0; + websocketService.start('/sensorws', function(evt) { + var obj = JSON.parse(evt.data); - var host = $location.host(); - var port = $location.port(); - var protocol = "ws://"; - if ($location.protocol() === 'https') { - protocol = 'wss://'; - } - websocketService.start(protocol + host + ":" + port + "/sensorws", function (evt) { - var obj = JSON.parse(evt.data); - $scope.$apply(function () { - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - console.log(key + " -> " + obj[key]); - $scope.sensor_values[key] = obj[key]; - } + $scope.$apply(function() { + for (var sensor_name in obj) { + var found = false; + for (var sensor_index in $scope.rowCollection) { + var sensor_object = $scope.rowCollection[sensor_index]; + if (sensor_object.name === sensor_name) { + sensor_object.value = obj[sensor_name]; + found = true; + break; + } } - }); + if (!found) { + console.log(sensor_name + ' -> ' + obj[sensor_name]); + $scope.next_id = $scope.next_id + 1; + + $scope.rowCollection.push({ + id : $scope.next_id, + name : sensor_name, + value : obj[sensor_name], + }); + } + }; + }); }); + $scope.rowCollection = []; + } ]); -app.factory('websocketService', function () { - return { - start: function (url, callback) { - var websocket = new WebSocket(url); - websocket.onopen = function () { - }; - websocket.onclose = function () { - }; - websocket.onmessage = function (evt) { - callback(evt); - }; - } +app.factory('websocketService', function($location) { + return { + start: function(url, callback) { + var host = $location.host(); + var port = 18080; + var protocol = 'wss://'; + if ($location.protocol() === 'http') { + protocol = 'ws://'; } + var websocket = new WebSocket(protocol + host + ':' + port + url); + websocket.onopen = function() {}; + websocket.onclose = function() {}; + websocket.onmessage = function(evt) { callback(evt); }; } -);
\ No newline at end of file + } +});
\ No newline at end of file |

