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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
backupApp.controller('LogController', function($scope, $routeParams, SystemInfo, ServerStatus, AppService, DialogService) {
$scope.state = ServerStatus.watch($scope);
$scope.BackupID = $routeParams.backupid;
$scope.SystemInfo = SystemInfo.watch($scope);
var liveRefreshTimer = null;
var PAGE_SIZE = 100;
function updateLivePoll() {
if ($scope.LiveRefreshing) {
$scope.LiveRefreshPending = true;
return;
}
if (liveRefreshTimer != null) {
clearTimeout(liveRefreshTimer);
liveRefreshTimer = null;
}
if ($scope.Page != 'live' || ($scope.LiveLogLevel || '') == '')
return;
$scope.LiveRefreshPending = false;
$scope.LiveRefreshing = true;
AppService.get('/logdata/poll?level=' + $scope.LiveLogLevel + '&id=' + $scope.LiveRefreshID + '&pagesize=' + PAGE_SIZE).then(
function(resp) {
for(var n in resp.data)
$scope.LiveRefreshID = Math.max($scope.LiveRefreshID, resp.data[n].ID);
if ($scope.LiveData == null)
$scope.LiveData = [];
resp.data.reverse();
$scope.LiveData.unshift.apply($scope.LiveData, resp.data);
$scope.LiveData.Length = Math.min(1000, $scope.LiveData.length);
$scope.LiveRefreshing = false;
if ($scope.LiveRefreshPending)
updateLivePoll();
else
if ($scope.Page == 'live' && $scope.LiveLogLevel != '')
liveRefreshTimer = setTimeout(updateLivePoll, 3000);
}, function(resp) {
if ($scope.Page == 'live' && $scope.LiveLogLevel != '')
liveRefreshTimer = setTimeout(updateLivePoll, 3000);
}
);
};
function LoadMoreData(url, key, idfield) {
if ($scope.LoadingData)
return;
var last = null;
if ($scope[key] != null && $scope[key].length > 0 )
last = $scope[key][$scope[key].length - 1][idfield];
$scope.LoadingData = true;
AppService.get(url + '?pagesize=' + PAGE_SIZE + (last == null ? '' : ('&offset=' + last))).then(
function(resp) {
if ($scope[key] == null)
$scope[key] = [];
$scope[key].push.apply($scope[key], resp.data);
$scope.LoadingData = false;
$scope[key + 'Complete'] = resp.data.length < PAGE_SIZE;
}, function(resp) {
var message = resp.statusText;
if (resp.data != null && resp.data.Message != null)
message = resp.data.Message;
$scope.LoadingData = false;
DialogService.dialog('Error', 'Failed to connect: ' + message);
});
};
$scope.$watch('LiveLogLevel', updateLivePoll);
$scope.$watch('Page', updateLivePoll);
$scope.$watch('Page', function() {
if ($scope.Page == 'remote' && $scope.RemoteData == null)
$scope.LoadMoreRemoteData();
});
if ($scope.BackupID == null) {
$scope.Page = 'stored';
$scope.LiveLogLevel = '';
$scope.LiveRefreshID = 0;
$scope.LiveRefreshing = false;
$scope.LiveRefreshPending = false;
$scope.LoadMoreStoredData = function() { LoadMoreData('/logdata/log', 'LogData', 'Timestamp'); };
$scope.LoadMoreStoredData();
} else {
$scope.Page = 'general';
$scope.LoadMoreGeneralData = function() { LoadMoreData('/backup/' + $scope.BackupID + '/log', 'GeneralData', 'ID'); };
$scope.LoadMoreRemoteData = function() { LoadMoreData('/backup/' + $scope.BackupID + '/remotelog', 'RemoteData', 'ID'); };
$scope.LoadMoreGeneralData();
}
});
|