node-red-contrib-snap4city-user
Version:
Nodes for Snap4city project, targeted to standard user (no developer)
218 lines (201 loc) • 8.56 kB
HTML
<!--/* NODE-RED-CONTRIB-SNAP4CITY-USER
Copyright (C) 2018 DISIT Lab http://www.disit.org - University of Florence
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */-->
<script type="text/javascript">
RED.nodes.registerType('get-public-kpidata-values', {
category: 'S4CKPIData',
color: '#b0dfe3',
defaults: {
name: {
value: ""
},
kpiId: {
value: ""
},
selectedKPIDataId: {
value: ""
},
startdate: {
value: ""
},
enddate: {
value: ""
},
last: {
value: ""
},
authentication: {
type: "snap4city-authentication",
required: false
}
},
outputs: 1,
inputs: 1,
icon: "white-globe.png",
label: function () {
return this.name || "get-public-kpidata-values";
},
oneditprepare: function () {
$("#node-input-currentNodeId").val(this.id);
initChangeAuthenticationPublicKPIData();
$("#node-input-authentication").change(function () {
initChangeAuthenticationPublicKPIData();
});
},
oneditsave: function () {
$("#node-input-selectedKPIDataId").val($("#node-input-kpiId").val());
$("#node-input-name").val("Value of public " + $("#node-input-kpiId").val().split("-")[1]);
}
});
var refreshPublicKPIDataSelection = function (accessToken, kpiDataList) {
$("#node-input-kpiId").empty();
if (kpiDataList != "") {
createKPIDataSelection(kpiDataList);
} else if (accessToken != "" && kpiDataList == "") {
$.ajax({
url: "myPersonalDataUrl",
type: "GET",
async: false,
success: function (_data) {
var domain = (RED.nodes.node($("#node-input-authentication").val()) != null ? RED.nodes.node($("#node-input-authentication").val()).domain : "");
if (domain != "") {
_data.myPersonalDataUrl = domain + "/datamanager/api/v1/";
}
$.ajax({
url: _data.myPersonalDataUrl +
"kpidata/public/?sourceRequest=iotapp&highLevelType=MyKPI&accessToken=" +
accessToken,
type: "GET",
async: true,
dataType: "json",
success: function (_data) {
createKPIDataSelection(_data);
},
error: function (err) {
console.log(err);
}
});
}
});
}
}
var initChangeAuthenticationPublicKPIData = function () {
$("#node-input-kpiId").val("");
var accessToken = "";
var kpiDataList = "";
$.ajax({
url: "retrieveAccessTokenAuthentication",
type: "POST",
async: false,
dataType: "json",
data: {
"authenticationNodeId": $("#node-input-authentication").val(),
"nodeId": $("#node-input-currentNodeId").val()
},
success: function (_data) {
if (_data.accessToken == "") {
$("#selectKpiDataContainer").hide();
$('#tipAuthenticationWrong').show();
$('#tipAuthentication').hide();
} else {
accessToken = _data.accessToken;
};
}
});
refreshPublicKPIDataSelection(accessToken, kpiDataList);
}
</script>
<script type="text/x-red" data-template-name="get-public-kpidata-values">
<input type="hidden" id="node-input-name">
<input type="hidden" id="node-input-currentNodeId">
<input type="hidden" id="node-input-selectedKPIDataId">
<div class="form-row" id="rowAuthentication">
<label for="node-input-authentication">Authentication</label>
<input type="text" id="node-input-authentication">
</div>
<div class="form-row" id="selectKpiDataContainer">
<label for="node-input-kpiId">
<i class="fa fa-dashboard"></i>Select KPI</label>
<select id="node-input-kpiId" style="width: 55%;">
</select>
</div>
<div class="form-row">
<label for="node-input-startdate">Start Date</label>
<input type="text" id="node-input-startdate" placeholder="yyyy-MM-ddTHH:mmX or timestamp">
</div>
<div class="form-row">
<label for="node-input-enddate">End Date</label>
<input type="text" id="node-input-enddate" placeholder="yyyy-MM-ddTHH:mmX or timestamp">
</div>
<div class="form-row">
<label for="node-input-last">Last</label>
<select id="node-input-last">
<option value="1">1</option>
<option value="2">2</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
</select>
</div>
<div class="form-tips" id="tipAuthentication" style="max-width: none">
You must have an account with Snap4city to use this node. You can register for one <a href="https://www.snap4city.org" target="_blank">here</a>.
</div>
<div class="form-tips" id="tipAuthenticationWrong" style="display:none; max-width: none">
Maybe the authentication data are wrong. Check them and redeploy the node.
</div>
<div class="form-tips" id="tipAuthenticationRedeploy" style="display:none; max-width: none">
Deploy the node to retrieve the updated list of dashboards.
</div>
<div class="form-tips" id="tipAuthenticationDeployFirstTime" style="display:none; max-width: none">
Insert the authentication data and deploy the node to retrieve the updated list of dashboards.
</div>
</script>
<script type="text/x-red" data-help-name="get-public-kpidata-values">
<p>It allows to retrieve the personal data inserted in My Personal KPI Data.</p>
<h3>Inputs</h3>
A JSON with these parameters:
<dl class="message-properties">
<dt>id
<span class="property-type">number</span>
</dt>
<dd> the id of the kpi data</dd>
<dt>startdate
<span class="property-type">string or number</span>
</dt>
<dd> Start date of the data search period in the format yyyy-MM-ddTHH:mmX (where X is the timezone) or timestamp
<dt>enddate
<span class="property-type">string or number</span>
</dt>
<dd>Start date of the data search period in the format yyyy-MM-ddTHH:mmX (where X is the timezone) or timestamp
<dt>last
<span class="property-type">number</span>
</dt>
<dd>If selected, it only retrieves the last n (where n is the value inserted) data of the inserted period</dd>
</dl>
<p>An example of the JSON array filled with correct data:</p>
<pre>
{
"id": 17849,
"startdate": "2020-04-14T16:30Z",
"enddate": "2020-04-16T18:30Z",
"last": 5
}
</pre>
<h3>Outputs</h3>
<dl class="message-properties">
<dd> Returns an array containing the data that have been saved in the search period</dd>
</dl>
<h3>Details</h3>
<p>The node can receive a JSON with the parameters described in the Inputs section and with them generate the output JSON.
If the values are not present in the input JSON, these are read by those in the configuration. If they are not present
in either part, an error is generated for the necessary parameters.</p>
</script>