Skip to content

Commit

Permalink
add an Insight link to the fabric tool bar if insight is running; the…
Browse files Browse the repository at this point in the history
…n make it a bit easier to switch between perspectives (including having a toolbar item which just switches perspective, like the Insight link)
  • Loading branch information
jstrachan committed Oct 11, 2013
1 parent 2e5fd1e commit 0fe96b5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 34 deletions.
67 changes: 35 additions & 32 deletions hawtio-web/src/main/webapp/app/core/js/navbar.ts
Expand Up @@ -4,6 +4,7 @@ module Core {

$scope.hash = null;
$scope.topLevelTabs = [];
$scope.currentPerspective = null;
$scope.perspectiveDetails = {
perspective: null
};
Expand All @@ -22,48 +23,51 @@ module Core {

$scope.isValid = (nav) => nav && nav.isValid(workspace);

$scope.$watch('perspectiveDetails.perspective', (newValue, oldValue) => {
if (angular.toJson(newValue) !== angular.toJson(oldValue)) {
var perspective = $scope.perspectiveDetails.perspective;
if (perspective) {
console.log("Changed the perspective to " + JSON.stringify(perspective));
$location.search(Perspective.perspectiveSearchId, perspective.id);
reloadPerspective();
$scope.topLevelTabs = Perspective.topLevelTabs($location, workspace, jolokia, localStorage);
if (oldValue) {
oldValue.lastPage = $location.url();
if (newValue.lastPage) {
$location.url(Core.trimLeading(newValue.lastPage, "#"));
}
$scope.switchPerspective = (perspective) => {
var searchPerspectiveId = $location.search()[Perspective.perspectiveSearchId];
if (perspective && ($scope.currentPerspective !== perspective || perspective.id !== searchPerspectiveId)) {
console.log("Changed the perspective to " + JSON.stringify(perspective) + " from search id " + searchPerspectiveId);
if ($scope.currentPerspective) {
$scope.currentPerspective.lastPage = $location.url();
}
var pid = perspective.id;
$location.search(Perspective.perspectiveSearchId, pid);
console.log("Setting perspective to " + pid);
$scope.currentPerspective = perspective;
reloadPerspective();
$scope.topLevelTabs = Perspective.topLevelTabs($location, workspace, jolokia, localStorage);
if (perspective.lastPage) {
var path = Core.trimLeading(perspective.lastPage, "#");
// lets avoid any old paths with ?p=" inside
var idx = path.indexOf("?p=") || path.indexOf("&p=");
if (idx > 0) {
path = path.substring(0, idx);
}
var sep = (path.indexOf("?") >= 0) ? "&" : "?";
path += sep + "p=" + pid;
$location.url(path);
}
}
});
};

// when we change the view/selection lets update the hash so links have the latest stuff
$scope.$on('$routeChangeSuccess', function () {
$scope.hash = workspace.hash();
reloadPerspective();
});



/*
$scope.$watch('hash', function() {
console.log("$scope.hash: ", $scope.hash);
console.log("$location:", $location);
console.log("viewRegistry:", viewRegistry);
});
*/

$scope.link = (nav) => {
var href;
if (angular.isString(nav)) {
href = nav;
}else {
href = nav.href();
}
return createHref($location, href, ['tab', 'nid']);
var removeParams = ['tab', 'nid'];
if (href.indexOf("?p=") >= 0 || href.indexOf("&p=") >= 0) {
removeParams.push("p");
}
return createHref($location, href, removeParams);
};

$scope.fullScreenLink = () => {
Expand Down Expand Up @@ -120,18 +124,17 @@ module Core {
};

function reloadPerspective() {

var perspectives = Perspective.getPerspectives($location, workspace, jolokia, localStorage);
var currentId = Perspective.currentPerspectiveId($location, workspace, jolokia, localStorage);

if (angular.toJson($scope.perspectives) !== angular.toJson(perspectives)) {
$scope.perspectives = perspectives;
console.log("reloading perspectives for " + currentId);

console.log("Current perspectives " + JSON.stringify($scope.perspectives));
var currentId = Perspective.currentPerspectiveId($location, workspace, jolokia, localStorage);
if (currentId != $scope.perspectiveId || angular.toJson($scope.perspectives) !== angular.toJson(perspectives)) {
$scope.perspectiveId = currentId;
$scope.perspectives = perspectives;
$scope.perspectiveDetails.perspective = $scope.perspectives.find({id: currentId});
console.log("Current perspective ID: " + currentId + " perspective: " + $scope.perspective);
console.log("Current perspective ID: " + currentId);
$scope.topLevelTabs = Perspective.topLevelTabs($location, workspace, jolokia, localStorage);

}
}

Expand Down
12 changes: 12 additions & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/fabricPlugin.ts
Expand Up @@ -100,6 +100,18 @@ module Fabric {
},
isActive: (workspace: Workspace) => workspace.isLinkActive("/wiki") && (workspace.linkContains("fabric", "profiles") || workspace.linkContains("editFeatures"))
});
workspace.topLevelTabs.push( {
id: "fabric.insight",
content: "Insight",
title: "View insight into your fabric looking at logs, metrics and messages across the fabric",
isValid: (workspace) => {
return Fabric.hasFabric(workspace) && Insight.hasInsight(workspace)
},
href: () => {
return "#/insight/all?p=insight";
},
isActive: (workspace:Workspace) => workspace.isLinkActive("/insight")
});

helpRegistry.addDevDoc("fabric", 'app/fabric/doc/developer.md');

Expand Down
4 changes: 4 additions & 0 deletions hawtio-web/src/main/webapp/app/insight/js/helper.ts
Expand Up @@ -4,6 +4,10 @@ module Insight {

export var allContainers = { id: '-- all --' };

export function hasInsight(workspace) {
return workspace.treeContainsDomainAndProperties('org.elasticsearch', {service: 'restjmx'});
}

export function createCharts($scope, chartsDef, element, jolokia) {

var chartsDiv = $(element);
Expand Down
9 changes: 9 additions & 0 deletions hawtio-web/src/main/webapp/app/perspective/js/helpers.ts
Expand Up @@ -51,6 +51,7 @@ module Perspective {
var list = topLevelTabs.includes || topLevelTabs.excludes;
angular.forEach(list, (tabSpec) => {
var href = tabSpec.href;
var id = tabSpec.id;
var rhref = tabSpec.rhref;
if (href) {
var tab = workspace.topLevelTabs.find((t) => {
Expand All @@ -60,6 +61,14 @@ module Perspective {
if (tab) {
answer.push(tab);
}
} else if (id) {
var tab = workspace.topLevelTabs.find((t) => {
var tid = t.id;
return tid && tid === id;
});
if (tab) {
answer.push(tab);
}
} else if (rhref) {
var tab = workspace.topLevelTabs.find((t) => {
var thref = t.href();
Expand Down
5 changes: 4 additions & 1 deletion hawtio-web/src/main/webapp/app/perspective/js/metadata.ts
Expand Up @@ -17,13 +17,16 @@ module Perspective {
},
{
href: "#/dashboard"
},
{
id: "fabric.insight"
}
]
}
},
insight: {
label: "Insight",
isValid: (workspace) => workspace.treeContainsDomainAndProperties('org.elasticsearch', {service: 'restjmx'}),
isValid: (workspace) => Insight.hasInsight(workspace),
topLevelTabs: {
includes: [
{
Expand Down
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/index.html
Expand Up @@ -77,7 +77,7 @@
</a>
<ul class="dropdown-menu">
<li ng-repeat="perspective in perspectives">
<a ng-click="perspectiveDetails.perspective = perspective"
<a ng-click="switchPerspective(perspective)"
ng-hide="perspectiveDetails.perspective.id === perspective.id"
title="Switch to the {{perspective.label}} perspective"
data-placement="bottom">
Expand Down

0 comments on commit 0fe96b5

Please sign in to comment.