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 | */ |
Felix Meschberger | afcbd60 | 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 | e1c2cde | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 23 | function renderData( eventData ) { |
Felix Meschberger | afcbd60 | 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 | e1c2cde | 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; |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 50 | var exceptionClass = $(".enableTraces").val() == 'true' ? 'ex' : null; |
Felix Meschberger | e1c2cde | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 51 | var service = dataEntry.service; |
Felix Meschberger | afcbd60 | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 52 | switch (dataEntry.raw_level) { // i18n |
| 53 | case 1: level = i18n.error; break; |
| 54 | case 2: level = i18n.warn; break; |
| 55 | case 3: level = i18n.info; break; |
| 56 | case 4: level = i18n.debug; break; |
| 57 | } |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 58 | var bundle = text(''); |
| 59 | if (dataEntry.bundleId) { |
| 60 | bundle = createElement( 'a', null, {href : appRoot + '/bundles/' + dataEntry.bundleId}, [ text (dataEntry.bundleName) ] ) |
| 61 | } |
Felix Meschberger | e1c2cde | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 62 | parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) ); |
Valentin Valchev | 5185b7c | 2010-04-14 13:59:53 +0000 | [diff] [blame] | 63 | parent.appendChild( td( null, { lvl:dataEntry.raw_level }, [ text( level ) ] ) ); |
Felix Meschberger | afcbd60 | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 64 | parent.appendChild( td( null, null, [ text( wordWrap(message) ) ] ) ); |
| 65 | parent.appendChild( td( null, null, [ text( wordWrap(service) ) ] ) ); |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 66 | parent.appendChild( td( null, null, [ bundle ] ) ); |
| 67 | parent.appendChild( td( exceptionClass, null, [ text( exception ) ] ) ); |
Felix Meschberger | e1c2cde | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /* displays a date in the user's local timezone */ |
| 71 | function printDate(time) { |
| 72 | var date = time ? new Date(time) : new Date(); |
| 73 | return date.toLocaleString(); |
| 74 | } |
| 75 | |
| 76 | function loadData() { |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 77 | $.post(pluginRoot, { |
| 78 | "minLevel" : $(".minLevel").val(), |
| 79 | "traces" : $(".enableTraces").val() |
| 80 | }, renderData, "json"); |
Felix Meschberger | afcbd60 | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 81 | return false; // for button |
Felix Meschberger | e1c2cde | 2009-04-18 12:07:10 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Felix Meschberger | afcbd60 | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 84 | $(document).ready(function() { |
| 85 | // install user interaction handlers |
| 86 | $(".reloadButton").click(loadData); |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 87 | $(".enableTraces").change(function() { |
| 88 | var val = $(this).val(); |
| 89 | $(".enableTraces").val(val); // same values for both select boxes |
| 90 | loadData(); |
| 91 | }) |
Felix Meschberger | afcbd60 | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 92 | $(".minLevel").change(function() { |
| 93 | var value = $(this).val(); |
| 94 | $(".minLevel").val(value); // same values for both select boxes |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 95 | loadData(); |
Felix Meschberger | afcbd60 | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 96 | }); |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 97 | // init tablesorte |
Valentin Valchev | 5185b7c | 2010-04-14 13:59:53 +0000 | [diff] [blame] | 98 | $('#plugin_table').tablesorter({ |
| 99 | textExtraction: function(node) { |
| 100 | var _ = $(node); |
| 101 | return _.attr('lvl') ? _.attr('lvl') : _.text(); |
| 102 | } |
| 103 | }); |
Valentin Valchev | c699a63 | 2012-01-25 13:04:07 +0000 | [diff] [blame] | 104 | |
Felix Meschberger | afcbd60 | 2010-02-18 13:02:12 +0000 | [diff] [blame] | 105 | logsElem = $("#logs"); |
| 106 | logs2Elem = $("#logs2"); |
| 107 | tableElem = $("#plugin_table"); |
| 108 | statElem = $(".statline"); |
| 109 | // load logs |
| 110 | loadData(); |
| 111 | }); |