-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
242 lines (212 loc) · 7.04 KB
/
index.html
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR=BLACK>
<STYLE>
div.row {
}
div.bottom {
width: 100%;
height: 50px; /* note: should be >= div.bar.height */
background-color: black`;
}
div.bar {
width: 100%;
background-color: antiquewhite;
height: 40px;
line-height: 40px;
position: fixed;
bottom: 0%;
}
span.timestamp {
font-family: "Courier New";
color: antiquewhite;
}
span.msg {
font-family: "Courier New";
font-size: 12px;
color: lightgray;
display: table-cell;
width: 100%;
word-break: break-all;
}
span.path {
font-family: "Courier New";
font-size: 12px;
color: antiquewhite;
display: table-cell;
max-width: 200px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-right: 10px;
}
span.paused {
float: right;
margin: 5px;
padding: 5px;
display: none;
}
span.baritem {
margin-right: 5px;
padding-right: 5px;
}
</STYLE>
<SCRIPT>
//config
var numRows = 1500
//Client-side filtering:
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
var namespace = getUrlParameter('namespace') //initial value
function setNamespaceFromQueryParam() {
var index=Array.apply(null, document.getElementById('namespaceDropdown').options).map(function (x) { return x.value }).indexOf(namespace)
if (index == -1) {
namespace = null
return;
}
filename_filter="_"+namespace+"_"
document.getElementById('namespaceDropdown').selectedIndex=index
namespaceDropdownChanged()
namespace = null;
}
//
var rows = []
function createRow(path, msg, visibility) {
var div = document.createElement("div");
if (!visibility) {
div.style.display = 'none';
}
div.className = "row"
var span1 = document.createElement("span");
div.path = path //for convenience
span1.className = "path"
span1.innerText = path
div.appendChild(span1)
var span2 = document.createElement("span");
div.msg = msg //for convenience
span2.className = "msg"
span2.innerHTML = msg
div.appendChild(span2)
document.body.insertBefore(div, document.getElementById("bottom"));
return div
}
if (!!window.EventSource) {
var source = new EventSource('/stream');
} else {
// Result to xhr polling :(
}
var filename_filter = null;
var paused = false;
source.addEventListener('message', function(e) {
//console.log(e.data);
try {
var obj = JSON.parse(e.data)
} catch (error) {
console.log("Error: skipping line: '"+e.data+"': "+error);
return
}
var searchText = document.getElementById('search').value
var visibility = ((filename_filter == null || obj.fileName.includes(filename_filter)) &&
(searchText == '' || obj.logObject.log.toLowerCase().includes(searchText.toLowerCase())));
var div = createRow(obj.fileName, obj.logObject.log, visibility)
if (!paused) {
setTimeout(function f() {window.scrollTo(0,document.body.scrollHeight); },50);
}
rows.push(div)
if (!paused) { //fix for firefox browser:
if (rows.length > numRows) {
var divToDelete = rows.shift()
document.body.removeChild(divToDelete)
}
}
}, false);
window.addEventListener("scroll", function (event) {
if(this.scrollY-(document.documentElement.scrollHeight - window.innerHeight) < -1.0) {
paused=true;
document.getElementById("paused").style.display="block"
} else {
paused=false;
document.getElementById("paused").style.display="none"
}
return true;
});
function namespaceDropdownChanged() {
var selection = document.getElementById('namespaceDropdown').options[document.getElementById('namespaceDropdown').selectedIndex].text;
if( selection == "(all)" ) {
filename_filter=null;
} else {
filename_filter="_"+selection+"_"
}
//hide divs not matching the new filename_filter:
for (var i in rows) {
if (filename_filter == null || rows[i].path.includes(filename_filter)) {
rows[i].style.display="block"
} else {
rows[i].style.display="none"
}
}
window.scrollTo(0,document.body.scrollHeight);
document.getElementById('search').value = ""
document.getElementById('search').style.backgroundColor = ""
}
function updateNamespaces() {
var items = []
//console.log("updating namespaces...");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var obj=JSON.parse(xhr.responseText);
var arrOptions = [];
var savedvalue = document.getElementById("namespaceDropdown").value
arrOptions.push("<option value='(all)'>(all)</option>");
for (var i in obj.items) {
var name = obj.items[i].metadata.name
//console.log(name);
arrOptions.push("<option value='"+name+"'>"+name+"</option>");
}
document.getElementById("namespaceDropdown").innerHTML = arrOptions.join();
//TODO: handle case where current namespace is deleted:
document.getElementById("namespaceDropdown").value = savedvalue
if(namespace!=null) {
setNamespaceFromQueryParam();
}
}
}
xhr.open('GET', '/namespaces', true);
xhr.send(null);
}
updateNamespaces();
var namespacePollingDelay = 10000;
setTimeout(function floop () { updateNamespaces(); setTimeout(floop, namespacePollingDelay) }, namespacePollingDelay)
function searchInputEvent(x)
{
var searchText = document.getElementById('search').value.toLowerCase()
var matched = false;
//hide divs not matching the search filter:
for (var i in rows) {
if ((searchText == "" || rows[i].msg.toLowerCase().includes(searchText)) &&
(filename_filter == null || rows[i].path.includes(filename_filter))) {
rows[i].style.display="block"
matched = true;
} else {
rows[i].style.display="none"
}
}
if (searchText == '') {
document.getElementById('search').style.backgroundColor = ""
} else if (matched) {
document.getElementById('search').style.backgroundColor = "green"
} else {
document.getElementById('search').style.backgroundColor = "red"
}
}
</SCRIPT>
<DIV ID=bottom CLASS="bottom"></DIV>
<DIV ID=bar CLASS="bar"><SPAN CLASS="baritem">Namespace: <select name="namespace" id="namespaceDropdown" onchange="namespaceDropdownChanged()"><option value="(all)" selected>(all)</option></select></SPAN><SPAN CLASS="baritem">ISearch: <INPUT TYPE=TEXT WIDTH=30 ID=search onInput="searchInputEvent()"></SPAN><SPAN id="paused" CLASS="paused"><A HREF="#" onClick="window.scrollTo(0,document.body.scrollHeight); return false">(paused)</A></SPAN></DIV>
</BODY>
</HTML>