mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Support Property In/Out on the JSON Node
This commit is contained in:
parent
ef726e6a5f
commit
219b232cad
@ -1,5 +1,13 @@
|
|||||||
|
|
||||||
<script type="text/html" data-template-name="json">
|
<script type="text/html" data-template-name="json">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-property"><i class="fa fa-sign-in"></i> <span data-i18n="common.label.propertyIn"></span></label>
|
||||||
|
<input type="text" id="node-input-property" style="width:70%;"/>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-action"><i class="fa fa-dot-circle-o"></i> <span data-i18n="json.label.action"></span></label>
|
<label for="node-input-action"><i class="fa fa-dot-circle-o"></i> <span data-i18n="json.label.action"></span></label>
|
||||||
<select style="width:70%" id="node-input-action">
|
<select style="width:70%" id="node-input-action">
|
||||||
@ -9,12 +17,8 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="json.label.property"></span></label>
|
<label for="node-input-propertyOut"><i class="fa fa-sign-out"></i> <span data-i18n="common.label.propertyOut"></span></label>
|
||||||
<input type="text" id="node-input-property" style="width:70%;"/>
|
<input type="text" id="node-input-propertyOut" style="width:70%;"/>
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
|
||||||
</div>
|
</div>
|
||||||
<hr align="middle"/>
|
<hr align="middle"/>
|
||||||
<div class="form-row node-json-to-json-options">
|
<div class="form-row node-json-to-json-options">
|
||||||
@ -33,7 +37,10 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
property: {value:"payload",required:true,
|
property: {value:"payload",required:true,
|
||||||
validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true}),
|
validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true}),
|
||||||
label:RED._("node-red:json.label.property")},
|
label:RED._("node-red:common.label.propertyIn")},
|
||||||
|
propertyOut: {value:"payload",required:true,
|
||||||
|
validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true}),
|
||||||
|
label:RED._("node-red:common.label.propertyOut")},
|
||||||
action: {value:""},
|
action: {value:""},
|
||||||
pretty: {value:false}
|
pretty: {value:false}
|
||||||
},
|
},
|
||||||
@ -50,7 +57,11 @@
|
|||||||
if (this.property === undefined) {
|
if (this.property === undefined) {
|
||||||
$("#node-input-property").val("payload");
|
$("#node-input-property").val("payload");
|
||||||
}
|
}
|
||||||
|
if (this.property === undefined) {
|
||||||
|
$("#node-input-propertyOut").val("payload");
|
||||||
|
}
|
||||||
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
||||||
|
$("#node-input-propertyOut").typedInput({default:'msg',types:['msg']});
|
||||||
$("#node-input-action").on("change", function() {
|
$("#node-input-action").on("change", function() {
|
||||||
if (this.value === "" || this.value === "str") {
|
if (this.value === "" || this.value === "str") {
|
||||||
$(".node-json-to-json-options").show();
|
$(".node-json-to-json-options").show();
|
||||||
|
@ -25,6 +25,7 @@ module.exports = function(RED) {
|
|||||||
this.indent = n.pretty ? 4 : 0;
|
this.indent = n.pretty ? 4 : 0;
|
||||||
this.action = n.action||"";
|
this.action = n.action||"";
|
||||||
this.property = n.property||"payload";
|
this.property = n.property||"payload";
|
||||||
|
this.propertyOut = n.propertyOut||this.property;
|
||||||
this.schema = null;
|
this.schema = null;
|
||||||
this.compiledSchema = null;
|
this.compiledSchema = null;
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ module.exports = function(RED) {
|
|||||||
// else
|
// else
|
||||||
if (node.action === "" || node.action === "obj") {
|
if (node.action === "" || node.action === "obj") {
|
||||||
try {
|
try {
|
||||||
RED.util.setMessageProperty(msg,node.property,JSON.parse(value));
|
RED.util.setMessageProperty(msg,node.propertyOut,JSON.parse(value));
|
||||||
if (validate) {
|
if (validate) {
|
||||||
if (this.compiledSchema(msg[node.property])) {
|
if (this.compiledSchema(msg[node.property])) {
|
||||||
delete msg.schema;
|
delete msg.schema;
|
||||||
@ -95,7 +96,7 @@ module.exports = function(RED) {
|
|||||||
try {
|
try {
|
||||||
if (validate) {
|
if (validate) {
|
||||||
if (this.compiledSchema(value)) {
|
if (this.compiledSchema(value)) {
|
||||||
RED.util.setMessageProperty(msg,node.property,JSON.stringify(value,null,node.indent));
|
RED.util.setMessageProperty(msg,node.propertyOut,JSON.stringify(value,null,node.indent));
|
||||||
delete msg.schema;
|
delete msg.schema;
|
||||||
send(msg);
|
send(msg);
|
||||||
done();
|
done();
|
||||||
@ -104,7 +105,7 @@ module.exports = function(RED) {
|
|||||||
done(`${RED._("json.errors.schema-error")}: ${ajv.errorsText(this.compiledSchema.errors)}`);
|
done(`${RED._("json.errors.schema-error")}: ${ajv.errorsText(this.compiledSchema.errors)}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RED.util.setMessageProperty(msg,node.property,JSON.stringify(value,null,node.indent));
|
RED.util.setMessageProperty(msg,node.propertyOut,JSON.stringify(value,null,node.indent));
|
||||||
send(msg);
|
send(msg);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user