blob: dc5870894cb0f770b2d0c1bb3c795a4c66922ba5 [file] [log] [blame]
Clement Escoffiercbf19c42010-07-12 17:43:48 +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 */
17function renderInstanceDetails(data) {
18 $(".statline").html(getInstancesStatLine(data));
19 createDetail( data.data );
20}
21
22function getInstancesStatLine(instances) {
23 return instances.count + " instances in total, "
24 + instances.valid_count + " valid instances, "
25 + instances.invalid_count + " invalid instances.";
26}
27
28function createDetail(instance) {
29 console.log("Create details");
30 var service = "No provided services"
31
32 var _ = tableBody;
33
34 // Set the name
35 _.find('td.Vname').html(instance.name);
36
37 // Set the state
38 _.find('td.Vstate').text(instance.state);
39
40 // Set the factory
41 _.find('td.Vfactory').html(instance.factory); //TODO Link
42
43 if (instance.services) {
44 $(tableServiceBody).empty();
45 for (var s in instance.services) {
46 var service = instance.services[s];
47 // For each service clone the template
48 var entry = serviceEntryTemplate.clone().appendTo(tableServiceBody).attr('id', 'service-' + service.specification);
49 entry.find('td.name').text(service.specification);
50 entry.find('td.state').text(service.state);
51
52 if (service.id) {
53 entry.find('td.id').text(service.id);
54 } else {
55 entry.find('td.id').html('<i>not registered</i>');
56 }
57
58 if (service.properties) {
59 var list = $('<ul>');
60 for (var x in service.properties) {
61 list.append($('<li>').append(service.properties[x].name + ' = ' + service.properties[x].value));
62 }
63 entry.find('td.properties').html(list);
64 } else {
65 entry.find('td.properties').html('<i>not properties</i>');
66 }
67 }
68 } else {
69 // Hide the table
70 $('services').hide();
71 _.find('td.Vservices').html("No provided services");
72 }
73
74 if (instance.req) {
75 $(tableReqBody).empty();
76 for (var s in instance.req) {
77 var service = instance.req[s];
78 console.dir(service);
79 // For each service clone the template
80 var entry = reqEntryTemplate.clone().appendTo(tableReqBody).attr('id', 'req-' + service.id);
81 entry.find('td.name').text(service.specification);
82 entry.find('td.id').text(service.id);
83 entry.find('td.state').text(service.state);
84
85 entry.find('td.policy').text(service.policy);
86 entry.find('td.optional').text(service.optional);
87 entry.find('td.aggregate').text(service.aggregate);
88
89
90 if (service.matching) {
91 var list = $('<ul>');
92 for (var x in service.matching) {
93 list.append($('<li>').append(service.matching[x].id)); // TODO Link
94 }
95 entry.find('td.matching').html(list);
96 } else {
97 entry.find('td.matching').html('<i>no matching services</i>');
98 }
99
100 if (service.used) {
101 var list = $('<ul>');
102 for (var x in service.used) {
103 list.append($('<li>').append(service.used[x].id)); // TODO Link
104 }
105 entry.find('td.used').html(list);
106 } else {
107 entry.find('td.used').html('<i>no used services</i>');
108 }
109
110 }
111 } else {
112 // Hide the table
113 $('reqServices').hide();
114 _.find('td.VreqServices').html("No required services");
115 }
116
117
118 _.find('pre.architecture_content').text(instance.architecture);
119}
120
121function retrieveDetails() {
122 $.get(pluginRoot + '/instances/' + instance_name + '.json', null, function(data) {
123 renderInstanceDetails(data);
124 }, "json");
125}
126
127function loadFactoriesData() {
128 window.location = factories_url;
129}
130
131function loadInstancesData() {
132 window.location = instances_url;
133}
134
135function loadHandlersData() {
136 window.location = handlers_url;
137}
138
139var tableBody = false;
140var tableServiceBody = false;
141var serviceEntryTemplate = false;
142
143var tableReqBody = false;
144var reqEntryTemplate = false;
145
146
147$(document).ready(function(){
148 tableBody = $('#plugin_table tbody');
149
150 tableServiceBody = $('.services tbody');
151 serviceEntryTemplate = tableServiceBody.find('tr').clone();
152
153 tableReqBody = $('.reqServices tbody');
154 reqEntryTemplate = tableReqBody.find('tr').clone();
155
156
157 retrieveDetails();
158
159 $(".instancesButton").click(loadInstancesData);
160 $(".factoriesButton").click(loadFactoriesData);
161 $(".handlersButton").click(loadHandlersData);
162
163 var extractMethod = function(node) {
164 var link = node.getElementsByTagName("a");
165 if ( link && link.length == 1 ) {
166 return link[0].innerHTML;
167 }
168 return node.innerHTML;
169 };
170
171});
172