-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathhydra-log.js
189 lines (158 loc) · 5.81 KB
/
hydra-log.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
angular
.module('nzbhydraApp')
.directive('hydralog', hydralog);
function hydralog() {
return {
templateUrl: "static/html/directives/log.html",
controller: controller
};
function controller($scope, $http, $interval, $uibModal, $sce, localStorageService, growl) {
$scope.tailInterval = null;
$scope.doUpdateLog = localStorageService.get("doUpdateLog") !== null ? localStorageService.get("doUpdateLog") : false;
$scope.doTailLog = localStorageService.get("doTailLog") !== null ? localStorageService.get("doTailLog") : false;
$scope.active = 0;
$scope.currentJsonIndex = 0;
$scope.hasMoreJsonLines = true;
function getLog(index) {
if ($scope.active === 0) {
return $http.get("internalapi/debuginfos/jsonlogs", {
params: {
offset: index,
limit: 500
}
}).then(function (response) {
var data = response.data;
$scope.jsonLogLines = angular.fromJson(data.lines);
$scope.hasMoreJsonLines = data.hasMore;
});
} else if ($scope.active === 1) {
return $http.get("internalapi/debuginfos/currentlogfile").then(function (response) {
var data = response.data;
$scope.log = $sce.trustAsHtml(data.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'"));
}, function (data) {
growl.error(data)
});
} else if ($scope.active === 2) {
return $http.get("internalapi/debuginfos/logfilenames").then(function (response) {
$scope.logfilenames = response.data;
});
}
}
$scope.logPromise = getLog();
$scope.select = function (index) {
$scope.active = index;
$scope.update();
};
$scope.scrollToBottom = function () {
document.getElementById("logfile").scrollTop = 10000000;
document.getElementById("logfile").scrollTop = 100001000;
};
$scope.update = function () {
getLog($scope.currentJsonIndex);
if ($scope.active === 1) {
$scope.scrollToBottom();
}
};
$scope.getOlderFormatted = function () {
getLog($scope.currentJsonIndex + 500).then(function () {
$scope.currentJsonIndex += 500;
});
};
$scope.getNewerFormatted = function () {
var index = Math.max($scope.currentJsonIndex - 500, 0);
getLog(index);
$scope.currentJsonIndex = index;
};
function startUpdateLogInterval() {
$scope.tailInterval = $interval(function () {
if ($scope.active === 1) {
$scope.update();
if ($scope.doTailLog && $scope.active === 1) {
$scope.scrollToBottom();
}
}
}, 5000);
}
$scope.toggleUpdate = function (doUpdateLog) {
$scope.doUpdateLog = doUpdateLog;
if ($scope.doUpdateLog) {
startUpdateLogInterval();
} else if ($scope.tailInterval !== null) {
console.log("Cancelling");
$interval.cancel($scope.tailInterval);
localStorageService.set("doTailLog", false);
$scope.doTailLog = false;
}
localStorageService.set("doUpdateLog", $scope.doUpdateLog);
};
$scope.toggleTailLog = function () {
localStorageService.set("doTailLog", $scope.doTailLog);
};
$scope.openModal = function openModal(entry) {
var modalInstance = $uibModal.open({
templateUrl: 'log-entry.html',
controller: LogModalInstanceCtrl,
size: "xl",
resolve: {
entry: function () {
return entry;
}
}
});
modalInstance.result.then();
};
$scope.$on('$destroy', function () {
if ($scope.tailInterval !== null) {
$interval.cancel($scope.tailInterval);
}
});
if ($scope.doUpdateLog) {
startUpdateLogInterval();
}
}
}
angular
.module('nzbhydraApp')
.controller('LogModalInstanceCtrl', LogModalInstanceCtrl);
function LogModalInstanceCtrl($scope, $uibModalInstance, entry) {
$scope.entry = entry;
$scope.ok = function () {
$uibModalInstance.dismiss();
};
}
angular
.module('nzbhydraApp')
.filter('formatTimestamp', formatTimestamp);
function formatTimestamp() {
return function (date) {
//1579392000
//1579374757
if (date === null || date === undefined) {
return null;
}
if (date < 1979374757) {
date *= 1000;
}
return moment(date).local().format("YYYY-MM-DD HH:mm");
}
}
angular
.module('nzbhydraApp')
.filter('escapeHtml', escapeHtml);
function escapeHtml($sanitize) {
return function (text) {
return $sanitize(text);
}
}
angular
.module('nzbhydraApp')
.filter('formatClassname', formatClassname);
function formatClassname() {
return function (fqn) {
return fqn.substr(fqn.lastIndexOf(".") + 1);
}
}