Skip to content

Commit

Permalink
Refactor container actions into helper class, ensure that the page tr…
Browse files Browse the repository at this point in the history
…ansitions to the fabric view when deleting a container from it's detail view
  • Loading branch information
gashcrumb committed Jul 11, 2013
1 parent f0c2249 commit 03bf4cc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
25 changes: 7 additions & 18 deletions hawtio-web/src/main/webapp/app/fabric/js/container.ts
@@ -1,6 +1,6 @@
module Fabric {

export function ContainerController($scope, workspace:Workspace, $routeParams, jolokia) {
export function ContainerController($scope, workspace:Workspace, $routeParams, jolokia, $location) {
$scope.containerId = $routeParams.containerId;

$scope.selectedProfiles = [];
Expand All @@ -25,30 +25,19 @@ module Fabric {
};

$scope.stop = () => {
// TODO proper notifications
stopContainer(jolokia, $scope.containerId, function () {
console.log("Stopped!")
}, function () {
console.log("Failed to stop!")
});
doStopContainer($scope, jolokia, $scope.containerId);
};

$scope.delete = () => {
// TODO proper notifications
destroyContainer(jolokia, $scope.containerId, function () {
console.log("Deleted!")
}, function () {
console.log("Failed to delete!")
// avoid any nasty errors that the container doesn't existing anymore
Core.unregister(jolokia, $scope);
doDeleteContainer($scope, jolokia, $scope.containerId, () => {
$location.path('/fabric/view');
});
};

$scope.start = () => {
// TODO proper notifications
startContainer(jolokia, $scope.containerId, function () {
console.log("Started!")
}, function () {
console.log("Failed to start!")
});
doStartContainer($scope, jolokia, $scope.containerId);
};

$scope.getType = () => {
Expand Down
21 changes: 3 additions & 18 deletions hawtio-web/src/main/webapp/app/fabric/js/fabricView.ts
Expand Up @@ -652,32 +652,17 @@ module Fabric {


$scope.deleteContainer = (name) => {
notification('info', "Deleting " + name);
destroyContainer(jolokia, name, () => {
notification('success', "Deleted " + name);
}, (response) => {
notification('error', "Failed to delete " + name + " due to " + response.error);
});
doDeleteContainer($scope, jolokia, name);
};


$scope.startContainer = (name) => {
notification('info', "Starting " + name);
startContainer(jolokia, name, () => {
notification('success', "Started " + name);
}, (response) => {
notification('error', "Failed to start " + name + " due to " + response.error);
});
doStartContainer($scope, jolokia, name);
};


$scope.stopContainer = (name) => {
notification('info', "Stopping " + name);
stopContainer(jolokia, name, () => {
notification('success', "Stopped " + name);
}, (response) => {
notification('error', "Failed to stop " + name + " due to " + response.error);
});
doStopContainer($scope, jolokia, name);
};


Expand Down
37 changes: 37 additions & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/helpers.ts
Expand Up @@ -20,6 +20,43 @@ module Fabric {
}
}

export function doDeleteContainer($scope, jolokia, name, onDelete:() => any = null) {
notification('info', "Deleting " + name);
destroyContainer(jolokia, name, () => {
notification('success', "Deleted " + name);
if (onDelete) {
onDelete();
}
Core.$apply($scope);
}, (response) => {
notification('error', "Failed to delete " + name + " due to " + response.error);
Core.$apply($scope);
});
}

export function doStartContainer($scope, jolokia, name) {
notification('info', "Starting " + name);
startContainer(jolokia, name, () => {
notification('success', "Started " + name);
Core.$apply($scope);
}, (response) => {
notification('error', "Failed to start " + name + " due to " + response.error);
Core.$apply($scope);
});
}

export function doStopContainer($scope, jolokia, name) {
notification('info', "Stopping " + name);
stopContainer(jolokia, name, () => {
notification('success', "Stopped " + name);
Core.$apply($scope);
}, (response) => {
notification('error', "Failed to stop " + name + " due to " + response.error);
Core.$apply($scope);
});
}


export function applyPatches(jolokia, files, targetVersion, newVersionName, proxyUser, proxyPass, success, error) {
doAction('applyPatches(java.util.List,java.lang.String,java.lang.String,java.lang.String,java.lang.String)', jolokia, [files, targetVersion, newVersionName, proxyUser, proxyPass], success, error);
}
Expand Down

0 comments on commit 03bf4cc

Please sign in to comment.