Felix Meschberger | e1c2cde | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | function renderStatusLine() { |
| 18 | $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" ); |
| 19 | } |
| 20 | |
| 21 | function renderView( /* Array of String */ columns, /* String */ buttons ) { |
| 22 | renderStatusLine(); |
| 23 | renderButtons(buttons); |
| 24 | var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>"; |
| 25 | for ( var name in columns ) { |
| 26 | txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + "</th>"; |
| 27 | } |
| 28 | txt = txt + "</tr></thead><tbody></tbody></table></div>"; |
| 29 | $("#plugin_content").append( txt ); |
| 30 | renderButtons(buttons); |
| 31 | renderStatusLine(); |
| 32 | } |
| 33 | |
| 34 | function renderButtons( buttons ) { |
| 35 | $("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" + |
| 36 | buttons + "</div></div></form>" ); |
| 37 | } |
| 38 | |
| 39 | function renderData( eventData ) { |
| 40 | $(".statusline").empty().append(eventData.status); |
| 41 | $("#plugin_table > tbody > tr").remove(); |
| 42 | for ( var idx in eventData.data ) { |
| 43 | entry( eventData.data[idx] ); |
| 44 | } |
| 45 | $("#plugin_table").trigger("update"); |
| 46 | } |
| 47 | |
| 48 | function entry( /* Object */ dataEntry ) { |
| 49 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
| 50 | entryInternal( trElement, dataEntry ); |
| 51 | $("#plugin_table > tbody").append(trElement); |
| 52 | } |
| 53 | |
| 54 | function entryInternal( /* Element */ parent, /* Object */ dataEntry ) { |
| 55 | var id = dataEntry.id; |
| 56 | var message = dataEntry.message; |
| 57 | var level = dataEntry.level; |
| 58 | var exception = dataEntry.exception; |
| 59 | var service = dataEntry.service; |
| 60 | |
| 61 | parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) ); |
| 62 | parent.appendChild( td( null, null, [ text( level ) ] ) ); |
| 63 | parent.appendChild( td( null, null, [ text( message ) ] ) ); |
| 64 | parent.appendChild( td( null, null, [ text( service ) ] ) ); |
| 65 | parent.appendChild( td( null, null, [ text( exception ) ] ) ); |
| 66 | } |
| 67 | |
| 68 | /* displays a date in the user's local timezone */ |
| 69 | function printDate(time) { |
| 70 | var date = time ? new Date(time) : new Date(); |
| 71 | return date.toLocaleString(); |
| 72 | } |
| 73 | |
| 74 | function loadData() { |
| 75 | $.get(pluginRoot + "/data.json", { "minLevel":$("#minLevel").val()}, function(data) { |
| 76 | renderData(data); |
| 77 | }, "json"); |
| 78 | } |
| 79 | |
| 80 | function renderLogs() { |
| 81 | $(document).ready(function(){ |
| 82 | renderView( ["Received", "Level", "Message", "Service", "Exception"], |
| 83 | "<span>Severity at least: <select id='minLevel'><option value='1'>ERROR</option>" + |
| 84 | "<option value='2'>WARN</option><option value='3'>INFO</option><option value='4' selected='selected'>DEBUG</option></select></span> "+ |
| 85 | "<button class='reloadButton' type='button' name='reload'>Reload</button>"); |
| 86 | loadData(); |
| 87 | |
| 88 | $("#plugin_table").tablesorter(); |
| 89 | $(".reloadButton").click(loadData); |
| 90 | $("#minLevel").change(function() { |
| 91 | $.post(pluginRoot, { "minLevel":$("#minLevel").val()}, function(data) { |
| 92 | renderData(data); |
| 93 | }, "json"); |
| 94 | }); |
| 95 | }); |
| 96 | } |