htt-form transformer-validation fix
This commit is contained in:
parent
86c2fe82b5
commit
05dabec2bb
@ -48,7 +48,9 @@ export default function ExtensionFormHttpDirective($compile, $templateCache, $tr
|
|||||||
enableBasicAutocompletion: true,
|
enableBasicAutocompletion: true,
|
||||||
enableLiveAutocompletion: true
|
enableLiveAutocompletion: true
|
||||||
},
|
},
|
||||||
onLoad: aceOnLoad
|
onLoad: function(_ace) {
|
||||||
|
_ace.$blockScrolling = 1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if(scope.isAdd) {
|
if(scope.isAdd) {
|
||||||
@ -120,22 +122,15 @@ export default function ExtensionFormHttpDirective($compile, $templateCache, $tr
|
|||||||
attribute.transformer = "";
|
attribute.transformer = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function aceOnLoad(_ace) {
|
scope.validateTransformer = function (model, editorName) {
|
||||||
_ace.$blockScrolling = 1;
|
if(model && model.length) {
|
||||||
_ace.on("change", function(){
|
|
||||||
var aceValue = _ace.getSession().getDocument().getValue();
|
|
||||||
var valid = true;
|
|
||||||
if(!aceValue && !aceValue.length) {
|
|
||||||
valid = false;
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
angular.fromJson(aceValue);
|
angular.fromJson(model);
|
||||||
|
scope.theForm[editorName].$setValidity('transformerJSON', true);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
valid = false;
|
scope.theForm[editorName].$setValidity('transformerJSON', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scope.theForm.$setValidity('transformerRequired', valid);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$compile(element.contents())(scope);
|
$compile(element.contents())(scope);
|
||||||
|
|||||||
@ -152,11 +152,14 @@
|
|||||||
<div flex class="tb-extension-custom-transformer"
|
<div flex class="tb-extension-custom-transformer"
|
||||||
ui-ace="extensionCustomTransformerOptions"
|
ui-ace="extensionCustomTransformerOptions"
|
||||||
ng-model="attribute.transformer"
|
ng-model="attribute.transformer"
|
||||||
name="test_{{$index}}">
|
name="attributeCustomTransformer_{{configIndex}}{{converterIndex}}{{attributeIndex}}"
|
||||||
|
ng-change='validateTransformer(attribute.transformer,"attributeCustomTransformer_" + configIndex + converterIndex + attributeIndex)'
|
||||||
|
required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tb-error-messages" ng-messages="theForm['test_' + $index].$error" role="alert">
|
<div class="tb-error-messages" ng-messages="theForm['attributeCustomTransformer_' + configIndex + converterIndex + attributeIndex].$error" role="alert">
|
||||||
<div ng-message="transformerRequired" class="tb-error-message">Ну привет :)</div>
|
<div ng-message="required" class="tb-error-message" translate>extension.json-required</div>
|
||||||
|
<div ng-message="transformerJSON" class="tb-error-message" translate>extension.json-parse</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -243,9 +246,16 @@
|
|||||||
<div flex class="tb-extension-custom-transformer-panel">
|
<div flex class="tb-extension-custom-transformer-panel">
|
||||||
<div flex class="tb-extension-custom-transformer"
|
<div flex class="tb-extension-custom-transformer"
|
||||||
ui-ace="extensionCustomTransformerOptions"
|
ui-ace="extensionCustomTransformerOptions"
|
||||||
ng-model="timeseries.transformer">
|
ng-model="timeseries.transformer"
|
||||||
|
name="timeseriesCustomTransformer_{{configIndex}}{{converterIndex}}{{timeseriesIndex}}"
|
||||||
|
ng-change='validateTransformer(timeseries.transformer,"timeseriesCustomTransformer_" + configIndex + converterIndex + timeseriesIndex)'
|
||||||
|
required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tb-error-messages" ng-messages="theForm['timeseriesCustomTransformer_' + configIndex + converterIndex + timeseriesIndex].$error" role="alert">
|
||||||
|
<div ng-message="required" class="tb-error-message" translate>extension.json-required</div>
|
||||||
|
<div ng-message="transformerJSON" class="tb-error-message" translate>extension.json-parse</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -769,6 +769,8 @@ export default angular.module('thingsboard.locale', [])
|
|||||||
"custom": "Custom",
|
"custom": "Custom",
|
||||||
"to-double": "To Double",
|
"to-double": "To Double",
|
||||||
"transformer": "Transformer",
|
"transformer": "Transformer",
|
||||||
|
"json-required": "Transformer json is required.",
|
||||||
|
"json-parse": "Unable to parse transformer json.",
|
||||||
"attributes": "Attributes",
|
"attributes": "Attributes",
|
||||||
"add-attribute": "Add attribute",
|
"add-attribute": "Add attribute",
|
||||||
"timeseries": "Timeseries",
|
"timeseries": "Timeseries",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user