node-red-contrib-chronos
Version:
Time-based Node-RED scheduling, repeating, queueing, routing, filtering and manipulating nodes
926 lines (855 loc) • 80.7 kB
HTML
<!--
Copyright (c) 2020 - 2026 Jens-Uwe Rossbach
This code is licensed under the MIT License.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<script type="text/html" data-template-name="chronos-change">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red-contrib-chronos/chronos-config:common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red-contrib-chronos/chronos-config:common.label.name">
</div>
<div class="form-row">
<label for="node-input-config"><i class="fa fa-cog"></i> <span data-i18n="node-red-contrib-chronos/chronos-config:common.label.config"></span></label>
<input type="text" id="node-input-config" data-i18n="[placeholder]node-red-contrib-chronos/chronos-config:common.label.config">
</div>
<div class="form-row">
<label for="node-input-mode"><i class="fa fa-clock-o"></i> <span data-i18n="change.label.mode"></span></label>
<select id="node-input-mode" style="width: 70%;">
<option value="moment" data-i18n="change.list.mode.moment"></option>
<option value="duration" data-i18n="change.list.mode.duration"></option>
</select>
</div>
<div class="form-row" style="padding-top: 10px; margin-bottom: 0px;">
<label style="width: auto;"><i class="fa fa-random"></i> <span data-i18n="change.label.rules"></span></label>
</div>
<div id="node-input-momentRules-row" class="form-row node-input-list-row" style="margin-bottom: 0px;">
<div class="form-row">
<ol id="node-input-momentRules"></ol>
</div>
</div>
<div id="node-input-durationRules-row" class="form-row node-input-list-row" style="margin-bottom: 0px;">
<div class="form-row">
<ol id="node-input-durationRules"></ol>
</div>
</div>
</script>
<script type="text/javascript">
(function()
{
const PATTERN_TIME = /^(?:\d|0\d|1\d|2[0-3]):(?:[0-5]\d)(?::(?:[0-5]\d))?\s*(?:a|am|A|AM|p|pm|P|PM)?$/;
const PATTERN_DATETIME = /^(?:(?:(?:(?:[1-9]\d)?\d\d)-(?:[1-9]|0[1-9]|1[0-2])-(?:[1-9]|0[1-9]|[12]\d|3[01])|(?:(?:[1-9]|0[1-9]|[12]\d|3[01])\.(?:[1-9]|0[1-9]|1[0-2])\.(?:(?:[1-9]\d)?\d\d))|(?:(?:[1-9]|0[1-9]|1[0-2])\/(?:[1-9]|0[1-9]|[12]\d|3[01])\/(?:(?:[1-9]\d)?\d\d)))\s)?(?:\d|0\d|1\d|2[0-3]):(?:[0-5]\d)(?::(?:[0-5]\d))?(?:\s(?:a|am|A|AM|p|pm|P|PM))?$/;
const PATTERN_CUSTOM_TIME = /^[a-zA-Z][0-9a-zA-Z_]*$/;
const PATTERN_DATE = /^(?:[2-9]\d\d\d)-(?:[1-9]|0[1-9]|1[0-2])-(?:[1-9]|0[1-9]|[12]\d|3[01])$/;
const PATTERN_UTC_OFFSET = /^(?:Z|[+-]\d\d:\d\d|-?\d+)$/;
const PATTERN_FP_PRECISION = /^(?:0|[1-9][0-9]*)$/;
RED.nodes.registerType("chronos-change",
{
category: "chronos",
color: "#DEB887",
icon: "chronos_change.svg",
inputs: 1,
outputs: 1,
paletteLabel: "time change",
label: function()
{
return (this.name || this._("change.label.node"));
},
labelStyle: function()
{
return (this.name ? "node_label_italic" : "");
},
inputLabels: function()
{
return this._("node-red-contrib-chronos/chronos-config:common.label.inputPort");
},
outputLabels: function(index)
{
return this._("change.label.outputPort");
},
defaults:
{
name:
{
value: ""
},
config:
{
value: "",
type: "chronos-config",
required: true
},
mode:
{
value: "time"
},
rules:
{
value: [{action: "set", target: {type: "msg", name: "payload"}, type: "now"}],
validate: function(items, opt)
{
if (!items || (items.length == 0))
{
return this._("state.error.noStates");
}
const mode = $("#node-input-mode").val();
const errors = [];
for (const item of items)
{
let res = RED.utils.validatePropertyExpression(item.target.name, opt);
if (res !== true)
{
errors.push(res);
}
if ((mode == "moment") && (item.action == "set") && (item.type == "date"))
{
if (!PATTERN_DATE.test(item.date))
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidDate"));
}
if ((item.time.type == "time") && !PATTERN_TIME.test(item.time.value))
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidTime"));
}
else if ((item.time.type == "custom") && !PATTERN_CUSTOM_TIME.test(item.time.value))
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidName"));
}
}
if ((mode == "duration") && (item.action == "set"))
{
if ((item.time1.type == "time") && !PATTERN_DATETIME.test(item.time1.value))
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidTime"));
}
else if ((item.time1.type == "custom") && !PATTERN_CUSTOM_TIME.test(item.time1.value))
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidName"));
}
else if (/^global|flow|msg$/.test(item.time1.type))
{
const res = RED.utils.validateTypedProperty(item.time1.value, item.time1.type, opt)
if (res !== true)
{
errors.push(res);
}
}
if ((item.time2.type == "time") && !PATTERN_DATETIME.test(item.time2.value))
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidTime"));
}
else if ((item.time2.type == "custom") && !PATTERN_CUSTOM_TIME.test(item.time2.value))
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidName"));
}
else if (/^global|flow|msg$/.test(item.time2.type))
{
const res = RED.utils.validateTypedProperty(item.time2.value, item.time2.type, opt)
if (res !== true)
{
errors.push(res);
}
}
}
if ((mode == "moment") && (item.action == "set") && (item.type == "jsonata"))
{
res = RED.utils.validateTypedProperty(item.expression, item.type, opt)
if (res !== true)
{
errors.push(res);
}
}
if ((item.action == "change") && ((item.type == "add") || (item.type == "subtract")))
{
const res = RED.utils.validateTypedProperty(item.value, item.valueType, opt)
if (res !== true)
{
errors.push(res);
}
}
if ((item.action == "convert") && (item.formatType == "custom") && !item.format)
{
errors.push(this._("change.error.invalidFormat"));
}
if ((mode == "moment") && (item.action == "convert") && (item.tzType === "timeZone") && !item.tzValue)
{
errors.push(this._("node-red-contrib-chronos/chronos-config:common.error.invalidTimeZone"));
}
if ((mode == "moment") && (item.action == "convert") && (item.tzType === "utcOffset") && !PATTERN_UTC_OFFSET.test(item.tzValue))
{
errors.push(this._("change.error.invalidUTCOffset"));
}
if ((mode == "duration") && (item.action == "convert") && (item.precisionType === "float") && !PATTERN_FP_PRECISION.test(item.precision))
{
errors.push(this._("change.error.invalidPrecision"));
}
}
return (errors.length > 0) ? errors : true;
}
}
},
oneditprepare: function()
{
const node = this;
let tokenCounter = 0;
$("body").on("mouseenter.chronos_change", ".red-ui-typedInput-option-trigger", function()
{
const _this = this;
const input = $(_this).parent().parent().find("input");
if (input.length >= 3)
{
const type = input.eq(2).val();
if ((type == "sun") || (type == "moon"))
{
const token = tokenCounter++;
_this._chronos_lastToken = token;
$.getJSON(
"chronos_config", {
command: "gettime",
timeType: type,
timeName: input.eq(0).val(),
currentDay: true,
config: $("#node-input-config").val()})
.done(result =>
{
if (_this._chronos_lastToken === token)
{
const label = $(_this).find("span.red-ui-typedInput-option-label");
_this._chronos_lastOptionLabel = label.html();
label.html(result);
}
});
}
}
}).on("mouseleave.chronos_change", ".red-ui-typedInput-option-trigger", function()
{
delete this._chronos_lastToken;
if (this._chronos_lastOptionLabel)
{
const label = $(this).find("span.red-ui-typedInput-option-label");
label.html(this._chronos_lastOptionLabel);
delete this._chronos_lastOptionLabel;
}
});
const sunTimes =
[
{
value: "nightEnd",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.nightEnd")
},
{
value: "nauticalDawn",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.nauticalDawn")
},
{
value: "dawn",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.dawn")
},
{
value: "sunrise",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.sunrise")
},
{
value: "sunriseEnd",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.sunriseEnd")
},
{
value: "goldenHourEnd",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.goldenHourEnd")
},
{
value: "solarNoon",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.solarNoon")
},
{
value: "goldenHour",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.goldenHour")
},
{
value: "sunsetStart",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.sunsetStart")
},
{
value: "sunset",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.sunset")
},
{
value: "dusk",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.dusk")
},
{
value: "nauticalDusk",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.nauticalDusk")
},
{
value: "night",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.night")
},
{
value: "nadir",
label: node._("node-red-contrib-chronos/chronos-config:common.list.sun.nadir")
}
];
const moonTimes =
[
{
value: "rise",
label: node._("node-red-contrib-chronos/chronos-config:common.list.moon.rise")
},
{
value: "set",
label: node._("node-red-contrib-chronos/chronos-config:common.list.moon.set")
}
];
const nowInput =
{
value: "now",
label: node._("change.label.now"),
hasValue: false
};
const dateInput =
{
value: "date",
label: node._("change.label.date"),
icon: "fa fa-calendar",
hasValue: true,
validate: PATTERN_DATE
};
const sunTimeInput =
{
value: "sun",
label: node._("node-red-contrib-chronos/chronos-config:common.label.sun"),
icon: "fa fa-sun-o",
options: sunTimes
};
const moonTimeInput =
{
value: "moon",
label: node._("node-red-contrib-chronos/chronos-config:common.label.moon"),
icon: "fa fa-moon-o",
options: moonTimes
};
const customInput =
{
value: "custom",
label: node._("node-red-contrib-chronos/chronos-config:common.label.custom"),
icon: "fa fa-user-o",
hasValue: true,
validate: PATTERN_CUSTOM_TIME
};
const partInput =
{
value: "num",
label: node._("change.label.number"),
icon: "red/images/typedInput/09.svg",
hasValue: true,
min: -27000,
max: 27000,
validate: function(v)
{
return (+v === +v) && (v >= partInput.min) && (v <= partInput.max);
}
};
const addsubInput =
{
value: "num",
label: node._("change.label.number"),
icon: "red/images/typedInput/09.svg",
hasValue: true,
validate: function(v)
{
return (+v === +v) && (v >= 1) && (v <= 1000000);
}
};
const momentRules = $("#node-input-momentRules").css("min-width", "510px").css("min-height", "150px").editableList(
{
removable: true,
sortable: true,
addItem: function(item, index, data)
{
const timeInput =
{
value: "time",
label: node._("node-red-contrib-chronos/chronos-config:common.label.time"),
icon: "fa fa-clock-o",
hasValue: true,
validate: PATTERN_TIME
};
const fragment = document.createDocumentFragment();
const actionBox = $("<div/>").appendTo(fragment);
const setBox = $("<div/>", {style: "margin-top: 5px;"}).appendTo(fragment);
const changeBox = $("<div/>", {style: "margin-top: 5px;"}).appendTo(fragment);
const convertBox = $("<div/>", {style: "margin-top: 5px;"}).appendTo(fragment);
const action = $("<select/>", {class: "node-input-action", style: "width: 120px;"})
.append($("<option></option>").val("set").text(node._("change.list.action.set")))
.append($("<option></option>").val("change").text(node._("change.list.action.change")))
.append($("<option></option>").val("convert").text(node._("change.list.action.convert")))
.appendTo(actionBox);
$("<label/>", {style: "margin-bottom: 0px; width: 120px; text-align: right;"})
.text(node._("change.label.setTo"))
.appendTo(setBox);
const setToBox = $("<div/>", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 8px;"}).appendTo(setBox);
const setToRow1 = $("<div/>").appendTo(setToBox);
const setToRow2 = $("<div/>", {style: "margin-top: 5px;"}).appendTo(setToBox);
const property = $("<input/>", {type: "text", class: "node-input-property", style: "margin-left: 8px;"})
.appendTo(actionBox)
.typedInput({types: ["global", "flow", "msg"]});
property.typedInput("width", "314px");
const date = $("<input/>", {type: "text", class: "node-input-date"})
.appendTo(setToRow1)
.typedInput({types: [nowInput, dateInput, "jsonata"]});
date.typedInput("width", "314px");
date._prevType = "now";
date.on("change", function()
{
const type = date.typedInput("type");
if ((type === "now") || (type === "jsonata"))
{
setToRow2.hide();
}
else
{
setToRow2.show();
}
if (type != date._prevType)
{
date._prevType = type;
if (type != "now")
{
date.typedInput("value", "");
}
}
});
const time = $("<input/>", {type: "text", class: "node-input-time"})
.appendTo(setToRow2)
.typedInput({types: [timeInput, sunTimeInput, moonTimeInput, customInput]});
time.typedInput("width", "314px");
time._prevType = "time";
time.on("change", function()
{
const type = time.typedInput("type");
if (type != time._prevType)
{
time._prevType = type;
if ((type != "sun") && (type != "moon"))
{
time.typedInput("value", "");
}
}
});
const changeType = $("<select/>", {class: "node-input-changeType", style: "width: 120px;"})
.append($("<option></option>").val("set").text(node._("change.list.changeType.set")))
.append($("<option></option>").val("add").text(node._("change.list.changeType.add")))
.append($("<option></option>").val("subtract").text(node._("change.list.changeType.subtract")))
.append($("<option></option>").val("startOf").text(node._("change.list.changeType.startOf")))
.append($("<option></option>").val("endOf").text(node._("change.list.changeType.endOf")))
.appendTo(changeBox);
const setPartBox = $("<div/>", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 8px;"}).appendTo(changeBox);
const addsubBox = $("<div/>", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 8px;"}).appendTo(changeBox);
const startEndOfBox = $("<div/>", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 8px;"}).appendTo(changeBox);
const setPartType = $("<select/>", {class: "node-input-setPartType", style: "width: 118px;"})
.append($("<option></option>").val("year").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.year")))
.append($("<option></option>").val("quarter").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.quarter")))
.append($("<option></option>").val("month").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.month")))
.append($("<option></option>").val("week").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.week")))
.append($("<option></option>").val("weekday").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.weekday")))
.append($("<option></option>").val("day").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.day")))
.append($("<option></option>").val("hour").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.hour")))
.append($("<option></option>").val("minute").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.minute")))
.append($("<option></option>").val("second").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.second")))
.append($("<option></option>").val("millisecond").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.millisecond")))
.appendTo(setPartBox);
$("<label/>", {style: "margin-bottom: 0px; width: auto; text-align: right; margin-left: 4px; margin-right: 4px;"})
.text("=")
.appendTo(setPartBox);
const setPartValue = $("<input/>", {type: "text", class: "node-input-setPartValue"})
.appendTo(setPartBox)
.typedInput({types: [partInput, "env", "global", "flow", "msg"]});
setPartValue.typedInput("width", "180px");
const addsub = $("<input/>", {type: "text", class: "node-input-addsub"})
.appendTo(addsubBox)
.typedInput({types: [addsubInput, "env", "global", "flow", "msg"]});
addsub.typedInput("width", "180px");
const addsubUnit = $("<select/>", {class: "node-input-addsubUnit", style: "width: 130px; margin-left: 4px"})
.append($("<option></option>").val("years").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.years")))
.append($("<option></option>").val("quarters").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.quarters")))
.append($("<option></option>").val("months").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.months")))
.append($("<option></option>").val("weeks").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.weeks")))
.append($("<option></option>").val("days").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.days")))
.append($("<option></option>").val("hours").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.hours")))
.append($("<option></option>").val("minutes").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.minutes")))
.append($("<option></option>").val("seconds").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.seconds")))
.append($("<option></option>").val("milliseconds").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.milliseconds")))
.appendTo(addsubBox);
const startEndOfArg = $("<select/>", {class: "node-input-startEndOfArg", style: "width: 314px;"})
.append($("<option></option>").val("year").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.year")))
.append($("<option></option>").val("quarter").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.quarter")))
.append($("<option></option>").val("month").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.month")))
.append($("<option></option>").val("week").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.week")))
.append($("<option></option>").val("day").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.day")))
.append($("<option></option>").val("hour").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.hour")))
.append($("<option></option>").val("minute").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.minute")))
.append($("<option></option>").val("second").text(node._("node-red-contrib-chronos/chronos-config:common.list.unit.second")))
.appendTo(startEndOfBox);
$("<label/>", {style: "margin-bottom: 0px; width: 120px; text-align: right;"})
.text(node._("change.label.convertTo"))
.appendTo(convertBox);
const convertToBox = $("<div/>", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 8px;"}).appendTo(convertBox);
const convertToRow1 = $("<div/>").appendTo(convertToBox);
const convertToRow2 = $("<div/>", {style: "margin-top: 5px;"}).appendTo(convertToBox);
const stringFormat =
$("<input/>", {
type: "text",
class: "node-input-stringFormat",
title: node._("change.label.format"),
placeholder: node._("change.label.customFormat")})
.appendTo(convertToRow1)
.typedInput({
types: [
{
value: "predefined",
label: node._("change.label.predefinedFormat"),
icon: "fa fa-calendar",
options:
[
{
value: "regional",
label: node._("change.list.convert.regionalDateTime")
},
{
value: "regionalDate",
label: node._("change.list.convert.regionalDate")
},
{
value: "regionalTime",
label: node._("change.list.convert.regionalTime")
},
{
value: "relative",
label: node._("change.list.convert.relativeTime")
},
{
value: "calendar",
label: node._("change.list.convert.calendar")
},
{
value: "iso8601",
label: node._("change.list.convert.iso8601")
},
{
value: "iso8601utc",
label: node._("change.list.convert.iso8601UTC")
}
]
},
{
value: "custom",
label: node._("change.label.customFormat"),
icon: "fa fa-user-o",
hasValue: true,
validate: /^.+$/
}]});
stringFormat.typedInput("width", "314px");
stringFormat._prevType = "predefined";
stringFormat.on("change", function()
{
const type = stringFormat.typedInput("type");
if (type != stringFormat._prevType)
{
stringFormat._prevType = type;
if (type == "custom")
{
stringFormat.typedInput("value", "");
}
}
});
const timeZone =
$("<input/>", {
type: "text",
class: "node-input-timeZone",
title: node._("change.label.format")})
.appendTo(convertToRow2)
.typedInput({
types: [
{
value: "current",
label: node._("change.label.currentTZ"),
hasValue: false
},
{
value: "timeZone",
label: node._("change.label.timeZone"),
icon: "fa fa-globe",
hasValue: true,
validate: /^.+$/
},
{
value: "utcOffset",
label: node._("change.label.utcOffset"),
icon: "fa fa-expand",
hasValue: true,
validate: PATTERN_UTC_OFFSET
}]});
timeZone.typedInput("width", "314px");
timeZone._prevType = "current";
timeZone.on("change", function()
{
const type = timeZone.typedInput("type");
if (type != timeZone._prevType)
{
timeZone._prevType = type;
if (type != "current")
{
timeZone.typedInput("value", "");
}
}
});
action.change(function()
{
setBox.hide();
changeBox.hide();
convertBox.hide();
const value = $(this).val();
switch (value)
{
case "set":
{
setBox.show();
break;
}
case "change":
{
changeBox.show();
break;
}
case "convert":
{
convertBox.show();
break;
}
}
});
changeType.change(function()
{
setPartBox.hide();
addsubBox.hide();
startEndOfBox.hide();
const value = $(this).val();
switch (value)
{
case "set":
{
setPartBox.show();
break;
}
case "add":
case "subtract":
{
addsubBox.show();
break;
}
case "startOf":
case "endOf":
{
startEndOfBox.show();
break;
}
}
});
setPartType.change(function()
{
const value = $(this).val();
switch (value)
{
case "year":
{
partInput.min = -270000;
partInput.max = 270000;
break;
}
case "quarter":
{
partInput.min = 1;
partInput.max = 4;
break;
}
case "month":
{
partInput.min = 1;
partInput.max = 12;
break;
}
case "week":
{
partInput.min = 1;
partInput.max = 52;
break;
}
case "weekday":
{
partInput.min = 1;
partInput.max = 7;
break;
}
case "day":
{
partInput.min = 1;
partInput.max = 31;
break;
}
case "hour":
{
partInput.min = 0;
partInput.max = 23;
break;
}
case "minute":
{
partInput.min = 0;
partInput.max = 59;
break;
}
case "second":
{
partInput.min = 0;
partInput.max = 59;
break;
}
case "millisecond":
{
partInput.min = 0;
partInput.max = 999;
break;
}
}
setPartValue.typedInput("validate");
});
const now = new Date();
if (!("action" in data))
{
data = {action: "set", target: {type: "msg", name: "payload"}, type: "now"};
}
// backward compatibility to 1.24.0 and below
if (data.action == "change")
{
if (data.type == "toString")
{
data.action = "convert";
delete data.type;
// backward compatibility to v1.19.1 and below
if (!data.formatType)
{
data.formatType = "custom";
}
// backward compatibility to v1.21.0 and below
if (data.formatType == "relative")
{
data.formatType = "predefined";
data.format = "relative";
}
else if (data.formatType == "calendar")
{
data.formatType = "predefined";
data.format = "calendar";
}
else if (data.formatType == "iso8601")
{
data.formatType = "predefined";
data.format = "iso8601";
}
else if (data.formatType == "iso8601utc")
{
data.formatType = "predefined";
data.format = "iso8601utc";
}
if (typeof data.tzType == "undefined")
{
data.tzType = "current";
data.tzValue = "";
}
}
else if ((data.type == "set") || (data.type == "add") || (data.type == "subtract"))
{
if (typeof data.valueType == "undefined")
{
data.valueType = "num";
}
}
}
setToRow2.hide();
// initialize to default
changeType.val("add");
addsubUnit.val("years");
startEndOfArg.val("year");
setPartType.val("year");
setPartValue.typedInput("value", now.getFullYear().toString());
addsub.typedInput("value", 1);
action.val(data.action);
property.typedInput("value", data.target.name);
property.typedInput("type", data.target.type);
if (data.action == "set")
{
date.typedInput("type", data.type);
if (data.type == "date")
{
date.typedInput("value", data.date);
time.typedInput("type", data.time.type);
time.typedInput("value", data.time.value);
}
else if (data.type == "jsonata")
{
date.typedInput("value", data.expression);
}
}
else if (data.action == "change")
{
if (data.type == "set")
{
setPartType.val(data.part);
setPartValue.typedInput("type", data.valueType);
setPartValue.typedInput("value", data.value);
}
else if ((data.type == "add") || (data.type == "subtract"))
{
addsub.typedInput("type", data.valueType);
addsub.typedInput("value", data.value);
addsubUnit.val(data.unit);
}
else if ((data.type == "startOf") || (data.type == "endOf"))
{
startEndOfArg.val(data.arg);
}
changeType.val(data.type);
}
else if (data.action == "convert")
{
stringFormat.typedInput("type", data.formatType);
stringFormat.typedInput("value", data.format);
timeZone.typedInput("type", data.tzType);
timeZone.typedInput("value", data.tzValue);
}
action.change();
changeType.change();
setPartType.change();
item[0].appendChild(fragment);
}
});
const durationRules = $("#node-input-durationRules").css("min-width", "510px").css("min-height", "150px").editableList(
{
removable: true,
sortable: true,
addItem: function(item, index, data)
{