UNPKG

node-red-contrib-agilite

Version:

Node-RED nodes to integrate with Agilit-e cloud or Agilit-e on-prem

438 lines (429 loc) 22.1 kB
<script type='text/javascript'> var agiliteKeywordsFunctions = { updateActionType:function(){ var value = $('#node-input-actionType option:selected').val() switch(value){ case '1':// Get Keywords By Profile Key document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'block' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'block' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'block' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '2':// Get Keyword Profile Keys By Group document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'none' document.querySelector('#rowGroupName').style.display = 'block' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'block' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '3':// Get Keyword Value by Label document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'block' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'block' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'block' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '4':// Get Keyword Label by Value document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'block' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'block' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'block' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '5':// Create Keyword Record document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'none' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '6':// Update Keyword Record document.querySelector('#rowRecordId').style.display = 'block' document.querySelector('#rowProfileKey').style.display = 'none' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '7':// Delete Keyword Record document.querySelector('#rowRecordId').style.display = 'block' document.querySelector('#rowProfileKey').style.display = 'none' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '8':// Set Values By Profile Key document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'block' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '9':// Set Value By Label document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'block' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'block' document.querySelector('#rowValue').style.display = 'block' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '10':// Set Label By Value document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'block' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'block' document.querySelector('#rowValue').style.display = 'block' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break case '11':// Get Data document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'none' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'block' document.querySelector('#rowRecordIds').style.display = 'block' break default: document.querySelector('#rowRecordId').style.display = 'none' document.querySelector('#rowProfileKey').style.display = 'none' document.querySelector('#rowGroupName').style.display = 'none' document.querySelector('#rowLabel').style.display = 'none' document.querySelector('#rowValue').style.display = 'none' document.querySelector('#rowSort').style.display = 'none' document.querySelector('#rowSort2').style.display = 'none' document.querySelector('#rowOutputFormat').style.display = 'none' document.querySelector('#rowOutputFormat2').style.display = 'none' document.querySelector('#rowProfileKeys').style.display = 'none' document.querySelector('#rowRecordIds').style.display = 'none' break } } } RED.nodes.registerType('keywords',{ category: 'agilite', inputs: 1, outputs:1, icon: 'keywords.png', color: '#ffa4a2', label: function () { return this.name || 'Keywords' }, paletteLabel : 'keywords', defaults : { server: { value : '', required: true, type: 'agilite-login' }, actionType: { value : '', required : true }, recordId: { value : '' }, recordIds: { value : '' }, profileKey: { value : '' }, profileKeys: { value : '' }, groupName: { value : '' }, labelKey: { value : '' }, valueKey: { value : '' }, sortBy: { value: '' }, sortBy2: { value: '' }, outputFormat: { value: '' }, outputFormat2: { value: '' }, name: { value: '' }, field: { value: 'payload', }, fieldType: { value: 'msg' }, failFlow: { value: true } }, oneditprepare: function(){ $('#node-input-actionType').change(function(){agiliteKeywordsFunctions.updateActionType()}) agiliteKeywordsFunctions.updateActionType() if (!this.fieldType) this.fieldType = 'msg' $('#node-input-field').typedInput({ default: 'msg', types: ['msg','flow','global'], typeField: $('#node-input-fieldType') }) } }) </script> <script type='text/x-red' data-template-name='keywords'> <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"></input> </div> <div class="form-row" id="rowActionType"> <label for="node-input-actionType"><i class="fa fa-arrow-circle-right"></i> Action Type</label> <select id="node-input-actionType" style="width:auto"> <option value="11">Get Data</option> <option value="5">Create Record</option> <option value="6">Update Record</option> <option value="7">Delete Record</option> <option value="1">Get Values By Profile Key</option> <option value="8">Set Values By Profile Key</option> <option value="2">Get Profile Keys By Group</option> <option value="3">Get Value By Label</option> <option value="9">Set Value By Label</option> <option value="4">Get Label By Value</option> <option value="10">Set Label By Value</option> </select> </div> <div class="form-row" id="rowRecordId"> <label for="node-input-recordId"><i class="fa fa-key"></i> Record Id {{}}</label> <input type="text" id="node-input-recordId" /> </div> <div class="form-row" id="rowProfileKey"> <label for="node-input-profileKey"><i class="fa fa-key"></i> Profile Key {{}}</label> <input type="text" id="node-input-profileKey" /> </div> <div class="form-row" id="rowProfileKeys"> <label for="node-input-profileKeys"><i class="fa fa-key"></i> Profile Keys {{}}</label> <input type="text" id="node-input-profileKeys" /> </div> <div class="form-row" id="rowRecordIds"> <label for="node-input-recordIds"><i class="fa fa-key"></i> Record Ids {{}}</label> <input type="text" id="node-input-recordIds" /> </div> <div class="form-row" id="rowGroupName"> <label for="node-input-groupName"><i class="fa fa-object-group"></i> Group Name {{}}</label> <input type="text" id="node-input-groupName" /> </div> <div class="form-row" id="rowLabel"> <label for="node-input-labelKey"><i class="fa fa-leaf"></i> Label Key {{}}</label> <input type="text" id="node-input-labelKey" /> </div> <div class="form-row" id="rowValue"> <label for="node-input-valueKey"><i class="fa fa-edit"></i> Value Key {{}}</label> <input type="text" id="node-input-valueKey" /> </div> <div class="form-row" id="rowSort"> <label for="node-input-sortBy"><i class="fa fa-sort"></i> Sort By</label> <select id="node-input-sortBy" style="width:auto"> <option value="">-Select-</option> <option value="asc">Ascending by Label</option> <option value="desc">Descending by Label</option> <option value="asc_value">Ascending by Value</option> <option value="desc_value">Descending by Value</option> </select> </div> <div class="form-row" id="rowSort2"> <label for="node-input-sortBy2"><i class="fa fa-sort"></i> Sort By</label> <select id="node-input-sortBy2" style="width:auto"> <option value="">-Select-</option> <option value="asc">Ascending</option> <option value="desc">Descending</option> </select> </div> <div class="form-row" id="rowOutputFormat"> <label for="node-input-outputFormat"><i class="fa fa-edit"></i> Output Format</label> <select id="node-input-outputFormat" style="width:auto"> <option value="">-Select-</option> <option value="array">Array</option> <option value="json">JSON</option> </select> </div> <div class="form-row" id="rowOutputFormat2"> <label for="node-input-outputFormat2"><i class="fa fa-edit"></i> Output Format</label> <select id="node-input-outputFormat2" style="width:auto"> <option value="">-Select-</option> <option value="string">String</option> <option value="json">JSON</option> </select> </div> <div class="form-row"> <label for="node-input-field"><i class="fa fa-edit"></i> <span data-i18n="template.label.property">Output to</span></label> <input type="text" id="node-input-field" placeholder="payload" style="width:250px"> <input type="hidden" id="node-input-fieldType"> </div> <div class="form-row"> <label for="node-input-failFlow"><i class="fa fa-exclamation-triangle"></i> <span data-i18n="template.label.property">Fail Flow on Error</span></label> <input type="checkbox" id="node-input-failFlow" style="width:initial" /> Yes </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Node Name" /> </div> </script> <script type='text/x-red' data-help-name='keywords'> <p>A node to fetch and update Agilit-e Keywords based on various conditions</p> <h3>Inputs</h3> <h4>General</h4> <dl class="message-properties"> <dt>Server (required)<span class="property-type">Configuration Node</span></dt> <dd>The server configuration to connect to the relevant Agilit-e API Server. This is achieved by providing the API Server URL (required) and an API Key (optional). <b>NOTE:</b> If providing an API Key, be sure to click on the "Authenticate" button, to have Node-RED authenticate the API Key before the Server configuration is used by Nodes.</dd> <dt>msg.payload<span class="property-type">object</span></dt> <dd>Optional data to be passed to Agilit-e for Handlebars evaluations in the relevant module's Profile.</dd> <br /> <p style="margin: 0 5px 0 5px"><b>NOTE:</b> Values can be provided manually in the Input Fields in this Node's UI Form, or programmatically using <a href="https://handlebarsjs.com/" target="_blank">Handlebars</a>, where the Input Field's Label includes <code>{{}}</code>. Labels with <code>{{}}</code> are <b>Handlebars-enabled</b> and evaluate prop values relative to the <code>msg</code> object (e.g. <code>{{profileKey}}</code> = <code>msg.profileKey</code>). A final note: The difference between using 2 curly braces vs 3, is that values evaluated using 2 curly braces are first encoded/escaped before evaluated, whereas values using 3 curly braces are not. It is usually safer to use 3 curly braces, but in most cases 2 will work fine.</p> </dl> <h3>Action Types</h3> <dl class="message-properties"> <h3 style="margin: 5px 5px 5px 5px">Get Data</h4> <dt>Profile Keys<span class="property-type">string | comma separated</span></dt> <dd>The unique keys of the Keyword Profiles that need to be fetched</dd> <dt>Record Ids<span class="property-type">string | comma separated</span></dt> <dd>The Record Ids (_id) of the Keyword Profiles that need to be fetched</dd> </dl> <dl class="message-properties"> <h3 style="margin: 5px 5px 5px 5px">Create Record</h4> <dt>msg.payload<span class="property-type">object</span></dt> <dd>The Keyword Profile data</dd> <dd> Example: <code> { data: { isActive: true/false, key: '', name: '', groupName: '', values: [{ key: '', value: '' }], solutions: [''] } } </code> </dd> </dl> <dl class="message-properties"> <h3 style="margin: 5px 5px 5px 5px">Update Record</h4> <dt>Record Id<span class="property-type">string</span></dt> <dd>The Record Id (_id) of the Keyword Profile that needs to be updated</dd> <dt>msg.payload<span class="property-type">object</span></dt> <dd>The Keyword Profile data</dd> <dd> Example: <code> { data: { isActive: true/false, key: '', name: '', groupName: '', values: [{ key: '', value: '' }], solutions: [''] } } </code> </dd> </dl> <dl class="message-properties"> <h3 style="margin: 5px 5px 5px 5px">Delete Record</h4> <dt>Record ID<span class="property-type">string</span></dt> <dd>The ID (_id) of the Keyword Profile you want to Delete</dd> </dl> <dl class="message-properties"> <h3 style="margin: 5px 5px 5px 5px">Get Values By Profile Key</h4> <dt>Profile Key<span class="property-type">string</span></dt> <dd>The unique <b>key</b> of the Keyword Profile you want to get the Values for</dd> <dt>Sort By<span class="property-type">select</span></dt> <dd>Sorting Options of the Keyword Values</dd> <dt>Output Format<span class="property-type">select</span></dt> <dd>Output Format Options of the Keyword Values</dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <p style="margin: 0 5px 0 5px">By default, this Node will output the result to <code>msg.payload</code>. This can be changed in the Node UI Form's <b>Output To</b> Field</p> </dl> <h3>Additional Properties</h3> <dl class="message-properties"> <p style="margin: 0 5px 0 5px">By default, if an error occurs, this Node will fail and stop the flow from continuing. This can be switched off in the Node UI Form's <b>Fail Flow on Error</b> Field. This allows one to manually manage the error by referencing the <code>msg.agilite.succcess</code> and <code>msg.agilite.errorMessage</code> prop values.</p> <br /> <p style="margin: 0 5px 0 5px">The following properties can be set in the <code>msg.agilite</code> object:</p> <dt>logProfileKey <span class="property-type">string</span></dt> <dd>The unique <b>key</b> to the Batch Logging Profile used for custom logging.</dd> <dt>apiKey <span class="property-type">string</span></dt> <dd>The Agilit-e API Key used to authenticate the Agilit-e transaction. This is not required if you've set up a Configuration Node that already has an API Key which has been authenticated.</dd> </script>