node-red-contrib-sun-position
Version:
NodeRED nodes to get sun and moon position
980 lines (958 loc) • 75.1 kB
HTML
<!DOCTYPE HTML>
<!--
This code is licensed under the Apache License Version 2.0.
Copyright (c) 2022 Robert Gester
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
-->
<script type="text/javascript">
(function() {
// category: 'time and astro',
RED.nodes.registerType('within-time-switch', {
category: 'common',
color: '#f37a33',
icon: 'time-switch-white.svg',
inputs: 1,
outputs: 2,
defaults: {
name: {
value: '',
required: false
},
nameInt: {
value: '',
required: false
},
positionConfig: {
value: '',
type: 'position-config',
required: true
},
startTime: {
value: '',
required: true,
validate: RED.validators.typedInput('startTimeType')
},
startTimeType: {
value: 'entered'
},
startOffset: {
value: 0,
validate(v) {
return (
(typeof v === 'undefined') ||
(typeof this.startOffsetType === 'undefined') ||
RED.validators.typedInput('startOffsetType')(v)
);
}
},
startOffsetType: {
value: 'none'
},
startOffsetMultiplier: {
value: 60000,
required: true,
validate: RED.validators.number()
},
endTime: {
value: '',
required: true,
validate: RED.validators.typedInput('endTimeType')
},
endTimeType: {
value: 'entered'
},
endOffset: {
value: 0,
validate(v) {
return (
(typeof v === 'undefined') ||
(typeof this.endOffsetType === 'undefined') ||
RED.validators.typedInput('endOffsetType')(v)
);
}
},
endOffsetType: {
value: 'none'
},
endOffsetMultiplier: {
value: 60000,
required: true,
validate: RED.validators.number()
},
timeRestrictions: {
value: 0,
validate(v) {
return (
(typeof v === 'undefined') ||
(typeof this.timeRestrictionsType === 'undefined') ||
RED.validators.typedInput('timeRestrictionsType')(v)
);
}
},
timeRestrictionsType: {
value: 'none'
},
timeDays: {
value: '*',
required: true
},
timeOnlyOddDays: {
value: false,
required: true
},
timeOnlyEvenDays: {
value: false,
required: true
},
timeOnlyOddWeeks: {
value: false,
required: true
},
timeOnlyEvenWeeks: {
value: false,
required: true
},
timeMonths: {
value: '*',
required: true
},
timedatestart: {
value: '',
required: false,
validate(v) {
return (
typeof v === 'undefined' ||
RED.validators.regex(/^$|^\d{4}-\d{1,2}-\d{1,2}$|^\d{2}-\d{1,2}-\d{1,2}$/)(v)
);
}
},
timedateend: {
value: '',
required: false,
validate(v) {
return (
typeof v === 'undefined' ||
RED.validators.regex(/^$|^\d{4}-\d{1,2}-\d{1,2}$|^\d{2}-\d{1,2}-\d{1,2}$/)(v)
);
}
},
propertyStart: {
value: '',
required: false,
validate: RED.validators.typedInput('propertyStartType')
},
propertyStartType: {
value: 'none'
},
propertyStartCompare: {
value: 'true'
},
propertyStartThreshold: {
value: '',
validate(v) {
return (
typeof v === 'undefined' ||
RED.validators.typedInput('propertyStartThresholdType')(v) ||
($('#node-input-startTimeAltType').length ?
$('#node-input-startTimeAlt').typedInput('type') === 'none' :
this.startTimeAlt === 'none') ||
typeof this.propertyStartType === 'undefined' ||
($('#node-input-propertyStartType').length ?
$('#node-input-propertyStart').typedInput('type') === 'none' :
this.propertyStartType === 'none')
);
}
},
propertyStartThresholdType: {
value: 'num'
},
startTimeAlt: {
value: '',
required: false,
validate(v) {
return RED.validators.typedInput('startTimeAltType')(v) || ($(
'#node-input-propertyStart').typedInput(
'type') === 'none');
}
},
startTimeAltType: {
value: 'entered'
},
startOffsetAlt: {
value: 0,
validate(v) {
return (
(typeof v === 'undefined') ||
(typeof this.startOffsetAltType === 'undefined') ||
RED.validators.typedInput('startOffsetAltType')(v) ||
($('#node-input-propertyStart').typedInput('type') === 'none') ||
($('#node-input-startTimeAlt').typedInput('type') === 'none')
);
}
},
startOffsetAltType: {
value: 'none'
},
startOffsetAltMultiplier: {
value: 60000,
required: true,
validate(v) {
return RED.validators.number()(v) ||
($('#node-input-propertyStart').typedInput('type') === 'none') ||
($('#node-input-startTimeAlt').typedInput('type') === 'none');
}
},
propertyEnd: {
value: '',
required: false,
validate: RED.validators.typedInput('propertyEndType')
},
propertyEndType: {
value: 'none'
},
propertyEndCompare: {
value: 'true'
},
propertyEndThreshold: {
value: '',
validate(v) {
return (
typeof v === 'undefined' ||
RED.validators.typedInput('propertyEndThresholdType')(v) ||
($('#node-input-startTimeAltType').length ?
$('#node-input-startTimeAlt').typedInput('type') === 'none' :
this.startTimeAlt === 'none') ||
typeof this.propertyEndType === 'undefined' ||
($('#node-input-propertyEndType').length ?
$('#node-input-propertyEnd').typedInput('type') === 'none' :
this.propertyEndType === 'none')
);
}
},
propertyEndThresholdType: {
value: 'num'
},
endTimeAlt: {
value: '',
required: false,
validate(v) {
return RED.validators.typedInput('endTimeAltType')(v) || ($('#node-input-propertyEnd').typedInput(
'type') === 'none');
}
},
endTimeAltType: {
value: 'entered'
},
endOffsetAlt: {
value: 0,
validate(v) {
return (
(typeof v === 'undefined') ||
(typeof this.startOffsetAltType === 'undefined') ||
RED.validators.typedInput('startOffsetAltType')(v) ||
($('#node-input-propertyEnd').typedInput('type') === 'none') ||
($('#node-input-endTimeAlt').typedInput('type') === 'none')
);
}
},
endOffsetAltType: {
value: 'none'
},
endOffsetAltMultiplier: {
value: 60000,
required: true,
validate(v) {
return RED.validators.number()(v) ||
($('#node-input-propertyEnd').typedInput('type') === 'none') ||
($('#node-input-endTimeAlt').typedInput('type') === 'none');
}
},
withinTimeValue: {
value: 'true',
required: false,
validate: RED.validators.typedInput('withinTimeValueType')
},
withinTimeValueType: {
value: 'msgInput',
required: true
},
outOfTimeValue: {
value: 'false',
required: false,
validate: RED.validators.typedInput('outOfTimeValueType')
},
outOfTimeValueType: {
value: 'msgInput',
required: true
},
tsCompare: {
value: '0'
}
},
outputLabels: ['within time', 'out of time'],
label() {
const getConcatId = (type1, value1, offset1Type, offset1, multipier1, property, type2, value2, offset2Type, offset2, multipier2) => {
if (property !== 'none' && property !== '' && value2) {
return RED.nodes.getType('position-config').getRDGNodeValLbl(this, type1, value1, offset1Type, offset1, multipier1, 12) + '/' +
RED.nodes.getType('position-config').getRDGNodeValLbl(this, type2, value2, offset2Type, offset2, multipier2, 12);
}
return RED.nodes.getType('position-config').getRDGNodeValLbl(this, type1, value1, offset1Type, offset1, multipier1, 12);
};
if (this.name) {
return this.name;
}
if (this.startTime && this.endTime) {
return getConcatId(this.startTimeType, this.startTime, this.startOffsetType, this.startOffset, this.startOffsetMultiplier,
this.propertyStartType,
this.startTimeAltType, this.startTimeAlt, this.startOffsetAltType, this.startOffsetAlt, this.startOffsetAltMultiplier) +
' - ' +
getConcatId(this.endTimeType, this.endTime, this.endOffsetType, this.endOffset, this.endOffsetMultiplier,
this.propertyEndType,
this.endTimeAltType, this.endTimeAlt, this.endOffsetAltType, this.endOffsetAlt, this.endOffsetAltMultiplier);
}
return 'within-time';
},
labelStyle() {
return this.name ? 'node_label_italic' : '';
},
inputLabels() {
return this._('node-red-contrib-sun-position/position-config:common.label.inputPort');
},
paletteLabel: 'within-time',
align: 'left',
oneditprepare() {
setTimeout(() => {
$('.is-to-show-initially').show();
$('.is-to-hide-initially').hide();
}, 300);
$('.enhanced-row-toggle').on('click', () => {
$('.enhanced-row').toggle(); // .hide();
});
const node = this;
const $nodeConfig = $('#node-input-positionConfig');
const setup = function(node) {
/* global getTypes getSelectFields appendOptions setupTInput initializeValue initCheckboxesBlock getCheckboxesStr getBackendData bdDateToTime */
const types = getTypes(node, () => $nodeConfig.val());
const selFields = getSelectFields();
let onInit = true;
// #region initialize
/**
* update multiplier settings from a previous version
* @param {number} mp - the multiplier value
* @param {string} name - the name of the element
* @param {function} onchange - the function to be called on field change
* @returns {number} the updated multiplier value
*/
function multiplierUpdate(mp, name, onchange) {
const $field = $('#node-input-' + name);
appendOptions(node, $field, 'multiplier', data => (data.id > 0));
if (mp === null || typeof mp === 'undefined' || isNaN(mp) || mp === '' || mp === 0) {
mp = 60000;
} else {
mp = parseFloat(mp);
if (mp === 1) {
mp = 1000;
} else if (mp === 60) {
mp = 60000;
} else if (mp === 3600) {
mp = 3600000;
}
}
$field.val(mp);
$field.on('change', onchange);
return mp;
}
// #endregion initialize
// #region timeStart
if ($('#node-input-timeOnlyOddDays').prop('checked') && $('#node-input-timeOnlyEvenDays').prop('checked') ) {
$('#node-input-timeOnlyOddDays').prop('checked',false);
$('#node-input-timeOnlyEvenDays').prop('checked',false);
}
if ($('#node-input-timeOnlyOddWeeks').prop('checked') && $('#node-input-timeOnlyEvenWeeks').prop('checked') ) {
$('#node-input-timeOnlyOddWeeks').prop('checked',false);
$('#node-input-timeOnlyEvenWeeks').prop('checked',false);
}
initializeValue(node, 'timeDays', '*');
initializeValue(node, 'timeMonths', '*');
initCheckboxesBlock('#within-time-switch-timeDays', node.timeDays);
initCheckboxesBlock('#within-time-switch-timeMonths', node.timeMonths);
setupTInput(node, {
typeProp: 'startTimeType',
valueProp: 'startTime',
width: 'calc(100% - 110px)',
defaultType: types.TimeEntered.value,
defaultValue: '',
types: [
types.TimeEntered,
types.TimeSun,
types.TimeSunCustom,
types.TimeSunNow,
types.TimeMoon,
'msg',
'flow',
'global',
'env',
types.SunTimeByAzimuth,
types.SunTimeByElevationNext,
types.SunTimeByElevationRise,
types.SunTimeByElevationSet
],
onFocus(_type, _value) {
const plVType = $('#node-input-startTime').typedInput('type');
const plVTypeAlt = $('#node-input-startTimeAlt').typedInput('type');
if (plVType === 'msg' ||
plVType === 'flow' ||
plVType === 'global' ||
plVTypeAlt === 'msg' ||
plVTypeAlt === 'flow' ||
plVTypeAlt === 'global') {
$('.msg-start-out-row').hide();
} else {
$('.msg-start-out-row').show();
}
},
onChange(_type, _value) {
if ( onInit) { return; }
getBackendData(d => {
const $div = $('#node-input-startTime-div');
const titleOrg = $div.attr('titleOrg');
$div.attr('title', bdDateToTime(d, ' - ') + titleOrg);
}, {
nodeId: node.id,
kind: 'getTimeData',
config: $nodeConfig.val(),
type: $('#node-input-startTime').typedInput('type'),
value: $('#node-input-startTime').typedInput('value'),
offsetType: $('#node-input-startOffset').typedInput('type'),
offset: $('#node-input-startOffset').typedInput('value'),
multiplier: $('#node-input-startOffsetMultiplier').val(),
noOffsetError: true
});
}
});
node.startOffsetMultiplier = multiplierUpdate(node.startOffsetMultiplier, 'startOffsetMultiplier', () => $('#node-input-startTime').change());
setupTInput(node, {
typeProp: 'startOffsetType',
valueProp: 'startOffset',
width: 'calc(100% - 255px)',
defaultType: (node.startOffset === 0 || node.startOffset === '') ? types.Undefined.value : 'num',
defaultValue: 0,
types: [types.Undefined, 'num', 'msg', 'flow', 'global', 'env', types.randomNumber, types.randmNumCachedDay, types.randmNumCachedWeek],
onChange(_type, _value) {
if ( onInit) { return; }
const type = $('#node-input-startOffset').typedInput('type');
if (type === types.Undefined.value) {
$('#node-input-startOffsetMultiplier').prop('disabled', true);
} else {
$('#node-input-startOffsetMultiplier').prop('disabled', false);
}
$('#node-input-startTime').change();
}
});
const $timeRestrictions = setupTInput(node, {
typeProp: 'timeRestrictionsType',
valueProp: 'timeRestrictions',
width: 'calc(100% - 255px)',
defaultType: types.Undefined.value,
defaultValue: '',
types: [
{
value: types.Undefined.value,
label: node._('within-time-switch.label.internally'),
hasValue: false
}, 'msg', 'flow', 'global', 'env', 'json', 'jsonata'],
onChange(_type, _value) {
const type = $timeRestrictions.typedInput('type');
if (type === types.Undefined.value) {
$('.node-input-row-timeLimits').show();
} else {
$('.node-input-row-timeLimits').hide();
}
}
});
const getDateShort = value => {
if (value) {
const val = value.split('-');
if (val.length > 2) {
return val[1] + '-' + val[2];
} else if (val.length === 2) {
return val[0] + '-' + val[1];
}
}
return '';
};
const $timeLimitDateStart = $('#node-input-timedatestart');
const $timeLimitDateEnd = $('#node-input-timedateend');
$timeLimitDateStart.change(() => {
const year = (new Date()).getFullYear();
$timeLimitDateEnd.attr('min', year + '-' + (getDateShort($timeLimitDateStart.val() || '01-01')));
$timeLimitDateEnd.attr('max', (year + 1) + '-' + (getDateShort($timeLimitDateStart.val()) || '12-31'));
});
$timeLimitDateEnd.change(() => {
const year = (new Date()).getFullYear();
$timeLimitDateStart.attr('min', year + '-01-01');
$timeLimitDateStart.attr('max', $timeLimitDateEnd.val() || (year + '-12-31'));
});
const year = (new Date()).getFullYear();
if (node.timedatestart) {
$timeLimitDateStart.val(year + '-' +(getDateShort(node.timedatestart) || '01-01'));
}
if (node.timedatestart && node.timedateend) {
const year = (new Date()).getFullYear();
const d1 = new Date(node.timedatestart);
const d2 = new Date(node.timedateend);
d1.setFullYear(year);
d2.setFullYear(year);
if (d2.getTime() < d1.getTime()) {
d2.setFullYear(year + 1);
}
const pad = (n, z = 2) => ('00' + n).slice(-z);
$timeLimitDateEnd.val(year + '-' + pad(d2.getMonth() + 1) + '-' + pad(d2.getDate()));
} else if (node.timedateend) {
$timeLimitDateEnd.val(year + '-' + (getDateShort(node.timedateend) || '12-31'));
}
$timeLimitDateStart.change();
$timeLimitDateEnd.change();
$timeRestrictions.change();
// #endregion timeStart
// #region timeEnd
setupTInput(node, {
typeProp: 'endTimeType',
valueProp: 'endTime',
width: 'calc(100% - 110px)',
defaultType: types.TimeEntered.value,
defaultValue: '',
types: [
types.TimeEntered,
types.TimeSun,
types.TimeSunCustom,
types.TimeSunNow,
types.TimeMoon,
'msg',
'flow',
'global',
'env',
types.SunTimeByAzimuth,
types.SunTimeByElevationNext,
types.SunTimeByElevationRise,
types.SunTimeByElevationSet
],
onFocus(_type, _value) {
const plVType = $('#node-input-endTime').typedInput('type');
const plVTypeAlt = $('#node-input-endTimeAlt').typedInput('type');
if (plVType === 'msg' ||
plVType === 'flow' ||
plVType === 'global' ||
plVTypeAlt === 'msg' ||
plVTypeAlt === 'flow' ||
plVTypeAlt === 'global') {
$('.msg-end-out-row').hide();
} else {
$('.msg-end-out-row').show();
}
},
onChange(_type, _value) {
if ( onInit) { return; }
getBackendData(d => {
const $div = $('#node-input-endTime-div');
const titleOrg = $div.attr('titleOrg');
$div.attr('title', bdDateToTime(d, ' - ') + titleOrg);
}, {
nodeId: node.id,
kind: 'getTimeData',
config: $nodeConfig.val(),
type: $('#node-input-endTime').typedInput('type'),
value: $('#node-input-endTime').typedInput('value'),
offsetType: $('#node-input-endOffset').typedInput('type'),
offset: $('#node-input-endOffset').typedInput('value'),
multiplier: $('#node-input-endOffsetMultiplier').val(),
noOffsetError: true
});
}
});
node.endOffsetMultiplier = multiplierUpdate(node.endOffsetMultiplier, 'endOffsetMultiplier', () => $('#node-input-endTime').change());
setupTInput(node, {
typeProp: 'endOffsetType',
valueProp: 'endOffset',
width: 'calc(100% - 255px)',
defaultType: (node.endOffset === 0 || node.endOffset === '') ? types.Undefined.value : 'num',
defaultValue: 0,
types: [types.Undefined, 'num', 'msg', 'flow', 'global', 'env', types.randomNumber, types.randmNumCachedDay, types.randmNumCachedWeek],
onChange(_type, _value) {
if ( onInit) { return; }
const type = $('#node-input-endOffset').typedInput('type');
if (type === types.Undefined.value) {
$('#node-input-endOffsetMultiplier').prop('disabled', true);
} else {
$('#node-input-endOffsetMultiplier').prop('disabled', false);
}
$('#node-input-endTime').change();
}
});
// #endregion timeEnd
// #region propertyStart
const $propertyStart = setupTInput(node, {
typeProp: 'propertyStartType',
valueProp: 'propertyStart',
width: 'calc(100% - 110px)',
defaultType: types.Undefined.value,
defaultValue: '' ,
types: [types.Undefined,
'msg',
'flow',
'global',
'env',
'jsonata',
types.MsgPayloadByTopic,
types.PhaseMoon,
types.SunInSky,
types.SunAzimuth,
types.SunElevation,
types.isDST,
types.WeekOfYear,
types.WeekOfYearEven,
types.DayOfYear,
types.DayOfYearEven
],
onChange(_type, _value) {
if (onInit) { return; }
const propCompare = $('#node-input-propertyStartCompare');
const propType = $('#node-input-propertyStart').typedInput('type');
if (propType === 'none') {
$('.alternate-time-start').hide();
$('.alternate-time-start-offset').hide();
propCompare.hide();
$('.row-propertyStartThreshold').hide();
$('#node-input-propertyStart').typedInput('width', 'calc(100% - 110px)');
} else if (propType === 'jsonata' ||
propType === types.PhaseMoon.value ||
propType === types.MsgPayloadByTopic.value) {
$('.alternate-time-start').show();
propCompare.show();
propCompare.attr('disabled', true);
propCompare.val(selFields.comparator[0].id); // only true is valid for jsonata
$('.row-propertyStartThreshold').hide();
$('#node-input-propertyStart').typedInput('width', 'calc(100% - 220px)');
} else {
$('.alternate-time-start').show();
propCompare.show();
propCompare.attr('disabled', false);
$('#node-input-propertyStart').typedInput('width', 'calc(100% - 220px)');
const condOp = propCompare.val();
let operandCount = 1;
const fields = selFields.comparator;
const fieldsLength = fields.length;
for (let index = 0; index < fieldsLength; index++) {
const el = fields[index];
if (el.id === condOp) {
operandCount = el.operandCount;
break;
}
}
if (operandCount > 1) {
$('.row-propertyStartThreshold').show(); // condOpB
} else {
$('.row-propertyStartThreshold').hide(); // condOpB
}
}
$('#node-input-startTimeAlt').change();
$('#node-input-propertyStartThreshold').change();
}
});
const $propertyStartCompare = $('#node-input-propertyStartCompare');
appendOptions(node, $propertyStartCompare, 'comparator');
$propertyStartCompare.val(node.propertyStartCompare || 'true');
$propertyStartCompare.change(() => { $('#node-input-propertyStart').change(); });
setupTInput(node, {
typeProp: 'propertyStartThresholdType',
valueProp: 'propertyStartThreshold',
width: 'calc(100% - 130px)',
defaultType: 'num',
defaultValue: '',
types: ['msg', 'flow', 'global', 'str', 'num', 'env']
});
// #endregion propertyStart
// #region timeAltStart
setupTInput(node, {
typeProp: 'startTimeAltType',
valueProp: 'startTimeAlt',
width: 'calc(100% - 110px)',
defaultType: types.TimeEntered.value,
defaultValue: '',
types: [
types.TimeEntered,
types.TimeSun,
types.TimeSunCustom,
types.TimeSunNow,
types.TimeMoon,
'msg',
'flow',
'global',
'env',
types.SunTimeByAzimuth,
types.SunTimeByElevationNext,
types.SunTimeByElevationRise,
types.SunTimeByElevationSet
],
onFocus(_type, _value) {
if (($('#node-input-startTimeAlt').typedInput('type') === 'none') ||
($('#node-input-propertyStart').typedInput('type') === 'none')) {
$('.alternate-time-start-offset').hide();
} else {
$('.alternate-time-start-offset').show();
}
},
onChange(_type, _value) {
if ( onInit) { return; }
getBackendData(d => {
const $div = $('#node-input-startTimeAlt-div');
const titleOrg = $div.attr('titleOrg');
$div.attr('title', bdDateToTime(d, ' - ') + titleOrg);
}, {
nodeId: node.id,
kind: 'getTimeData',
config: $nodeConfig.val(),
type: $('#node-input-startTimeAlt').typedInput('type'),
value: $('#node-input-startTimeAlt').typedInput('value'),
offsetType: $('#node-input-startOffsetAlt').typedInput('type'),
offset: $('#node-input-startOffsetAlt').typedInput('value'),
multiplier: $('#node-input-startOffsetAltMultiplier').val(),
noOffsetError: true
});
}
});
node.startOffsetAltMultiplier = multiplierUpdate(node.startOffsetAltMultiplier, 'startOffsetAltMultiplier', () => $('#node-input-startTimeAlt').change());
setupTInput(node, {
typeProp: 'startOffsetAltType',
valueProp: 'startOffsetAlt',
width: 'calc(100% - 255px)',
defaultType: (node.startOffsetAlt === 0 || node.startOffsetAlt === '') ? types.Undefined.value : 'num',
defaultValue: 0,
types: [types.Undefined, 'num', 'flow', 'global', 'env', types.randomNumber, types.randmNumCachedDay, types.randmNumCachedWeek],
onChange(_type, _value) {
if ( onInit) { return; }
const type = $('#node-input-startOffsetAlt').typedInput('type');
if (type === types.Undefined.value) {
$('#node-input-startOffsetAltMultiplier').prop('disabled', true);
} else {
$('#node-input-startOffsetAltMultiplier').prop('disabled', false);
}
$('#node-input-startTimeAlt').change();
}
});
// #endregion timeAltStart
// #region propertyEnd
const $propertyEnd = setupTInput(node, {
typeProp: 'propertyEndType',
valueProp: 'propertyEnd',
width: 'calc(100% - 110px)',
defaultType: types.Undefined.value,
defaultValue: '' ,
types: [types.Undefined,
'msg',
'flow',
'global',
'env',
'jsonata',
types.MsgPayloadByTopic,
types.PhaseMoon,
types.SunInSky,
types.SunAzimuth,
types.SunElevation,
types.isDST,
types.WeekOfYear,
types.WeekOfYearEven,
types.DayOfYear,
types.DayOfYearEven
],
onChange(_type, _value) {
if ( onInit) { return; }
const propCompare = $('#node-input-propertyEndCompare');
const propType = $('#node-input-propertyEnd').typedInput('type');
if (propType === 'none') {
$('.alternate-time-end').hide();
$('.alternate-time-end-offset').hide();
propCompare.hide();
$('.row-propertyEndThreshold').hide();
$('#node-input-propertyEnd').typedInput('width', 'calc(100% - 110px)');
} else if (propType === 'jsonata' ||
propType === types.PhaseMoon.value ||
propType === types.MsgPayloadByTopic.value) {
$('.alternate-time-end').show();
propCompare.show();
propCompare.attr('disabled', true);
propCompare.val(selFields.comparator[0].id); // only true is valid for jsonata
$('.row-propertyEndThreshold').hide();
$('#node-input-propertyEnd').typedInput('width', 'calc(100% - 220px)');
} else {
$('.alternate-time-end').show();
propCompare.show();
propCompare.attr('disabled', false);
$('#node-input-propertyEnd').typedInput('width', 'calc(100% - 220px)');
const condOp = propCompare.val();
let operandCount = 1;
const fields = selFields.comparator;
const fieldsLength = fields.length;
for (let index = 0; index < fieldsLength; index++) {
const el = fields[index];
if (el.id === condOp) {
operandCount = el.operandCount;
break;
}
}
if (operandCount > 1) {
$('.row-propertyEndThreshold').show(); // condOpB
} else {
$('.row-propertyEndThreshold').hide(); // condOpB
}
}
$('#node-input-endTimeAlt').change();
$('#node-input-propertyEndThreshold').change();
}
});
const $propertyEndCompare = $('#node-input-propertyEndCompare');
appendOptions(node, $propertyEndCompare, 'comparator');
$propertyEndCompare.val(node.propertyEndCompare || 'true');
$propertyEndCompare.change(() => { $('#node-input-propertyEnd').change(); });
setupTInput(node, {
typeProp: 'propertyEndThresholdType',
valueProp: 'propertyEndThreshold',
width: 'calc(100% - 130px)',
defaultType: 'num',
defaultValue: '',
types: ['msg', 'flow', 'global', 'str', 'num', 'env']
});
// #endregion propertyEnd
// #region timeAltEnd
setupTInput(node, {
typeProp: 'endTimeAltType',
valueProp: 'endTimeAlt',
width: 'calc(100% - 110px)',
defaultType: types.TimeEntered.value,
defaultValue: '',
types: [
types.TimeEntered,
types.TimeSun,
types.TimeSunCustom,
types.TimeSunNow,
types.TimeMoon,
'msg',
'flow',
'global',
'env',
types.SunTimeByAzimuth,
types.SunTimeByElevationNext,
types.SunTimeByElevationRise,
types.SunTimeByElevationSet
],
onFocus(_type, _value) {
if (($('#node-input-endTimeAlt').typedInput('type') === 'none') ||
($('#node-input-propertyEnd').typedInput('type') === 'none')) {
$('.alternate-time-end-offset').hide();
} else {
$('.alternate-time-end-offset').show();
}
},
onChange(_type, _value) {
if ( onInit) { return; }
getBackendData(d => {
const $div = $('#node-input-endTimeAlt-div');
const titleOrg = $div.attr('titleOrg');
$div.attr('title', bdDateToTime(d, ' - ') + titleOrg);
}, {
nodeId: node.id,
kind: 'getTimeData',
config: $nodeConfig.val(),
type: $('#node-input-endTimeAlt').typedInput('type'),
value: $('#node-input-endTimeAlt').typedInput('value'),
offsetType: $('#node-input-endOffsetAlt').typedInput('type'),
offset: $('#node-input-endOffsetAlt').typedInput('value'),
multiplier: $('#node-input-endOffsetAltMultiplier').val(),
noOffsetError: true
});
}
});
node.endOffsetAltMultiplier = multiplierUpdate(node.endOffsetAltMultiplier, 'endOffsetAltMultiplier', () => $('#node-input-endTimeAlt').change());
setupTInput(node, {
typeProp: 'endOffsetAltType',
valueProp: 'endOffsetAlt',
width: 'calc(100% - 255px)',
defaultType: (node.endOffsetAlt === 0 || node.endOffsetAlt === '') ? types.Undefined.value : 'num',
defaultValue: 0,
types: [types.Undefined, 'num', 'flow', 'global', 'env', types.randomNumber, types.randmNumCachedDay, types.randmNumCachedWeek],
onChange(_type, _value) {
if ( onInit) { return; }
const type = $('#node-input-endOffsetAlt').typedInput('type');
if (type === types.Undefined.value) {
$('#node-input-endOffsetAltMultiplier').prop('disabled', true);
} else {
$('#node-input-endOffsetAltMultiplier').prop('disabled', false);
}
$('#node-input-endTimeAlt').change();
}
});
// #endregion timeAltEnd
// #region Output Values
if (node.withinTimeValueType === 'input') {
node.withinTimeValueType = types.MsgInput.value;
}
setupTInput(node, {
typeProp: 'withinTimeValueType',
valueProp: 'withinTimeValue',
width: 'calc(100% - 110px)',
defaultType: types.MsgInput.value,
defaultValue: node.withinTimeValue,
types: [
types.MsgInput,
'str',
'num',
'bool',
'date',
'json',
'bin',
'env',
'msg',
'flow',
'global',
'jsonata',
types.numPercent,
types.randomNumber,
types.randmNumCachedDay,
types.randmNumCachedWeek,
types.strPlaceholder,
types.SunCalc,
types.SunInSky,
types.MoonCalc,
types.MoonPhase,
types.SunAzimuth,
types.SunElevation,
types.SunTimeByAzimuth,
types.SunTimeByElevationObj,
types.SunTimeByElevationNext,
types.SunTimeByElevationRise,
types.SunTimeByElevationSet,
types.isDST,
types.WeekOfYear,
types.WeekOfYearEven,
types.DayOfYear,
types.DayOfYearEven,
types.nodeId,
types.nodeName,
types.nodePath
]
});
if (node.outOfTimeValueType === 'input') {
node.outOfTimeValueType = types.MsgInput.value;
}
setupTInput(node, {
typeProp: 'outOfTimeValueType',