diff --git a/webinterface/pom.xml b/webinterface/pom.xml index b7e6ddd..df755ce 100644 --- a/webinterface/pom.xml +++ b/webinterface/pom.xml @@ -19,7 +19,7 @@ asys webinterface - 0.4-SNAPSHOT + 0.5-SNAPSHOT bundle diff --git a/webinterface/src/main/java/asys/webinterface/AjaxHandler.java b/webinterface/src/main/java/asys/webinterface/AjaxHandler.java index f6342e0..d711c7f 100644 --- a/webinterface/src/main/java/asys/webinterface/AjaxHandler.java +++ b/webinterface/src/main/java/asys/webinterface/AjaxHandler.java @@ -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; + } } diff --git a/webinterface/src/main/resources/static/bundle-list.component.js b/webinterface/src/main/resources/static/bundle-list.component.js index 1cb6487..b9ace6d 100644 --- a/webinterface/src/main/resources/static/bundle-list.component.js +++ b/webinterface/src/main/resources/static/bundle-list.component.js @@ -4,16 +4,35 @@ angular. module('asysApp'). component('bundleList', { template: - '', + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
IDNameStateVersionLast modified
{{bundle.id}}{{bundle.name}}{{bundle.state | stateFormat}}{{bundle.version}}{{bundle.lastModified | date:"dd/MM/yyyy HH:mm"}}
', 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+')'} + } }); \ No newline at end of file