mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Improve inject node payload options
This commit is contained in:
parent
d52cd1ce00
commit
c47c72cf48
@ -16,7 +16,15 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="inject">
|
<script type="text/x-red" data-template-name="inject">
|
||||||
<div class="form-row node-input-payload">
|
<div class="form-row node-input-payload">
|
||||||
<label for="node-input-payload"><i class="icon-envelope"></i> Payload</label>
|
<label for="node-input-payloadType"><i class="icon-envelope"></i> Payload</label>
|
||||||
|
<select id="node-input-payloadType" style="width:125px !important">
|
||||||
|
<option value="date">timestamp</option>
|
||||||
|
<option value="none">blank</option>
|
||||||
|
<option value="string">string</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row" id="node-input-row-payload">
|
||||||
|
<label for="node-input-payload"></label>
|
||||||
<input type="text" id="node-input-payload" placeholder="Payload">
|
<input type="text" id="node-input-payload" placeholder="Payload">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -61,7 +69,6 @@
|
|||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-tips">Tip: Injects Date.now() if no payload set</div>
|
|
||||||
<script>
|
<script>
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -187,6 +194,7 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
topic: {value:""},
|
topic: {value:""},
|
||||||
payload: {value:""},
|
payload: {value:""},
|
||||||
|
payloadType: {value:"date"},
|
||||||
repeat: {value:""},
|
repeat: {value:""},
|
||||||
crontab: {value:""},
|
crontab: {value:""},
|
||||||
once: {value:false}
|
once: {value:false}
|
||||||
@ -278,6 +286,24 @@
|
|||||||
$("#inject-time-type-select option").filter(function() {return $(this).val() == repeattype;}).attr('selected',true);
|
$("#inject-time-type-select option").filter(function() {return $(this).val() == repeattype;}).attr('selected',true);
|
||||||
$("#inject-time-row-"+repeattype).show();
|
$("#inject-time-row-"+repeattype).show();
|
||||||
|
|
||||||
|
if (this.payloadType == null) {
|
||||||
|
if (this.payload == "") {
|
||||||
|
this.payloadType = "date";
|
||||||
|
} else {
|
||||||
|
this.payloadType = "string";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#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);
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
|
@ -25,6 +25,7 @@ function InjectNode(n) {
|
|||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.topic = n.topic;
|
this.topic = n.topic;
|
||||||
this.payload = n.payload;
|
this.payload = n.payload;
|
||||||
|
this.payloadType = n.payloadType;
|
||||||
this.repeat = n.repeat;
|
this.repeat = n.repeat;
|
||||||
this.crontab = n.crontab;
|
this.crontab = n.crontab;
|
||||||
this.once = n.once;
|
this.once = n.once;
|
||||||
@ -56,8 +57,16 @@ function InjectNode(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.on("input",function(msg) {
|
this.on("input",function(msg) {
|
||||||
var msg = {topic:this.topic,payload:this.payload};
|
var msg = {topic:this.topic};
|
||||||
if (msg.payload == "") { msg.payload = Date.now(); }
|
console.log(this.payloadType);
|
||||||
|
console.log(this.payload);
|
||||||
|
if ( (this.payloadType == null && this.payload == "") || this.payloadType == "date") {
|
||||||
|
msg.payload = Date.now();
|
||||||
|
} else if (this.payloadType == null || this.payloadType == "string") {
|
||||||
|
msg.payload = this.payload;
|
||||||
|
} else {
|
||||||
|
msg.payload = "";
|
||||||
|
}
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
msg = null;
|
msg = null;
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user