Skip to content

Commit

Permalink
Fix #200
Browse files Browse the repository at this point in the history
  • Loading branch information
gashcrumb committed Mar 26, 2013
1 parent 1f011b6 commit 970cbd3
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 79 deletions.
150 changes: 79 additions & 71 deletions hawtio-web/src/main/webapp/app/jmx/html/operations.html
@@ -1,93 +1,101 @@
<script type="text/ng-template" id="array_item.html">
<div ng-switch on="typeOf(data)">
<div class="tab" ng-switch-when="array">
<ol>
<li ng-repeat="data in data" ng-include="'array_item.html'"></li>
</ol>
</div>
<div class="tab" ng-switch-when="object">
<ul class="unstyled">
<li ng-repeat="(key, value) in data" ng-include="'object_item.html'"></li>
</ul>
</div>
<p style="display: inline;" ng-switch-default>{{data}}</p>
</div>
</script>
<div ng-controller="Jmx.OperationsController">

<script type="text/ng-template" id="object_item.html">
<div>
<strong>{{key}}:</strong>
<div style="display: inline;" ng-switch on="typeOf(value)">
<script type="text/ng-template" id="array_item.html">
<div ng-switch on="typeOf(data)">
<div class="tab" ng-switch-when="array">
<ol>
<li ng-repeat="data in value" ng-include="'array_item.html'"></li>
<li ng-repeat="data in data" ng-include="'array_item.html'"></li>
</ol>
</div>
<div class="tab" ng-switch-when="object">
<ul class="unstyled">
<li ng-repeat="(key, value) in value" ng-include="'object_item.html'"></li>
<li ng-repeat="(key, value) in data" ng-include="'object_item.html'"></li>
</ul>
</div>
<p style="display: inline;" ng-switch-default>{{value}}</p>
<p style="display: inline;" ng-switch-default>{{data}}</p>
</div>
</div>
</script>
</script>

<ul class="unstyled" ng-controller="Jmx.OperationsController">
<li ng-repeat="item in operations">
<div class="expandable closed" ng-controller="Jmx.OperationController">
<div title="{{desc}}" class="title">
<i class="expandable-indicator"></i> {{title}}
<script type="text/ng-template" id="object_item.html">
<div>
<strong>{{key}}:</strong>
<div style="display: inline;" ng-switch on="typeOf(value)">
<div class="tab" ng-switch-when="array">
<ol>
<li ng-repeat="data in value" ng-include="'array_item.html'"></li>
</ol>
</div>
<div class="tab" ng-switch-when="object">
<ul class="unstyled">
<li ng-repeat="(key, value) in value" ng-include="'object_item.html'"></li>
</ul>
</div>
<p style="display: inline;" ng-switch-default>{{value}}</p>
</div>
<div class="expandable-body well">
</div>
</script>

<form class="form-horizontal no-bottom-margin" ng-show="operationResult!=''">
<fieldset>
<div class="alert alert-{{operationStatus}} no-bottom-margin">
<div class="control-group">
<div class="row-fluid" ng-show="isOperationsEmpty()">
The selected MBean has no JMX operations.
</div>

<ul class="unstyled" ng-hide="isOperationsEmpty()">
<li ng-repeat="item in operations">
<div class="expandable closed" ng-controller="Jmx.OperationController">
<div title="{{desc}}" class="title">
<i class="expandable-indicator"></i> {{title}}
</div>
<div class="expandable-body well">

<form class="form-horizontal no-bottom-margin" ng-show="operationResult!=''">
<fieldset>
<div class="alert alert-{{operationStatus}} no-bottom-margin">
<div class="control-group">

<div ng-switch on="typeOf(operationResult)">
<ol ng-switch-when="array">
<li ng-repeat="data in operationResult" ng-include="'array_item.html'"></li>
</ol>
<ul class="unstyled" ng-switch-when="object">
<li ng-repeat="(key, value) in operationResult" ng-include="'object_item.html'"></li>
</ul>
<span ng-switch-default>{{operationResult}}</span>
<div ng-switch on="typeOf(operationResult)">
<ol ng-switch-when="array">
<li ng-repeat="data in operationResult" ng-include="'array_item.html'"></li>
</ol>
<ul class="unstyled" ng-switch-when="object">
<li ng-repeat="(key, value) in operationResult" ng-include="'object_item.html'"></li>
</ul>
<span ng-switch-default>{{operationResult}}</span>
</div>

</div>
<div class="control-group">
<div class="controls">
<button class="btn" ng-click="ok()"><i class="icon-ok"></i> Ok</button>
</div>
</div>
</div>
</fieldset>
</form>

<form id="opForm" class="form-horizontal no-bottom-margin" ng-show="operationResult==''">
<fieldset>
<legend>{{desc}}</legend>
<div class="control-group" ng-repeat="arg in args">
<!-- Todo Add form validation -->
<label class="control-label">{{arg.name}}: </label>
<div class="controls" ng-switch on="arg.formType">
<input ng-switch-when="text" type='text' ng-model="arg.value">
<input ng-switch-when="number" type='number' ng-model="arg.value">
<span class="help-block">type: {{arg.type}}</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn" ng-click="ok()"><i class="icon-ok"></i> Ok</button>
</div>
</div>
</div>
</fieldset>
</form>

