FELIX-4947 Webconsole plugin for OSGi Subsystems

Initial commit with basic functionality working. This plugin was highly inspired by the existing web console bundles page.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1688806 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/subsystems/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole-plugins/subsystems/src/main/resources/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000..43a9f27
--- /dev/null
+++ b/webconsole-plugins/subsystems/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,32 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more

+# contributor license agreements.  See the NOTICE file distributed with

+# this work for additional information regarding copyright ownership.

+# The ASF licenses this file to You under the Apache License, Version 2.0

+# (the "License"); you may not use this file except in compliance with

+# the License.  You may obtain a copy of the License at

+#

+#      http://www.apache.org/licenses/LICENSE-2.0

+#

+# Unless required by applicable law or agreed to in writing, software

+# distributed under the License is distributed on an "AS IS" BASIS,

+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+# See the License for the specific language governing permissions and

+# limitations under the License.

+

+#

+# Web Console strings for reference all strings here are commented.

+# This file may be used to produce a translation of the strings

+#

+# Note that properties files are ISO-8859-1 encoded. To provide translations

+# for languages requiring different character encodings, you may use the

+# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/

+# to translate the natively encoded files to ISO-8859-1 during bundle build

+#

+# Translations requiring non-ISO-8859-1 encoding are placed in the

+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said

+# plugin while building the bundle

+#

+

+# Components plugin

+subsystems.name=Subsystem Name

+

diff --git a/webconsole-plugins/subsystems/src/main/resources/res/plugin.html b/webconsole-plugins/subsystems/src/main/resources/res/plugin.html
new file mode 100644
index 0000000..a901fdf
--- /dev/null
+++ b/webconsole-plugins/subsystems/src/main/resources/res/plugin.html
@@ -0,0 +1,92 @@
+<!-- 

+  Licensed to the Apache Software Foundation (ASF) under one or more

+  contributor license agreements.  See the NOTICE file distributed with

+  this work for additional information regarding copyright ownership.

+  The ASF licenses this file to You under the Apache License, Version 2.0

+  (the "License"); you may not use this file except in compliance with

+  the License.  You may obtain a copy of the License at

+ 

+     http://www.apache.org/licenses/LICENSE-2.0

+

+  Unless required by applicable law or agreed to in writing, software

+  distributed under the License is distributed on an "AS IS" BASIS,

+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+  See the License for the specific language governing permissions and

+  limitations under the License.

+-->

+<script type="text/javascript" src="${pluginRoot}/res/plugin.js"></script>

+<script type="text/javascript">

+// <![CDATA[

+var ssData = ${__data__};

+// ]]>

+</script>

+<p class="statline">&nbsp;</p>

+

+

+<div id="subsystems"> <!-- data available -->

+	<!-- top header -->

+	<form method='post' enctype='multipart/form-data' action="${pluginRoot}">

+        <div class="ui-widget-header ui-corner-top buttonGroup">

+            <button class='installButton' type='button'>${install}</button>

+		</div>

+	</form>

+	

+	<table id="plugin_table" class="tablesorter nicetable noauto">

+	<thead>

+		<tr>

+			<th class="col_Id">${id}</th>

+                        <th class="col_Name">${subsystems.name}</th>

+			<th class="col_Version">${version}</th>

+			<th class="col_Status">Status</th>

+			<th class="col_Actions">Actions</th>

+		</tr>

+	</thead>

+	<tbody>

+		<tr>

+			<td>&nbsp;</td> <!-- id -->

+			<td> <!-- name with arrow -->

+				<div class="bIcon ui-icon ui-icon-triangle-1-e" style="float:left" title="Details">&nbsp;</div>

+			</td> 

+            <td>&nbsp;</td> <!-- version -->

+			<td>&nbsp;</td> <!-- status -->

+			<td>

+				<ul class="icons">

+					<li class="dynhover ui-helper-hidden" title="${start}"><span class="ui-icon ui-icon-play">&nbsp;</span></li>

