Added more nodes
This commit is contained in:
parent
a33c6da509
commit
1dc5e9fdb1
16 changed files with 228 additions and 10 deletions
55
node-red-grist/add-records.html
Normal file
55
node-red-grist/add-records.html
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<script type="text/javascript">
|
||||
RED.nodes.registerType('grist-add-records', {
|
||||
|
||||
category: 'grist',
|
||||
color: '#00bb00',
|
||||
defaults: {
|
||||
server: { value: "", type: "grist-server", required: true },
|
||||
document: { value: "", type: "grist-document", required: true },
|
||||
tableId: { value: "", required: true },
|
||||
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
icon: "font-awesome/fa-table",
|
||||
label: function () {
|
||||
return this.tableId ? `[Add] ${this.tableId}` : "Add records";
|
||||
},
|
||||
paletteLabel: "Add records",
|
||||
oneditprepare: function () {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-template-name="grist-add-records">
|
||||
<div class="form-row">
|
||||
<label for="node-input-document"><i class="fa fa-file-text"></i> Document</label>
|
||||
<input type="text" id="node-input-document" placeholder="Document">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
|
||||
<input type="text" id="node-input-server" placeholder="Server">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<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>
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-help-name="grist-add-records">
|
||||
<p>Adds records to a grist table.</p>
|
||||
<h3>Inputs</h3>
|
||||
<p>
|
||||
<code>msg.payload</code> array of records (or a single record object) to add.
|
||||
</p>
|
||||
<h3>Outputs</h3>
|
||||
<p>
|
||||
Array of records that have been added
|
||||
</p>
|
||||
<h3>Attributes</h3>
|
||||
<p>
|
||||
|
||||
</script>
|
||||
24
node-red-grist/add-records.js
Normal file
24
node-red-grist/add-records.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const { GristDocAPI } = require('grist-api');
|
||||
const mustache = require('mustache');
|
||||
module.exports = function (RED) {
|
||||
function AddRecordsNode(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
let node = this;
|
||||
this.document = RED.nodes.getNode(config.document);
|
||||
this.server = RED.nodes.getNode(config.server);
|
||||
this.table = config.tableId
|
||||
|
||||
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 api = new GristDocAPI(this.document.docid, { apiKey: this.server.apiKey, server: url });
|
||||
const data = Array.isArray(msg.payload) ? msg.payload : [msg.payload]
|
||||
|
||||
api.addRecords(this.table, data).then(data => {
|
||||
node.send({ payload: data, topic: this.table })
|
||||
}).catch(reason => done(reason, "Failed to perform grist request to " + url));
|
||||
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("grist-add-records", AddRecordsNode);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<script type="text/javascript">
|
||||
RED.nodes.registerType('grist-records', {
|
||||
RED.nodes.registerType('grist-get-records', {
|
||||
name: "Get records",
|
||||
category: 'grist',
|
||||
color: '#00bb00',
|
||||
|
|
@ -13,8 +13,10 @@
|
|||
outputs: 1,
|
||||
icon: "font-awesome/fa-table",
|
||||
label: function () {
|
||||
return this.tableId || "Get records";
|
||||
return this.tableId ? `[Get] ${this.tableId}` : "Get records";
|
||||
|
||||
},
|
||||
paletteLabel: "Get records",
|
||||
oneditprepare: function () {
|
||||
$("#node-input-filter").typedInput({
|
||||
type: "json",
|
||||
|
|
@ -26,7 +28,7 @@
|
|||
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-template-name="grist-records">
|
||||
<script type="text/html" data-template-name="grist-get-records">
|
||||
<div class="form-row">
|
||||
<label for="node-input-document"><i class="fa fa-file-text"></i> Document</label>
|
||||
<input type="text" id="node-input-document" placeholder="Document">
|
||||
|
|
@ -47,7 +49,7 @@
|
|||
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-help-name="grist-records">
|
||||
<script type="text/html" data-help-name="grist-get-records">
|
||||
<p>Retrieves records from a grist table.</p>
|
||||
<h3>Inputs</h3>
|
||||
<p>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
const { GristDocAPI } = require('grist-api');
|
||||
const mustache = require('mustache');
|
||||
module.exports = function (RED) {
|
||||
function RecordsNode(config) {
|
||||
function GetRecordsNode(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
let node = this;
|
||||
this.document = RED.nodes.getNode(config.document);
|
||||
|
|
@ -21,5 +21,5 @@ module.exports = function (RED) {
|
|||
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("grist-records", RecordsNode);
|
||||
RED.nodes.registerType("grist-get-records", GetRecordsNode);
|
||||
}
|
||||
57
node-red-grist/update-records.html
Normal file
57
node-red-grist/update-records.html
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<script type="text/javascript">
|
||||
|
||||
RED.nodes.registerType('grist-update-records', {
|
||||
|
||||
category: 'grist',
|
||||
color: '#00bb00',
|
||||
defaults: {
|
||||
server: { value: "", type: "grist-server", required: true },
|
||||
document: { value: "", type: "grist-document", required: true },
|
||||
tableId: { value: "", required: true },
|
||||
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
icon: "font-awesome/fa-table",
|
||||
label: function () {
|
||||
return this.tableId ? `[Update] ${this.tableId}` : "Update records";
|
||||
},
|
||||
paletteLabel: "Update records",
|
||||
oneditprepare: async function () {
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-template-name="grist-update-records">
|
||||
<div class="form-row">
|
||||
<label for="node-input-document"><i class="fa fa-file-text"></i> Document</label>
|
||||
<input type="text" id="node-input-document" placeholder="Document">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-server"><i class="fa fa-server"></i> Server</label>
|
||||
<input type="text" id="node-input-server" placeholder="Server">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<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>
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-help-name="grist-update-records">
|
||||
<p>Updates records in a grist table.</p>
|
||||
<h3>Inputs</h3>
|
||||
<p>
|
||||
<code>msg.payload</code> array of records (or a single record object) to add. Each record must contain the ID.
|
||||
</p>
|
||||
<h3>Outputs</h3>
|
||||
<p>
|
||||
No data. Called as soon as update was performed.
|
||||
</p>
|
||||
<h3>Attributes</h3>
|
||||
<p>
|
||||
|
||||
</script>
|
||||
24
node-red-grist/update-records.js
Normal file
24
node-red-grist/update-records.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const { GristDocAPI } = require('grist-api');
|
||||
const mustache = require('mustache');
|
||||
module.exports = function (RED) {
|
||||
function UpdateRecordsNode(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
let node = this;
|
||||
this.document = RED.nodes.getNode(config.document);
|
||||
this.server = RED.nodes.getNode(config.server);
|
||||
this.table = config.tableId
|
||||
|
||||
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 api = new GristDocAPI(this.document.docid, { apiKey: this.server.apiKey, server: url });
|
||||
const data = Array.isArray(msg.payload) ? msg.payload : [msg.payload]
|
||||
|
||||
api.updateRecords(this.table, data).then(data => {
|
||||
node.send({ payload: data, topic: this.table })
|
||||
}).catch(reason => done(reason, "Failed to perform grist request to " + url));
|
||||
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("grist-update-records", UpdateRecordsNode);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue