summaryrefslogtreecommitdiffstats
path: root/logfiles-tail-html.lsp
blob: 921439c946af733813e3b3a1bd0352fb0ccd138c (plain)
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
<% local form, viewlibrary, page_info = ... %>
<% require("viewfunctions") %>

<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"></script>
<script type="text/javascript">
	var currentoffset = -1024
	var ID
	function Update(){
		$.ajaxSetup({cache:false});
		$.getJSON(
			'<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action) %>',
			{name:'<% io.write(html.html_escape(form.value.filename.value)) if form.value.grep.value ~= "" then io.write("',grep:'"..html.html_escape(form.value.grep.value)) end %>', offset:currentoffset},
			function(data) {
				if (currentoffset != data.value.filesize.value){

					/* Before updating content, determine where we're scrolled to.  If we're within
					   25 pixels of the bottom, we'll stick to the bottom. */
					var content = $("#filecontent").get(0);
					var currentHeight = 0;
					var scrollTop = content.scrollTop;
					if (content.scrollHeight > 0)
						currentHeight = content.scrollHeight;
					else
						if (content.offsetHeight > 0)
							currentHeight = content.offsetHeight;
					if (currentHeight - scrollTop - ((content.style.pixelHeight) ? content.style.pixelHeight : content.offsetHeight) < 25)
						scrollTop = currentHeight;

					$("#filecontent").val($("#filecontent").val() + data.value.filecontent.value);

					/* Now, set the scroll. */
					if (scrollTop < currentHeight)
						content.scrollTop = scrollTop;
					else
						content.scrollTop = content.scrollHeight;

					currentoffset = data.value.filesize.value;
					$("DT:contains('File size')").next().text(currentoffset);
				};
			}
		);
		ID=window.setTimeout("Update();", 1000);
	}
	function handleerror(event, request, settings){
		$(this).append("Error requesting page " + settings.url + "<BR>Perhaps the session has timed out.");
		$("#Stop").click();
	}; 
	$(function(){
		$("#errtxt").ajaxError(handleerror);
		$("#Start").attr("disabled","disabled");
	   	<% if not form.value.filename.errtxt then %>
	   	Update();
		<% else %>
		$("#Stop").attr("disabled","disabled");
		<% end %>
	});
</script>

<H1>Tail File</H1>
<DL>
<% 
displayitem(form.value.filename)
displayitem(form.value.filesize)
if form.value.grep.value ~= "" then
	displayitem(form.value.grep)
end
%>
<textarea id="filecontent">
</textarea>
<p class="error" id="errtxt"></p>
<DT>Start / Stop tailing file</DT>
<DD>
<input TYPE="button" ID="Start" VALUE="Start" onClick='$("#errtxt").empty(); Update(); $("#Start").attr("disabled","disabled");$("#Stop").removeAttr("disabled");'>
<input TYPE="button" ID="Stop" VALUE="Stop" onClick='window.clearTimeout(ID); $("#Stop").attr("disabled","disabled");$("#Start").removeAttr("disabled");'>
</DD>
</DL>