+					<li class="dynhover ui-helper-hidden" title="${stop}"><span class="ui-icon ui-icon-stop">&nbsp;</span></li>

+                    <li class="dynhover" title="${bundles.uninstall}"><span class="ui-icon ui-icon-trash">&nbsp;</span></li>

+				</ul>

+			</td>

+		</tr>

+	</tbody>

+	</table>

+</div> <!-- end data available -->

+

+<!-- bottom header -->

+<form method='post' enctype='multipart/form-data' action="${pluginRoot}">

+    <div class="ui-widget-header ui-corner-bottom buttonGroup">

+        <button class='installButton' type='button'>${install}</button>

+	</div>

+</form>

+

+<!-- status line -->

+<p class="statline">&nbsp;</p>

+

+<div id="uploadDialog" class="ui-helper-hidden" title="Upload / Install Subsystem">

+    <form method="post" enctype="multipart/form-data" action="${pluginRoot}">

+    <table class="nicetable">

+        <tr>

+            <td style="text-align:right">Start Subsystem</td>

+            <td>

+                <input type="hidden" name="action" value="install"/>

+                <input type="checkbox" name="subsystemstart" value="start"/>

+            </td>

+        </tr>

+        <tr>

+            <td>

+                <td>&nbsp;</td>

+                <input class="multi" accept="jar|zip|esa" type="file" name="subsystemfile" />

+            </td>

+        </tr>

+    </table>

+    </form>

+</div>

diff --git a/webconsole-plugins/subsystems/src/main/resources/res/plugin.js b/webconsole-plugins/subsystems/src/main/resources/res/plugin.js
new file mode 100644
index 0000000..e2c6c57
--- /dev/null
+++ b/webconsole-plugins/subsystems/src/main/resources/res/plugin.js
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *	  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+function renderData( subsystemData ) {
+	tableBody.empty();
+	for (var idx in subsystemData.data) {
+		entry( subsystemData.data[idx] );
+	}	
+}
+
+function entry( dataEntry ) {
+	var id = dataEntry.id;
+	var name = dataEntry.name;
+	var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + id);
+	
+	_.find('td:eq(0)').text(id);
+	_.find('td:eq(1)').text(name);
+	_.find('td:eq(2)').text(dataEntry.version);
+	_.find('td:eq(3)').text(dataEntry.state);
+	
+	// setup buttons
+	if (dataEntry.state === "ACTIVE") {
+		_.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'stop') });
+	} else {
+		_.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'start') });
+	}
+	_.find('li:eq(2)').click(function() { changeDataEntryState(id, 'uninstall') });
+}
+
+function changeDataEntryState(id, action) {
+	$.post(pluginRoot + '/' + id, {'action': action}, function(data) {
+		renderData(data);
+		
+		// This is a total hack, but it's the only way in which I could get the 
+		// table to re-sort itself. TODO remove the next line and find a proper way.
+		window.location.reload();
+	}, 'json');
+}
+
+var tableBody = false;
+var tableEntryTemplate = false;
+var pluginTable = false;
+var uploadDialog = false;
+
+$(document).ready(function(){
+	$('.installButton').click(function() {
+		uploadDialog.dialog('open');
+		return false;
+	});	
+	
+	pluginTable = $('#plugin_table');
+	tableBody = pluginTable.find('tbody');
+	tableEntryTemplate = tableBody.find('tr').clone();
+	
+	// upload dialog
+	var uploadDialogButtons = {};
+	uploadDialogButtons["Install"] = function() {
+		$(this).find('form').submit();
+	}
+	uploadDialog = $('#uploadDialog').dialog({
+		autoOpen: false,
+		modal   : true,
+		width   : '50%',
+		buttons : uploadDialogButtons
+	});	
+
+	renderData(ssData);
+
+	$('.reloadButton').click(document.location.reload);
+
+	pluginTable.tablesorter({
+		headers: {
+			0: { sorter:'digit'},
+			4: { sorter: false }
+		},
+		sortList: [[1,0]],
+		textExtraction:mixedLinksExtraction
+	});
+});
+