Skip to content

Commit

Permalink
Implement deleting versions/profiles, ensure profiles/versions in use…
Browse files Browse the repository at this point in the history
… can't be deleted, other stuff
  • Loading branch information
gashcrumb committed Apr 26, 2013
1 parent 26b3c58 commit c53f342
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 18 deletions.
56 changes: 51 additions & 5 deletions hawtio-web/src/main/webapp/app/fabric/html/profiles.html
Expand Up @@ -3,21 +3,36 @@
<div class="pull-left">
<form class="form-inline no-bottom-margin">
<fieldset>
<div class="btn-group inline-block">
<a href="" title="Create new Profile" class="btn"><i class="icon-plus"></i></a>
<a href="" title="Delete selected Profiles" class="btn" ng-disabled="selected.length == 0 || selectedHasContainers()" ng-click="deleteProfileDialog.open()"><i class="icon-minus"></i></a>
</div>

&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;

<div class="control-group inline-block">
<label for="versions">Versions: </label>
<select id="versions" ng-model="version" ng-options="v.id for v in versions"></select>
</div>
&nbsp;
<div class="control-group inline-block">
<label for="activeOnly" title="Only show profiles that have been applied to a container">Active only: </label>
<input type="checkbox" id="activeOnly" name="activeOnly" ng-model="activeOnly">
<div class="btn-group inline-block">
<a href="" title="Create new Version" class="btn"><i class="icon-plus"></i></a>
<a href="" title="Delete this Version" class="btn" ng-disabled="versionCanBeDeleted()" ng-click="deleteVersionDialog.open()"><i class="icon-minus"></i></a>
</div>
&nbsp;
</fieldset>
</form>
</div>
<div class="pull-right">
<form class="form-inline no-bottom-margin">
<fieldset>
<div class="control-group inline-block">
<label for="activeOnly" title="Only show profiles that have been applied to a container">Active only: </label>
<input type="checkbox" id="activeOnly" name="activeOnly" ng-model="activeOnly">
</div>
<div class="control-group inline-block">
<input class="search-query" type="text" ng-model="gridOptions.filterOptions.filterText" placeholder="Filter...">
</div>
Expand All @@ -26,8 +41,39 @@
</div>
</div>

<div modal="deleteVersionDialog.show" close="deleteVersionDialog.close()" options="deleteVersionDialog.options">
<form class="form-horizontal no-bottom-margin" ng-submit="deleteVersionDialog.close()">
<div class="modal-header"><h4>Delete version?</h4></div>
<div class="modal-body">
Are you sure you want to delete version {{version.id}}?
</div>
<div class="modal-footer">
<input class="btn btn-danger" type="submit" ng-click="deleteVersion()" value="Delete">
<input class="btn btn-primary" ng-click="deleteVersionDialog.close()" value="Cancel">
</div>
</form>
</div>

<div class="row-fluid">
<div modal="deleteProfileDialog.show" close="deleteProfileDialog.close()" options="deleteProfileDialog.options">
<form class="form-horizontal no-bottom-margin" ng-submit="deleteProfileDialog.close()">
<div class="modal-header"><h4>Delete profiles?</h4></div>
<div class="modal-body">
Are you sure you want to delete the selected profiles:
<ol>
<li ng-repeat="profile in selected">{{profile.id}}</li>
</ol>
</div>
<div class="modal-footer">
<input class="btn btn-danger" type="submit" ng-click="deleteSelected()" value="Delete">
<input class="btn btn-primary" ng-click="deleteProfileDialog.close()" value="Cancel">
</div>
</form>
</div>

