Skip to content
Snippets Groups Projects
Commit f446ceb9 authored by Erik Reid's avatar Erik Reid
Browse files

added a simple smart(ish) update button gui

parent 66c8cd48
No related branches found
No related tags found
No related merge requests found
.grid-container {
display: grid;
}
.ok {
}
.error {
color: red;
font-weight: bold;
}
<!doctype html>
<html ng-app="inventoryApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="update.js"></script>
<link rel="stylesheet" href="update.css">
</head>
<body>
<div ng-controller="update">
<div class="grid-container">
<div class="grid-item">
<button type="button"
class="btn btn-primary btn-lg"
ng-click="launch_update()"
ng-disabled="latch_pending">Update Inventory Provider</button>
</div>
<div class="grid-item" ng-class="latch_error||update_request_error ? 'error' : 'ok'">
{{ latch_info }}
</div>
<div class="grid-item" ng-class="update_request_error ? 'error' : 'ok'">
{{ update_request_status }}
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
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();
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment