added filter feature

This commit is contained in:
Michael Kolb 2023-01-07 17:42:16 +01:00
parent f1de06d486
commit 3e318f4b78
2 changed files with 19 additions and 3 deletions

View file

@ -5,15 +5,24 @@
defaults: {
server:{value:"", type:"grist-server",required:true},
document: {value:"",type:"grist-document",required:true},
tableId: {value:"",required:true}
tableId: {value:"",required:true},
filter: {value:"",required:false}
},
inputs:1,
outputs:1,
icon: "font-awesome/fa-table",
label: function() {
return this.tableId || "records";
},
oneditprepare: function () {
$("#node-input-filter").typedInput({
type:"json",
types:["json"]
})
}
});
</script>
<script type="text/html" data-template-name="grist-records">
@ -29,6 +38,11 @@
<label for="node-input-tableId"><i class="fa fa-table"></i> Table Name</label>
<input type="text" id="node-input-tableId" placeholder="Table Name">
</div>
<div class="form-row">
<label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
<input type="text" id="node-input-filter">
</div>
</script>

View file

@ -7,12 +7,14 @@ module.exports = function(RED) {
this.document = RED.nodes.getNode(config.document);
this.server = RED.nodes.getNode(config.server);
this.table = config.tableId
this.filter = config.filter
node.on('input', async function(msg, send, done) {
const protocol=this.server.tlsEnabled === true ? "https" : "http";
const url=protocol+"://"+this.server.hostname+":"+this.server.port;
const filter=this.filter && this.filter !== "" ? JSON.parse(this.filter) : undefined
const api = new GristDocAPI(this.document.docid,{apiKey:this.server.apiKey,server:url});
api.fetchTable(this.table).then(data => {
api.fetchTable(this.table,filter).then(data => {
node.send({payload:data,topic:this.table})
}).catch(reason => done(reason,"Failed to perform grist request to "+url));