Clement Escoffier | 0d1174a | 2010-07-12 17:42:47 +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 | */ |
| 17 | function renderFactoryDetails(data) { |
| 18 | $(".statline").html(getFactoriesStatLine(data)); |
| 19 | createDetail( data.data ); |
| 20 | //$("#plugin_table").trigger("update"); |
| 21 | } |
| 22 | |
| 23 | function getFactoriesStatLine(factories) { |
| 24 | return factories.count + " factories in total, " |
| 25 | + factories.valid_count + " valid factories, " |
| 26 | + factories.invalid_count + " invalid factories."; |
| 27 | } |
| 28 | |
| 29 | function createDetail(factory) { |
| 30 | console.log("Create details"); |
| 31 | var name = factory.name; |
| 32 | var state = factory.state; |
| 33 | var bundle = factory.bundle; |
| 34 | var service = "No provided services" |
| 35 | |
| 36 | console.log("Create entry : " + factory); |
| 37 | |
| 38 | var _ = tableBody; |
| 39 | |
| 40 | // Set the name |
| 41 | _.find('td.Vname').html(factory.name); |
| 42 | // Set the bundle //TODO we can create a link here ? |
| 43 | _.find('td.Vbundle').text(factory.bundle); |
| 44 | // Set the state |
| 45 | _.find('td.Vstate').text(factory.state); |
| 46 | |
| 47 | // Set the services |
| 48 | // If define, use a list |
| 49 | if (factory.services) { |
| 50 | var list = $('<ul>'); |
| 51 | for (var s in factory.services) { |
| 52 | list.append($('<li>').append(factory.services[s])); |
| 53 | } |
| 54 | _.find('td.Vservices').html(list); |
| 55 | } else { // Undefined |
| 56 | _.find('td.Vservices').html('<i>No provided service specifications</i>'); |
| 57 | } |
| 58 | |
| 59 | // Set the properties |
| 60 | $(tablePropBody).empty(); |
| 61 | if (factory.properties) { |
| 62 | for (var s in factory.properties) { |
| 63 | var prop = factory.properties[s]; |
| 64 | // For each properties clone the template |
| 65 | var entry = propEntryTemplate.clone().appendTo(tablePropBody).attr('id', 'property-' + prop.name); |
| 66 | entry.find('td.name').text(prop.name); |
| 67 | entry.find('td.type').text(prop.type); |
| 68 | entry.find('td.mandatory').text(prop.mandatory); |
| 69 | entry.find('td.immutable').text(prop.immutable); |
| 70 | if (prop.value) { |
| 71 | entry.find('td.value').text(prop.value); |
| 72 | } else { |
| 73 | entry.find('td.value').html('<i>No default value</i>'); |
| 74 | } |
| 75 | } |
| 76 | } else { |
| 77 | // Hide the table |
| 78 | $('table.properties').hide(); |
| 79 | } |
| 80 | |
| 81 | // Set the required handlers. |
| 82 | if (factory.requiredHandlers) { |
| 83 | var list = $('<ul>'); |
| 84 | for (var s in factory.requiredHandlers) { |
| 85 | list.append($('<li>').append(factory.requiredHandlers[s])); |
| 86 | } |
| 87 | _.find('td.VrequiredHandlers').html(list); |
| 88 | } else { // Undefined |
| 89 | _.find('td.VrequiredHandlers').html('<i>No required handlers</i>'); |
| 90 | } |
| 91 | |
| 92 | // Set the missing handlers. |
| 93 | if (factory.missingHandlers) { |
| 94 | var list = $('<ul>'); |
| 95 | for (var s in factory.missingHandlers) { |
| 96 | list.append($('<li>').append(factory.missingHandlers[s])); |
| 97 | } |
| 98 | _.find('td.VmissingHandlers').html(list); |
| 99 | } else { // Undefined |
| 100 | _.find('td.VmissingHandlers').html('<i>No missing handlers</i>'); |
| 101 | } |
| 102 | |
| 103 | // Set the created instances. |
| 104 | if (factory.instances) { |
| 105 | var list = $('<ul>'); |
| 106 | for (var s in factory.instances) { |
| 107 | list.append($('<li>').append(factory.instances[s])); |
| 108 | } |
| 109 | _.find('td.VcreatedInstances').html(list); |
| 110 | } else { // Undefined |
| 111 | _.find('td.VcreatedInstances').html('<i>No created instances</i>'); |
| 112 | } |
| 113 | |
| 114 | _.find('pre.architecture_content').text(factory.architecture); |
| 115 | } |
| 116 | |
| 117 | function retrieveDetails() { |
| 118 | $.get(pluginRoot + '/factories/' + factory_name + '.json', null, function(data) { |
| 119 | renderFactoryDetails(data); |
| 120 | }, "json"); |
| 121 | } |
| 122 | |
| 123 | function loadFactoriesData() { |
| 124 | window.location = factories_url; |
| 125 | } |
| 126 | |
| 127 | function loadInstancesData() { |
| 128 | window.location = instances_url; |
| 129 | } |
| 130 | |
| 131 | function loadHandlersData() { |
| 132 | window.location = handlers_url; |
| 133 | } |
| 134 | |
| 135 | var tableBody = false; |
| 136 | var tablePropBody = false; |
| 137 | var propEntryTemplate = false; |
| 138 | |
| 139 | $(document).ready(function(){ |
| 140 | tableBody = $('#plugin_table tbody'); |
| 141 | |
| 142 | tablePropBody = $('.properties tbody'); |
| 143 | propEntryTemplate = tablePropBody.find('tr').clone(); |
| 144 | |
| 145 | retrieveDetails(); |
| 146 | |
| 147 | $(".instancesButton").click(loadInstancesData); |
| 148 | $(".factoriesButton").click(loadFactoriesData); |
| 149 | $(".handlersButton").click(loadHandlersData); |
| 150 | |
| 151 | var extractMethod = function(node) { |
| 152 | var link = node.getElementsByTagName("a"); |
| 153 | if ( link && link.length == 1 ) { |
| 154 | return link[0].innerHTML; |
| 155 | } |
| 156 | return node.innerHTML; |
| 157 | }; |
| 158 | |
| 159 | }); |
| 160 | |