WebInterface: более подробная информация о бандлах
id, name, symname, state, version, last modified
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<groupId>asys</groupId>
|
<groupId>asys</groupId>
|
||||||
<artifactId>webinterface</artifactId>
|
<artifactId>webinterface</artifactId>
|
||||||
<version>0.4-SNAPSHOT</version>
|
<version>0.5-SNAPSHOT</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package asys.webinterface;
|
package asys.webinterface;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
@@ -30,16 +29,7 @@ public class AjaxHandler implements HttpHandler {
|
|||||||
|
|
||||||
String jsonPath = httpExchange.getRequestURI().getPath();
|
String jsonPath = httpExchange.getRequestURI().getPath();
|
||||||
if (jsonPath.equals("/ajax/bundles.json")) {
|
if (jsonPath.equals("/ajax/bundles.json")) {
|
||||||
JsonArray jsonArray = new JsonArray();
|
outJson = bundleList().toString();
|
||||||
|
|
||||||
for (Bundle bundle : context.getBundle(0).getBundleContext().getBundles()) {
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
|
||||||
jsonObject.addProperty("name", bundle.getHeaders().get("Bundle-Name"));
|
|
||||||
jsonObject.addProperty("symname", bundle.getSymbolicName());
|
|
||||||
jsonArray.add(jsonObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
outJson = jsonArray.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
httpExchange.getResponseHeaders().add("Context-Type", "application/json;charset=utf-8");
|
httpExchange.getResponseHeaders().add("Context-Type", "application/json;charset=utf-8");
|
||||||
@@ -48,4 +38,21 @@ public class AjaxHandler implements HttpHandler {
|
|||||||
responseBody.write(outJson.getBytes(defaultCharset));
|
responseBody.write(outJson.getBytes(defaultCharset));
|
||||||
responseBody.close();
|
responseBody.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JsonArray bundleList() {
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
|
||||||
|
for (Bundle bundle : context.getBundle(0).getBundleContext().getBundles()) {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("id", bundle.getBundleId());
|
||||||
|
jsonObject.addProperty("state", bundle.getState());
|
||||||
|
jsonObject.addProperty("name", bundle.getHeaders().get("Bundle-Name"));
|
||||||
|
jsonObject.addProperty("symname", bundle.getSymbolicName());
|
||||||
|
jsonObject.addProperty("lastModified", bundle.getHeaders().get("Bnd-LastModified"));
|
||||||
|
jsonObject.addProperty("version", bundle.getVersion().toString());
|
||||||
|
jsonArray.add(jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,35 @@ angular.
|
|||||||
module('asysApp').
|
module('asysApp').
|
||||||
component('bundleList', {
|
component('bundleList', {
|
||||||
template:
|
template:
|
||||||
'<ul>' +
|
'<table width="100%">' +
|
||||||
'<li ng-repeat="bundle in $ctrl.bundles">' +
|
'<thead><tr>' +
|
||||||
'<b>{{bundle.name}}</b>' +
|
'<th>ID</th><th>Name</th><th>State</th><th>Version</th><th>Last modified</th>' +
|
||||||
'<p>{{bundle.symname}}</p>' +
|
'</tr></thead>' +
|
||||||
'</li>' +
|
'<tbody>' +
|
||||||
'</ul>',
|
'<tr ng-repeat="bundle in $ctrl.bundles">' +
|
||||||
|
'<td>{{bundle.id}}</td>' +
|
||||||
|
'<td>{{bundle.name}}</td>' +
|
||||||
|
'<td>{{bundle.state | stateFormat}}</td>' +
|
||||||
|
'<td>{{bundle.version}}</td>' +
|
||||||
|
'<td>{{bundle.lastModified | date:"dd/MM/yyyy HH:mm"}}</td>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</tbody>' +
|
||||||
|
'</table>',
|
||||||
controller: function PhoneListController($http) {
|
controller: function PhoneListController($http) {
|
||||||
var self = this;
|
var self = this;
|
||||||
$http.get('/ajax/bundles.json').then(function(response) {
|
$http.get('/ajax/bundles.json').then(function(response) {
|
||||||
self.bundles = response.data;
|
self.bundles = response.data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}).
|
||||||
|
filter('stateFormat', function() {
|
||||||
|
return function(state) {
|
||||||
|
if (state == 1) {return 'UNINSTALLED';}
|
||||||
|
else if (state == 2) {return 'INSTALLED';}
|
||||||
|
else if (state == 4) {return 'RESOLVED';}
|
||||||
|
else if (state == 8) {return 'STARTING';}
|
||||||
|
else if (state == 16) {return 'STOPPING';}
|
||||||
|
else if (state == 32) {return 'ACTIVE';}
|
||||||
|
else {return 'UNKNOW('+state+')'}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user