node-red-contrib-viseo-ms-graph
Version:
VISEO Bot Maker - Microsoft Graph
285 lines (257 loc) • 14.4 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('ms-graph-excel',{
category: '💾_data',
color: '#8accff',
defaults: {
name: { value: undefined },
token: { value: undefined, required: true},
tokenType: { value: "msg"},
session: { value: undefined },
sessionType: { value: "msg"},
workbook: { value: undefined },
worksheet: { value: undefined },
range: { value: undefined },
method: { value: 'append' },
action: { value: 'set' },
clear: {value: false},
line: { value: false},
column: { value: false},
fields: { value: 'all' },
save: { value: true},
saveloc: { value: "_sheet"},
selfields: {value: [""]},
cell_l: { value: undefined},
cell_c: { value: undefined},
input: { value: "payload" },
output: { value: "payload" },
savelocType: {value: 'global'},
inputType: {value: 'msg'},
outputType: {value: 'msg'},
worksheetType: {value: 'str'},
workbookType: {value: 'str'},
rangeType: {value: 'str'},
cell_lType: {value: 'str'},
cell_cType: {value: 'str'}
},
inputs: 1,
outputs: 1,
icon: "azure.png",
align: "left",
paletteLabel: 'Excel',
label: function() {
return (this.name) || "Excel";
},
oneditprepare: function() {
$("#node-input-name").typedInput({ default: 'str', types: ['str'], type:'str' });
$("#node-input-token").typedInput({ default: 'str', types: ['str','msg','global'], typeField: $("#node-input-tokenType") });
$("#node-input-session").typedInput({ default: 'str', types: ['str','msg','global'], typeField: $("#node-input-sessionType") });
$("#node-input-workbook").typedInput({ default: 'str', types: ['str','msg','global'], typeField: $("#node-input-workbookType") });
$("#node-input-worksheet").typedInput({ default: 'str', types: ['str','msg','global'], typeField: $("#node-input-worksheetType") });
$("#node-input-range").typedInput({ default: 'str', types: ['str','msg','global'], typeField: $("#node-input-rangeType") });
$("#node-input-cell_l").typedInput({ default: 'str', types: ['str','msg','global'], typeField: $("#node-input-cell_lType") });
$("#node-input-cell_c").typedInput({ default: 'str', types: ['str','msg','global'], typeField: $("#node-input-cell_cType") });
$("#node-input-saveloc").typedInput({ default: 'global', types: ['msg','global'], typeField: $("#node-input-savelocType") });
$("#node-input-input").typedInput({ default: 'msg', types: ['msg','global'], typeField: $("#node-input-inputType") });
$("#node-input-output").typedInput({ default: 'msg', types: ['msg','global'], typeField: $("#node-input-outputType") });
$("#node-input-save").change( function() {
$('.save').hide();
if ($(this).is(":checked")) {
$(".save").show();
$("#node-input-saveloc").typedInput('show');
}
}).change();
$("#node-input-action").change(function() {
$(".set, .get, .ctn, .cell").hide();
if ($(this).val() === "set") {
$(".set").show();
if ($("#node-input-fields").val() === "select") $(".ctn").show();
if ($("#node-input-method").val() === "new") $(".new").show();
$("#node-input-input").typedInput('show');
}
else if ($(this).val() === "get") $(".get").show();
else if ($(this).val() === "cell") {
$(".cell").show();
$("#node-input-cell_c").typedInput('show');
$("#node-input-cell_l").typedInput('show');
}
});
$("#node-input-fields").change(function() {
$(".ctn").hide();
if ($(this).val() === "select") $(".ctn").show();
});
$("#node-input-method").change(function(){
$(".new").hide();
if ($(this).val() === "new") $(".new").show();
})
$("#node-input-selfields-ctn").css('min-height','100px').editableList({
addItem: function ( row, index, data ) {
var content = data.field || '';
var hiddenField = $('<span/>', {}).appendTo(row);
var titleField = $('<input/>', { class:"node-input-property-ctn", type:"text", style:"width:90%", value: content, placeholder:"Key"}).appendTo(row);
},
sortable: true,
removable: true
});
for (var i=0; i<this.selfields.length; i++) {
var field = this.selfields[i];
$("#node-input-selfields-ctn").editableList('addItem', { field: field, i:i });
}
},
oneditsave: function(){
let fields = $("#node-input-selfields-ctn").editableList('items'),
results = new Array();
fields.each(function(i) {
var content = $(this).find('.node-input-property-ctn').val();
if (content) results.push(content);
});
this.selfields = (results.length === 0) ? [""] : results;
}
});
</script>
<script type="text/x-red" data-template-name="ms-graph-excel">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Excel" style="width:70%;">
</div>
<br>
<b>MS Graph Excel settings </b>
<div class="form-row">
<br>
<label for="node-input-token"><i class="fa fa-lock"></i> Token</label>
<input type="text" id="node-input-token" style="width:70%;">
<input type="hidden" id="node-input-tokenType">
</div>
<div class="form-row">
<label for="node-input-session"><i class="fa fa-lock"></i> Session ID</label>
<input type="text" id="node-input-session" style="width:70%;" placeholder="Use existing session (empty: new session)" >
<input type="hidden" id="node-input-sessionType">
</div>
<div class="form-row">
<label for="node-input-workbook"><i class="fa fa-table"></i> Workbook</label>
<input type="text" id="node-input-workbook" style="width: 70%" placeholder="Workbook ID/name">
<input type="hidden" id="node-input-workbookType">
</div>
<div class="form-row">
<label for="node-input-worksheet"><i class="fa fa-table"></i> Worksheet</label>
<input type="text" id="node-input-worksheet" style="width: 70%" placeholder="Worksheet ID/name">
<input type="hidden" id="node-input-worksheetType">
</div>
<div class="form-row">
<label for="node-input-range"><i class="fa fa-table"></i> Range</label>
<input type="text" id="node-input-range" style="width: 70%" placeholder="Range (empty: auto)">
<input type="hidden" id="node-input-rangeType">
</div>
<div class="form-row">
<label for="node-input-save"><i class="fa fa-save"></i> Save</label>
<input type="checkbox" style="width: auto; vertical-align:top;" id="node-input-save"> <span>Save sheet's data in memory</span>
</div>
<div class="form-row save">
<input type="text" id="node-input-saveloc" style="width: 70%; margin-left: 105px;" placeholder="">
<input type="hidden" id="node-input-savelocType">
</div>
<br>
<b>Request settings</b>
<div class="form-row">
<br>
<label for="node-input-action"><i class="fa fa-tasks"></i> Action</label>
<select id="node-input-action" style="width: 34%">
<option value="set">Set data</option>
<option value="get">Get data</option>
<option value="cell">Get cell</option>
<option value="clear">Clear data</option>
</select>
<select class="set" id="node-input-method" style="width: 35%">
<option value="update">Update</option>
<option value="new">New</option>
</select>
</div>
<div class="form-row new get">
<label for="node-input-column"><i class="fa fa-tags"></i> Labels</label>
<input type="checkbox" style="width: auto; vertical-align:top;" id="node-input-line"> <span>First line for labels</span>
<input type="checkbox" style="width: auto; vertical-align:top; margin-left:25px;" id="node-input-column"> <span>First column for labels</span>
</div>
<div class="form-row set">
<label for="node-input-input"><i class="fa fa-sign-in"></i> Input</label>
<input type="text" id="node-input-input" style="width: 70%" placeholder="payload"/>
<input type="hidden" id="node-input-inputType">
</div>
<div class="form-row set">
<label for="node-input-fields"><i class="fa fa-tags"></i> Fields</label>
<select id="node-input-fields" style="width: 70%">
<option value="all">All</option>
<option value="select">Select</option>
</select>
</div>
<div class="form-row cell">
<label for="node-input-cell_c"><i class="fa fa-table"></i> Cell</label>
<input type="text" id="node-input-cell_c" style="width: 35%" placeholder="Column"/>
<input type="text" id="node-input-cell_l" style="width: 34%" placeholder="Line"/>
<input type="hidden" id="node-input-cell_lType">
<input type="hidden" id="node-input-cell_cType">
</div>
<div class="form-row ctn" style="width:70%; margin-left: 105px;">
<ol id="node-input-selfields-ctn"></ol>
<!-- <textarea id="node-input-selfields" rows="5" style="width:70%; margin-left: 105px;" placeholder="path.to.field"></textarea> -->
</div>
<div class="form-row">
<label for="node-input-output"><i class="fa fa-sign-out"></i> Output</label>
<input type="text" id="node-input-output" style="width: 70%" placeholder="payload"/>
<input type="hidden" id="node-input-outputType">
</div>
</script>
<style>
.help-section > ol > h4,
.help-section > h3 { font-weight: bold; }
</style>
<script type="text/x-red" data-help-name="ms-graph-excel">
<p>Manipulate a Google spreadhseet with Sheets API. </p>
<h3>Details</h3>
<p>Properties</p>
<dl class="message-properties">
<dt>Token <span class="property-type">string</span></dt>
<dd>from a Microsoft Graph authentication</dd>
<dt>Session ID <span class="property-type">string</span></dt>
<dd>if a session was created - leave empty to create a new one</dd>
<dt>Workbook <span class="property-type">string</span></dt>
<dd>the name of the file, included in the request URL such as <code>https://graph.microsoft.com/{version}/me/drive/root:/{workbook}:/workbook</code> </dd>
<dt>Worksheet <span class="property-type">string</span></dt>
<dd>name/ID of the sheet/tab in the document</dd>
<dt>Range <span class="property-type">string</span></dt>
<dd>to get/set/update, ex: "A1:C2" ; please be careful when you want to set data: the range has to be the exact one ; leave empty to use an automatic range</dd>
<dt>Save <span class="property-type">string</span></dt>
<dd>if checked, where to save the data in order to avoid multiple calls to the Excel API</dd>
<dt>Output <span class="property-type">string</span></dt>
<dd>where to store the results</dd>
</dl>
<p>
<b>Note:</b> the client must authenticate with the "Files.Read" and "Files.ReadWrite" scopes.
</p>
<p><b>Note:</b> If <i>Save</i> is checked, please delete the content of its location every time the sheet's data has been changed!
This can be done with a simple "inject" node followed by a "change" node (delete <code>global._sheet</code>).
</p>
<p>
<code>Set data</code> updates or replaces (new) the value of the range, or append after. The <i>input</i> has to be an <b>array</b> or a <b>JSON object</b>. If the input
is an object, it is possible to use the object keys as labels, eg first line and/or column. If you chose the 'append' method, this will not impact the result.
</p>
<p>
<b>Note:</b> You can chose to only write some <i>fields</i> of the input object in the spreadsheet. Chose these fields as: if the input object is
<code>msg.payload = { "monday": 3, "tuesday": 25, "wednesday": 12, "thursday": 6, "friday": 2" }</code> then I can chose to write only the <i>monday</i>
and <i>tuesday</i> fields in my worksheet.
</p>
<p>
<code>Get data</code> gets the value of the range. Check <i>labels</i> for line and/or column if the first line and/or the first column in your
spreadsheet is used for labels. The keys of the resulting objects will be adjusted accordingly.
</p>
<p>
<code>Get cell</code> gets the value of a cell. Precise line and column labels. Both should be precised. If nothing is found, the result is "Not found".
</p>
<h3>References</h3>
<ul>
<li><a href="https://docs.microsoft.com/en-us/graph/api/resources/excel?view=graph-rest-beta">Microsoft Graph</a> - Excel reference</li>
<li><a href="https://github.com/NGRP/node-red-contrib-viseo/">VISEO BotMaker</a> - the nodes github repository</li>
</ul>
<h3>Tracking</h3>
<p>This node is likely to display an error message if no key is configured in the VISEO Bot Maker project.
If such an error appears, please get a key <a href="https://key.bot.viseo.io/">here</a>.
</p>
</script>