@isaac-platform/isaac-node-red
Version:
Set of Node-RED nodes to communicate with an ISAAC system
110 lines (97 loc) • 2.93 kB
HTML
<script type="text/javascript">
function isValidIpAddress(ipAddress) {
return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
ipAddress,
);
}
function parseUrl(value) {
let url = value;
if (!url.match(/^[a-zA-Z]+:\/\//)) {
url = `http://${url}`;
}
return new URL(url);
}
RED.nodes.registerType('isaac-connection', {
category: 'config',
color: '#C0C0C0',
icon: 'isaac.svg',
defaults: {
ipAddress: {
value: '',
required: true,
validate: (value) => {
try {
const parsedUrl = parseUrl(value);
return isValidIpAddress(parsedUrl.host);
} catch (e) {
return false;
}
},
},
subsystemExternalId: { value: '', required: true },
accessToken: { value: '', required: false },
},
label: function () {
return `${this.subsystemExternalId} - ${this.ipAddress}`;
},
oneditsave: function () {
var node = this;
const value = $('#node-config-input-ipAddress').val();
let parsedUrl;
try {
parsedUrl = parseUrl(value);
} catch (e) {
console.error(e);
RED.notify(`"${value}" is not a valid URL`, {
type: 'error',
});
return;
}
if (!isValidIpAddress(parsedUrl.host)) {
// since the validate only marks the field with a red border, this will actually
// alert the user (via RED.notify) that the IP address format is invalid.
RED.notify('Invalid IP, must be in valid IP format, ie: 127.0.0.1', {
type: 'error',
});
return;
}
$('#node-config-input-ipAddress').val(parsedUrl.origin);
},
});
</script>
<style>
.form-row.inline {
display: flex;
}
.block {
display: block;
}
.full-width {
width: 100% ;
}
</style>
<script type="text/html" data-template-name="isaac-connection">
<div class="form-row">
<label for="node-config-input-ipAddress">IP Address</label>
<input type="text" id="node-config-input-ipAddress" />
</div>
<div class="form-row">
<label for="node-config-input-subsystemExternalId">Subsystem External Id</label>
<input type="text" id="node-config-input-subsystemExternalId" />
</div>
<div class="form-row">
<label for="node-config-input-accessToken">Access Token</label>
<input type="text" id="node-config-input-accessToken" />
</div>
</script>
<script type="text/html" data-help-name="isaac-connection">
<p>
In order for any of the nodes to connect correctly to ISAAC, some information is required here before beginning.
</p>
<p>IP Address: The IP Address of the ISAAC instance.</p>
<p>
Subsystem External Id: The external Id of the subsystem. This is user-provided when creating the module within
ISAAC. The external Id for the ISAAC module is: <code>ISAAC_DEFAULT_SUBSYSTEM</code>
</p>
<p>Access Token: The token of the ISAAC user to use to perform operations.</p>
</script>