Skip to content

Commit

Permalink
Mostly implement #37
Browse files Browse the repository at this point in the history
  • Loading branch information
gashcrumb committed Jun 27, 2013
1 parent 81d48b1 commit 4a0f18a
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 17 deletions.
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/fabric/html/fabricView.html
Expand Up @@ -209,7 +209,7 @@
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" ng-model=saveCredentials> Save these credentials as the default
<input type="checkbox" ng-model="saveCredentials"> Save these credentials as the default
</label>
</div>
</div>
Expand Down
32 changes: 31 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/html/patching.html
Expand Up @@ -2,12 +2,42 @@

<div class="row-fluid">
<div class="span4">
<p>1) Upload 1 or more patch files to apply to this fabric</p>
<p>1) Upload one or more patch files to apply to this fabric</p>
<div hawtio-file-upload="files" target="patches"></div>
</div>
<div class="span4">
<p>2) Select what version to derive the new patched version from</p>
<div fabric-version-selector="targetVersion"></div>
<p>Enter a name for the new version, or leave blank to use the next available version:</p>
<input type="text" ng-model="newVersionName">
<p>Enter administrator credentials for fabric</p>
<div class="control-group">
<label class="control-label">User Name: </label>
<div class="controls">
<input type="text" ng-model="proxyUser">
</div>
</div>
<div class="control-group">
<label class="control-label">Password: </label>
<div class="controls">
<input type="password" ng-model="proxyPassword">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" ng-model="saveJmxCredentials"> Save these credentials as the default
</label>
</div>
</div>
</div>
<div class="span1">
<p>3) <ng-pluralize count="files.length"
when="{'0': 'Upload files to apply',
'one': 'Apply patch',
'other': 'Apply patches'}"
></ng-pluralize></p>
<button class="btn btn-success" ng-disabled="!valid()" ng-click="go()"><i class="icon-ok"></i> Apply</button>
</div>
</div>

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

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);
}

export function setContainerProperty(jolokia, containerId, property, value, success, error) {
doAction('setContainerProperty(java.lang.String, java.lang.String, java.lang.Object)', jolokia, [containerId, property, value], success, error);
}
Expand Down
41 changes: 37 additions & 4 deletions hawtio-web/src/main/webapp/app/fabric/js/patching.ts
@@ -1,12 +1,45 @@
module Fabric {
export function PatchingController($scope, jolokia) {
export function PatchingController($scope, jolokia, localStorage, $location) {

$scope.files = [];
$scope.targetVersion = null;
$scope.newVersionName = '';
$scope.proxyUser = localStorage['fabric.userName'];
$scope.proxyPassword = localStorage['fabric.password'];
$scope.saveJmxCredentials = false;

$scope.$watch('targetVersion', (newValue, oldValue) => {
console.log("targetVersion: ", $scope.targetVersion);
});
$scope.valid = () => {
return $scope.files.length > 0 && $scope.targetVersion !== null && $scope.proxyUser && $scope.proxyPassword;
}

$scope.go = () => {
var message = $scope.files.length + ' patches';

if ($scope.files.length === 1) {
message = "patch: " + $scope.files[0].fileName;
}

notification('info', "Applying " + message);

if ($scope.saveJmxCredentials) {
localStorage['fabric.userName'] = $scope.proxyUser;
localStorage['fabric.password'] = $scope.proxyPassword;
}

var files = $scope.files.map((file) => { return file.absolutePath; });

applyPatches(jolokia, files, $scope.targetVersion.id, $scope.newVersionName, $scope.proxyUser, $scope.proxyPassword,
() => {
notification('success', "Successfully applied " + message);
$location.url("/fabric/view");
$scope.$apply();
}, (response) => {
notification('error', "Failed to apply " + message + " due to " + response.error);
$scope.$apply();
});


}

}
}
Expand Up @@ -15,17 +15,18 @@ module Fabric {
public controller = ($scope, $element, $attrs, jolokia) => {
$scope.versions = [];
$scope.responseJson = '';
$scope.selectedVersionId = '';


$scope.$watch('versions', (newValue, oldValue) => {
if (newValue !== oldValue) {
if (!$scope.selectedVersion) {
$scope.selectedVersion = $scope.versions.find((version) => { return version.defaultVersion; });
} else {
$scope.selectedVersion = $scope.versions.find((version) => { return version.id === $scope.selectedVersion.id; } );
if ($scope.selectedVersionId === '') {
$scope.selectedVersion = $scope.versions.find((version) => { return version.defaultVersion; });
} else {
$scope.selectedVersion = $scope.versions.find((version) => { return version.id === $scope.selectedVersion.id; } );
}
}
console.log("selectedVersion: ", $scope.selectedVersion);

}
}, true);

Expand All @@ -35,7 +36,7 @@ module Fabric {
if ($scope.responseJson !== responseJson) {
$scope.responseJson = responseJson;
$scope.versions = response.value;
//$scope.$apply();
$scope.$apply();
}
}

Expand Down
14 changes: 10 additions & 4 deletions hawtio-web/src/main/webapp/app/ui/js/fileUpload.ts
Expand Up @@ -94,14 +94,20 @@ module UI {
},
success: (response, statusText, xhr, $form) => {
notification('success', "Uploaded " + fileName);
button.prop('disabled', false);
$scope.percentComplete = 0;
setTimeout( () => {
button.prop('disabled', false);
$scope.percentComplete = 0;
$scope.$apply();
}, 1000);
$scope.$apply();
},
error: (response, statusText, xhr, $form) => {
notification('error', "Failed to upload " + fileName + " due to " + statusText);
button.prop('disabled', false);
$scope.percentComplete = 0;
setTimeout( () => {
button.prop('disabled', false);
$scope.percentComplete = 0;
$scope.$apply();
}, 1000);
$scope.$apply();
},
uploadProgress: (event, position, total, percentComplete) => {
Expand Down
12 changes: 11 additions & 1 deletion hawtio-web/src/main/webapp/css/site-base.less
Expand Up @@ -1557,12 +1557,22 @@ td.adding {
.file-upload div form fieldset .input-prepend .btn {
float: left;
}

@-moz-document url-prefix() {
/* hack to get the add button to line up correctly in FF */
.input-prepend .btn {
padding-top: 5px;
padding-bottom: 5px;
}

}

.input-prepend .progress {
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
position: relative;
left: 1px;
top: 0px;
min-height: 28px;
min-height: 30px;
width: 160px;
}

0 comments on commit 4a0f18a

Please sign in to comment.