@@ -17,6 +17,41 @@ module.exports = function (RED) {
1717 // Retrieve the config node
1818 this . positionConfig = RED . nodes . getNode ( config . positionConfig ) ;
1919 // this.debug('initialize time Node ' + util.inspect(config, { colors: true, compact: 10, breakLength: Infinity }));
20+ this . input = {
21+ type : config . inputType ,
22+ value : config . input ,
23+ format : config . inputFormat ,
24+ offsetType : config . inputOffsetType ,
25+ offset : config . inputOffset ,
26+ multiplier : config . inputOffsetMultiplier
27+ } ;
28+
29+ this . result1 = {
30+ type : config . result1Type ,
31+ value : config . result1 ,
32+ format : config . result1Format
33+ } ;
34+
35+ this . result1Value = {
36+ type : config . result1ValueType ,
37+ value : config . result1Value ,
38+ format : config . result1Format ,
39+ offsetType : config . result1OffsetType ,
40+ offset : config . result1Offset ,
41+ multiplier : config . result1Multiplier ,
42+ next : true
43+ } ;
44+ if ( this . positionConfig && this . result1Value . type === 'jsonata' ) {
45+ try {
46+ this . result1Value . expr = this . positionConfig . getJSONataExpression ( this , this . result1Value . value ) ;
47+ } catch ( err ) {
48+ this . error ( RED . _ ( 'node-red-contrib-sun-position/position-config:errors.invalid-expr' , { error :err . message } ) ) ;
49+ this . result1Value . expr = null ;
50+ }
51+ }
52+
53+ this . rules = config . rules ;
54+ this . checkall = config . checkall ;
2055 const node = this ;
2156
2257 this . on ( 'input' , ( msg , send , done ) => {
@@ -26,8 +61,8 @@ module.exports = function (RED) {
2661
2762 if ( node . positionConfig === null ||
2863 typeof node . positionConfig === 'undefined' ||
29- config . inputType === null ||
30- typeof config . inputType === 'undefined' ) {
64+ node . input . type === null ||
65+ typeof node . input . type === 'undefined' ) {
3166 node . status ( {
3267 fill : 'red' ,
3368 shape : 'ring' ,
@@ -37,49 +72,33 @@ module.exports = function (RED) {
3772 }
3873
3974 try {
40- // const inputData = node.positionConfig.getDateFromProp(node, msg, config.inputType, config.input, config.inputFormat, config.inputOffset, config.inputOffsetType, config.inputOffsetMultiplier);
41- const inputData = node . positionConfig . getTimeProp ( node , msg , {
42- type : config . inputType ,
43- value : config . input ,
44- format : config . inputFormat ,
45- offsetType : config . inputOffsetType ,
46- offset : config . inputOffset ,
47- multiplier : config . inputOffsetMultiplier
48- } ) ;
75+ // const inputData = node.positionConfig.getDateFromProp(node, msg, node.input.type, node.input.value);
76+ const inputData = node . positionConfig . getTimeProp ( node , msg , node . input ) ;
4977 if ( inputData . error ) {
5078 throw new Error ( inputData . error ) ;
5179 }
5280
53- if ( config . result1Type !== 'none' ) {
81+ if ( node . result1 . type !== 'none' ) {
5482 let resultObj = null ;
55- if ( config . result1ValueType === 'input' ) {
56- resultObj = hlp . getFormattedDateOut ( inputData . value , config . result1Format ) ;
83+ if ( node . result1Value . type === 'input' ) {
84+ resultObj = hlp . getFormattedDateOut ( inputData . value , node . result1 . format ) ;
5785 } else {
58- resultObj = node . positionConfig . getOutDataProp ( node , msg , {
59- type : config . result1ValueType ,
60- value : config . result1Value ,
61- format : config . result1Format ,
62- offsetType : config . result1OffsetType ,
63- offset : config . result1Offset ,
64- multiplier : config . result1Multiplier ,
65- next : true
66- } ) ;
86+ resultObj = node . positionConfig . getOutDataProp ( node , msg , node . result1Value ) ;
6787 }
6888
6989 if ( resultObj === null || typeof resultObj === 'undefined' ) {
70- throw new Error ( 'could not evaluate ' + config . result1ValueType + '.' + config . result1Value ) ;
90+ throw new Error ( 'could not evaluate ' + node . result1Value . type + '.' + node . result1Value . value ) ;
7191 } else if ( resultObj . error ) {
7292 node . error ( 'error on getting result: ' + resultObj . error ) ;
7393 } else {
74- node . positionConfig . setMessageProp ( this , msg , config . result1Type , config . result1 , resultObj ) ;
94+ node . positionConfig . setMessageProp ( this , msg , node . result1 . type , node . result1 . value , resultObj ) ;
7595 }
7696 }
7797
7898 const resObj = [ ] ;
79- const rules = config . rules ;
80- const rulesLength = rules . length ;
99+ const rulesLength = node . rules . length ;
81100 for ( let i = 0 ; i < rulesLength ; ++ i ) {
82- const rule = rules [ i ] ;
101+ const rule = node . rules [ i ] ;
83102 let operatorValid = true ;
84103 if ( rule . propertyType !== 'none' ) {
85104 const res = RED . util . evaluateNodeProperty ( rule . propertyValue , rule . propertyType , node , msg ) ;
@@ -223,7 +242,7 @@ module.exports = function (RED) {
223242 if ( result ) {
224243 resObj . push ( msg ) ;
225244 node . debug ( i + ' result=' + util . inspect ( result , { colors : true , compact : 10 , breakLength : Infinity } ) ) ;
226- if ( config . checkall != 'true' ) { // eslint-disable-line eqeqeq
245+ if ( node . checkall != 'true' ) { // eslint-disable-line eqeqeq
227246 node . debug ( i + ' end cause checkall' ) ;
228247 break ;
229248 }
0 commit comments