<div ng-hide="profiles.length > 0" class="row-fluid">
Please wait, loading profile data...
</div>
<div ng-show="profiles.length > 0" class="row-fluid">
<div class="gridStyle" ng-grid="gridOptions"></div>
</div>
</div>
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/fabricPlugin.ts
@@ -1,7 +1,7 @@
module Fabric {
export var jmxDomain = 'org.fusesource.fabric';

angular.module('fabric', ['bootstrap', 'ngResource', 'ngGrid', 'hawtio-forms', 'hawtioCore']).config(($routeProvider) => {
angular.module('fabric', ['bootstrap', 'ui.bootstrap', 'ui.bootstrap.dialog', 'ngResource', 'ngGrid', 'hawtio-forms', 'hawtioCore']).config(($routeProvider) => {
$routeProvider.
when('/fabric/containers', {templateUrl: 'app/fabric/html/containers.html'}).
when('/fabric/createContainer', {templateUrl: 'app/fabric/html/createContainer.html'}).
Expand Down
26 changes: 21 additions & 5 deletions hawtio-web/src/main/webapp/app/fabric/js/helpers.ts
Expand Up @@ -14,12 +14,28 @@ module Fabric {
}
}

export function containerAction(action, jolokia, id, success, error) {
export function createVersion(jolokia, base, id, success, error) {
doAction('createVersion(java.lang.String, java.lang.String)', jolokia, [base, id], success, error);
}

export function createProfile(jolokia, version, id, success, error) {
doAction('createProfile(java.lang.String, java.lang.String)', jolokia, [version, id], success, error);
}

export function deleteVersion(jolokia, id, success, error) {
doAction('deleteVersion(java.lang.String)', jolokia, [id], success, error);
}

export function deleteProfile(jolokia, version, id, success, error) {
doAction('deleteProfile(java.lang.String, java.lang.String)', jolokia, [version, id], success, error);
}

export function doAction(action, jolokia, arguments, success, error) {
jolokia.request(
{
type: 'exec', mbean: managerMBean,
operation: action,
arguments: [id]
arguments: arguments
},
{
method: 'POST',
Expand All @@ -29,15 +45,15 @@ module Fabric {
}

export function stopContainer(jolokia, id, success, error) {
containerAction('stopContainer(java.lang.String)', jolokia, id, success, error);
doAction('stopContainer(java.lang.String)', jolokia, [id], success, error);
}

export function destroyContainer(jolokia, id, success, error) {
containerAction('destroyContainer(java.lang.String)', jolokia, id, success, error);
doAction('destroyContainer(java.lang.String)', jolokia, [id], success, error);
}

export function startContainer(jolokia, id, success, error) {
containerAction('startContainer(java.lang.String)', jolokia, id, success, error);
doAction('startContainer(java.lang.String)', jolokia, [id], success, error);
}


Expand Down
73 changes: 66 additions & 7 deletions hawtio-web/src/main/webapp/app/fabric/js/profiles.ts
@@ -1,10 +1,14 @@
module Fabric {

export function ProfilesController($scope, $location:ng.ILocationService, workspace:Workspace, jolokia) {

$scope.version = {id: "1.0"};



$scope.defaultVersion = jolokia.execute(managerMBean, "defaultVersion()");
$scope.version = { id: $scope.defaultVersion.id };
$scope.selected = [];

$scope.deleteVersionDialog = new Core.Dialog();
$scope.deleteProfileDialog = new Core.Dialog();

var key = $location.search()['pv'];
if (key) {
$scope.version = { id: key };
Expand Down Expand Up @@ -43,16 +47,34 @@ module Fabric {
{type: 'exec', mbean: managerMBean, operation: 'getProfiles(java.lang.String)', arguments: [$scope.version.id]}],
onSuccess(render));
});



$scope.selectedHasContainers = () => {
return $scope.selected.findAll(function(item) { return item.containerCount > 0 }).length > 0;
}

$scope.versionCanBeDeleted = () => {
if ($scope.version.id === $scope.defaultVersion.id) {
return true;
}
if ($scope.versions.length === 0) {
return true;
}
return $scope.profiles.findAll(function(item) {return item.containerCount > 0 }).length > 0;
}

$scope.gridOptions = {
data: 'profiles',
showFilter: false,
showColumnMenu: false,
filterOptions: {
filterText: ''
},
selectedItems: $scope.selected,
showSelectionCheckbox: true,
multiSelect: true,
selectWithCheckboxOnly: true,
keepLastSelected: false,
checkboxCellTemplate: '<div class="ngSelectionCell"><input tabindex="-1" class="ngSelectionCheckbox" type="checkbox" ng-checked="row.selected" ng-disabled="row.entity.containerCount > 0 || row.entity.childIds.length > 0"/></div>',
columnDefs: [
{
field: 'id',
Expand Down Expand Up @@ -90,6 +112,32 @@ module Fabric {
]
};

$scope.deleteVersion = () => {

// avoid getting any not found errors while deleting the version
Core.unregister(jolokia, $scope);

deleteVersion(jolokia, $scope.version.id, function() {
notification('success', "Deleted version " + $scope.version.id);
$scope.version = $scope.defaultVersion;
$scope.$apply();
}, function(response) {
notification('error', "Failed to delete version " + $scope.version.id + " due to " + response.error);
$scope.version = $scope.defaultVersion;
$scope.$apply();
});
}

$scope.deleteSelected = () => {
$scope.selected.each(function(profile) {
deleteProfile(jolokia, $scope.version.id, profile.id, function() {
notification('success', "Deleted profile " + profile.id);
}, function(response) {
notification('error', "Failed to delete profile " + profile.id + ' due to ' + response.error);
})
});
}

function filterActive(data) {
var rc = data;
if ($scope.activeOnly) {
Expand All @@ -107,7 +155,18 @@ module Fabric {
if (!Object.equal($scope.versionResponse, response.value)) {
$scope.versionResponse = response.value

$scope.versions = response.value.map(function(version) { return {id: version.id, default:version.defaultVersion}});
$scope.versions = response.value.map(function(version) {
var v = {
id: version.id,
'defaultVersion': version.defaultVersion
}

if (v['defaultVersion']) {
$scope.defaultVersion = v;
}

return v;
});
$scope.version = setSelect($scope.version, $scope.versions);

$scope.$apply();
Expand Down

0 comments on commit c53f342

Please sign in to comment.