Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
HAWKULAR-1053 change loading of recursive children and metrics
Browse files Browse the repository at this point in the history
When recursive children are loaded slash needs to be hashed to %2F. When metrics are loaded for selected resource whole path from feed id should be taken, not only id.
  • Loading branch information
karelhala committed Feb 29, 2016
1 parent 571e197 commit f0e80b8
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 47 deletions.
Expand Up @@ -18,7 +18,7 @@
<div class="card-pf">
<h3>Resource children tree</h3>
<div ng-if="$ctrl.childrenTree.length !== 0">
<hk-boot-nav-tree tree-data="$ctrl.childrenTree" on-node-selected="$ctrl.onBranchSelect(branch)"></hk-boot-nav-tree>
<hk-boot-nav-tree tree-data="$ctrl.childrenTree" on-node-selected="$ctrl.onLoadMetrics(resource)"></hk-boot-nav-tree>
</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions console/src/main/scripts/plugins/metrics/html/explorer.html
@@ -1,5 +1,5 @@
<div ng-controller="ExplorerController as exc">
<div class="hk-sidebar hk-explorer-sidebar">
<div ng-controller="InventoryExplorerController as exc">
<div class="hk-sidebar hk-explorer-sidebar" >
<hk-side-filter-container selected-feed="exc.selectedFeed"
selected-resource="exc.selectedResource"
load-metrics="exc.getMetrics(resource)"></hk-side-filter-container>
Expand All @@ -14,13 +14,13 @@
<div class="col-md-4">
<div class="card-pf">
<h3>Selected Feed</h3>
<div class="card-pf-title">{{exc.selectedFeed.id}}</div>
<span class="hk-selected-resource">{{exc.selectedFeed.id}}</span>
</div>
</div>
<div class="col-md-4">
<div class="card-pf">
<h3>Selected Resource</h3>
<div class="card-pf-title">{{exc.selectedResource.id}}</div>
<span class="hk-selected-resource">{{exc.selectedResource.id}}</span>
</div>
</div>
<div class="col-md-4">
Expand All @@ -35,7 +35,7 @@ <h3>Selected Resource</h3>
</li>
</ul>
</div>
<div class="card-pf-title">{{exc.selectedMetric.name}}</div>
<span class="hk-selected-resource">{{exc.selectedMetric.name}}</span>
</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion console/src/main/scripts/plugins/metrics/less/metrics.less
Expand Up @@ -348,6 +348,10 @@ a:hover {

.row-cards-pf {
clear: both;

.card-pf .hk-selected-resource {
word-break: break-all;
}
}

.card-pf-title {
Expand Down Expand Up @@ -2600,7 +2604,7 @@ body {
background: none;

.card-pf {
overflow: auto;
word-break: break-all;
}
}

Expand Down
Expand Up @@ -46,6 +46,7 @@ module HawkularMetrics {
}

public feedSelected(feed) {
this.selectedResource = null;
this.HawkularInventory.ResourceUnderFeed.query({
feedId: feed.id
}).$promise.then((resourceList) => {
Expand All @@ -55,29 +56,26 @@ module HawkularMetrics {
}

public resourceSelected(resource) {
this.selectedResource = resource;
if (this.hasOwnProperty('loadMetrics') && typeof this['loadMetrics'] === 'function') {
this['loadMetrics']({resource: this.selectedResource});
}
this.onLoadMetrics(resource);
this.fetchResourceChildren(resource, this.selectedFeed);
}

private fetchResourceChildren(resource, feed) {
this.HawkularInventory.ResourceRecursiveChildrenUnderFeed.get({
feedId: feed.id,
resourcePath: resource.id
resourcePath: resource.id.replace(/\//g, '%2F')
}).$promise.then((children) => {
let preffix = feed.id + ExplorerController.pathDelimiter;
let preffix = feed.id + InventoryExplorerController.pathDelimiter;
let grouppedChildren = _.groupBy(children, (item: any) => item.path.substring(
item.path.lastIndexOf(preffix) + preffix.length,
item.path.lastIndexOf(ExplorerController.pathDelimiter))
item.path.lastIndexOf(InventoryExplorerController.pathDelimiter))
);
const orderedChildren = {};
Object.keys(grouppedChildren).sort().forEach(function(key) {
let orderedChildren = {};
Object.keys(grouppedChildren).sort().forEach((key) => {
orderedChildren[key] = grouppedChildren[key];
});
let childrenAsTree = _.reduce(orderedChildren, (curr: any, value: any, key: string) => {
const path = key.split(ExplorerController.pathDelimiter);
const path = key.split(InventoryExplorerController.pathDelimiter);
if (path.length === 1) {
curr.text = SideFilterController.stripSpecialCharsFromLabel(path[0]);
curr.nodes = SideFilterController.fillChildrenNodes(value);
Expand All @@ -97,8 +95,7 @@ module HawkularMetrics {
}

private static stripSpecialCharsFromLabel(childId): string {
let label = childId;
label = label.substring(label.lastIndexOf('/') + 1, label.length);
let label = childId.substring(childId.lastIndexOf('/') + 1, childId.length);
label = (label.lastIndexOf('%2F') !== -1)
? label.substring(label.lastIndexOf('%2F') + '%2F'.length, label.length)
: label;
Expand All @@ -125,8 +122,11 @@ module HawkularMetrics {
}
}

public onBranchSelect(branch) {
this.selectedResource = branch;
private onLoadMetrics(resource) {
resource.resourcePath = resource.path.substr(
resource.path.indexOf(this.selectedFeed.id) + this.selectedFeed.id.length
);
this.selectedResource = resource;
if (this.hasOwnProperty('loadMetrics') && typeof this['loadMetrics'] === 'function') {
this['loadMetrics']({resource: this.selectedResource});
}
Expand Down
31 changes: 18 additions & 13 deletions console/src/main/scripts/plugins/metrics/ts/directives/navTree.ts
Expand Up @@ -21,20 +21,25 @@
module HawkularMetrics {
export class HkNavTreeDirective {
public link = (scope: any, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => {
angular.element(document).ready(function () {
scope.$slider = $(element)['treeview']({
collapseIcon: 'fa fa-angle-down',
data: scope.treeData,
expandIcon: 'fa fa-angle-right',
emptyIcon: 'fa fa-file',
showIcon: false,
levels: 1,
onNodeSelected: (event, data) => {
scope.onNodeSelected({branch: data});
},
showBorder: false
});
scope.$watch('treeData',() => {
scope.onRefresh();
});
scope.onRefresh = () => {
angular.element(document).ready(function () {
scope.$slider = $(element)['treeview']({
collapseIcon: 'fa fa-angle-down',
data: scope.treeData,
expandIcon: 'fa fa-angle-right',
emptyIcon: 'fa fa-file',
showIcon: false,
levels: 1,
onNodeSelected: (event, data) => {
scope.onNodeSelected({resource: data});
},
showBorder: false
});
});
};
};
public template = '<div></div>';
public replace = 'true';
Expand Down
Expand Up @@ -20,7 +20,7 @@

module HawkularMetrics {

export class ExplorerController implements IRefreshable {
export class InventoryExplorerController implements IRefreshable {
public title: string = 'Metrics Explorer';
public pleaseWait = true;
public resourceButtonEnabled = false;
Expand Down Expand Up @@ -71,7 +71,7 @@ module HawkularMetrics {
this.charts = tmp;
_.forEach(tmp, (metric: any) => {
this.registerForAlerts(metric.feed, metric.resource);
this.$log.log('Found metric in storage: ' + metric.id);
this.$log.log('Found metric in storage: ' + metric.id);
});
if ($rootScope.currentPersona) {
this.startTimeStamp = +moment().subtract(($routeParams.timeOffset || 3600000), 'milliseconds');
Expand Down Expand Up @@ -122,9 +122,11 @@ module HawkularMetrics {

public getMetrics(resource) {
this.pleaseWait = true;
this.selectedMetric = null;
this.buttonActive = false;
this.HawkularInventory['MetricOfResourceUnderFeed']['get']({
feedId: this.selectedFeed.id,
resourcePath: resource.id.replace(/\//g, '%2F')
resourcePath: resource.resourcePath.replace(/\/r;/g, '/').slice(1)
},
(metricList) => {
this.metrics = metricList;
Expand All @@ -142,7 +144,7 @@ module HawkularMetrics {
}

private registerForAlerts(feed, resource) {
ExplorerController.stripLastCharactersFromResourceId(resource, 2);
InventoryExplorerController.stripLastCharactersFromResourceId(resource, 2);
this.HawkularAlertRouterManager.registerForAlerts(
feed.id + '/' + resource.id,
'explorer',
Expand Down Expand Up @@ -177,9 +179,6 @@ module HawkularMetrics {
}

public showChart() {
this.$log.log('showChart');
this.$log.log(this.selectedMetric);

// Only add if not empty and not yet in the array.
if (this.selectedMetric != null && this.selectedMetric !== '' &&
this.charts.indexOf(this.selectedMetric) === -1) {
Expand Down Expand Up @@ -277,6 +276,6 @@ module HawkularMetrics {
// });
//}]);

_module.controller('ExplorerController', ExplorerController);
_module.controller('InventoryExplorerController', InventoryExplorerController);

}
7 changes: 3 additions & 4 deletions console/src/main/scripts/plugins/metrics/ts/viewController.ts
Expand Up @@ -20,14 +20,13 @@

module HawkularMetrics {

export class ViewController {
export class ViewContainerController {
public viewClass: string;
constructor(private $scope: any,
private $rootScope: any,
private $location: ng.ILocationService
) {
const viewClasses = {
'app-list': 'container-fluid',
'explorer/view': 'container-fluid'
};
Object.freeze(viewClasses);
Expand All @@ -48,11 +47,11 @@ module HawkularMetrics {
}
});
if (!changed) {
this.viewClass = ViewController.defaultClass;
this.viewClass = ViewContainerController.defaultClass;
}
}
public static get defaultClass(): string { return 'container'; }
}

_module.controller('HawkularMetrics.ViewController', ViewController);
_module.controller('HawkularMetrics.ViewContainerController', ViewContainerController);
}
2 changes: 1 addition & 1 deletion console/src/main/webapp/index.html
Expand Up @@ -87,7 +87,7 @@
</nav>

<div ng-controller="HawtioNav.ViewController">
<div ng-controller="HawkularMetrics.ViewController as hkvc">
<div ng-controller="HawkularMetrics.ViewContainerController as hkvc">
<div class="{{hkvc.viewClass}} screen-content" ng-include src="viewPartial"></div>
</div>
</div>
Expand Down

0 comments on commit f0e80b8

Please sign in to comment.