mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
few changes after testing feature manager implementation
This commit is contained in:
parent
2f59f1566c
commit
a0c8aeb159
@ -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<String> pathParams = new ArrayList<>();
|
||||
private List<String> queryParams = new ArrayList<>();
|
||||
private List<String> formParams = new ArrayList<>();
|
||||
|
||||
|
||||
public ConfigurationBasedFeatureManager(
|
||||
List<org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature> features) {
|
||||
@ -59,7 +55,10 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
|
||||
Map<String, Object> apiParams = new HashMap<>();
|
||||
apiParams.put(METHOD, operation.getMethod().toUpperCase());
|
||||
apiParams.put(URI, operation.getContext());
|
||||
setPathParams(operation.getContext());
|
||||
List<String> pathParams = new ArrayList<>();
|
||||
List<String> queryParams = new ArrayList<>();
|
||||
List<String> 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<String> pathParams) {
|
||||
Matcher regexMatcher = PATH_PARAM_REGEX.matcher(context);
|
||||
while (regexMatcher.find()) {
|
||||
pathParams.add(regexMatcher.group(1));
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -36,10 +36,14 @@
|
||||
</style>
|
||||
{{#each control_operations}}
|
||||
<a href="javascript:operationSelect('{{operation}}')">
|
||||
{{#if icon}}
|
||||
<img src="{{@app.context}}/{{icon}}" style="width: 48px;"/>
|
||||
{{#if iconFont}}
|
||||
<i class="fw {{iconFont}}"></i>
|
||||
{{else}}
|
||||
<i class="fw fw-service"></i>
|
||||
{{#if icon}}
|
||||
<img src="{{@app.context}}/{{icon}}" style="width: 48px;"/>
|
||||
{{else}}
|
||||
<i class="fw fw-service"></i>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<span>{{name}}</span>
|
||||
</a>
|
||||
@ -61,7 +65,8 @@
|
||||
<br>
|
||||
</h4>
|
||||
|
||||
<form action="{{@unit.params.backendApiUri}}{{params.0.uri}}" method="{{params.0.method}}" style="padding-bottom: 20px;" id="form-{{operation}}">
|
||||
<form action="{{params.0.uri}}" method="{{params.0.method}}" style="padding-bottom: 20px;"
|
||||
data-payload="{{payload}}" id="form-{{operation}}">
|
||||
{{#each params.0.pathParams}}
|
||||
<input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="path" value="{{value}}" />
|
||||
<br />
|
||||
|
||||
@ -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];
|
||||
}
|
||||
@ -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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user