Commit 05dabec2bb1a7514c7a072360069cde914985ffb
1 parent
86c2fe82
htt-form transformer-validation fix
Showing
3 changed files
with
28 additions
and
21 deletions
@@ -48,7 +48,9 @@ export default function ExtensionFormHttpDirective($compile, $templateCache, $tr | @@ -48,7 +48,9 @@ export default function ExtensionFormHttpDirective($compile, $templateCache, $tr | ||
48 | enableBasicAutocompletion: true, | 48 | enableBasicAutocompletion: true, |
49 | enableLiveAutocompletion: true | 49 | enableLiveAutocompletion: true |
50 | }, | 50 | }, |
51 | - onLoad: aceOnLoad | 51 | + onLoad: function(_ace) { |
52 | + _ace.$blockScrolling = 1; | ||
53 | + } | ||
52 | }; | 54 | }; |
53 | 55 | ||
54 | if(scope.isAdd) { | 56 | if(scope.isAdd) { |
@@ -120,24 +122,17 @@ export default function ExtensionFormHttpDirective($compile, $templateCache, $tr | @@ -120,24 +122,17 @@ export default function ExtensionFormHttpDirective($compile, $templateCache, $tr | ||
120 | attribute.transformer = ""; | 122 | attribute.transformer = ""; |
121 | } | 123 | } |
122 | 124 | ||
123 | - function aceOnLoad(_ace) { | ||
124 | - _ace.$blockScrolling = 1; | ||
125 | - _ace.on("change", function(){ | ||
126 | - var aceValue = _ace.getSession().getDocument().getValue(); | ||
127 | - var valid = true; | ||
128 | - if(!aceValue && !aceValue.length) { | ||
129 | - valid = false; | ||
130 | - } else { | ||
131 | - try { | ||
132 | - angular.fromJson(aceValue); | ||
133 | - } catch(e) { | ||
134 | - valid = false; | ||
135 | - } | 125 | + scope.validateTransformer = function (model, editorName) { |
126 | + if(model && model.length) { | ||
127 | + try { | ||
128 | + angular.fromJson(model); | ||
129 | + scope.theForm[editorName].$setValidity('transformerJSON', true); | ||
130 | + } catch(e) { | ||
131 | + scope.theForm[editorName].$setValidity('transformerJSON', false); | ||
136 | } | 132 | } |
137 | - scope.theForm.$setValidity('transformerRequired', valid); | ||
138 | - }); | 133 | + } |
139 | } | 134 | } |
140 | - | 135 | + |
141 | $compile(element.contents())(scope); | 136 | $compile(element.contents())(scope); |
142 | } | 137 | } |
143 | 138 |
@@ -152,11 +152,14 @@ | @@ -152,11 +152,14 @@ | ||
152 | <div flex class="tb-extension-custom-transformer" | 152 | <div flex class="tb-extension-custom-transformer" |
153 | ui-ace="extensionCustomTransformerOptions" | 153 | ui-ace="extensionCustomTransformerOptions" |
154 | ng-model="attribute.transformer" | 154 | ng-model="attribute.transformer" |
155 | - name="test_{{$index}}"> | 155 | + name="attributeCustomTransformer_{{configIndex}}{{converterIndex}}{{attributeIndex}}" |
156 | + ng-change='validateTransformer(attribute.transformer,"attributeCustomTransformer_" + configIndex + converterIndex + attributeIndex)' | ||
157 | + required> | ||
156 | </div> | 158 | </div> |
157 | </div> | 159 | </div> |
158 | - <div class="tb-error-messages" ng-messages="theForm['test_' + $index].$error" role="alert"> | ||
159 | - <div ng-message="transformerRequired" class="tb-error-message">Ну привет :)</div> | 160 | + <div class="tb-error-messages" ng-messages="theForm['attributeCustomTransformer_' + configIndex + converterIndex + attributeIndex].$error" role="alert"> |
161 | + <div ng-message="required" class="tb-error-message" translate>extension.json-required</div> | ||
162 | + <div ng-message="transformerJSON" class="tb-error-message" translate>extension.json-parse</div> | ||
160 | </div> | 163 | </div> |
161 | </div> | 164 | </div> |
162 | 165 | ||
@@ -243,9 +246,16 @@ | @@ -243,9 +246,16 @@ | ||
243 | <div flex class="tb-extension-custom-transformer-panel"> | 246 | <div flex class="tb-extension-custom-transformer-panel"> |
244 | <div flex class="tb-extension-custom-transformer" | 247 | <div flex class="tb-extension-custom-transformer" |
245 | ui-ace="extensionCustomTransformerOptions" | 248 | ui-ace="extensionCustomTransformerOptions" |
246 | - ng-model="timeseries.transformer"> | 249 | + ng-model="timeseries.transformer" |
250 | + name="timeseriesCustomTransformer_{{configIndex}}{{converterIndex}}{{timeseriesIndex}}" | ||
251 | + ng-change='validateTransformer(timeseries.transformer,"timeseriesCustomTransformer_" + configIndex + converterIndex + timeseriesIndex)' | ||
252 | + required> | ||
247 | </div> | 253 | </div> |
248 | </div> | 254 | </div> |
255 | + <div class="tb-error-messages" ng-messages="theForm['timeseriesCustomTransformer_' + configIndex + converterIndex + timeseriesIndex].$error" role="alert"> | ||
256 | + <div ng-message="required" class="tb-error-message" translate>extension.json-required</div> | ||
257 | + <div ng-message="transformerJSON" class="tb-error-message" translate>extension.json-parse</div> | ||
258 | + </div> | ||
249 | </div> | 259 | </div> |
250 | 260 | ||
251 | 261 |
@@ -769,6 +769,8 @@ export default angular.module('thingsboard.locale', []) | @@ -769,6 +769,8 @@ export default angular.module('thingsboard.locale', []) | ||
769 | "custom": "Custom", | 769 | "custom": "Custom", |
770 | "to-double": "To Double", | 770 | "to-double": "To Double", |
771 | "transformer": "Transformer", | 771 | "transformer": "Transformer", |
772 | + "json-required": "Transformer json is required.", | ||
773 | + "json-parse": "Unable to parse transformer json.", | ||
772 | "attributes": "Attributes", | 774 | "attributes": "Attributes", |
773 | "add-attribute": "Add attribute", | 775 | "add-attribute": "Add attribute", |
774 | "timeseries": "Timeseries", | 776 | "timeseries": "Timeseries", |