fixing icon issue in operation bar

4.x.x
kamidu 8 years ago committed by amalhub
parent 16b67bebda
commit 2c20070720

@ -40,52 +40,66 @@ var operationModule = function () {
privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { privateMethods.getOperationsFromFeatures = function (deviceType, operationType) {
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types/" + deviceType + "/features"; var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types/" + deviceType + "/features";
var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
var features = JSON.parse(responsePayload.responseText); var features = JSON.parse(responsePayload.responseText);
var featureList = []; var featureList = [];
var feature; var feature;
for (var i = 0; i < features.length; i++) { for (var i = 0; i < features.length; i++) {
feature = {}; feature = {};
feature["operation"] = features[i].code; feature["operation"] = features[i].code;
feature["name"] = features[i].name; feature["name"] = features[i].name;
feature["description"] = features[i].description; feature["description"] = features[i].description;
feature["contentType"] = features[i].contentType; feature["contentType"] = features[i].contentType;
feature["deviceType"] = deviceType; feature["deviceType"] = deviceType;
feature["params"] = []; feature["params"] = [];
var featuresEntry = utility.getDeviceTypeConfig(deviceType)["deviceType"]["features"]; var featuresEntry = utility.getDeviceTypeConfig(deviceType)["deviceType"]["features"];
if (featuresEntry) { if (featuresEntry) {
var featureEntry = featuresEntry[features[i].code]; var featureEntry = featuresEntry[features[i].code];
if (featureEntry) { if (featureEntry) {
var permissionEntry = featureEntry["permission"]; var permissionEntry = featureEntry["permission"];
if (permissionEntry) { if (permissionEntry) {
feature["permission"] = permissionEntry feature["permission"] = permissionEntry
} }
} }
} }
var metaData = features[i].metadataEntries; var metaData = features[i].metadataEntries;
if (metaData) { if (metaData) {
for (var j = 0; j < metaData.length; j++) { for (var j = 0; j < metaData.length; j++) {
feature["params"].push(metaData[j].value); feature["params"].push(metaData[j].value);
} }
featureList.push(feature); featureList.push(feature);
} }
} }
return featureList; return featureList;
}, function (responsePayload) { }, function (responsePayload) {
var response = {}; var response = {};
response["status"] = "error"; response["status"] = "error";
return response; return response;
} }
); );
return featuresList; return featuresList;
}; };
publicMethods.getControlOperations = function (deviceType) { publicMethods.getControlOperations = function (deviceType) {
var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation");
var features = utility.getDeviceTypeConfig(deviceType).deviceType.features;
for (var op in operations) { for (var op in operations) {
var iconIdentifier = operations[op].operation; var iconIdentifier = operations[op].operation;
var icon = utility.getOperationIcon(deviceType, iconIdentifier); if (features && features[iconIdentifier]) {
if (icon) { var icon = features[iconIdentifier].icon;
operations[op]["icon"] = icon; if (icon) {
operations[op]["iconFont"] = icon;
} else if (iconPath) {
var iconPath = utility.getOperationIcon(deviceType, iconIdentifier);
operations[op]["icon"] = iconPath;
}
var formParams = features[iconIdentifier].formParams;
if (formParams) {
operations[op]["uiParams"] = formParams;
}
// var icon = utility.getOperationIcon(deviceType, iconIdentifier);
// if (icon) {
// log.error("icon found : " + icon );
// operations[op]["icon"] = icon;
} }
} }
return operations; return operations;
@ -99,9 +113,9 @@ var operationModule = function () {
var user = session.get(constants.USER_SESSION_KEY); var user = session.get(constants.USER_SESSION_KEY);
var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation;
var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId +
'","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' +
constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX +
getAccessToken(deviceType, user.username, deviceId) + '"}'; getAccessToken(deviceType, user.username, deviceId) + '"}';
return post(endPoint, params, JSON.parse(header), "json"); return post(endPoint, params, JSON.parse(header), "json");
}; };
@ -109,9 +123,9 @@ var operationModule = function () {
var user = session.get(constants.USER_SESSION_KEY); var user = session.get(constants.USER_SESSION_KEY);
var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation;
var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId +
'","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' + '","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' +
constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) + constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) +
'"}'; '"}';
var result = get(endPoint, {}, JSON.parse(header), "json"); var result = get(endPoint, {}, JSON.parse(header), "json");
if (result.data) { if (result.data) {
var values = result.data.sensorValue.split(','); var values = result.data.sensorValue.split(',');

Loading…
Cancel
Save