-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathrestart-service.js
80 lines (71 loc) · 3.06 KB
/
restart-service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
angular
.module('nzbhydraApp')
.factory('RestartService', RestartService);
function RestartService(growl, NzbHydraControlService, $uibModal) {
return {
restart: restart,
startCountdown: startCountdown
};
function restart(message) {
NzbHydraControlService.restart().then(function (response) {
startCountdown(message, response.data.message);
}, function () {
growl.info("Unable to send restart command.");
})
}
function startCountdown(message, baseUrl) {
$uibModal.open({
templateUrl: 'static/html/restart-modal.html',
controller: RestartModalInstanceCtrl,
size: "md",
backdrop: 'static',
keyboard: false,
resolve: {
message: function () {
return message;
},
baseUrl: function () {
return baseUrl;
}
}
});
}
}
angular
.module('nzbhydraApp')
.controller('RestartModalInstanceCtrl', RestartModalInstanceCtrl);
function RestartModalInstanceCtrl($scope, $timeout, $http, $window, RequestsErrorHandler, message, baseUrl) {
message = (angular.isDefined(message) ? message : "");
$scope.message = message + "Will reload page when NZBHydra is back";
$scope.baseUrl = baseUrl;
$scope.pingUrl = angular.isDefined(baseUrl) ? (baseUrl + "/internalapi/control/ping") : "internalapi/control/ping";
$scope.internalCaR = function (message, timer) {
if (timer === 45) {
$scope.message = message + " Restarting takes longer than expected. You might want to check the log to see what's going on.";
} else {
$scope.message = message + " Will reload page when NZBHydra is back.";
$timeout(function () {
RequestsErrorHandler.specificallyHandled(function () {
$http.get($scope.pingUrl, {ignoreLoadingBar: true}).then(
function () {
$timeout(function () {
$scope.message = "Reloading page...";
if (angular.isDefined($scope.baseUrl)) {
$window.location.href = $scope.baseUrl;
} else {
$window.location.reload();
}
}, 2000); //Give Hydra some time to load in the background, it might return the ping but not be completely up yet
}, function () {
$scope.internalCaR(message, timer + 1);
});
});
}, 1000);
$scope.message = message + " Will reload page when NZBHydra is back.";
}
};
//Wait three seconds because otherwise the currently running instance will be found
$timeout(function () {
$scope.internalCaR(message, 0);
}, 3000)
}