From a0c8aeb1594cda000561fcec9a7917c3e82f067c Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 17 Nov 2016 18:35:40 +0530 Subject: [PATCH] few changes after testing feature manager implementation --- .../ConfigurationBasedFeatureManager.java | 11 ++++----- .../modules/business-controllers/operation.js | 23 ++++++++----------- .../operation-bar.hbs | 13 +++++++---- .../operation-bar.js | 9 ++++++++ .../public/js/operation-bar.js | 8 ++++++- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/feature/ConfigurationBasedFeatureManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/feature/ConfigurationBasedFeatureManager.java index fb100be94b..7e53718442 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/feature/ConfigurationBasedFeatureManager.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/feature/ConfigurationBasedFeatureManager.java @@ -42,10 +42,6 @@ public class ConfigurationBasedFeatureManager implements FeatureManager { private static final String QUERY_PARAMS = "queryParams"; private static final String FORM_PARAMS = "formParams"; private static final Pattern PATH_PARAM_REGEX = Pattern.compile("\\{(.*?)\\}"); - private List pathParams = new ArrayList<>(); - private List queryParams = new ArrayList<>(); - private List formParams = new ArrayList<>(); - public ConfigurationBasedFeatureManager( List features) { @@ -59,7 +55,10 @@ public class ConfigurationBasedFeatureManager implements FeatureManager { Map apiParams = new HashMap<>(); apiParams.put(METHOD, operation.getMethod().toUpperCase()); apiParams.put(URI, operation.getContext()); - setPathParams(operation.getContext()); + List pathParams = new ArrayList<>(); + List queryParams = new ArrayList<>(); + List formParams = new ArrayList<>(); + setPathParams(operation.getContext(), pathParams); apiParams.put(PATH_PARAMS, pathParams); if (operation.getQueryParameters() != null) { queryParams = operation.getQueryParameters().getParameter(); @@ -116,7 +115,7 @@ public class ConfigurationBasedFeatureManager implements FeatureManager { return false; } - private void setPathParams(String context) { + private void setPathParams(String context, List pathParams) { Matcher regexMatcher = PATH_PARAM_REGEX.matcher(context); while (regexMatcher.find()) { pathParams.add(regexMatcher.group(1)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index c34cc04302..fd85d978f6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -45,16 +45,6 @@ var operationModule = function () { var feature; for (var i = 0; i < features.length; i++) { feature = {}; - var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; - if (analyticStreams) { - for (var stream in analyticStreams) { - if (analyticStreams[stream].name == features[i].name) { - feature.ui_unit = analyticStreams[stream].ui_unit; - break; - } - } - } - feature["operation"] = features[i].code; feature["name"] = features[i].name; feature["description"] = features[i].description; @@ -80,10 +70,17 @@ var operationModule = function () { publicMethods.getControlOperations = function (deviceType) { var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); + var features = utility.getDeviceTypeConfig(deviceType).deviceType.features; for (var op in operations) { - var iconPath = utility.getOperationIcon(deviceType, operations[op].operation); - if (iconPath) { - operations[op]["icon"] = iconPath; + var iconIdentifier = operations[op].operation; + if (features[iconIdentifier]) { + var icon = features[iconIdentifier].icon; + if (icon) { + operations[op]["iconFont"] = icon; + } else if (iconPath) { + var iconPath = utility.getOperationIcon(deviceType, iconIdentifier); + operations[op]["icon"] = iconPath; + } } } return operations; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.hbs index ca52690eb0..fe87cb7896 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.hbs @@ -36,10 +36,14 @@ {{#each control_operations}} - {{#if icon}} - + {{#if iconFont}} + {{else}} - + {{#if icon}} + + {{else}} + + {{/if}} {{/if}} {{name}} @@ -61,7 +65,8 @@
-
+ {{#each params.0.pathParams}}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.js index d1a58b9bd3..f556252439 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/operation-bar.js @@ -21,6 +21,7 @@ function onRequest(context) { var operationModule = require("/app/modules/business-controllers/operation.js")["operationModule"]; var device = context.unit.params.device; var autoCompleteParams = context.unit.params.autoCompleteParams; + var encodedFeaturePayloads=context.unit.params.encodedFeaturePayloads; var controlOperations = operationModule.getControlOperations(device.type); var queryParams = []; var formParams = []; @@ -34,6 +35,9 @@ function onRequest(context) { currentParamList[j]["pathParams"] = processParams(currentParam["pathParams"], autoCompleteParams); } controlOperations[i]["params"] = currentParamList; + if (encodedFeaturePayloads) { + controlOperations[i]["payload"] = getPayload(encodedFeaturePayloads, controlOperations[i]["operation"]); + } } return {"control_operations": controlOperations, "device": device}; } @@ -52,4 +56,9 @@ function processParams(paramsList, autoCompleteParams) { paramsList[i] = {"name": paramName, "value": paramValue, "type": paramType}; } return paramsList; +} + +function getPayload(featuresPayload, featureCode){ + var featuresJSONPayloads = JSON.parse(featuresPayload); + return featuresJSONPayloads[featureCode]; } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js index 68bb7f5f18..f577f90545 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js @@ -50,10 +50,16 @@ function submitForm(formId) { var httpMethod = form.attr("method").toUpperCase(); var contentType = form.attr("enctype"); console.log(payload); - if (contentType == undefined || contentType.isEmpty()) { + var featurePayload = form.attr("data-payload"); + if (featurePayload) { + contentType = "application/json"; + payload = JSON.parse(atob(featurePayload)); + + } else if (contentType == undefined || contentType.isEmpty()) { contentType = "application/x-www-form-urlencoded"; payload = uriencodedFormStr; } + alert(featurePayload); //setting responses callbacks var defaultStatusClasses = "fw fw-stack-1x"; var content = $("#operation-response-template").find(".content");