Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +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 | */ |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 17 | var tableEntryTemplate = false; |
| 18 | var tableBody = false; |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 19 | |
| 20 | function renderData(eventData) { |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 21 | $('.statline').empty().append(i18n.statline.msgFormat(eventData.serviceCount)); |
| 22 | $('#plugin_table > tbody > tr').remove(); |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 23 | for ( var idx in eventData.data) { |
| 24 | entry(eventData.data[idx]); |
| 25 | } |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 26 | if (drawDetails) { |
| 27 | renderDetails(eventData); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | function entry( /* Object */dataEntry) { |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 32 | var id = dataEntry.id; |
| 33 | var name = dataEntry.id; |
| 34 | |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 35 | var _ = tableEntryTemplate.clone().attr('id', 'entry' + id).appendTo(tableBody); |
| 36 | _.find('.bIcon').attr('id', 'img' + id).click(function() { |
| 37 | showDetails(id); |
| 38 | }).after(drawDetails ? name : ('<a href="' + window.location.pathname + '/' + id + '">' + name + '</a>')); |
| 39 | |
Carsten Ziegeler | 12222fd | 2014-12-29 13:43:03 +0000 | [diff] [blame] | 40 | _.find('td:eq(1)').text(dataEntry.ranking); |
| 41 | _.find('td:eq(2)').text(dataEntry.types); |
| 42 | _.find('td:eq(3)').html('<a href="' + bundlePath + dataEntry.bundleId + '">' + dataEntry.bundleSymbolicName + ' (' + dataEntry.bundleId + ')</a>' ); |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | function showDetails(id) { |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 46 | $.get(pluginRoot + '/' + id + '.json', null, function(data) { |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 47 | renderDetails(data); |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 48 | }, 'json'); |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | function hideDetails(id) { |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 52 | $('#img' + id).each(function() { |
| 53 | $('#pluginInlineDetails' + id).remove(); |
| 54 | $(this). |
| 55 | removeClass('ui-icon-triangle-1-w').//left |
| 56 | removeClass('ui-icon-triangle-1-s').//down |
| 57 | addClass('ui-icon-triangle-1-e').//right |
| 58 | unbind('click').click(function() {showDetails(id)}); |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 59 | }); |
| 60 | } |
| 61 | |
| 62 | function renderDetails(data) { |
| 63 | data = data.data[0]; |
Carsten Ziegeler | 12222fd | 2014-12-29 13:43:03 +0000 | [diff] [blame] | 64 | $('#entry' + data.id + ' > td').eq(2).append('<div id="pluginInlineDetails' + data.id + '"/>'); |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 65 | $('#img' + data.id).each(function() { |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 66 | if (drawDetails) { |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 67 | var ref = window.location.pathname; |
| 68 | ref = ref.substring(0, ref.lastIndexOf('/')); |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 69 | $(this). |
| 70 | removeClass('ui-icon-triangle-1-e').//right |
| 71 | removeClass('ui-icon-triangle-1-s').//down |
| 72 | addClass('ui-icon-triangle-1-w').//left |
| 73 | attr('title', i18n.back). |
| 74 | unbind('click').click(function() {window.location = ref;}); |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 75 | } else { |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 76 | $(this). |
| 77 | removeClass('ui-icon-triangle-1-w').//left |
| 78 | removeClass('ui-icon-triangle-1-e').//right |
| 79 | addClass('ui-icon-triangle-1-s').//down |
| 80 | attr('title', i18n.detailsHide). |
| 81 | unbind('click').click(function() {hideDetails(data.id)}); |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 82 | } |
| 83 | }); |
Felix Meschberger | de0ceed | 2010-04-08 08:05:20 +0000 | [diff] [blame] | 84 | var details = ""; |
| 85 | if (data.props) { |
| 86 | details += renderObjectAsTable(data.props); |
| 87 | } |
| 88 | if (data.usingBundles) { |
| 89 | details += renderUsingBundlesAsTable(data.usingBundles); |
| 90 | } |
| 91 | if (details) { |
| 92 | details = '<table border="0"><tbody>' + details + '</tbody></table>'; |
| 93 | $('#pluginInlineDetails' + data.id).append( details ); |
| 94 | } |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | function renderObjectAsTable(/* Object*/ details) { |
| 98 | var txt = ''; |
| 99 | |
| 100 | for (var idx in details) { |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 101 | var prop = details[idx]; |
| 102 | |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 103 | txt += '<tr><td class="aligntop" noWrap="true" style="border:0px none">' |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 104 | + prop.key |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 105 | + '</td><td class="aligntop" style="border:0px none">'; |
Valentin Valchev | f837029 | 2014-07-14 12:38:23 +0000 | [diff] [blame] | 106 | if (typeof prop.value !== 'undefined') { |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 107 | if ($.isArray(prop.value)) { |
| 108 | var i = 0; |
| 109 | for ( var pi in prop.value) { |
| 110 | var value = prop.value[pi]; |
| 111 | if (i > 0) { |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 112 | txt = txt + '<br/>'; |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 113 | } |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 114 | txt = txt + value; |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 115 | i++; |
| 116 | } |
| 117 | } else { |
| 118 | txt = txt + prop.value; |
| 119 | } |
| 120 | } else { |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 121 | txt = txt + '\u00a0'; |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 122 | } |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 123 | txt = txt + '</td></tr>'; |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 124 | } |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 125 | |
Felix Meschberger | de0ceed | 2010-04-08 08:05:20 +0000 | [diff] [blame] | 126 | return txt; |
| 127 | } |
| 128 | |
| 129 | function renderUsingBundlesAsTable(/* Object[] */ bundles) { |
| 130 | var txt = ''; |
| 131 | |
| 132 | for (var idx in bundles) { |
| 133 | var bundle = bundles[idx]; |
| 134 | txt += '<a href="' + bundlePath + '/' + bundle.bundleId + '">' |
| 135 | + bundle.bundleSymbolicName + ' (' + bundle.bundleId + ')' |
| 136 | + '</a><br/>'; |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Felix Meschberger | de0ceed | 2010-04-08 08:05:20 +0000 | [diff] [blame] | 139 | if (txt) { |
| 140 | txt = '<tr><td class="aligntop" noWrap="true" style="border:0px none">' |
| 141 | + i18n.usingBundles |
| 142 | + '</td><td class="aligntop" style="border:0px none">' |
| 143 | + txt |
| 144 | + '</td></tr>'; |
| 145 | } |
| 146 | |
Felix Meschberger | 2fc6a6e | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 147 | return txt; |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 150 | |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 151 | $(document).ready(function() { |
| 152 | tableBody = $('#plugin_table tbody'); |
| 153 | tableEntryTemplate = tableBody.find('tr').clone(); |
| 154 | tableBody.empty(); |
| 155 | |
| 156 | renderData(data); |
| 157 | |
| 158 | $('#plugin_table').tablesorter( { |
| 159 | headers : { |
Carsten Ziegeler | 12222fd | 2014-12-29 13:43:03 +0000 | [diff] [blame] | 160 | 0 : { sorter : 'digit' }, |
| 161 | 1 : { sorter : 'digit' } |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 162 | }, |
| 163 | sortList : [ [ 1, 0 ] ], |
| 164 | textExtraction : mixedLinksExtraction |
Felix Meschberger | d46d5ac | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 165 | }); |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 166 | }); |