mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Update Inject node to use typedInput
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="inject">
|
||||
<!--
|
||||
<div class="form-row node-input-payload">
|
||||
<label for="node-input-payloadType"><i class="fa fa-envelope"></i> <span data-i18n="common.label.payload"></span></label>
|
||||
<select id="node-input-payloadType" style="width:73%">
|
||||
@@ -28,6 +29,12 @@
|
||||
<label for="node-input-payload"></label>
|
||||
<input type="text" id="node-input-payload" style="width:70%">
|
||||
</div>
|
||||
-->
|
||||
<div class="form-row">
|
||||
<label for="node-input-payload"><i class="fa fa-envelope"></i> <span data-i18n="common.label.payload"></span></label>
|
||||
<input type="text" id="node-input-payload" style="width:300px">
|
||||
<input type="hidden" id="node-input-payloadType">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label>
|
||||
@@ -196,23 +203,51 @@
|
||||
outputs:1,
|
||||
icon: "inject.png",
|
||||
label: function() {
|
||||
if (this.payloadType === "string") {
|
||||
if (this.name) {
|
||||
return this.name;
|
||||
} else if (this.payloadType === "string" ||
|
||||
this.payloadType === "str" ||
|
||||
this.payloadType === "num" ||
|
||||
this.payloadType === "bool" ||
|
||||
this.payloadType === "json") {
|
||||
if ((this.topic !== "") && ((this.topic.length + this.payload.length) <= 32)) {
|
||||
return this.name||this.topic + ":" + this.payload;
|
||||
}
|
||||
else if (this.payload.length < 24) {
|
||||
return this.name||this.payload;
|
||||
return this.topic + ":" + this.payload;
|
||||
} else if (this.payload.length > 0 && this.payload.length < 24) {
|
||||
return this.payload;
|
||||
} else {
|
||||
return this._("inject.inject");
|
||||
}
|
||||
} else if (this.payloadType === 'date') {
|
||||
return this._("inject.timestamp")
|
||||
} else if (this.payloadType === 'flow' && this.payload.length < 19) {
|
||||
return 'flow.'+this.payload;
|
||||
} else if (this.payloadType === 'global' && this.payload.length < 17) {
|
||||
return 'global.'+this.payload;
|
||||
} else {
|
||||
return this._("inject.inject");
|
||||
}
|
||||
if ((this.topic.length < 24) && (this.topic.length > 0)) {
|
||||
return this.name||this.topic;
|
||||
}
|
||||
else { return this.name||(this.payloadType==="date"?this._("inject.timestamp"):null)||this._("inject.inject"); }
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.payloadType == null) {
|
||||
if (this.payload == "") {
|
||||
this.payloadType = "date";
|
||||
} else {
|
||||
this.payloadType = "str";
|
||||
}
|
||||
} else if (this.payloadType === 'string' || this.payloadType === 'none') {
|
||||
this.payloadType = "str";
|
||||
}
|
||||
$("#node-input-payloadType").val(this.payloadType);
|
||||
|
||||
$("#node-input-payload").typedInput({
|
||||
default: 'str',
|
||||
typeField: $("#node-input-payloadType"),
|
||||
options:['flow','global','str','num','bool','json',{value:"date",label:this._("inject.timestamp"),hasValue:false}]
|
||||
});
|
||||
|
||||
$("#inject-time-type-select").change(function() {
|
||||
$("#node-input-crontab").val('');
|
||||
var id = $("#inject-time-type-select option:selected").val();
|
||||
@@ -373,24 +408,8 @@
|
||||
$("#inject-time-type-select option").filter(function() {return $(this).val() == repeattype;}).attr('selected',true);
|
||||
$("#inject-time-row-"+repeattype).show();
|
||||
|
||||
if (this.payloadType == null) {
|
||||
if (this.payload == "") {
|
||||
this.payloadType = "date";
|
||||
} else {
|
||||
this.payloadType = "string";
|
||||
}
|
||||
}
|
||||
$("#node-input-payload").typedInput('type',this.payloadType);
|
||||
|
||||
$("#node-input-payloadType").change(function() {
|
||||
var id = $("#node-input-payloadType option:selected").val();
|
||||
if (id === "string") {
|
||||
$("#node-input-row-payload").show();
|
||||
} else {
|
||||
$("#node-input-row-payload").hide();
|
||||
}
|
||||
});
|
||||
$("#node-input-payloadType").val(this.payloadType);
|
||||
$("#node-input-payloadType").change();
|
||||
$("#inject-time-type-select").change();
|
||||
$("#inject-time-interval-time-start").change();
|
||||
|
||||
|
@@ -53,10 +53,12 @@ module.exports = function(RED) {
|
||||
var msg = {topic:this.topic};
|
||||
if ( (this.payloadType == null && this.payload === "") || this.payloadType === "date") {
|
||||
msg.payload = Date.now();
|
||||
} else if (this.payloadType == null || this.payloadType === "string") {
|
||||
} else if (this.payloadType == null) {
|
||||
msg.payload = this.payload;
|
||||
} else {
|
||||
} else if (this.payloadType == 'none') {
|
||||
msg.payload = "";
|
||||
} else {
|
||||
msg.payload = RED.util.evaluateNodeProperty(this.payload,this.payloadType,this,msg);
|
||||
}
|
||||
this.send(msg);
|
||||
msg = null;
|
||||
|
@@ -37,8 +37,6 @@
|
||||
"repeat": "Repeat"
|
||||
},
|
||||
"timestamp": "timestamp",
|
||||
"string": "string",
|
||||
"blank": "blank",
|
||||
"none": "none",
|
||||
"interval": "interval",
|
||||
"interval-time": "interval between times",
|
||||
@@ -460,7 +458,7 @@
|
||||
},
|
||||
"errors": {
|
||||
"invalid-from": "Invalid 'from' property: __error__",
|
||||
"invalid-json": "Invalid 'to' JSON property"
|
||||
"invalid-json": "Invalid 'to' JSON property"
|
||||
}
|
||||
},
|
||||
"range": {
|
||||
|
@@ -184,12 +184,12 @@
|
||||
|
||||
selectField.find("option").filter(function() {return $(this).val() == rule.t;}).attr('selected',true);
|
||||
if (rule.t == "btwn") {
|
||||
btwnValueField.val(rule.v);
|
||||
btwnValueField.typedInput('value',rule.v);
|
||||
btwnValueField.typedInput('type',rule.vt||'num');
|
||||
btwnValue2Field.val(rule.v2);
|
||||
btwnValue2Field.typedInput('value',rule.v2);
|
||||
btwnValue2Field.typedInput('type',rule.v2t||'num');
|
||||
} else if (typeof rule.v != "undefined") {
|
||||
valueField.val(rule.v);
|
||||
valueField.typedInput('value',rule.v);
|
||||
valueField.typedInput('type',rule.vt||'str');
|
||||
}
|
||||
if (rule.case) {
|
||||
@@ -266,12 +266,12 @@
|
||||
var r = {t:type};
|
||||
if (!(type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else")) {
|
||||
if (type === "btwn") {
|
||||
r.v = rule.find(".node-input-rule-btwn-value").val();
|
||||
r.v = rule.find(".node-input-rule-btwn-value").typedInput('value');
|
||||
r.vt = rule.find(".node-input-rule-btwn-value").typedInput('type');
|
||||
r.v2 = rule.find(".node-input-rule-btwn-value2").val();
|
||||
r.v2 = rule.find(".node-input-rule-btwn-value2").typedInput('value');
|
||||
r.v2t = rule.find(".node-input-rule-btwn-value2").typedInput('type');
|
||||
} else {
|
||||
r.v = rule.find(".node-input-rule-value").val();
|
||||
r.v = rule.find(".node-input-rule-value").typedInput('value');
|
||||
r.vt = rule.find(".node-input-rule-value").typedInput('type');
|
||||
}
|
||||
if (type === "regex") {
|
||||
|
@@ -172,13 +172,13 @@
|
||||
});
|
||||
|
||||
selectField.find("option").filter(function() {return $(this).val() == rule.t;}).attr('selected',true);
|
||||
propertyName.val(rule.p);
|
||||
propertyName.typedInput('value',rule.p);
|
||||
propertyName.typedInput('type',rule.pt)
|
||||
propertyValue.val(rule.to);
|
||||
propertyValue.typedInput('value',rule.to);
|
||||
propertyValue.typedInput('type',rule.tot)
|
||||
fromValue.val(rule.from);
|
||||
fromValue.typedInput('value',rule.from);
|
||||
fromValue.typedInput('type',rule.fromt)
|
||||
toValue.val(rule.to);
|
||||
toValue.typedInput('value',rule.to);
|
||||
toValue.typedInput('type',rule.tot)
|
||||
selectField.change();
|
||||
|
||||
@@ -258,18 +258,17 @@
|
||||
var type = rule.find(".node-input-rule-type option:selected").val();
|
||||
var r = {
|
||||
t:type,
|
||||
p:rule.find(".node-input-rule-property-name").val(),
|
||||
p:rule.find(".node-input-rule-property-name").typedInput('value'),
|
||||
pt:rule.find(".node-input-rule-property-name").typedInput('type')
|
||||
};
|
||||
if (type === "set") {
|
||||
r.to = rule.find(".node-input-rule-property-value").val();
|
||||
r.to = rule.find(".node-input-rule-property-value").typedInput('value');
|
||||
r.tot = rule.find(".node-input-rule-property-value").typedInput('type');
|
||||
} else if (type === "change") {
|
||||
r.from = rule.find(".node-input-rule-property-search-value").val();
|
||||
r.from = rule.find(".node-input-rule-property-search-value").typedInput('value');
|
||||
r.fromt = rule.find(".node-input-rule-property-search-value").typedInput('type');
|
||||
r.to = rule.find(".node-input-rule-property-replace-value").val();
|
||||
r.to = rule.find(".node-input-rule-property-replace-value").typedInput('value');
|
||||
r.tot = rule.find(".node-input-rule-property-replace-value").typedInput('type');
|
||||
r.re = rule.find(".node-input-rule-property-re").prop('checked');
|
||||
}
|
||||
node.rules.push(r);
|
||||
});
|
||||
|
Reference in New Issue
Block a user