blob: acfdcec457b16cc9edeff1f1aca1cbcd92b8fa84 [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;
50 var service = dataEntry.service;
Felix Meschbergerafcbd602010-02-18 13:02:12 +000051 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 Meschbergere1c2cde2009-04-18 12:07:10 +000057 parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) );
Valentin Valchev5185b7c2010-04-14 13:59:53 +000058 parent.appendChild( td( null, { lvl:dataEntry.raw_level }, [ text( level ) ] ) );
Felix Meschbergerafcbd602010-02-18 13:02:12 +000059 parent.appendChild( td( null, null, [ text( wordWrap(message) ) ] ) );
60 parent.appendChild( td( null, null, [ text( wordWrap(service) ) ] ) );
Felix Meschbergere1c2cde2009-04-18 12:07:10 +000061 parent.appendChild( td( null, null, [ text( exception ) ] ) );
62}
63
64/* displays a date in the user's local timezone */
65function printDate(time) {
66 var date = time ? new Date(time) : new Date();
67 return date.toLocaleString();
68}
69
70function loadData() {
Felix Meschbergerafcbd602010-02-18 13:02:12 +000071 $.get(pluginRoot + "/data.json", { "minLevel":$(".minLevel").val()}, renderData, "json");
72 return false; // for button
Felix Meschbergere1c2cde2009-04-18 12:07:10 +000073}
74
Felix Meschbergerafcbd602010-02-18 13:02:12 +000075$(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 });
Valentin Valchev5185b7c2010-04-14 13:59:53 +000085 // init tablesorte
86 $('#plugin_table').tablesorter({
87 textExtraction: function(node) {
88 var _ = $(node);
89 return _.attr('lvl') ? _.attr('lvl') : _.text();
90 }
91 });
92
Felix Meschbergerafcbd602010-02-18 13:02:12 +000093 logsElem = $("#logs");
94 logs2Elem = $("#logs2");
95 tableElem = $("#plugin_table");
96 statElem = $(".statline");
97 // load logs
98 loadData();
99});