Felix Meschberger | 2c4a606 | 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 | */ |
Felix Meschberger | e31daea | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 17 | |
| 18 | var logsElem = false; |
| 19 | var logs2Elem = false; |
| 20 | var tableElem = false; |
| 21 | var statElem = false; |
| 22 | |
Felix Meschberger | 2c4a606 | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 23 | function renderData( eventData ) { |
Felix Meschberger | e31daea | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 24 | statElem.empty().append(eventData.status ? i18n.status_ok : i18n.status_missing); |
| 25 | logsElem.css("display", eventData.status ? "block" : "none" ); |
| 26 | if (eventData.status) { |
| 27 | $("#plugin_table > tbody > tr").remove(); |
| 28 | var hasEntries = false; |
| 29 | for ( var idx in eventData.data ) { |
| 30 | entry( eventData.data[idx] ); |
| 31 | hasEntries = true; |
| 32 | } |
| 33 | logs2Elem.css("display", hasEntries ? "block" : "none" ); |
| 34 | |
| 35 | if (hasEntries) tableElem.trigger("update").trigger("applyWidgets"); |
| 36 | } |
Felix Meschberger | 2c4a606 | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | function entry( /* Object */ dataEntry ) { |
| 40 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
| 41 | entryInternal( trElement, dataEntry ); |
| 42 | $("#plugin_table > tbody").append(trElement); |
| 43 | } |
| 44 | |
| 45 | function entryInternal( /* Element */ parent, /* Object */ dataEntry ) { |
| 46 | var id = dataEntry.id; |
| 47 | var message = dataEntry.message; |
| 48 | var level = dataEntry.level; |
| 49 | var exception = dataEntry.exception; |
| 50 | var service = dataEntry.service; |
Felix Meschberger | e31daea | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 51 | switch (dataEntry.raw_level) { // i18n |
| 52 | case 1: level = i18n.error; break; |
| 53 | case 2: level = i18n.warn; break; |
| 54 | case 3: level = i18n.info; break; |
| 55 | case 4: level = i18n.debug; break; |
| 56 | } |
Felix Meschberger | 2c4a606 | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 57 | parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) ); |
| 58 | parent.appendChild( td( null, null, [ text( level ) ] ) ); |
Felix Meschberger | e31daea | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 59 | parent.appendChild( td( null, null, [ text( wordWrap(message) ) ] ) ); |
| 60 | parent.appendChild( td( null, null, [ text( wordWrap(service) ) ] ) ); |
Felix Meschberger | 2c4a606 | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 61 | parent.appendChild( td( null, null, [ text( exception ) ] ) ); |
| 62 | } |
| 63 | |
| 64 | /* displays a date in the user's local timezone */ |
| 65 | function printDate(time) { |
| 66 | var date = time ? new Date(time) : new Date(); |
| 67 | return date.toLocaleString(); |
| 68 | } |
| 69 | |
| 70 | function loadData() { |
Felix Meschberger | e31daea | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 71 | $.get(pluginRoot + "/data.json", { "minLevel":$(".minLevel").val()}, renderData, "json"); |
| 72 | return false; // for button |
Felix Meschberger | 2c4a606 | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Felix Meschberger | e31daea | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 75 | $(document).ready(function() { |
| 76 | // install user interaction handlers |
| 77 | $(".reloadButton").click(loadData); |
| 78 | $(".minLevel").change(function() { |
| 79 | var value = $(this).val(); |
| 80 | $(".minLevel").val(value); // same values for both select boxes |
| 81 | $.post(pluginRoot, {"minLevel":value}, function(data) { |
| 82 | renderData(data); |
| 83 | }, "json"); |
| 84 | }); |
| 85 | logsElem = $("#logs"); |
| 86 | logs2Elem = $("#logs2"); |
| 87 | tableElem = $("#plugin_table"); |
| 88 | statElem = $(".statline"); |
| 89 | // load logs |
| 90 | loadData(); |
| 91 | }); |