blob: 00f2221c487bb3b7a8d24f1e77de682446548da0 [file] [log] [blame]
Felix Meschbergere1c2cde2009-04-18 12:07:10 +00001/*
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 Meschbergerafcbd602010-02-18 13:02:12 +000017
18var logsElem = false;
19var logs2Elem = false;
20var tableElem = false;
21var statElem = false;
22
Felix Meschbergere1c2cde2009-04-18 12:07:10 +000023function renderData( eventData ) {
Felix Meschbergerafcbd602010-02-18 13:02:12 +000024 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 Meschbergere1c2cde2009-04-18 12:07:10 +000037}
38
39function entry( /* Object */ dataEntry ) {
40 var trElement = tr( null, { id: "entry" + dataEntry.id } );
41 entryInternal( trElement, dataEntry );
42 $("#plugin_table > tbody").append(trElement);
43}
44
45function 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 Valchevc699a632012-01-25 13:04:07 +000050 var exceptionClass = $(".enableTraces").val() == 'true' ? 'ex' : null;
Felix Meschbergere1c2cde2009-04-18 12:07:10 +000051 var service = dataEntry.service;
Felix Meschbergerafcbd602010-02-18 13:02:12 +000052 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 Valchevc699a632012-01-25 13:04:07 +000058 var bundle = text('');
59 if (dataEntry.bundleId) {
60 bundle = createElement( 'a', null, {href : appRoot + '/bundles/' + dataEntry.bundleId}, [ text (dataEntry.bundleName) ] )
61 }
Felix Meschbergere1c2cde2009-04-18 12:07:10 +000062 parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) );
Valentin Valchev5185b7c2010-04-14 13:59:53 +000063 parent.appendChild( td( null, { lvl:dataEntry.raw_level }, [ text( level ) ] ) );
Felix Meschbergerafcbd602010-02-18 13:02:12 +000064 parent.appendChild( td( null, null, [ text( wordWrap(message) ) ] ) );
65 parent.appendChild( td( null, null, [ text( wordWrap(service) ) ] ) );
Valentin Valchevc699a632012-01-25 13:04:07 +000066 parent.appendChild( td( null, null, [ bundle ] ) );
67 parent.appendChild( td( exceptionClass, null, [ text( exception ) ] ) );
Felix Meschbergere1c2cde2009-04-18 12:07:10 +000068}
69
70/* displays a date in the user's local timezone */
71function printDate(time) {
72 var date = time ? new Date(time) : new Date();
73 return date.toLocaleString();
74}
75
76function loadData() {
Valentin Valchevc699a632012-01-25 13:04:07 +000077 $.post(pluginRoot, {
78 "minLevel" : $(".minLevel").val(),
79 "traces" : $(".enableTraces").val()
80 }, renderData, "json");
Felix Meschbergerafcbd602010-02-18 13:02:12 +000081 return false; // for button
Felix Meschbergere1c2cde2009-04-18 12:07:10 +000082}
83
Felix Meschbergerafcbd602010-02-18 13:02:12 +000084$(document).ready(function() {
85 // install user interaction handlers
86 $(".reloadButton").click(loadData);
Valentin Valchevc699a632012-01-25 13:04:07 +000087 $(".enableTraces").change(function() {
88 var val = $(this).val();
89 $(".enableTraces").val(val); // same values for both select boxes
90 loadData();
91 })
Felix Meschbergerafcbd602010-02-18 13:02:12 +000092 $(".minLevel").change(function() {
93 var value = $(this).val();
94 $(".minLevel").val(value); // same values for both select boxes
Valentin Valchevc699a632012-01-25 13:04:07 +000095 loadData();
Felix Meschbergerafcbd602010-02-18 13:02:12 +000096 });
Valentin Valchevc699a632012-01-25 13:04:07 +000097 // init tablesorte
Valentin Valchev5185b7c2010-04-14 13:59:53 +000098 $('#plugin_table').tablesorter({
99 textExtraction: function(node) {
100 var _ = $(node);
101 return _.attr('lvl') ? _.attr('lvl') : _.text();
102 }
103 });
Valentin Valchevc699a632012-01-25 13:04:07 +0000104
Felix Meschbergerafcbd602010-02-18 13:02:12 +0000105 logsElem = $("#logs");
106 logs2Elem = $("#logs2");
107 tableElem = $("#plugin_table");
108 statElem = $(".statline");
109 // load logs
110 loadData();
111});