<form id="opForm" class="form-horizontal no-bottom-margin" ng-show="operationResult==''">
<fieldset>
<legend>{{desc}}</legend>
<div class="control-group" ng-repeat="arg in args">
<!-- Todo Add form validation -->
<label class="control-label">{{arg.name}}: </label>
<div class="controls" ng-switch on="arg.formType">
<input ng-switch-when="text" type='text' ng-model="arg.value">
<input ng-switch-when="number" type='number' ng-model="arg.value">
<span class="help-block">type: {{arg.type}}</span>
<button class="btn cancel"><i class="icon-remove"></i> Cancel</button>
<button class="btn" ng-click="reset()" ng-show="args"><i class="icon-undo"></i> Reset</button>
<button class="btn btn-success execute" ng-click="execute()"><i class="{{executeIcon}}"></i> Execute</button>
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn cancel"><i class="icon-remove"></i> Cancel</button>
<button class="btn" ng-click="reset()" ng-show="args"><i class="icon-undo"></i> Reset</button>
<button class="btn btn-success execute" ng-click="execute()"><i class="{{executeIcon}}"></i> Execute</button>
</div>
</div>
</fieldset>
</form>
</fieldset>
</form>
</div>
</div>
</div>
</li>
</ul>
</li>
</ul>

</div>
11 changes: 10 additions & 1 deletion hawtio-web/src/main/webapp/app/jmx/js/charts.ts
Expand Up @@ -5,6 +5,7 @@ module Jmx {
$scope.updateRate = parseInt(localStorage['updateRate']);

$scope.$on('$destroy', function () {
$scope.deregRouteChange();
$scope.dereg();
if ($scope.context) {
$scope.context.stop();
Expand All @@ -23,7 +24,15 @@ module Jmx {
}
};

$scope.dereg = $scope.$watch('workspace.selection', render);
$scope.deregRouteChange = $scope.$on("$routeChangeSuccess", function (event, current, previous) {
// lets do this asynchronously to avoid Error: $digest already in progress
setTimeout(render, 50);
});

$scope.dereg = $scope.$watch('workspace.selection', function () {
if (workspace.moveIfViewInvalid()) return;
render();
});

function render() {
var node = workspace.selection;
Expand Down
35 changes: 28 additions & 7 deletions hawtio-web/src/main/webapp/app/jmx/js/operations.ts
@@ -1,4 +1,6 @@
module Jmx {

/*
export interface IArg {
name : string;
type : string;
Expand All @@ -11,7 +13,7 @@ module Jmx {
args : IArg[];
execute : (args : IArg[]) => void;
}
} */

// IOperationControllerScope
export function OperationController($scope, workspace:Workspace, jolokia, $document) {
Expand Down Expand Up @@ -137,6 +139,7 @@ module Jmx {

}

/*
export interface IOperation {
[key : string] : { name : string; humanReadable : string; args : string; };
[key : string] : any;
Expand All @@ -148,10 +151,13 @@ module Jmx {
sanitize : (value : IOperation) => IOperation;
operations : IOperation;
}
*/

export function OperationsController($scope, $routeParams : ng.IRouteParamsService, workspace:Workspace, jolokia) {

export function OperationsController($scope : IOperationsControllerScope, $routeParams : ng.IRouteParamsService, workspace:Workspace, jolokia) {
$scope.operations = {};

var sanitize = (value : IOperation) => {
var sanitize = (value) => {
for (var item in value) {
item = "" + item;
value[item].name = item;
Expand All @@ -171,9 +177,21 @@ module Jmx {
return query;
};

$scope.$watch('workspace.selection', function() {
$scope.isOperationsEmpty = () => {
return $.isEmptyObject($scope.operations);
}

$scope.$on("$routeChangeSuccess", function (event, current, previous) {
// lets do this asynchronously to avoid Error: $digest already in progress
setTimeout(render, 50);
});

$scope.$watch('workspace.selection', function () {
if (workspace.moveIfViewInvalid()) return;
render();
});

function render() {
var node = workspace.selection;
if (!node) {
return;
Expand All @@ -187,7 +205,7 @@ module Jmx {
var query = asQuery(objectName);

var update_values = (response) => {
var ops: IOperation = response.value.op;
var ops = response.value.op;

var answer = {};

Expand All @@ -205,6 +223,7 @@ module Jmx {
}
});
$scope.operations = sanitize(answer);
console.log("Operations: ", $scope.operations);
$scope.$apply();
};

Expand All @@ -213,7 +232,9 @@ module Jmx {
notification('error', 'Failed to query available operations: ' + response.error);
}
}));
}

render();

});
}
};
}

0 comments on commit 970cbd3

Please sign in to comment.