|
|
@ -18,38 +18,41 @@
|
|
|
|
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
|
|
|
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
|
|
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
|
|
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
|
|
|
var process = require("process");
|
|
|
|
var process = require("process");
|
|
|
|
|
|
|
|
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
|
|
|
function onRequest(context) {
|
|
|
|
function onRequest(context) {
|
|
|
|
var log = new Log("device-view.js");
|
|
|
|
var log = new Log("device-view.js");
|
|
|
|
var deviceType = context.uriParams.deviceType;
|
|
|
|
var deviceType = context.uriParams.deviceType;
|
|
|
|
var deviceId = request.getParameter("id");
|
|
|
|
var deviceId = request.getParameter("id");
|
|
|
|
var attributes = [];
|
|
|
|
var attributes = [];
|
|
|
|
var featureList = [];
|
|
|
|
var featureList = [];
|
|
|
|
|
|
|
|
var user = userModule.getCarbonUser();
|
|
|
|
|
|
|
|
var tenantDomain = user.domain;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var autoCompleteParams = [
|
|
|
|
|
|
|
|
{"name" : "deviceId", "value" : deviceId}
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
context.handlebars.registerHelper('if_eq', function(a, b, opts) {
|
|
|
|
|
|
|
|
if(a == b) // Or === depending on your needs
|
|
|
|
|
|
|
|
return opts.fn(this);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return opts.inverse(this);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var displayData = {};
|
|
|
|
|
|
|
|
|
|
|
|
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
|
|
|
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
|
|
|
+ "/events/" + deviceType;
|
|
|
|
+ "/device-types/config/" + deviceType;
|
|
|
|
|
|
|
|
displayData.deviceType = deviceType;
|
|
|
|
|
|
|
|
displayData.tenantDomain = tenantDomain;
|
|
|
|
serviceInvokers.XMLHttp.get(
|
|
|
|
serviceInvokers.XMLHttp.get(
|
|
|
|
restAPIEndpoint,
|
|
|
|
restAPIEndpoint,
|
|
|
|
function (restAPIResponse) {
|
|
|
|
function (restAPIResponse) {
|
|
|
|
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
|
|
|
if (restAPIResponse["status"] == 200 && restAPIResponse["responseText"]) {
|
|
|
|
var data = parse(restAPIResponse["responseText"]);
|
|
|
|
var typeData = parse(restAPIResponse["responseText"]);
|
|
|
|
if (data.eventAttributes.attributes.length > 0) {
|
|
|
|
displayData.type = typeData;
|
|
|
|
for (var i = 0; i < data.eventAttributes.attributes.length; i++) {
|
|
|
|
if (typeData.deviceTypeMetaDefinition) {
|
|
|
|
var attribute = data.eventAttributes.attributes[i];
|
|
|
|
var features = typeData.deviceTypeMetaDefinition.features;
|
|
|
|
if (attribute['name'] == "deviceId") {
|
|
|
|
if (features) {
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes.push(attribute['name']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var featureEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
|
|
|
|
|
|
|
+ "/device-types/" + deviceType + "/features";
|
|
|
|
|
|
|
|
serviceInvokers.XMLHttp.get(featureEndpoint, function (responsePayload) {
|
|
|
|
|
|
|
|
var features = JSON.parse(responsePayload.responseText);
|
|
|
|
|
|
|
|
var feature;
|
|
|
|
var feature;
|
|
|
|
for (var i = 0; i < features.length; i++) {
|
|
|
|
for (var i = 0; i < features.length; i++) {
|
|
|
|
feature = {};
|
|
|
|
feature = {};
|
|
|
@ -58,22 +61,12 @@ function onRequest(context) {
|
|
|
|
feature["description"] = features[i].description;
|
|
|
|
feature["description"] = features[i].description;
|
|
|
|
featureList.push(feature);
|
|
|
|
featureList.push(feature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}, function (responsePayload) {
|
|
|
|
}
|
|
|
|
featureList = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
var autoCompleteParams = [
|
|
|
|
|
|
|
|
{"name" : "deviceId", "value" : deviceId}
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
context.handlebars.registerHelper('if_eq', function(a, b, opts) {
|
|
|
|
|
|
|
|
if(a == b) // Or === depending on your needs
|
|
|
|
|
|
|
|
return opts.fn(this);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return opts.inverse(this);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var displayData = {};
|
|
|
|
|
|
|
|
var eventRestAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
|
|
|
var eventRestAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"]
|
|
|
|
+ "/events/" + deviceType;
|
|
|
|
+ "/events/" + deviceType;
|
|
|
|
serviceInvokers.XMLHttp.get(
|
|
|
|
serviceInvokers.XMLHttp.get(
|
|
|
@ -87,6 +80,11 @@ function onRequest(context) {
|
|
|
|
var eventExample = {};
|
|
|
|
var eventExample = {};
|
|
|
|
for (var i = 0; i < typeData.eventAttributes.attributes.length; i++) {
|
|
|
|
for (var i = 0; i < typeData.eventAttributes.attributes.length; i++) {
|
|
|
|
var attribute = typeData.eventAttributes.attributes[i];
|
|
|
|
var attribute = typeData.eventAttributes.attributes[i];
|
|
|
|
|
|
|
|
if (attribute['name'] == "deviceId") {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes.push(attribute['name']);
|
|
|
|
|
|
|
|
|
|
|
|
switch (attribute.type) {
|
|
|
|
switch (attribute.type) {
|
|
|
|
case "STRING":
|
|
|
|
case "STRING":
|
|
|
|
eventExample[attribute.name] = "string";
|
|
|
|
eventExample[attribute.name] = "string";
|
|
|
@ -129,6 +127,8 @@ function onRequest(context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
displayData.tenantDomain = tenantDomain;
|
|
|
|
|
|
|
|
|
|
|
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
|
|
|
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
|
|
|
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
|
|
|
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
|
|
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
|
|
|
var device = deviceModule.viewDevice(deviceType, deviceId);
|
|
|
|