Skip to content

Commit

Permalink
Switch to async fetching, also ensure profile details are only re-ren…
Browse files Browse the repository at this point in the history
…dered if the returned data changes
  • Loading branch information
gashcrumb committed Oct 15, 2013
1 parent 0b351e7 commit 0d8628e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
17 changes: 9 additions & 8 deletions hawtio-web/src/main/webapp/app/fabric/js/profile.ts
Expand Up @@ -132,13 +132,11 @@ module Fabric {
Core.unregister(jolokia, $scope);
if ($scope.versionId && $scope.profileId && !$scope.versionId.isBlank() && !$scope.profileId.isBlank()) {

if (jolokia.execute(Fabric.managerMBean, "versions()").some((version) => { return version.id === $scope.versionId })) {
Core.register(jolokia, $scope, {
type: 'exec', mbean: managerMBean,
operation: 'getProfile(java.lang.String, java.lang.String)',
arguments: [$scope.versionId, $scope.profileId]
}, onSuccess(render));
}
Core.register(jolokia, $scope, {
type: 'exec', mbean: managerMBean,
operation: 'getProfile(java.lang.String, java.lang.String)',
arguments: [$scope.versionId, $scope.profileId]
}, onSuccess(render));
}
};

Expand Down Expand Up @@ -324,10 +322,13 @@ module Fabric {
if (!angular.isDefined($scope.row)) {
$scope.loading = false;
}
if (!Object.equal($scope.row, response.value)) {
var responseJson = angular.toJson(response.value);

if ($scope.profileResponseJson !== responseJson) {
if (!$scope.activeTab) {
$scope.activeTab = "features";
}
$scope.profileResponseJson = responseJson;
$scope.row = response.value;
var id = $scope.row.id;
var version = $scope.row.version;
Expand Down
Expand Up @@ -212,13 +212,28 @@ module Fabric {

$scope.$watch('versionId', (newValue, oldValue) => {
if ($scope.versionId && $scope.versionId !== '') {
if (jolokia.execute(Fabric.managerMBean, "versions()").some((version) => { return version.id === newValue })) {
$scope.init();
} else {
Core.unregister(jolokia, $scope);
}
} else {
Core.unregister(jolokia, $scope);
jolokia.request({
type: 'exec',
mbean: Fabric.managerMBean,
operation: 'versions()',
arguments: []
}, {
method: 'POST',
success: (response) => {
if (response.value.some((version) => {
return version.id === newValue;
})) {
$scope.init();
} else {
Core.unregister(jolokia, $scope);
}
Core.$apply($scope);
},
error: (response) => {
Core.unregister(jolokia, $scope);
Core.$apply($scope);
}
});
}
});

Expand Down

0 comments on commit 0d8628e

Please sign in to comment.