added template support for filter expression
This commit is contained in:
parent
4980181634
commit
a33c6da509
8 changed files with 59 additions and 35 deletions
Binary file not shown.
BIN
.yarn/cache/follow-redirects-npm-1.15.3-ca69c47b72-584da22ec5.zip
vendored
Normal file
BIN
.yarn/cache/follow-redirects-npm-1.15.3-ca69c47b72-584da22ec5.zip
vendored
Normal file
Binary file not shown.
Binary file not shown.
BIN
.yarn/cache/mustache-npm-4.2.0-1fe3d6d77a-928fcb63e3.zip
vendored
Normal file
BIN
.yarn/cache/mustache-npm-4.2.0-1fe3d6d77a-928fcb63e3.zip
vendored
Normal file
Binary file not shown.
|
|
@ -1,28 +1,29 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('grist-records',{
|
RED.nodes.registerType('grist-records', {
|
||||||
|
name: "Get records",
|
||||||
category: 'grist',
|
category: 'grist',
|
||||||
color: '#00bb00',
|
color: '#00bb00',
|
||||||
defaults: {
|
defaults: {
|
||||||
server:{value:"", type:"grist-server",required:true},
|
server: { value: "", type: "grist-server", required: true },
|
||||||
document: {value:"",type:"grist-document",required:true},
|
document: { value: "", type: "grist-document", required: true },
|
||||||
tableId: {value:"",required:true},
|
tableId: { value: "", required: true },
|
||||||
filter: {value:"",required:false}
|
filter: { value: "", required: false }
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs: 1,
|
||||||
outputs:1,
|
outputs: 1,
|
||||||
icon: "font-awesome/fa-table",
|
icon: "font-awesome/fa-table",
|
||||||
label: function() {
|
label: function () {
|
||||||
return this.tableId || "records";
|
return this.tableId || "Get records";
|
||||||
},
|
},
|
||||||
oneditprepare: function () {
|
oneditprepare: function () {
|
||||||
$("#node-input-filter").typedInput({
|
$("#node-input-filter").typedInput({
|
||||||
type:"json",
|
type: "json",
|
||||||
types:["json"]
|
types: ["json", "str"]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-template-name="grist-records">
|
<script type="text/html" data-template-name="grist-records">
|
||||||
|
|
@ -47,5 +48,16 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/html" data-help-name="grist-records">
|
<script type="text/html" data-help-name="grist-records">
|
||||||
<p>Retrieves records from a grist table</p>
|
<p>Retrieves records from a grist table.</p>
|
||||||
|
<h3>Inputs</h3>
|
||||||
|
<p>
|
||||||
|
The input message object is available for the <code>filter</code> property via mustache template syntax.
|
||||||
|
</p>
|
||||||
|
<h3>Outputs</h3>
|
||||||
|
<p>
|
||||||
|
Array of grist rows (records).
|
||||||
|
</p>
|
||||||
|
<h3>Attributes</h3>
|
||||||
|
<p>
|
||||||
|
<code>filter</code> JSON object with filter definition. Supports mustache syntax for templates.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -1,24 +1,25 @@
|
||||||
const {GristDocAPI} = require('grist-api');
|
const { GristDocAPI } = require('grist-api');
|
||||||
|
const mustache = require('mustache');
|
||||||
module.exports = function(RED) {
|
module.exports = function (RED) {
|
||||||
function RecordsNode(config) {
|
function RecordsNode(config) {
|
||||||
RED.nodes.createNode(this,config);
|
RED.nodes.createNode(this, config);
|
||||||
let node = this;
|
let node = this;
|
||||||
this.document = RED.nodes.getNode(config.document);
|
this.document = RED.nodes.getNode(config.document);
|
||||||
this.server = RED.nodes.getNode(config.server);
|
this.server = RED.nodes.getNode(config.server);
|
||||||
this.table = config.tableId
|
this.table = config.tableId
|
||||||
this.filter = config.filter
|
this.filter = config.filter
|
||||||
|
|
||||||
node.on('input', async function(msg, send, done) {
|
node.on('input', async function (msg, send, done) {
|
||||||
const protocol=this.server.tlsEnabled === true ? "https" : "http";
|
const protocol = this.server.tlsEnabled === true ? "https" : "http";
|
||||||
const url=protocol+"://"+this.server.hostname+":"+this.server.port;
|
const url = protocol + "://" + this.server.hostname + ":" + this.server.port;
|
||||||
const filter=this.filter && this.filter !== "" ? JSON.parse(this.filter) : undefined
|
const filter = this.filter && this.filter !== "" ? JSON.parse(mustache.render(this.filter, { msg })) : undefined
|
||||||
const api = new GristDocAPI(this.document.docid,{apiKey:this.server.apiKey,server:url});
|
node.log(`filter evaluated to: ${JSON.stringify(filter)}`)
|
||||||
api.fetchTable(this.table,filter).then(data => {
|
const api = new GristDocAPI(this.document.docid, { apiKey: this.server.apiKey, server: url });
|
||||||
node.send({payload:data,topic:this.table})
|
api.fetchTable(this.table, filter).then(data => {
|
||||||
}).catch(reason => done(reason,"Failed to perform grist request to "+url));
|
node.send({ payload: data, topic: this.table })
|
||||||
|
}).catch(reason => done(reason, "Failed to perform grist request to " + url));
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("grist-records",RecordsNode);
|
RED.nodes.registerType("grist-records", RecordsNode);
|
||||||
}
|
}
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"grist-api": "^0.1.7"
|
"grist-api": "^0.1.7",
|
||||||
|
"mustache": "^4.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
yarn.lock
22
yarn.lock
|
|
@ -10,6 +10,7 @@ __metadata:
|
||||||
resolution: "@gorootde/node-red-grist@workspace:."
|
resolution: "@gorootde/node-red-grist@workspace:."
|
||||||
dependencies:
|
dependencies:
|
||||||
grist-api: ^0.1.7
|
grist-api: ^0.1.7
|
||||||
|
mustache: ^4.2.0
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
|
@ -35,12 +36,12 @@ __metadata:
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"follow-redirects@npm:^1.14.0":
|
"follow-redirects@npm:^1.14.0":
|
||||||
version: 1.15.2
|
version: 1.15.3
|
||||||
resolution: "follow-redirects@npm:1.15.2"
|
resolution: "follow-redirects@npm:1.15.3"
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
debug:
|
debug:
|
||||||
optional: true
|
optional: true
|
||||||
checksum: faa66059b66358ba65c234c2f2a37fcec029dc22775f35d9ad6abac56003268baf41e55f9ee645957b32c7d9f62baf1f0b906e68267276f54ec4b4c597c2b190
|
checksum: 584da22ec5420c837bd096559ebfb8fe69d82512d5585004e36a3b4a6ef6d5905780e0c74508c7b72f907d1fa2b7bd339e613859e9c304d0dc96af2027fd0231
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|
@ -56,9 +57,9 @@ __metadata:
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.2.0":
|
"graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.2.0":
|
||||||
version: 4.2.10
|
version: 4.2.11
|
||||||
resolution: "graceful-fs@npm:4.2.10"
|
resolution: "graceful-fs@npm:4.2.11"
|
||||||
checksum: 3f109d70ae123951905d85032ebeae3c2a5a7a997430df00ea30df0e3a6c60cf6689b109654d6fdacd28810a053348c4d14642da1d075049e6be1ba5216218da
|
checksum: ac85f94da92d8eb6b7f5a8b20ce65e43d66761c55ce85ac96df6865308390da45a8d3f0296dd3a663de65d30ba497bd46c696cc1e248c72b13d6d567138a4fc7
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|
@ -100,6 +101,15 @@ __metadata:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"mustache@npm:^4.2.0":
|
||||||
|
version: 4.2.0
|
||||||
|
resolution: "mustache@npm:4.2.0"
|
||||||
|
bin:
|
||||||
|
mustache: bin/mustache
|
||||||
|
checksum: 928fcb63e3aa44a562bfe9b59ba202cccbe40a46da50be6f0dd831b495be1dd7e38ca4657f0ecab2c1a89dc7bccba0885eab7ee7c1b215830da765758c7e0506
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"universalify@npm:^0.1.0":
|
"universalify@npm:^0.1.0":
|
||||||
version: 0.1.2
|
version: 0.1.2
|
||||||
resolution: "universalify@npm:0.1.2"
|
resolution: "universalify@npm:0.1.2"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue