Skip to content

Commit

Permalink
Fix #333, can now set profiles on containers en-masse
Browse files Browse the repository at this point in the history
  • Loading branch information
gashcrumb committed May 9, 2013
1 parent 512f547 commit d9834c2
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 4 deletions.
36 changes: 34 additions & 2 deletions hawtio-web/src/main/webapp/app/fabric/html/assignProfiles.html
@@ -1,11 +1,43 @@
<div>
<div ng-controller="Fabric.AssignProfilesController">

<div class="row-fluid">
<div class="pull-left">
<a class='btn' ng-href="#/fabric/containers"><i class='icon-remove'></i> Cancel</a>
<a class='btn inline-block' ng-href="#/fabric/containers"><i class='icon-remove'></i> Cancel</a>
</div>
<div class="pull-right">
<a ng-disabled="canApply()" class="btn btn-danger" href="" ng-click="showApply = true"><i class="icon-cogs"></i> Apply Changes</a>
</div>
</div>

<div class="row-fluid form-horizontal">
<div class="span8 offset2">
<div class="control-group">
<label class="inline-block">1. Select the version containing the profiles and containers to be modified: </label>
<select ng-model="version" ng-options="v.id for v in versions"></select>
</div>

</div>
</div>

<div class="row-fluid">
<div class="span4 offset2">
<p>2. Select the profiles to be applied:</p>
<input class="search-query column-filter" type="text" ng-model="profileGridOptions.filterOptions.filterText" placeholder="Filter...">
<div class="gridStyle" ng-grid="profileGridOptions"></div>
</div>
<div class="span4">
<p>3. Select the target containers to apply these profiles on:</p>
<input class="search-query column-filter" type="text" ng-model="containerGridOptions.filterOptions.filterText" placeholder="Filter...">
<div class="gridStyle" ng-grid="containerGridOptions"></div>
</div>
</div>

<div hawtio-confirm-dialog="showApply" ok-button-text="Yes" cancel-button-text="No" on-ok="applyProfiles()" title="Apply profiles?">
<div class="dialog-body">
<p>Are you sure you want to set these {{selectedProfiles.length}} profiles on {{selectedContainers.length}} containers?</p>
</div>
</div>



</div>
143 changes: 143 additions & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/assignProfiles.ts
@@ -0,0 +1,143 @@
module Fabric {

export function AssignProfilesController($scope, jolokia, $location) {

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

$scope.versions = [];
$scope.profiles = [];
$scope.containers = [];
$scope.versionResponse = [];
$scope.profileIds = [];
$scope.containerIds = [];

$scope.selectedProfiles = [];
$scope.selectedContainers = [];

$scope.showApply = false;

$scope.profileGridOptions = {
data: 'profiles',
selectedItems: $scope.selectedProfiles,
showSelectionCheckbox: true,
multiSelect: true,
keepLastSelected: false,
columnDefs: [{
field: 'id',
displayName: 'Profile Name'
}],
filterOptions: {
filterText: ''
}
};

$scope.containerGridOptions = {
data: 'containers',
selectedItems: $scope.selectedContainers,
showSelectionCheckbox: true,
multiSelect: true,
keepLastSelected: false,
columnDefs: [{
field: 'id',
displayName: 'Container Name'
}],
filterOptions: {
filterText: ''
}
};

$scope.canApply = () => {
return !($scope.selectedProfiles.length > 0 && $scope.selectedContainers.length > 0);
}

$scope.applyProfiles = () => {
var containerIds = $scope.selectedContainers.map((container) => { return container.id });
var profileIds = $scope.selectedProfiles.map((profile) => { return profile.id });
var versionId = $scope.version.id;

notification('info', "Applying profiles to containers");
$location.path("/fabric/containers");

applyProfiles(jolokia, versionId, profileIds, containerIds, () => {
notification('success', "Successfully applied profiles");
}, (response) => {
notification('error', "Failed to apply profiles due to " + response.error);
});
}

$scope.render = (response) => {

switch(response.request.operation) {
case 'versions()':
if (!Object.equal($scope.versionResponse, response.value)) {
$scope.versionResponse = response.value
$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();
}
break;

case 'getProfileIds(java.lang.String)':
if (!Object.equal($scope.profileIds, response.value)) {
$scope.profileIds = response.value;
$scope.profiles = [];

$scope.profileIds.each((profile) => {
$scope.profiles.push({
id: profile
});
});

$scope.$apply();
}
break;

case 'containerIdsForVersion(java.lang.String)':
if (!Object.equal($scope.containerIds, response.value)) {
$scope.containerIds = response.value;
$scope.containers = [];

$scope.containerIds.each((container) => {
$scope.containers.push({
id: container
});
});

$scope.$apply();
}

break;

}
};

$scope.$watch('version', (oldValue, newValue) => {

if (oldValue === newValue) {
notification('info', "Please wait, fetching data for version " + $scope.version.id);
}

Core.unregister(jolokia, $scope);
Core.register(jolokia, $scope, [
{type: 'exec', mbean: managerMBean, operation: 'versions()'},
{type: 'exec', mbean: managerMBean, operation: 'getProfileIds(java.lang.String)', arguments: [$scope.version.id]},
{type: 'exec', mbean: managerMBean, operation: 'containerIdsForVersion(java.lang.String)', arguments: [$scope.version.id]}
], onSuccess($scope.render));
});

}

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

export function applyProfiles(jolokia, version, profiles, containers, success, error) {
doAction('applyProfilesToContainers(java.lang.String, java.util.List, java.util.List)', jolokia, [version, profiles, containers], success, error);
}

export function migrateContainers(jolokia, version, containers, success, error) {
doAction('applyVersionToContainers(java.lang.String, java.util.List)', jolokia, [version, containers], success, error);
}
Expand Down
Expand Up @@ -27,7 +27,6 @@ module Fabric {
}
};


$scope.containerGridOptions = {
data: 'containers',
selectedItems: $scope.selectedContainers,
Expand Down
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/profiles.ts
Expand Up @@ -70,7 +70,7 @@ module Fabric {
$location.search(q);

if (oldValue === newValue) {
notification('info', "Please wait, fetching profile data for version" + $scope.version.id);
notification('info', "Please wait, fetching profile data for version " + $scope.version.id);
}

Core.unregister(jolokia, $scope);
Expand Down

0 comments on commit d9834c2

Please sign in to comment.