Skip to content

Commit

Permalink
Make Bundle links a little bit nicer
Browse files Browse the repository at this point in the history
Turns the bundle links from simple numbers into a clickable label with the BSN on it.
  • Loading branch information
bosschaert committed Apr 5, 2013
1 parent 40cc743 commit 6536d42
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
22 changes: 18 additions & 4 deletions hawtio-web/src/main/webapp/app/osgi/js/helpers.ts
@@ -1,15 +1,16 @@
module Osgi {

export function defaultBundleValues(workspace:Workspace, $scope, values) {
var allValues = values;
angular.forEach(values, (row) => {
row["ImportData"] = parseActualPackages(row["ImportedPackages"])
row["ExportData"] = parseActualPackages(row["ExportedPackages"]);
row["IdentifierLink"] = bundleLinks(workspace, row["Identifier"]);
row["Hosts"] = bundleLinks(workspace, row["Hosts"]);
row["Fragments"] = bundleLinks(workspace, row["Fragments"]);
row["Hosts"] = labelBundleLinks(workspace, row["Hosts"], allValues);
row["Fragments"] = labelBundleLinks(workspace, row["Fragments"], allValues);
row["ImportedPackages"] = row["ImportedPackages"].union([]);
row["StateStyle"] = getStateStyle("label", row["State"]);
row["RequiringBundles"] = bundleLinks(workspace, row["RequiringBundles"]);
row["RequiringBundles"] = labelBundleLinks(workspace, row["RequiringBundles"], allValues);
});
return values;
}
Expand Down Expand Up @@ -177,6 +178,19 @@ module Osgi {
return collection;
}

export function labelBundleLinks(workspace, values, allValues) {
var answer = "";
var sorted = toCollection(values).sort((a,b) => {return a-b});
angular.forEach(sorted, function (value, key) {
var prefix = "";
if (answer.length > 0) {
prefix = " ";
}
var labelText = allValues[value].SymbolicName;
answer += prefix + "<a class='label' href='" + url("#/osgi/bundle/" + value + workspace.hash()) + "'>" + labelText + "</a>";
});
return answer;
}

export function bundleLinks(workspace, values) {
var answer = "";
Expand All @@ -186,7 +200,7 @@ module Osgi {
if (answer.length > 0) {
prefix = " ";
}
answer += prefix + "<a href='" + url("#/osgi/bundle/" + value + workspace.hash()) + "'>" + value + "</a>";
answer += prefix + "<a class='label' href='" + url("#/osgi/bundle/" + value + workspace.hash()) + "'>" + value + "</a>";
});
return answer;
}
Expand Down
18 changes: 18 additions & 0 deletions hawtio-web/src/test/specs/spec/OSGiSpec.js
Expand Up @@ -77,6 +77,24 @@ describe("OSGi", function() {
expect(result["org.foo.bar"]).toEqual(expected);
});

it("helpers.labelBundleLinks", function() {
var mockWorkSpace = {hash: function() {return "";}};
var allValues = {39: {SymbolicName: "com.example.foo"},
52: {SymbolicName: "org.acme.bar"}};

var res = Osgi.labelBundleLinks(mockWorkSpace, "52", allValues);
expect(res).toContain("#/osgi/bundle/52");
expect(res).toContain("org.acme.bar");
expect(res).not.toContain("#/osgi/bundle/39");
expect(res).not.toContain("com.example.foo");

var res2 = Osgi.labelBundleLinks(mockWorkSpace, "39", allValues);
expect(res2).not.toContain("#/osgi/bundle/52");
expect(res2).not.toContain("org.acme.bar");
expect(res2).toContain("#/osgi/bundle/39");
expect(res2).toContain("com.example.foo");
});

it("bundle.readBSNHeader", function() {
expect(Osgi.readBSNHeaderData("blah.blah")).toEqual("");
expect(Osgi.readBSNHeaderData("blah.blah;foo=bar;zoo:=zar")).toEqual("foo=bar;zoo:=zar");
Expand Down

0 comments on commit 6536d42

Please sign in to comment.