19 changed files with 336 additions and 31 deletions
@ -0,0 +1,2 @@ |
|||
!function(e){function t(r){if(n[r])return n[r].exports;var u=n[r]={exports:{},id:r,loaded:!1};return e[r].call(u.exports,u,u.exports,t),u.loaded=!0,u.exports}var n={};return t.m=e,t.c=n,t.p="/static/",t(0)}([function(e,t,n){e.exports=n(3)},function(e,t){e.exports=' <section layout=column> <label translate class="tb-title no-padding">tb.rulenode.filter</label> <tb-js-func ng-model=configuration.jsScript function-name=Filter function-args="{{ [\'msg\'] }}" no-validate=true> </tb-js-func> </section> '},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function u(e){var t=function(t,n,r,u){var o=i.default;n.html(o),t.$watch("configuration",function(e,n){angular.equals(e,n)||u.$setViewValue(t.configuration)}),u.$render=function(){t.configuration=u.$viewValue},e(n.contents())(t)};return{restrict:"E",require:"^ngModel",scope:{},link:t}}u.$inject=["$compile"],Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var o=n(1),i=r(o)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var u=n(2),o=r(u),i=n(5),a=r(i);t.default=angular.module("thingsboard.ruleChain.config",[]).directive("tbFilterNodeScriptConfig",o.default).config(a.default).name},function(e,t){"use strict";function n(e){var t={tb:{rulenode:{filter:"Filter"}}};angular.merge(e.en_US,t)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function u(e,t){(0,i.default)(t);for(var n in t){var r=t[n];e.translations(n,r)}}u.$inject=["$translateProvider","locales"],Object.defineProperty(t,"__esModule",{value:!0}),t.default=u;var o=n(4),i=r(o)}]); |
|||
//# sourceMappingURL=rulenode-core-config.js.map
|
|||
@ -0,0 +1,73 @@ |
|||
/* |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
/* eslint-disable import/no-unresolved, import/default */ |
|||
|
|||
import ruleNodeConfigTemplate from './rulenode-config.tpl.html'; |
|||
|
|||
/* eslint-enable import/no-unresolved, import/default */ |
|||
|
|||
/*@ngInject*/ |
|||
export default function RuleNodeConfigDirective($compile, $templateCache, $injector, $translate) { |
|||
|
|||
var linker = function (scope, element, attrs, ngModelCtrl) { |
|||
var template = $templateCache.get(ruleNodeConfigTemplate); |
|||
element.html(template); |
|||
|
|||
scope.$watch('configuration', function (newVal, prevVal) { |
|||
if (!angular.equals(newVal, prevVal)) { |
|||
ngModelCtrl.$setViewValue(scope.configuration); |
|||
} |
|||
}); |
|||
|
|||
ngModelCtrl.$render = function () { |
|||
scope.configuration = ngModelCtrl.$viewValue; |
|||
}; |
|||
|
|||
scope.useDefinedDirective = function() { |
|||
return scope.nodeDefinition.configDirective && !scope.definedDirectiveError; |
|||
}; |
|||
|
|||
validateDefinedDirective(); |
|||
|
|||
function validateDefinedDirective() { |
|||
if (scope.nodeDefinition.uiResourceLoadError && scope.nodeDefinition.uiResourceLoadError.length) { |
|||
scope.definedDirectiveError = scope.nodeDefinition.uiResourceLoadError; |
|||
} else { |
|||
var definedDirective = scope.nodeDefinition.configDirective; |
|||
if (definedDirective && definedDirective.length) { |
|||
if (!$injector.has(definedDirective + 'Directive')) { |
|||
scope.definedDirectiveError = $translate.instant('rulenode.directive-is-not-loaded', {directiveName: definedDirective}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
$compile(element.contents())(scope); |
|||
}; |
|||
|
|||
return { |
|||
restrict: "E", |
|||
require: "^ngModel", |
|||
scope: { |
|||
nodeDefinition:'=', |
|||
required:'=ngRequired', |
|||
readonly:'=ngReadonly' |
|||
}, |
|||
link: linker |
|||
}; |
|||
|
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2018 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
|
|||
<tb-rule-node-defined-config ng-if="useDefinedDirective()" |
|||
ng-model="configuration" |
|||
rule-node-directive="{{nodeDefinition.configDirective}}" |
|||
ng-required="required" |
|||
ng-readonly="readonly"> |
|||
</tb-rule-node-defined-config> |
|||
<div class="tb-rulenode-directive-error" ng-if="definedDirectiveError">{{definedDirectiveError}}</div> |
|||
<tb-json-object-edit ng-if="!useDefinedDirective()" |
|||
class="tb-rule-node-configuration-json" |
|||
ng-model="configuration" |
|||
label="{{ 'rulenode.configuration' | translate }}" |
|||
ng-required="required" |
|||
fill-height="true"> |
|||
</tb-json-object-edit> |
|||
@ -0,0 +1,63 @@ |
|||
/* |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
const SNAKE_CASE_REGEXP = /[A-Z]/g; |
|||
|
|||
/*@ngInject*/ |
|||
export default function RuleNodeDefinedConfigDirective($compile) { |
|||
|
|||
var linker = function (scope, element, attrs, ngModelCtrl) { |
|||
|
|||
attrs.$observe('ruleNodeDirective', function() { |
|||
loadTemplate(); |
|||
}); |
|||
|
|||
scope.$watch('configuration', function (newVal, prevVal) { |
|||
if (!angular.equals(newVal, prevVal)) { |
|||
ngModelCtrl.$setViewValue(scope.configuration); |
|||
} |
|||
}); |
|||
|
|||
ngModelCtrl.$render = function () { |
|||
scope.configuration = ngModelCtrl.$viewValue; |
|||
}; |
|||
|
|||
function loadTemplate() { |
|||
var directive = snake_case(attrs.ruleNodeDirective, '-'); |
|||
var template = `<${directive} ng-model="configuration" ng-required="required" ng-readonly="readonly"></${directive}>`; |
|||
element.html(template); |
|||
$compile(element.contents())(scope); |
|||
} |
|||
|
|||
function snake_case(name, separator) { |
|||
separator = separator || '_'; |
|||
return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) { |
|||
return (pos ? separator : '') + letter.toLowerCase(); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
return { |
|||
restrict: "E", |
|||
require: "^ngModel", |
|||
scope: { |
|||
required:'=ngRequired', |
|||
readonly:'=ngReadonly' |
|||
}, |
|||
link: linker |
|||
}; |
|||
|
|||
} |
|||
Loading…
Reference in new issue