Archived
0

WebInterface: более подробная информация о бандлах

id, name, symname, state, version, last modified
This commit is contained in:
2016-12-14 23:29:23 +03:00
parent 4228ea932b
commit d9fb538407
3 changed files with 44 additions and 18 deletions

View File

@@ -19,7 +19,7 @@
<groupId>asys</groupId>
<artifactId>webinterface</artifactId>
<version>0.4-SNAPSHOT</version>
<version>0.5-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>

View File

@@ -4,7 +4,6 @@
*/
package asys.webinterface;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.sun.net.httpserver.HttpExchange;
@@ -30,16 +29,7 @@ public class AjaxHandler implements HttpHandler {
String jsonPath = httpExchange.getRequestURI().getPath();
if (jsonPath.equals("/ajax/bundles.json")) {
JsonArray jsonArray = new JsonArray();
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();
outJson = bundleList().toString();
}
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.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;
}
}

View File

@@ -4,16 +4,35 @@ angular.
module('asysApp').
component('bundleList', {
template:
'<ul>' +
'<li ng-repeat="bundle in $ctrl.bundles">' +
'<b>{{bundle.name}}</b>' +
'<p>{{bundle.symname}}</p>' +
'</li>' +
'</ul>',
'<table width="100%">' +
'<thead><tr>' +
'<th>ID</th><th>Name</th><th>State</th><th>Version</th><th>Last modified</th>' +
'</tr></thead>' +
'<tbody>' +
'<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) {
var self = this;
$http.get('/ajax/bundles.json').then(function(response) {
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+')'}
}
});