Commit 5e55293b by Johannes Edmeier

Fix using objects as arguments for jmx operations

With this commit objects are passed now correctly to jolokia. The object's needs to be written in json, which is validated for well- formedness. From now on the attributes are read autmatically when the bean gets selected and I fixed that errors weren't displayed. fixes #301
parent e0bd77bf
......@@ -18,17 +18,15 @@
var angular = require('angular');
module.exports = {
bindings: {
value: '=model',
disabled: '<disabled',
type: '@type'
value: '<sbaValue',
disabled: '<sbaDisabled',
type: '@sbaType',
onChange: '&sbaChange'
},
controller: function ($scope) {
controller: function () {
'ngInject';
var ctrl = this;
ctrl.jsonEdited = function () {
ctrl.value = angular.fromJson($scope.json);
};
ctrl.$onInit = function () {
ctrl.inputType = (function () {
......@@ -50,7 +48,7 @@ module.exports = {
default:
return null;
}
}());
} ());
ctrl.selectOptions = (function () {
switch (ctrl.type) {
......@@ -64,10 +62,23 @@ module.exports = {
})();
ctrl.isObject = ctrl.selectOptions === null && ctrl.inputType === null;
};
ctrl.$onChanges = function () {
if (ctrl.isObject) {
$scope.$watch('$ctrl.value', function (value) {
ctrl.json = angular.toJson(value, true);
});
ctrl.json = angular.toJson(ctrl.value, true);
}
};
ctrl.valueChanged = function () {
ctrl.onChange({ value: ctrl.value, error: null });
};
ctrl.jsonChanged = function () {
try {
ctrl.onChange({ value: angular.fromJson(ctrl.json), error: null });
} catch (error) {
ctrl.onChange({ value: null, error: error });
}
};
},
......
<input ng-show="$ctrl.inputType" class="input-xxlarge" type="{{$ctrl.inputType}}" ng-model="$ctrl.value" ng-disabled="$ctrl.disabled" />
<select ng-show="$ctrl.selectOptions" class="input-xxlarge" ng-model="$ctrl.value" ng-disabled="$ctrl.disabled">
<input ng-show="$ctrl.inputType" class="input-xxlarge" type="{{$ctrl.inputType}}" ng-model="$ctrl.value" ng-readonly="$ctrl.disabled"
ng-change="$ctrl.valueChanged()"></input>
<select ng-show="$ctrl.selectOptions" class="input-xxlarge" ng-model="$ctrl.value" ng-readonly="$ctrl.disabled" ng-change="$ctrl.valueChanged()">
<option ng-repeat="opt in $ctrl.selectOptions" value="{{opt}}" ng-selected="$ctrl.value == opt">{{opt}}</option>
</select>
<textarea ng-show="$ctrl.isObject" style="word-break: break-all;" class="input-xxlarge" rows="6" ng-model="$ctrl.json" ng-blur="$ctrl.jsonEdited" ng-disabled="$ctrl.disabled" />
<textarea ng-show="$ctrl.isObject" style="word-break: break-all;" class="input-xxlarge" rows="6" ng-model="$ctrl.json" ng-change="$ctrl.jsonChanged()"
ng-readonly="$ctrl.disabled"></textarea>
\ No newline at end of file
......@@ -15,6 +15,7 @@
*/
'use strict';
var angular = require('angular');
module.exports = {
bindings: {
bean: '<bean',
......@@ -24,19 +25,32 @@ module.exports = {
'ngInject';
var ctrl = this;
ctrl.attributeValues = {};
ctrl.attributeErrors = {};
ctrl.error = null;
ctrl.invocation = null;
ctrl.$onChanges = function () {
if (ctrl.bean) {
ctrl.initAttributes();
ctrl.readAttributeValues();
} else {
ctrl.attributes = {};
ctrl.error = null;
}
};
ctrl.initAttributes = function () {
ctrl.attributes = {};
angular.forEach(ctrl.bean.attributes, function (descriptor, name) {
ctrl.attributes[name] = { value: null, error: null, descriptor: descriptor };
});
};
ctrl.readAttributeValues = function () {
ctrl.readingAttributes = true;
ctrl.error = null;
ctrl.attributeErrors = {};
ctrl.attributeValues = {};
ApplicationJmx.readAllAttr(ctrl.application, ctrl.bean).then(
function (response) {
ctrl.attributeValues = response.value;
angular.forEach(response.value, function (value, name) {
ctrl.attributes[name].value = value;
});
ctrl.readingAttributes = false;
}
).catch(function (response) {
......@@ -45,11 +59,16 @@ module.exports = {
});
};
ctrl.writeAttributeValue = function (name, value) {
ctrl.attributeErrors[name] = null;
ApplicationJmx.writeAttr(ctrl.application, ctrl.bean, name, value).catch(
ctrl.updateAttributeValue = function (name, value, error) {
ctrl.attributes[name].value = value;
ctrl.attributes[name].error = error;
};
ctrl.writeAttributeValue = function (name) {
ctrl.attributes[name].error = null;
ApplicationJmx.writeAttr(ctrl.application, ctrl.bean, name, ctrl.attributes[name].value).catch(
function (response) {
ctrl.attributeErrors[name] = response.error;
ctrl.attributes[name].error = response.error;
});
};
......
<h3 ng-bind="$ctrl.bean.name"><br/><small ng-bind="$ctrl.bean.description"></small></h3>
<div ng-show="error" class="alert alert-error"> <b>Error:</b> {{$ctrl.error}}</div>
<div ng-show="$ctrl.error" class="alert alert-error"> <b>Error:</b> {{$ctrl.error}}</div>
<dl>
<dt>Id</dt>
<dd style="word-break: break-all;" ng-bind="$ctrl.bean.id"></dd>
<dt ng-repeat-start="(name, value) in $ctrl.bean.nameProps" ng-bind="name"></dt>
<dd ng-repeat-end ng-bind="value"></dd>
<dt>Id</dt>
<dd style="word-break: break-all;" ng-bind="$ctrl.bean.id"></dd>
<dt ng-repeat-start="(name, value) in $ctrl.bean.nameProps" ng-bind="name"></dt>
<dd ng-repeat-end ng-bind="value"></dd>
</dl>
<form class="form-horizontal">
<fieldset ng-show="$ctrl.bean.attributes">
<legend>Attributes
<button class="btn" ng-click="$ctrl.readAttributeValues()">read</button>
<span ng-show="$ctrl.readingAttributes"><i class="fa fa-spinner fa-pulse"></i></span>
</legend>
<div class="control-group" ng-repeat="(name, attribute) in $ctrl.bean.attributes track by name" ng-class="{error: $ctrl.attributeErrors[attribute.name]}">
<label class="control-label" for="{{name}}" style="word-break: break-all;">
<fieldset ng-show="$ctrl.bean.attributes">
<legend>Attributes
<button class="btn" ng-click="$ctrl.readAttributeValues()">reload</button>
<span ng-show="$ctrl.readingAttributes"><i class="fa fa-spinner fa-pulse"></i></span>
</legend>
<div class="control-group" ng-repeat="(name, attribute) in $ctrl.attributes track by name" ng-class="{error: attribute.error}">
<label class="control-label" for="{{name}}" style="word-break: break-all;">
{{name}}
<br/><small class="muted" ng-bind="attribute.type"></small>
<br/><small class="muted" ng-bind="attribute.descriptor.type"></small>
</label>
<div class="controls">
<div class="input-prepend">
<button class="btn" type="button" ng-click="$ctrl.writeAttributeValue(name, $ctrl.attributeValues[name])" ng-disabled="!attribute.rw">write</button>
<sba-java-type-input type="{{attribute.type}}" model="$ctrl.attributeValues[name]" disabled="!attribute.rw"></sba-java-type-input>
</div>
<span class="help-block" ng-bind="attribute.desc"></span>
<span class="help-inline" ng-bind="$ctrl.attributeErrors[name]"></span>
</div>
</div>
</fieldset>
<fieldset ng-show="$ctrl.bean.operations">
<legend>Operations</legend>
<div class="control-group" ng-if="!$ctrl.invocation">
<button ng-repeat="(name, op) in $ctrl.bean.operations track by name" class="btn btn-block" style="text-align: left; padding: 8px 15px;" ng-click="$ctrl.doInvoke(name, op)">
<div class="controls">
<div class="input-prepend">
<button class="btn" type="button" ng-click="$ctrl.writeAttributeValue(name)" ng-disabled="!attribute.descriptor.rw">write</button>
<sba-java-type-input sba-type="{{attribute.descriptor.type}}" sba-value="attribute.value" sba-change="$ctrl.updateAttributeValue(name, value, error)"
sba-disabled="!attribute.descriptor.rw"></sba-java-type-input>
</div>
<span class="help-block" ng-bind="attribute.descriptor.desc"></span>
<span class="help-inline" ng-bind="attribute.error"></span>
</div>
</div>
</fieldset>
<fieldset ng-show="$ctrl.bean.operations">
<legend>Operations</legend>
<div class="control-group" ng-if="!$ctrl.invocation">
<button ng-repeat="(name, op) in $ctrl.bean.operations track by name" class="btn btn-block" style="text-align: left; padding: 8px 15px;"
ng-click="$ctrl.doInvoke(name, op)">
<b ng-bind="name"></b>
<span ng-if="!op.length">(<span ng-repeat-start="arg in op.args" data-toggle="tooltip" title="{{arg.desc}}">{{arg.type}} {{arg.name}}</span><span ng-repeat-end ng-if="!$last">, </span> )</span>
<br/>
......@@ -38,9 +40,9 @@
<span class="help-block"><small class="muted" ng-show="op.length > 0">overloaded</small></span>
<span class="help-block" ng-bind="op.desc"></span>
</button>
</div>
<div ng-if="$ctrl.invocation">
<sba-jmx-invocation operation-name="$ctrl.invocation.name" operation-descriptor="$ctrl.invocation.operation" on-cancel="$ctrl.cancelInvoke()" />
</div>
</fieldset>
</form>
</div>
<div ng-if="$ctrl.invocation">
<sba-jmx-invocation operation-name="$ctrl.invocation.name" operation-descriptor="$ctrl.invocation.operation" on-cancel="$ctrl.cancelInvoke()"></sba-jmx-invocation>
</div>
</fieldset>
</form>
\ No newline at end of file
......@@ -23,10 +23,21 @@ module.exports = {
var ctrl = this;
ctrl.$onInit = function () {
ctrl.arguments = new Array(ctrl.invocation.descriptor.args.length);
ctrl.errors = new Array(ctrl.invocation.descriptor.args.length);
};
ctrl.applyParameters = function () {
ctrl.invocation.arguments = ctrl.arguments;
ctrl.invocation.proceedJmxInvocation();
var hasError = ctrl.arguments.find(function (arg) {
return arg !== null && arg.error !== null;
});
if (!hasError) {
ctrl.invocation.arguments = ctrl.arguments.map(function (arg) {
return arg.value;
});
ctrl.invocation.proceedJmxInvocation();
}
};
ctrl.updateArg = function (index, value, error) {
ctrl.arguments[index] = { value: value, error: error };
};
},
template: require('./jmxInvokeInputParameters.tpl.html')
......
<form class="form">
<p>Please input the arguments for {{$ctrl.invocation.signature}} <small class="muted">: {{$ctrl.invocation.descriptor.ret}}</small></p>
<div class="control-group" ng-repeat="arg in $ctrl.invocation.descriptor.args">
<label class="control-label" for="{{arg.name}}" style="word-break: break-all;">{{arg.name}} <small class="muted" style="word-break: break-all;" ng-bind="arg.type"></small></label>
<div class="controls">
<sba-java-type-input type="{{arg.type}}" decription="{{arg.desc}}" model="$ctrl.arguments[$index]" />
</div>
</div>
<button class="btn btn-primary" ng-click="$ctrl.applyParameters()">Execute</button>
</form>
<p>Please input the arguments for {{$ctrl.invocation.signature}} <small class="muted">: {{$ctrl.invocation.descriptor.ret}}</small></p>
<div class="control-group" ng-repeat="arg in $ctrl.invocation.descriptor.args" ng-class="{ error : $ctrl.arguments[$index].error }">
<label class="control-label" for="{{arg.name}}" style="word-break: break-all;">{{arg.name}} <small class="muted" style="word-break: break-all;" ng-bind="arg.type"></small></label>
<div class="controls">
<sba-java-type-input sba-type="{{arg.type}}" sba-decription="{{arg.desc}}" sba-change="$ctrl.updateArg($index, value, error)"></sba-java-type-input>
<span class="help-inline" ng-bind="$ctrl.arguments[$index].error"></span>
</div>
</div>
<button class="btn btn-primary" ng-click="$ctrl.applyParameters()">Execute</button>
</form>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment