Merge pull request #4513 from gorenje/html_node_content_and_attributes

HTML node: add option for collecting attributes and content
This commit is contained in:
Nick O'Leary 2024-03-07 16:24:28 +00:00 committed by GitHub
commit 0b9dd11fff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 3 deletions

View File

@ -14,6 +14,7 @@
<option value="html" data-i18n="html.output.html"></option>
<option value="text" data-i18n="html.output.text"></option>
<option value="attr" data-i18n="html.output.attr"></option>
<option value="compl" data-i18n="html.output.compl"></option>
<!-- <option value="val">return the value from a form element</option> -->
</select>
</div>
@ -28,6 +29,10 @@
<label for="node-input-outproperty">&nbsp;</label>
<span data-i18n="html.label.in" style="padding-left:8px; padding-right:2px; vertical-align:-1px;"></span> <input type="text" id="node-input-outproperty" style="width:64%">
</div>
<div id='html-prefix-row' class="form-row" style="display: none;">
<label for="node-input-chr" style="width: 230px;"><i class="fa fa-tag"></i> <span data-i18n="html.label.prefix"></span></label>
<input type="text" id="node-input-chr" style="text-align:center; width: 40px;" placeholder="_">
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
@ -45,7 +50,8 @@
outproperty: {value:"payload", validate: RED.validators.typedInput({ type: 'msg', allowUndefined: true }) },
tag: {value:""},
ret: {value:"html"},
as: {value:"single"}
as: {value:"single"},
chr: { value: "_" }
},
inputs:1,
outputs:1,
@ -59,6 +65,13 @@
oneditprepare: function() {
$("#node-input-property").typedInput({default:'msg',types:['msg']});
$("#node-input-outproperty").typedInput({default:'msg',types:['msg']});
$('#node-input-ret').on( 'change', () => {
if ( $('#node-input-ret').val() == "compl" ) {
$('#html-prefix-row').show()
} else {
$('#html-prefix-row').hide()
}
});
}
});
</script>

View File

@ -25,6 +25,7 @@ module.exports = function(RED) {
this.tag = n.tag;
this.ret = n.ret || "html";
this.as = n.as || "single";
this.chr = n.chr || "_";
var node = this;
this.on("input", function(msg,send,done) {
var value = RED.util.getMessageProperty(msg,node.property);
@ -47,6 +48,11 @@ module.exports = function(RED) {
if (node.ret === "attr") {
pay2 = Object.assign({},this.attribs);
}
if (node.ret === "compl") {
var bse = {}
bse[node.chr] = $(this).html().trim()
pay2 = Object.assign(bse, this.attribs);
}
//if (node.ret === "val") { pay2 = $(this).val(); }
/* istanbul ignore else */
if (pay2) {
@ -69,6 +75,11 @@ module.exports = function(RED) {
var attribs = Object.assign({},this.attribs);
pay.push( attribs );
}
if (node.ret === "compl") {
var bse = {}
bse[node.chr] = $(this).html().trim()
pay.push( Object.assign(bse, this.attribs) )
}
//if (node.ret === "val") { pay.push( $(this).val() ); }
}
index++;

View File

@ -894,12 +894,14 @@
"label": {
"select": "Selector",
"output": "Output",
"in": "in"
"in": "in",
"prefix": "Property name for HTML content"
},
"output": {
"html": "the html content of the elements",
"text": "only the text content of the elements",
"attr": "an object of any attributes of the elements"
"attr": "an object of any attributes of the elements",
"compl": "an object of any attributes of the elements and html contents"
},
"format": {
"single": "as a single message containing an array",