blob: b2dd3f20eed04a970f91820b1cf6fa55a542ee6e [file] [log] [blame]
Carsten Ziegelerd524ac92008-10-23 16:44:07 +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 */
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000017function render() {
18 renderStatusLine();
19 renderTable( ["Received", "Topic", "Properties"] );
20 renderStatusLine();
21}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000022
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000023function renderStatusLine() {
24 document.write( "<div class='fullwidth'>");
25 document.write( "<div class='statusline'></div>" );
26 document.write( "</div>" );
27}
28
29function renderTable( /* Array of String */ columns ) {
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000030 document.write( "<div class='fullwidth tablelayout'>");
31 renderButtons();
32 document.write( "<div class='table'>");
33 document.write( "<table id='events' class='tablelayout'>" );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000034
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000035 document.write( "<thead><tr>" );
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000036 for ( var name in columns ) {
37 document.write( "<th>" + columns[name] + "</th>" );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000038 }
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000039 document.write( "</tr></thead><tbody>" );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000040 document.write( "</tbody></table>" );
41 document.write( "</div>");
42 renderButtons();
43 document.write( "</div>");
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000044}
45
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000046function renderButtons( ) {
47 document.write( "<div class='fullwidth'>");
48 document.write( "<div class='buttons'>" );
49 document.write( "<div class='button'><button id='reloadButton' type='button' name='reload'>Reload</button></div>" );
50 document.write( "<div class='button'><button id='clearButton' type='button' name='clear'>Clear List</button></div>" );
51 document.write( "</div>" );
52 document.write( "</div>" );
53}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000054
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000055function renderData( eventData ) {
56 $(".statusline").empty().append(eventData.status);
57 $("#events > tbody > tr").remove();
58 for ( var idx in eventData.data ) {
59 entry( eventData.data[idx] );
60 }
61}
62
63function entry( /* Object */ dataEntry ) {
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000064 var trElement = tr( null, { id: "entry" + dataEntry.id } );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000065 entryInternal( trElement, dataEntry );
66 $("#events > tbody").append(trElement);
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000067}
68
69
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000070function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000071 var id = dataEntry.id;
72 var topic = dataEntry.topic;
73 var properties = dataEntry.properties;
74
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000075 parent.appendChild( td( null, null, [ text( new Date(dataEntry.received) ) ] ) );
76 parent.appendChild( td( null, null, [ text( topic ) ] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000077
78 var tableE = createElement("table");
79 var bodyE = createElement("tbody");
80 tableE.appendChild(bodyE);
81
82 for( var p in dataEntry.properties ) {
Carsten Ziegeler7ba2bfe2008-10-24 05:23:56 +000083 bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ),
84 td(null, null, [text(dataEntry.properties[p])])]));
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000085 }
86
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000087 parent.appendChild( td( null, null, [tableE] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000088}
89
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000090function loadData() {
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000091 $.get(pluginRoot + "/data.json", null, function(data) {
92 renderData(data);
93 }, "json");
94}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000095
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000096function renderEvents() {
97 render();
98
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000099 loadData();
100
101 $("#events").tablesorter();
102 $("#reloadButton").click(loadData);
103 $("#clearButton").click(function () {
104 $("#events > tbody > tr").remove();
105 $.post(pluginRoot, { "action":"clear" }, function(data) {
106 renderData(data);
107 }, "json");
108 });
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000109}