diff options
| author | Ed Tanous <ed.tanous@intel.com> | 2017-08-15 09:37:42 -0700 |
|---|---|---|
| committer | Ed Tanous <ed.tanous@intel.com> | 2017-10-11 13:34:56 -0700 |
| commit | 911ac31759cb7b77a856af8806b4e064d50d7422 (patch) | |
| tree | c4b714fabb2b956936ab6dffc18d9ff418756cf4 /static/js | |
| parent | 8f0c0481d2280919b38a31656ba21a4347d12620 (diff) | |
| download | bmcweb-911ac31759cb7b77a856af8806b4e064d50d7422.tar.gz bmcweb-911ac31759cb7b77a856af8806b4e064d50d7422.zip | |
Large updates to webserver
Do not merge yet
Change-Id: I38c56844c1b0e3e8e5493c2705e62e6db7ee2102
Diffstat (limited to 'static/js')
| -rw-r--r-- | static/js/bmcApp.js | 13 | ||||
| -rw-r--r-- | static/js/dbusWebsocketFactory.js | 20 | ||||
| -rw-r--r-- | static/js/fwupdateController.js | 143 | ||||
| -rw-r--r-- | static/js/fwupdateconfirmController.js | 5 | ||||
| -rw-r--r-- | static/js/sensorController.js | 86 |
5 files changed, 137 insertions, 130 deletions
diff --git a/static/js/bmcApp.js b/static/js/bmcApp.js index fb641ab..f1e02c7 100644 --- a/static/js/bmcApp.js +++ b/static/js/bmcApp.js @@ -71,6 +71,19 @@ app.directive('windowSize', [ } ]); +app.directive('fileInput', ['$parse', function ($parse) { + return { + restrict: 'A', + link: function (scope, element, attributes) { + element.bind('change', function () { + $parse(attributes.fileInput) + .assign(scope,element[0].files) + scope.$apply() + }); + } + }; +}]); + app.run([ '$rootScope', '$cookieStore', '$state', 'AuthenticationService', '$http', '$templateCache', diff --git a/static/js/dbusWebsocketFactory.js b/static/js/dbusWebsocketFactory.js new file mode 100644 index 0000000..716f2df --- /dev/null +++ b/static/js/dbusWebsocketFactory.js @@ -0,0 +1,20 @@ +angular.module('bmcApp').factory('dbusWebsocketService', [ + '$location', + function($location) { + return { + start: function(dbus_namespace, callback) { + var url = '/dbus_monitor?path_namespace=' + dbus_namespace; + 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 diff --git a/static/js/fwupdateController.js b/static/js/fwupdateController.js index d5eab07..e33a30f 100644 --- a/static/js/fwupdateController.js +++ b/static/js/fwupdateController.js @@ -1,86 +1,87 @@ angular.module('bmcApp').controller('fwupdateController', [ '$scope', '$http', '$uibModal', '$state', function($scope, $http, $uibModal, $state) { - $scope.upload = function(files) { - r = new FileReader(); - r.onload = function(e) { - get_image_info = function(buffer) { - image_info = {'valid' : false} - var expected = '*SignedImage*\0\0\0' + $scope.files = []; + $scope.$watch('files', function(newValue, oldValue) { + if (newValue.length > 0) { + console.log('Loading firware file ' + $scope.files[0]); + r = new FileReader(); + r.onload = function(e) { + get_image_info = function(buffer) { + image_info = {'valid' : false}; + var expected = '*SignedImage*\0\0\0'; - var dv1 = new Int8Array(e.target.result, 0, 16); + var dv1 = new Int8Array(e.target.result, 0, 16); - for (var i = 0; i != expected.length; i++) { - if (dv1[i] != expected.charCodeAt(i)) { - return image_info; + for (var i = 0; i != expected.length; i++) { + if (dv1[i] != expected.charCodeAt(i)) { + return image_info; + } } - } - image_info['valid'] = true; - var generation = new Int8Array(e.target.result, 16, 17)[0]; - image_info['generation'] = generation; - if ((generation < 4) || - (generation > 5)) { // not VLN generation header + image_info['valid'] = true; + var generation = new Int8Array(e.target.result, 16, 17)[0]; + image_info['generation'] = generation; + if ((generation < 4) || + (generation > 5)) { // not VLN generation header - return image_info; - } else { - var version_minor = new Uint16Array(e.target.result, 20, 22)[0]; - image_info['major_version'] = - new Uint8Array(e.target.result, 28, 29)[0]; - image_info['submajor_version'] = - new Uint8Array(e.target.result, 29, 30)[0].toString(16); - var version_minor2 = new Uint16Array(e.target.result, 30, 32)[0]; - image_info['sha1_version'] = - ('0000' + version_minor2.toString(16)).substr(-4) + - ('0000' + version_minor.toString(16)).substr(-4); + return image_info; + } else { + var version_minor = new Uint16Array(e.target.result, 20, 22)[0]; + image_info['major_version'] = + new Uint8Array(e.target.result, 28, 29)[0]; + image_info['submajor_version'] = + new Uint8Array(e.target.result, 29, 30)[0].toString(16); + var version_minor2 = new Uint16Array(e.target.result, 30, 32)[0]; + image_info['sha1_version'] = + ('0000' + version_minor2.toString(16)).substr(-4) + + ('0000' + version_minor.toString(16)).substr(-4); } - return image_info; - }; - var image_info = get_image_info(e.target.result); - $scope.image_info = image_info; - - var objectSelectionModal = $uibModal.open({ - templateUrl : 'static/partial-fwupdateconfirm.html', - controller : function($scope) { - $scope.image_info = image_info; - $scope.file_to_load = file_to_load; - // The function that is called for modal closing (positive button) - - $scope.okModal = function() { - // Closing the model with result - objectSelectionModal.close($scope.selection); - $http({ - method : 'POST', - url : '/intel/firmwareupload', - data : e.target.result, - transformRequest : [], - headers : {'Content-Type' : 'application/octet-stream'} - }) - .then( - function successCallback(response) { - console.log('Success uploaded. Response: ' + - response.data) - }, - function errorCallback(response) { - console.log('Error status: ' + response.status) - }); - }; - - // The function that is called for modal dismissal(negative button) + return image_info; + }; + var image_info = get_image_info(e.target.result); + $scope.image_info = image_info; - $scope.dismissModal = function() { - objectSelectionModal.dismiss(); - }; + var objectSelectionModal = $uibModal.open({ + templateUrl : 'static/partial-fwupdateconfirm.html', + controller : function($scope) { + $scope.image_info = image_info; + $scope.file_to_load = file_to_load; + // The function that is called for modal closing (positive button) - } + $scope.okModal = function() { + // Closing the model with result + objectSelectionModal.close($scope.selection); + $http({ + method : 'POST', + url : '/intel/firmwareupload', + data : e.target.result, + transformRequest : [], + headers : {'Content-Type' : 'application/octet-stream'} + }) + .then( + function successCallback(response) { + console.log('Success uploaded. Response: ' + + response.data) + }, + function errorCallback(response) { + console.log('Error status: ' + response.status) + }); + }; - }); - }; - var file_to_load = files[0]; - $scope.file_to_load = file_to_load; - r.readAsArrayBuffer(files[0]); + // The function that is called for modal dismissal(negative + // button) - }; + $scope.dismissModal = function() { + objectSelectionModal.dismiss(); + }; + } + }); + }; + var file_to_load = $scope.files[0]; + $scope.file_to_load = $scope.files[0]; + r.readAsArrayBuffer($scope.files[0]); + } + }); - $scope.filename = ''; } ]);
\ No newline at end of file diff --git a/static/js/fwupdateconfirmController.js b/static/js/fwupdateconfirmController.js deleted file mode 100644 index 845e73d..0000000 --- a/static/js/fwupdateconfirmController.js +++ /dev/null @@ -1,5 +0,0 @@ -angular.module('bmcApp').controller('fwupdateconfirmController', [ - '$scope', '$stateParams',function($scope, $stateParams) { - $scope.filename = $stateParams.filename; - } -]);
\ No newline at end of file diff --git a/static/js/sensorController.js b/static/js/sensorController.js index 3943192..272dfee 100644 --- a/static/js/sensorController.js +++ b/static/js/sensorController.js @@ -1,59 +1,37 @@ -angular.module('bmcApp') - .controller( - 'sensorController', - [ - '$scope', '$http', '$location', 'websocketService', - function($scope, $http, $location, websocketService) { - $scope.smartTablePageSize = 10; - $scope.next_id = 0; - websocketService.start('/dbus_monitor', function(evt) { - var obj = JSON.parse(evt.data); +angular.module('bmcApp').controller('sensorController', [ + '$scope', '$http', '$location', 'dbusWebsocketService', + function($scope, $http, $location, dbusWebsocketService) { + $scope.smartTablePageSize = 10; + $scope.next_id = 0; + dbusWebsocketService.start('/xyz/openbmc_project/sensors', function(evt) { + var obj = JSON.parse(evt.data); - $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.$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.push({ + id : $scope.next_id, + name : sensor_name, + value : obj[sensor_name], }); + } + }; + }); + }); - $scope.rowCollection = []; + $scope.rowCollection = []; - } - ]) - .factory('websocketService', [ - '$location', - 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 + } +]); |

