"use strict";
/**
* Concatenates up to 9 arrays (assuming the number of columns are the same in each array.
* @param {array} ar1, ar2 ... ar 9 arrays to be concatenated.
* @return joined (concatenated array)
* @customfunction
*/
function arrayConcat(ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9) {
var rsp = ar1;
if (ar2 != null) {rsp = rsp.concat(ar2);}
if (ar3 != null) {rsp = rsp.concat(ar3);}
if (ar4 != null) {rsp = rsp.concat(ar4);}
if (ar5 != null) {rsp = rsp.concat(ar5);}
if (ar6 != null) {rsp = rsp.concat(ar6);}
if (ar7 != null) {rsp = rsp.concat(ar7);}
if (ar8 != null) {rsp = rsp.concat(ar8);}
if (ar9 != null) {rsp = rsp.concat(ar9);}
return rsp;
}
/**
* Joins two arrays (of different data) on column values in array 2, equalling column values in array 1.
* @param {array} ar1 ar1 first array to be joined.
* @param {array} ar2 ar2 second array to be joined.
* @param {col1} col1 col1 joining column in array 1
* @param {col2} col2 col2 joing column in array 2
* @return joined arrays
* @customfunction
*/
function arrayJoin(ar1, col1, ar2, col2) {
var rsp = [];
for (var i = 0; i < ar1.length; i++){
for (var j=0; j < ar2.length; j++){
if (ar1[i][col1-1] === ar2[j][col2-1]) {
rsp.push(arrayConcat(ar1[i],ar2[j]));
// rsp.push(ar1[i]);
// rsp.push(ar1[i]);
}
}
}
return rsp;
}
/**
* Gets a list of configuration ID for various single core cable installations.
* ConfigurationID and description.
* @param {boolean} header header optional parameter, will display header row if set to true
* @return ID and description.
* @customfunction
*/
function configurations(header) {
var json = httpGetCall("electrical/installation/singleCoreConfigurations");
var data = JSON.parse(json);
var result = dataItemArray(data,enDataType.configurations, header);
return result;
}
/**
* Verify connection and authorisation to the Electrical Functions API server. Returns 'true' if successful.
* @return Returns 'true' if successful
* @customfunction
*/
function verify() {
var json = httpGetCall("utilities/verify");
var data = JSON.parse(json);
return (data == "undefined") ? false: true;
}