1 |
41837
|
michele.ar
|
var module = angular.module('dnetLogUI', ['luegg.directives']);
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
module.controller('dnetLogCtrl', function ($scope, $http, $timeout, $sce) {
|
5 |
|
|
initSpinner();
|
6 |
|
|
|
7 |
|
|
$scope.logs = [];
|
8 |
|
|
$scope.size = 100;
|
9 |
|
|
$scope.interval = 2000;
|
10 |
|
|
$scope.prepaused = false;
|
11 |
|
|
$scope.paused = false;
|
12 |
|
|
|
13 |
|
|
$scope.last = undefined;
|
14 |
|
|
|
15 |
|
|
$scope.filterLog = '';
|
16 |
|
|
|
17 |
|
|
$scope.highlight = function(text, search) {
|
18 |
|
|
return $sce.trustAsHtml(search ? text.replace(new RegExp(search, 'gi'), '<span style="color: red">$&</span>') : text);
|
19 |
|
|
};
|
20 |
|
|
|
21 |
|
|
$scope.pause = function() {
|
22 |
|
|
$scope.prepaused = true;
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
$scope.play = function() {
|
26 |
|
|
if ($scope.paused) {
|
27 |
|
|
$scope.nextLogs();
|
28 |
|
|
}
|
29 |
|
|
$scope.prepaused = false;
|
30 |
|
|
$scope.paused = false;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
$scope.loadLogs = function() {
|
34 |
|
|
showSpinner();
|
35 |
|
|
$scope.logs = [];
|
36 |
|
|
|
37 |
|
|
if ($scope.size) {
|
38 |
|
|
$http.get('log/tail/' + $scope.size).success(function(data) {
|
39 |
|
|
hideSpinner();
|
40 |
|
|
if (data.length > 0) {
|
41 |
|
|
$scope.logs = data;
|
42 |
|
|
|
43 |
|
|
if (!$scope.last) { // The nextLogs cycle is already running
|
44 |
|
|
$timeout($scope.nextLogs, $scope.interval);
|
45 |
|
|
}
|
46 |
|
|
} else {
|
47 |
|
|
$timeout($scope.loadLogs, $scope.interval);
|
48 |
|
|
}
|
49 |
|
|
}).error(function() {
|
50 |
|
|
show_notification("error","An error occurred while fetching logs");
|
51 |
|
|
hideSpinner();
|
52 |
|
|
});
|
53 |
|
|
} else {
|
54 |
|
|
show_notification("error","Invalid value in [Number of lines]");
|
55 |
|
|
$scope.paused = true;
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
$scope.nextLogs = function() {
|
60 |
|
|
$scope.nextLogsStarted = true;
|
61 |
|
|
|
62 |
|
|
$scope.last = $scope.logs[$scope.logs.length - 1].id;
|
63 |
|
|
|
64 |
|
|
$http.get('log/continue/' + $scope.last).success(function(data) {
|
65 |
|
|
if (data.length > 0) {
|
66 |
|
|
var newLogs = [];
|
67 |
|
|
for (var i=0; i < $scope.logs.length; i++) {
|
68 |
|
|
newLogs.push($scope.logs[i]);
|
69 |
|
|
}
|
70 |
|
|
for (var i=0; i < data.length; i++) {
|
71 |
|
|
newLogs.push(data[i]);
|
72 |
|
|
}
|
73 |
|
|
if (newLogs.length > $scope.size) {
|
74 |
|
|
newLogs.splice
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
$scope.logs = newLogs.length <= $scope.size ? newLogs : newLogs.slice(-$scope.size);
|
78 |
|
|
}
|
79 |
|
|
if ($scope.prepaused) {
|
80 |
|
|
$scope.paused = true;
|
81 |
|
|
} else {
|
82 |
|
|
$timeout($scope.nextLogs, $scope.interval);
|
83 |
|
|
}
|
84 |
|
|
}).error(function() {
|
85 |
|
|
show_notification("error","An error occurred while fetching logs");
|
86 |
|
|
hideSpinner();
|
87 |
|
|
});
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
$scope.setTmpParams = function() {
|
91 |
|
|
$scope.tmpInterval = $scope.interval;
|
92 |
|
|
$scope.tmpSize = $scope.size;
|
93 |
|
|
};
|
94 |
|
|
|
95 |
|
|
$scope.updateParams = function(tmpInterval, tmpSize) {
|
96 |
|
|
$scope.interval = tmpInterval;
|
97 |
|
|
$scope.size = tmpSize;
|
98 |
|
|
};
|
99 |
|
|
|
100 |
|
|
$scope.updateLogLevel = function(currentResource, currentLevel) {
|
101 |
|
|
showSpinner();
|
102 |
|
|
$http.get('log/level/' + currentLevel + "/" + currentResource).success(function(data) {
|
103 |
|
|
show_notification("info","Log level updated");
|
104 |
|
|
hideSpinner();
|
105 |
|
|
}).error(function(err) {
|
106 |
|
|
show_notification("error","An error occurred updating log level:\n" + err);
|
107 |
|
|
hideSpinner();
|
108 |
|
|
});
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
$scope.resizeMainElement = function(elem) {
|
112 |
|
|
var height = 0;
|
113 |
|
|
var body = window.document.body;
|
114 |
|
|
if (window.innerHeight) {
|
115 |
|
|
height = window.innerHeight;
|
116 |
|
|
} else if (body.parentElement.clientHeight) {
|
117 |
|
|
height = body.parentElement.clientHeight;
|
118 |
|
|
} else if (body && body.clientHeight) {
|
119 |
|
|
height = body.clientHeight;
|
120 |
|
|
}
|
121 |
|
|
elem.style.height = ((height - elem.offsetTop - 100) + "px");
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
$scope.resizeMainElement(document.getElementById('divLogs'))
|
125 |
|
|
$scope.loadLogs();
|
126 |
|
|
});
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
window.onresize = function() {
|
130 |
|
|
var elem = document.getElementById('divLogs');
|
131 |
|
|
angular.element(elem).scope().resizeMainElement(elem);
|
132 |
|
|
// elem.scrollTop = elem.scrollHeight;
|
133 |
|
|
};
|