htt-form transformer-validation fix

This commit is contained in:
Sergey Tarnavskiy 2017-11-16 15:31:39 +02:00
parent 86c2fe82b5
commit 05dabec2bb
3 changed files with 28 additions and 21 deletions

View File

@ -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(){ try {
var aceValue = _ace.getSession().getDocument().getValue(); angular.fromJson(model);
var valid = true; scope.theForm[editorName].$setValidity('transformerJSON', true);
if(!aceValue && !aceValue.length) { } catch(e) {
valid = false; scope.theForm[editorName].$setValidity('transformerJSON', false);
} else {
try {
angular.fromJson(aceValue);
} catch(e) {
valid = false;
}
} }
scope.theForm.$setValidity('transformerRequired', valid); }
});
} }
$compile(element.contents())(scope); $compile(element.contents())(scope);

View File

@ -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>

View File

@ -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",