Merge pull request #235 from rasika90/master

Allowing Auto Completing API Params on Operations Bar
revert-dabc3590
Ruwan 9 years ago
commit e88adfd71f

@ -46,15 +46,15 @@
<form action="{{@unit.params.backendApiUri}}{{params.0.uri}}" method="{{method}}" style="padding-bottom: 20px;" id="form-{{operation}}"> <form action="{{@unit.params.backendApiUri}}{{params.0.uri}}" method="{{method}}" style="padding-bottom: 20px;" id="form-{{operation}}">
{{#each params.0.pathParams}} {{#each params.0.pathParams}}
<input type="text" id="{{this}}" placeholder="{{this}}" class="form-control" data-param-type="path" /> <input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="path" value="{{value}}" />
<br /> <br />
{{/each}} {{/each}}
{{#each params.0.formParams}} {{#each params.0.formParams}}
<input type="text" id="{{this}}" name="{{this}}" placeholder="{{this}}" class="form-control" data-param-type="form" /> <input type="{{type}}" id="{{name}}" name="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="form" value="{{value}}" />
<br /> <br />
{{/each}} {{/each}}
{{#each params.0.queryParams}} {{#each params.0.queryParams}}
<input type="text" id="{{this}}" placeholder="{{this}}" class="form-control" data-param-type="query" /> <input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="query" value="{{value}}" />
<br /> <br />
{{/each}} {{/each}}
<button id="btnSend" type="button" onclick="submitForm('form-{{operation}}')" class="btn btn-default">&nbsp;&nbsp;&nbsp;&nbsp;Send <button id="btnSend" type="button" onclick="submitForm('form-{{operation}}')" class="btn btn-default">&nbsp;&nbsp;&nbsp;&nbsp;Send

@ -20,6 +20,36 @@ function onRequest(context) {
var log = new Log("operation.js"); var log = new Log("operation.js");
var operationModule = require("/app/modules/operation.js").operationModule; var operationModule = require("/app/modules/operation.js").operationModule;
var device = context.unit.params.device; var device = context.unit.params.device;
var autoCompleteParams = context.unit.params.autoCompleteParams;
var controlOperations = operationModule.getControlOperations(device.type); var controlOperations = operationModule.getControlOperations(device.type);
var queryParams = [];
var formParams = [];
var pathParams = [];
for (var i = 0; i < controlOperations.length; i++) {
var currentParamList = controlOperations[i]["params"];
for (var j = 0; j < currentParamList.length; j++) {
var currentParam = currentParamList[j];
currentParamList[j]["formParams"] = processParams(currentParam["formParams"], autoCompleteParams);
currentParamList[j]["queryParams"] = processParams(currentParam["queryParams"], autoCompleteParams);
currentParamList[j]["pathParams"] = processParams(currentParam["pathParams"], autoCompleteParams);
}
controlOperations[i]["params"] = currentParamList;
}
return {"control_operations": controlOperations, "device": device}; return {"control_operations": controlOperations, "device": device};
} }
function processParams(paramsList, autoCompleteParams) {
for (var i = 0; i < paramsList.length; i++) {
var paramName = paramsList[i];
var paramValue = "";
var paramType = "text";
for (var k = 0; k < autoCompleteParams.length; k++) {
if (paramName == autoCompleteParams[k].name) {
paramValue = autoCompleteParams[k].value;
paramType = "hidden";
}
}
paramsList[i] = {"name": paramName, "value": paramValue, "type": paramType};
}
return paramsList;
}

@ -15,7 +15,7 @@
Operations Operations
</div> </div>
<div class="add-margin-top-4x"> <div class="add-margin-top-4x">
{{unit "iot.unit.device.operation-bar" device=device backendApiUri=backendApiUri}} {{unit "iot.unit.device.operation-bar" device=device backendApiUri=backendApiUri autoCompleteParams=autoCompleteParams}}
</div> </div>
{{/zone}} {{/zone}}

@ -20,12 +20,16 @@ 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 autoCompleteParams = [
{"name" : "deviceId", "value" : deviceId},
{"name" : "protocol", "value" : "MQTT"}
];
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/app/modules/device.js").deviceModule; var deviceModule = require("/app/modules/device.js").deviceModule;
var device = deviceModule.viewDevice(deviceType, deviceId); var device = deviceModule.viewDevice(deviceType, deviceId);
if (device && device.status != "error") { if (device && device.status != "error") {
return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/virtual_firealarm/"}; return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/virtual_firealarm/", "autoCompleteParams" : autoCompleteParams};
} else { } else {
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
exit(); exit();

Loading…
Cancel
Save