Add device type specific platform config UIs

merge-requests/69/head
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.", value = "The device type name, such as ios, android, windows or fire-alarm.",
required = true) required = true)
@PathParam("type") @PathParam("type")
@Size(max = 45) @Size(min = 2, max = 45)
String type, String type,
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",

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

@ -3,7 +3,7 @@
{{#each applications}} {{#each applications}}
<a style="text-align: center;width: 100px;height: 100px;"> <a style="text-align: center;width: 100px;height: 100px;">
{{#equal platform "android"}}<i class="fw fw-android"></i>{{/equal}} {{#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}} {{#equal platform "windows"}}<i class="fw fw-windows"></i>{{/equal}}
<span>{{name}}</span> <span>{{name}}</span>
</a> </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 specific language governing permissions and limitations
under the License. under the License.
}} }}
{{#zone "topCss"}}
{{css "css/platform-configuration.css"}}
{{/zone}}
{{#zone "content"}} {{#zone "content"}}
{{#if isAuthorized}} {{#if isAuthorized}}
<div class="row"> <div class="row">
@ -37,7 +42,7 @@
<br> <br>
<div class="wr-advance-operations"> <div class="wr-advance-operations">
<div class="row no-gutter"> <div class="row">
<div class="wr-hidden-operations-nav col-lg-4"> <div class="wr-hidden-operations-nav col-lg-4">
{{#unless isCloud}} {{#unless isCloud}}
@ -63,7 +68,11 @@
<span class="fw-stack fw-move-right fw-move-bottom"> <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 fw-stroke fw-inverse"></i>
<i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-circle fw-stack-2x"></i>
{{#if unitName}}
<i class="fw fw-{{name}} fw-stack-1x fw-inverse"></i> <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>
</span> </span>
{{label}} Configurations {{label}} Configurations
@ -124,7 +133,11 @@
<!-- general--> <!-- general-->
{{#each deviceTypes}} {{#each deviceTypes}}
<div class="wr-hidden-operation" data-operation="{{name}}" style="display: none;"> <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> </div>
{{/each}} {{/each}}

@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * 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) { function onRequest(context) {
@ -29,17 +46,18 @@ function onRequest(context) {
var deviceTypesArray = []; var deviceTypesArray = [];
var typesListResponse = deviceModule.getDeviceTypes(); var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") { if (typesListResponse["status"] == "success") {
var data = typesListResponse["content"].deviceTypes; var data = typesListResponse["content"];
if (data) { if (data) {
for (var i = 0; i < data.length; i++) { 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"); var configUnitName = utility.getTenantedDeviceUnitName(deviceTypeName, "platform.configuration");
if (configUnitName) { if (configUnitName) {
var deviceTypeConfig = utility.getDeviceTypeConfig(deviceTypeName); var deviceTypeConfig = utility.getDeviceTypeConfig(deviceTypeName);
var deviceTypeLabel = deviceTypeName;
if (deviceTypeConfig) { if (deviceTypeConfig) {
deviceTypeLabel = deviceTypeConfig.deviceType.label; deviceTypeLabel = deviceTypeConfig.deviceType.label;
} }
}
deviceTypesArray.push({ deviceTypesArray.push({
name: deviceTypeName, name: deviceTypeName,
label: deviceTypeLabel, label: deviceTypeLabel,
@ -48,7 +66,6 @@ function onRequest(context) {
} }
} }
} }
}
var geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.enabled; var geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.enabled;
return { return {
"geoServicesEnabled": geoServicesEnabled, "geoServicesEnabled": geoServicesEnabled,

@ -16,6 +16,8 @@
* under the License. * under the License.
*/ */
var configRowId = 0;
$(document).ready(function () { $(document).ready(function () {
var configParams = { var configParams = {
@ -59,7 +61,7 @@ $(document).ready(function () {
/** /**
* Following click function would execute * Following click function would execute
* when a user clicks on "Save" button * 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 () { $("button#save-general-btn").click(function () {
var notifierFrequency = $("input#monitoring-config-frequency").val(); var notifierFrequency = $("input#monitoring-config-frequency").val();
@ -154,3 +156,121 @@ var artifactGeoUpload = function () {
showPopup(); showPopup();
}, contentType); }, 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}}
{{#if iosPluginFlag}} {{#if iosPluginFlag}}
<li> <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 DEP Configurations
</a> </a>
</li> </li>

@ -348,7 +348,7 @@
content:"\e602"; content:"\e602";
} }
.fw-apple:before { .fw-ios:before {
content:"\e604"; content:"\e604";
} }

Loading…
Cancel
Save