var myApp = angular.module('inventoryApp', []); myApp.controller('update', function($scope, $http, $timeout) { $scope.latch_pending = false; $scope.latch_error = false; $scope.latch_info = "module version ????"; $scope.update_request_status = ""; $scope.update_request_error = false; $scope.check_status = function() { $http({ method: 'GET', url: window.location.origin + "/version" }).then( /* ok response */ function(rsp) { console.log('got version rsp: ' + JSON.stringify(rsp.data)); $scope.latch_info = "module version " + rsp.data.module; $scope.latch_pending = rsp.data.latch.pending; $scope.latch_error = rsp.data.latch.failure; if (!$scope.latch_pending) { $scope.update_request_status = ""; } $timeout($scope.check_status, 5000); }, /* error response */ function(rsp) { console.log("got error response: " + JSON.stringify(rsp)); $scope.latch_info = "communication error"; $scope.latch_pending = false; $scope.latch_error = true; $timeout($scope.check_status(), 5000); } ); } $scope.launch_update = function() { $scope.update_request_status = "sending update request"; $scope.update_request_error = false; $scope.latch_pending = true; $http({ method: 'GET', url: window.location.origin + "/jobs/update" }).then( /* ok response */ function(rsp) { $scope.update_request_status = "update is running"; $scope.update_request_error = false; console.log('got update rsp: ' + JSON.stringify(rsp.data)); }, /* error response */ function(rsp) { $scope.update_request_status = "update request failed"; $scope.update_request_error = true; console.log("got error response: " + JSON.stringify(rsp)); } ); } $scope.check_status(); });