Add device type specific platform config UIs

4.x.x
Charitha Goonetilleke 6 years ago
parent c1118363d8
commit fbaf21adc6

@ -348,7 +348,7 @@ public interface DeviceTypeManagementService {
value = "The device type name, such as ios, android, windows or fire-alarm.",
required = true)
@PathParam("type")
@Size(max = 45)
@Size(min = 2, max = 45)
String type,
@ApiParam(
name = "If-Modified-Since",

@ -83,7 +83,7 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
@Override
@GET
@Path("/{type}")
public Response getDeviceTypeByName(@PathParam("type") @Size(max = 45) String type) {
public Response getDeviceTypeByName(@PathParam("type") @Size(min = 2, max = 45) String type) {
if (type != null && type.length() > 0) {
try {
DeviceType deviceType = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(type);
@ -129,11 +129,16 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
@GET
@Override
@Path("/{type}/configs")
public Response getConfigs(@PathParam("type") @Size(max = 45) String type,
public Response getConfigs(@PathParam("type") @Size(min = 2, max = 45) String type,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
PlatformConfiguration platformConfiguration;
try {
platformConfiguration = DeviceMgtAPIUtils.getDeviceManagementService().getConfiguration(type);
if (platformConfiguration == null) {
platformConfiguration = new PlatformConfiguration();
platformConfiguration.setType(type);
platformConfiguration.setConfiguration(new ArrayList<>());
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the '" + type + "' platform configuration";
log.error(msg, e);

@ -3,7 +3,7 @@
{{#each applications}}
<a style="text-align: center;width: 100px;height: 100px;">
{{#equal platform "android"}}<i class="fw fw-android"></i>{{/equal}}
{{#equal platform "ios"}}<i class="fw fw-apple"></i>{{/equal}}
{{#equal platform "ios"}}<i class="fw fw-ios"></i>{{/equal}}
{{#equal platform "windows"}}<i class="fw fw-windows"></i>{{/equal}}
<span>{{name}}</span>
</a>

@ -0,0 +1,41 @@
{{!
Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
WSO2 Inc. licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file except
in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
}}
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h2 class="sub-title panel-title">
Platform Configuration - {{@unit.params.deviceType}}
</h2>
</div>
<div id="{{@unit.params.deviceType}}-config-body" class="panel-collapse panel-body" role="tabpanel">
<div id="{{@unit.params.deviceType}}-config-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div class="form-group" id="{{@unit.params.deviceType}}-config-field-wrapper">
</div>
<div class="wr-input-control wr-btn-grp">
<button class="wr-btn" onclick="onDynamicConfigSubmit('{{@unit.params.deviceType}}')">Save</button>
</div>
</div>
</div>
{{#zone "bottomJs"}}
<script type="text/javascript">
$(document).ready(function () {
loadDynamicDeviceTypeConfig('{{@unit.params.deviceType}}');
});
</script>
{{/zone}}

@ -15,6 +15,11 @@
specific language governing permissions and limitations
under the License.
}}
{{#zone "topCss"}}
{{css "css/platform-configuration.css"}}
{{/zone}}
{{#zone "content"}}
{{#if isAuthorized}}
<div class="row">
@ -37,7 +42,7 @@
<br>
<div class="wr-advance-operations">
<div class="row no-gutter">
<div class="row">
<div class="wr-hidden-operations-nav col-lg-4">
{{#unless isCloud}}
@ -63,7 +68,11 @@
<span class="fw-stack fw-move-right fw-move-bottom">
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
<i class="fw fw-circle fw-stack-2x"></i>
<i class="fw fw-{{name}} fw-stack-1x fw-inverse"></i>
{{#if unitName}}
<i class="fw fw-{{name}} fw-stack-1x fw-inverse"></i>
{{else}}
<i class="fw fw-devices fw-stack-1x fw-inverse"></i>
{{/if}}
</span>
</span>
{{label}} Configurations
@ -124,7 +133,11 @@
<!-- general-->
{{#each deviceTypes}}
<div class="wr-hidden-operation" data-operation="{{name}}" style="display: none;">
{{unit unitName}}
{{#if unitName}}
{{unit unitName deviceType=name}}
{{else}}
{{unit "cdmf.unit.dynamic.platform.configuration" deviceType=name}}
{{/if}}
</div>
{{/each}}

@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
function onRequest(context) {
@ -29,23 +46,23 @@ function onRequest(context) {
var deviceTypesArray = [];
var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") {
var data = typesListResponse["content"].deviceTypes;
var data = typesListResponse["content"];
if (data) {
for (var i = 0; i < data.length; i++) {
var deviceTypeName = data[i];
var deviceTypeName = data[i].name;
var deviceTypeLabel = deviceTypeName.charAt(0).toUpperCase() + deviceTypeName.slice(1);;
var configUnitName = utility.getTenantedDeviceUnitName(deviceTypeName, "platform.configuration");
if (configUnitName) {
var deviceTypeConfig = utility.getDeviceTypeConfig(deviceTypeName);
var deviceTypeLabel = deviceTypeName;
if (deviceTypeConfig) {
deviceTypeLabel = deviceTypeConfig.deviceType.label;
}
deviceTypesArray.push({
name: deviceTypeName,
label: deviceTypeLabel,
unitName: configUnitName
});
}
deviceTypesArray.push({
name: deviceTypeName,
label: deviceTypeLabel,
unitName: configUnitName
});
}
}
}

@ -16,6 +16,8 @@
* under the License.
*/
var configRowId = 0;
$(document).ready(function () {
var configParams = {
@ -41,25 +43,25 @@ $(document).ready(function () {
}
invokerUtil.get(
"/api/device-mgt/v1.0/configuration",
function (data) {
data = JSON.parse(data);
if (data && data.configuration) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == configParams["NOTIFIER_FREQUENCY"]) {
$("input#monitoring-config-frequency").val(config.value / 1000);
}
"/api/device-mgt/v1.0/configuration",
function (data) {
data = JSON.parse(data);
if (data && data.configuration) {
for (var i = 0; i < data.configuration.length; i++) {
var config = data.configuration[i];
if (config.name == configParams["NOTIFIER_FREQUENCY"]) {
$("input#monitoring-config-frequency").val(config.value / 1000);
}
}
}, function (data) {
console.log(data);
});
}
}, function (data) {
console.log(data);
});
/**
* Following click function would execute
* when a user clicks on "Save" button
* on General platform configuration page in WSO2 EMM Console.
* on General platform configuration page in Entgra devicemgt Console.
*/
$("button#save-general-btn").click(function () {
var notifierFrequency = $("input#monitoring-config-frequency").val();
@ -87,33 +89,33 @@ $(document).ready(function () {
var addConfigAPI = "/api/device-mgt/v1.0/configuration";
invokerUtil.put(
addConfigAPI,
addConfigFormData,
function (data, textStatus, jqXHR) {
data = jqXHR.status;
if (data == 200) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}, function (data) {
data = data.status;
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
addConfigAPI,
addConfigFormData,
function (data, textStatus, jqXHR) {
data = jqXHR.status;
if (data == 200) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}, function (data) {
data = data.status;
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}
);
}
});
@ -154,3 +156,121 @@ var artifactGeoUpload = function () {
showPopup();
}, contentType);
};
var loadDynamicDeviceTypeConfig = function (deviceType) {
var configAPI = '/api/device-mgt/v1.0/device-types/' + deviceType + '/configs';
invokerUtil.get(
configAPI,
function (data) {
data = JSON.parse(data);
var fieldWrapper = "#" + deviceType + "-config-field-wrapper";
$(fieldWrapper).html("");
if (data.configuration) {
var config;
var i;
for (i = 0; i < data.configuration.length; i++) {
config = data.configuration[i];
onDynamicConfigAddNew(deviceType, config.name, config.value);
}
}
$(fieldWrapper).append(
'<div class="row form-group ' + deviceType + '-config-row"' +
' id="' + deviceType + '-config-row-' + (++configRowId) + '">' +
'<div class="col-xs-3">' +
'<input type="text" class="form-control ' + deviceType + '-config-name" placeholder="name"/>' +
'</div>' +
'<div class="col-xs-4">' +
'<textarea aria-describedby="basic-addon1" placeholder="value" data-error-msg="invalid value"' +
' class="form-control ' + deviceType + '-config-value" rows="1" cols="30"></textarea>' +
'</div>' +
'<button type="button" class="wr-btn wr-btn-horizontal"' +
' onclick="onDynamicConfigAddNew(\'' + deviceType + '\', \'\', \'\')">' +
'<i class="fa fa-plus"></i>' +
'</button>' +
'</div>'
);
}, function (data) {
console.log(data);
}
);
};
var onDynamicConfigSubmit = function (deviceType) {
var errorMsgWrapper = "#" + deviceType + "-config-error-msg";
var errorMsg = "#" + deviceType + "-config-error-msg span";
var addConfigFormData = {};
var configList = [];
$('.' + deviceType + '-config-row').each(function () {
var configName = $(this).find("." + deviceType + "-config-name").val();
var configVal = $(this).find("." + deviceType + "-config-value").val();
if (configName && configName.trim() !== "" && configVal && configVal.trim() !== "") {
var configurationEntry = {};
configurationEntry.name = configName.trim();
configurationEntry.contentType = "text";
configurationEntry.value = configVal.trim();
configList.push(configurationEntry);
}
});
addConfigFormData.type = deviceType;
addConfigFormData.configuration = configList;
var addConfigAPI = '/api/device-mgt/v1.0/admin/device-types/' + deviceType + '/configs';
invokerUtil.post(
addConfigAPI,
addConfigFormData,
function (data, textStatus, jqXHR) {
data = jqXHR.status;
if (data == 200) {
$("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden");
} else if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 400) {
$(errorMsg).text("Configurations cannot be empty.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}, function (data) {
data = data.status;
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted.");
} else {
$(errorMsg).text("An unexpected error occurred.");
}
$(errorMsgWrapper).removeClass("hidden");
}
);
};
var onDynamicConfigAddNew = function (deviceType, name, value) {
$("#" + deviceType + "-config-field-wrapper").append(
'<div class="row form-group ' + deviceType + '-config-row"' +
' id="' + deviceType + '-config-row-' + (++configRowId) + '">' +
'<div class="col-xs-3">' +
'<input type="text" class="form-control ' + deviceType + '-config-name" placeholder="name"' +
' value="' + name + '"/>' +
'</div>' +
'<div class="col-xs-4">' +
'<textarea aria-describedby="basic-addon1" placeholder="value" data-error-msg="invalid value"' +
' class="form-control ' + deviceType + '-config-value" rows="1" cols="30">' + value + '</textarea>' +
'</div>' +
'<button type="button" class="wr-btn wr-btn-horizontal"' +
' onclick="onDynamicConfigRemove(\'' + deviceType + '\', ' + configRowId + ')">' +
'<i class="fa fa-minus"></i>' +
'</button>' +
'</div>'
);
};
var onDynamicConfigRemove = function (deviceType, rawId) {
$("#" + deviceType + "-config-row-" + rawId).remove()
};

@ -118,7 +118,7 @@
{{/if}}
{{#if iosPluginFlag}}
<li>
<a href="{{@app.context}}/dep/devices"><i class="fw fw-apple"></i>
<a href="{{@app.context}}/dep/devices"><i class="fw fw-ios"></i>
DEP Configurations
</a>
</li>

Loading…
Cancel
Save