Merge branch 'release-2.0.x' of https://github.com/wso2/carbon-device-mgt into release-2.0.x

revert-70aa11f8
inoshperera 8 years ago
commit 346fd28814

@ -144,6 +144,7 @@
org.wso2.carbon.event.output.adapter.core, org.wso2.carbon.event.output.adapter.core,
org.wso2.carbon.event.output.adapter.core.exception, org.wso2.carbon.event.output.adapter.core.exception,
org.osgi.framework, org.osgi.framework,
org.wso2.carbon.device.mgt.core.operation.mgt,
org.wso2.carbon.core org.wso2.carbon.core
</Import-Package> </Import-Package>
</instructions> </instructions>

@ -22,17 +22,21 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder; import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder;
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants; import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants;
import org.wso2.carbon.event.output.adapter.core.MessageType; import org.wso2.carbon.event.output.adapter.core.MessageType;
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration; import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException; import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -57,7 +61,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME, configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME)); config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD, configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION, configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION,
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION)); config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION));
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES, configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES,
@ -79,23 +83,48 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
@Override @Override
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
Map<String, String> dynamicProperties = new HashMap<>();
Operation operation = ctx.getOperation(); Operation operation = ctx.getOperation();
Properties properties = operation.getProperties(); Properties properties = operation.getProperties();
if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) { if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) {
Map<String, String> dynamicProperties = new HashMap<>();
dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC)); dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC));
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
operation.getPayLoad());
} else { } else {
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) {
+ ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType() PolicyOperation policyOperation = (PolicyOperation) operation;
.toString().toLowerCase() + "/" + operation.getCode(); List<ProfileOperation> profileOperations = policyOperation.getProfileOperations();
dynamicProperties.put("topic", topic); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
if (operation.getPayLoad() == null) { String deviceType = ctx.getDeviceId().getType();
operation.setPayLoad(""); String deviceId = ctx.getDeviceId().getId();
for (ProfileOperation profileOperation : profileOperations) {
Map<String, String> dynamicProperties = new HashMap<>();
String topic = tenantDomain + "/"
+ deviceType + "/" + deviceId + "/" + profileOperation.getType()
.toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase();
dynamicProperties.put("topic", topic);
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
profileOperation.getPayLoad());
}
} else {
Map<String, String> dynamicProperties = new HashMap<>();
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/"
+ ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType()
.toString().toLowerCase() + "/" + operation.getCode();
dynamicProperties.put("topic", topic);
if (operation.getPayLoad() == null) {
operation.setPayLoad("");
}
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
operation.getPayLoad());
} }
} }
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
operation.getPayLoad());
} }
@Override @Override
@ -109,3 +138,4 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
} }
} }

@ -72,7 +72,7 @@ import javax.ws.rs.core.Response;
"Further, this is strictly restricted to admin users only ") "Further, this is strictly restricted to admin users only ")
public interface UserManagementAdminService { public interface UserManagementAdminService {
@PUT @POST
@Path("/{username}/credentials") @Path("/{username}/credentials")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,

@ -89,7 +89,7 @@
<filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class> <filter-class>org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter</filter-class>
<init-param> <init-param>
<param-name>patterns</param-name> <param-name>patterns</param-name>
<param-value>"text/html*","application/json*","text/plain*"</param-value> <param-value>text/html" ,application/json" ,text/plain</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>filterAction</param-name> <param-name>filterAction</param-name>

@ -24,6 +24,7 @@ var uriMatcher = new URIMatcher(String(uri));
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
var utility = require("/app/modules/utility.js")["utility"];
function appendQueryParam (url, queryParam , value) { function appendQueryParam (url, queryParam , value) {
if (url.indexOf("?") > 0) { if (url.indexOf("?") > 0) {
@ -60,7 +61,7 @@ if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
// response callback // response callback
function (backendResponse) { function (backendResponse) {
response["status"] = backendResponse["status"]; response["status"] = backendResponse["status"];
response["content"] = backendResponse["responseText"]; response["content"] = utility.encodeJson(backendResponse["responseText"]);
} }
); );
} }

@ -117,15 +117,44 @@ var invokers = function () {
log.debug("Response status : " + xmlHttpRequest.status); log.debug("Response status : " + xmlHttpRequest.status);
log.debug("Response payload if any : " + xmlHttpRequest.responseText); log.debug("Response payload if any : " + xmlHttpRequest.responseText);
if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || if (xmlHttpRequest.status == 401) {
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { if ((xmlHttpRequest.responseText == TOKEN_EXPIRED ||
tokenUtil.refreshTokenPair(); xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers); tokenUtil.refreshTokenPair();
} else { return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers);
} else if (privateMethods.isInvalidCredential(xmlHttpRequest.responseText)) {
tokenUtil.refreshTokenPair();
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count, headers);
}
} else {
return responseCallback(xmlHttpRequest); return responseCallback(xmlHttpRequest);
} }
}; };
/**
* This method verify whether the access token is expired using response payload.
* This is required when using API gateway.
* @param responsePayload response payload.
* return true if it is invalid otherwise false.
*/
privateMethods["isInvalidCredential"] =
function (responsePayload) {
if (responsePayload) {
try {
payload = parse(responsePayload);
if (payload["fault"]["code"] == 900901) {
log.debug("Access token is invalid: " + payload["fault"]["code"]);
log.debug(payload["fault"]["description"]);
return true;
}
} catch (err) {
// do nothing
}
}
return false;
};
/** /**
* This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled. * This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled.
* @param httpMethod HTTP request type. * @param httpMethod HTTP request type.

@ -153,5 +153,24 @@ utility = function () {
return scopesList; return scopesList;
}; };
/**
* Escapes special characters such as <,>,',",...etc
* This will prevent XSS attacks upon JSON.
* @param text
* @returns {*}
*/
publicMethods.encodeJson = function (text) {
return text
.replace(/\\u003c/g, "&lt;")
.replace(/</g, "&lt;")
.replace(/\\u003e/g, "&gt;")
.replace(/>/g, "&gt;")
.replace(/\\u0027/g, "&#39;")
.replace(/'/g, "&#39;")
.replace(/\\"/g, "&quot;")
.replace(/\\u0022/g, "&quot;")
};
return publicMethods; return publicMethods;
}(); }();

@ -375,15 +375,15 @@ function loadDevices(searchType, searchParam) {
var fnCreatedRow = function (row, data, dataIndex) { var fnCreatedRow = function (row, data, dataIndex) {
$(row).attr('data-type', 'selectable'); $(row).attr('data-type', 'selectable');
$(row).attr('data-deviceid', data.deviceIdentifier); $(row).attr('data-deviceid', htmlspecialchars(data.deviceIdentifier));
$(row).attr('data-devicetype', data.deviceType); $(row).attr('data-devicetype', htmlspecialchars(data.deviceType));
$(row).attr('data-url', context + '/device/' + data.deviceType + '?id=' + data.deviceIdentifier); $(row).attr('data-url', context + '/device/' + htmlspecialchars(data.deviceType) + '?id=' + htmlspecialchars(data.deviceIdentifier));
var model = getPropertyValue(data.properties, 'DEVICE_MODEL'); var model = htmlspecialchars(getPropertyValue(data.properties, 'DEVICE_MODEL'));
var vendor = getPropertyValue(data.properties, 'VENDOR'); var vendor = htmlspecialchars(getPropertyValue(data.properties, 'VENDOR'));
var owner = data.user; var owner = htmlspecialchars(data.user);
var status = data.status; var status = htmlspecialchars(data.status);
var ownership = data.ownership; var ownership = htmlspecialchars(data.ownership);
var deviceType = data.deviceType; var deviceType = htmlspecialchars(data.deviceType);
var category = getDeviceTypeCategory(deviceType); var category = getDeviceTypeCategory(deviceType);
$.each($('td', row), function (colIndex) { $.each($('td', row), function (colIndex) {
switch (colIndex) { switch (colIndex) {
@ -417,6 +417,10 @@ function loadDevices(searchType, searchParam) {
}); });
}; };
function htmlspecialchars(text){
return jQuery('<div/>').text(text).html();
}
var dataFilter = function (data) { var dataFilter = function (data) {
data = JSON.parse(data); data = JSON.parse(data);
var objects = []; var objects = [];

@ -112,6 +112,10 @@ function toTitleCase(str) {
}); });
} }
function htmlspecialchars(text){
return jQuery('<div/>').text(text).html();
}
function loadGroups() { function loadGroups() {
var groupListing = $("#group-listing"); var groupListing = $("#group-listing");
var currentUser = groupListing.data("currentUser"); var currentUser = groupListing.data("currentUser");
@ -134,10 +138,10 @@ function loadGroups() {
var objects = []; var objects = [];
$(data.deviceGroups).each(function (index) { $(data.deviceGroups).each(function (index) {
objects.push({ objects.push({
groupId: data.deviceGroups[index].id, groupId: htmlspecialchars(data.deviceGroups[index].id),
name: data.deviceGroups[index].name, name: htmlspecialchars(data.deviceGroups[index].name),
description: data.deviceGroups[index].description, description: htmlspecialchars(data.deviceGroups[index].description),
owner: data.deviceGroups[index].owner owner: htmlspecialchars(data.deviceGroups[index].owner)
}) })
}); });
var json = { var json = {

@ -109,6 +109,7 @@ function getSelectedPolicies() {
return policyList; return policyList;
} }
$(document).ready(function () { $(document).ready(function () {
/** /**

@ -86,6 +86,10 @@ function InitiateViewOption() {
// $(location).attr('href', $(this).data("url")); // $(location).attr('href', $(this).data("url"));
} }
function htmlspecialchars(text){
return jQuery('<div/>').text(text).html();
}
function loadRoles() { function loadRoles() {
var loadingContent = $("#loading-content"); var loadingContent = $("#loading-content");
loadingContent.show(); loadingContent.show();
@ -98,8 +102,8 @@ function loadRoles() {
$(data.roles).each(function (index) { $(data.roles).each(function (index) {
objects.push( objects.push(
{ {
name: data.roles[index], name: htmlspecialchars(data.roles[index]),
DT_RowId: "role-" + data.roles[index] DT_RowId: "role-" + htmlspecialchars(data.roles[index])
} }
) )
}); });

@ -258,6 +258,10 @@ function InitiateViewOption() {
} }
} }
function htmlspecialchars(text){
return jQuery('<div/>').text(text).html();
}
function loadUsers() { function loadUsers() {
var loadingContentView = "#loading-content"; var loadingContentView = "#loading-content";
$(loadingContentView).show(); $(loadingContentView).show();
@ -269,11 +273,11 @@ function loadUsers() {
$(data.users).each(function (index) { $(data.users).each(function (index) {
objects.push({ objects.push({
filter: data.users[index].username, filter: htmlspecialchars(data.users[index].username),
firstname: data.users[index].firstname ? data.users[index].firstname : "", firstname: htmlspecialchars(data.users[index].firstname) ? htmlspecialchars(data.users[index].firstname) : "",
lastname: data.users[index].lastname ? data.users[index].lastname : "", lastname: htmlspecialchars(data.users[index].lastname) ? htmlspecialchars(data.users[index].lastname) : "",
emailAddress: data.users[index].emailAddress ? data.users[index].emailAddress : "", emailAddress: htmlspecialchars(data.users[index].emailAddress) ? htmlspecialchars(data.users[index].emailAddress) : "",
DT_RowId: "user-" + data.users[index].username DT_RowId: "user-" + htmlspecialchars(data.users[index].username)
}) })
}); });

@ -273,6 +273,7 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter
thisTable.removeClass("table-selectable"); thisTable.removeClass("table-selectable");
$(button).addClass("active").html('Select'); $(button).addClass("active").html('Select');
$(button).parent().next().children().addClass("disabled"); $(button).parent().next().children().addClass("disabled");
$('.DTTT_selected.selected').removeClass(rowSelectedClass);
// EMM related function // EMM related function
$(document).on('click', '.viewEnabledIcon', InitiateViewOption); $(document).on('click', '.viewEnabledIcon', InitiateViewOption);
//--- End of EMM related codes //--- End of EMM related codes

@ -41,22 +41,22 @@ $(document).ready(function () {
/* for device list sorting drop down */ /* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({ $(".ctrl-filter-type-switcher").popover({
html : true, html: true,
content : function () { content: function () {
return $("#content-filter-types").html(); return $("#content-filter-types").html();
} }
}); });
$(".ast-container").on("click", ".claim-btn", function(e){ $(".ast-container").on("click", ".claim-btn", function (e) {
e.stopPropagation(); e.stopPropagation();
var deviceId = $(this).data("deviceid"); var deviceId = $(this).data("deviceid");
var deviceListing = $("#device-listing"); var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("current-user"); var currentUser = deviceListing.data("current-user");
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
invokerUtil.put(serviceURL, deviceIdentifier, function(message){ invokerUtil.put(serviceURL, deviceIdentifier, function (message) {
console.log(message); console.log(message);
}, function(message){ }, function (message) {
console.log(message); console.log(message);
}); });
}); });
@ -68,15 +68,15 @@ $(document).ready(function () {
* @param button: Select All Device button * @param button: Select All Device button
*/ */
function selectAllDevices(button) { function selectAllDevices(button) {
if(!$(button).data('select')){ if (!$(button).data('select')) {
$(deviceCheckbox).each(function(index){ $(deviceCheckbox).each(function (index) {
$(this).prop('checked', true); $(this).prop('checked', true);
addDeviceSelectedClass(this); addDeviceSelectedClass(this);
}); });
$(button).data('select', true); $(button).data('select', true);
$(button).html('Deselect All Devices'); $(button).html('Deselect All Devices');
}else{ } else {
$(deviceCheckbox).each(function(index){ $(deviceCheckbox).each(function (index) {
$(this).prop('checked', false); $(this).prop('checked', false);
addDeviceSelectedClass(this); addDeviceSelectedClass(this);
}); });
@ -92,7 +92,7 @@ function selectAllDevices(button) {
* @param selection: Selection button * @param selection: Selection button
*/ */
function changeDeviceView(view, selection) { function changeDeviceView(view, selection) {
$(".view-toggle").each(function() { $(".view-toggle").each(function () {
$(this).removeClass("selected"); $(this).removeClass("selected");
}); });
$(selection).addClass("selected"); $(selection).addClass("selected");
@ -117,27 +117,33 @@ function addDeviceSelectedClass(checkbox) {
} }
function toTitleCase(str) { function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); return str.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
} }
var deviceTypeCount, compiledDeviceTypesCount = 0; var deviceTypeCount, compiledDeviceTypesCount = 0;
function loadDevices(searchType, searchParam){ function htmlspecialchars(text) {
return jQuery('<div/>').text(text).html();
}
function loadDevices(searchType, searchParam) {
var deviceListing = $("#device-listing"); var deviceListing = $("#device-listing");
var deviceListingSrc = deviceListing.attr("src"); var deviceListingSrc = deviceListing.attr("src");
var currentUser = deviceListing.data("currentUser"); var currentUser = deviceListing.data("currentUser");
$('#ast-container').html(""); $('#ast-container').html("");
deviceTypeCount = deviceTypesList.length; deviceTypeCount = deviceTypesList.length;
if(deviceTypesList.length > 0){ if (deviceTypesList.length > 0) {
for (var i = 0; i < deviceTypesList.length; i++) { for (var i = 0; i < deviceTypesList.length; i++) {
var viewModel = {}; var viewModel = {};
viewModel.thumb = deviceTypesList[i].thumb; viewModel.thumb = deviceTypesList[i].thumb;
viewModel.appContext = clientJsAppContext; viewModel.appContext = clientJsAppContext;
viewModel.deviceTypeName = deviceTypesList[i].deviceTypeName; viewModel.deviceTypeName = htmlspecialchars(deviceTypesList[i].deviceTypeName);
viewModel.deviceTypeId = deviceTypesList[i].deviceTypeId; viewModel.deviceTypeId = htmlspecialchars(deviceTypesList[i].deviceTypeId);
viewModel.deviceCategory = deviceTypesList[i].deviceCategory; viewModel.deviceCategory = htmlspecialchars(deviceTypesList[i].deviceCategory);
viewModel.deviceTypeLabel = deviceTypesList[i].deviceTypeLabel; viewModel.deviceTypeLabel = htmlspecialchars(deviceTypesList[i].deviceTypeLabel);
compileTemplate(viewModel, deviceListingSrc); compileTemplate(viewModel, deviceListingSrc);
} }
} else { } else {
@ -155,12 +161,12 @@ function loadDevices(searchType, searchParam){
} }
function compileTemplate(viewModel, templateSrc){ function compileTemplate(viewModel, templateSrc) {
$.template("device-listing", templateSrc, function (template) { $.template("device-listing", templateSrc, function (template) {
$("#ast-container").html($("#ast-container").html() + template(viewModel)); $("#ast-container").html($("#ast-container").html() + template(viewModel));
compiledDeviceTypesCount++; compiledDeviceTypesCount++;
if(deviceTypeCount == compiledDeviceTypesCount){ if (deviceTypeCount == compiledDeviceTypesCount) {
$('#device-type-grid').datatables_extended({"bFilter": false, "order": [[ 1, "asc" ]]}); $('#device-type-grid').datatables_extended({"bFilter": false, "order": [[1, "asc"]]});
} }
}); });
} }
@ -171,17 +177,16 @@ function compileTemplate(viewModel, templateSrc){
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container"; var assetContainer = "#ast-container";
function openCollapsedNav(){ function openCollapsedNav() {
$('.wr-hidden-nav-toggle-btn').addClass('active'); $('.wr-hidden-nav-toggle-btn').addClass('active');
$('#hiddenNav').slideToggle('slideDown', function(){ $('#hiddenNav').slideToggle('slideDown', function () {
if($(this).css('display') == 'none'){ if ($(this).css('display') == 'none') {
$('.wr-hidden-nav-toggle-btn').removeClass('active'); $('.wr-hidden-nav-toggle-btn').removeClass('active');
} }
}); });
} }
/* /*
* DOM ready functions. * DOM ready functions.
*/ */
@ -196,22 +201,22 @@ $(document).ready(function () {
/* for device list sorting drop down */ /* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({ $(".ctrl-filter-type-switcher").popover({
html : true, html: true,
content : function () { content: function () {
return $("#content-filter-types").html(); return $("#content-filter-types").html();
} }
}); });
$(".ast-container").on("click", ".claim-btn", function(e){ $(".ast-container").on("click", ".claim-btn", function (e) {
e.stopPropagation(); e.stopPropagation();
var deviceId = $(this).data("deviceid"); var deviceId = $(this).data("deviceid");
var deviceListing = $("#device-listing"); var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("current-user"); var currentUser = deviceListing.data("current-user");
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
invokerUtil.put(serviceURL, deviceIdentifier, function(message){ invokerUtil.put(serviceURL, deviceIdentifier, function (message) {
console.log(message); console.log(message);
}, function(message){ }, function (message) {
console.log(message); console.log(message);
}); });
}); });
@ -222,20 +227,20 @@ $(document).ready(function () {
$("[data-toggle=popover]").popover(); $("[data-toggle=popover]").popover();
$(".ctrl-filter-type-switcher").popover({ $(".ctrl-filter-type-switcher").popover({
html : true, html: true,
content: function() { content: function () {
return $('#content-filter-types').html(); return $('#content-filter-types').html();
} }
}); });
$('#nav').affix({ $('#nav').affix({
offset: { offset: {
top: $('header').height() top: $('header').height()
} }
}); });
$(document).on("click", "tr.clickable-row", function(){ $(document).on("click", "tr.clickable-row", function () {
window.document.location = $(this).data('href'); window.document.location = $(this).data('href');
}) })
}); });

@ -67,11 +67,4 @@
}); });
} }
</script> </script>
<script type="text/javascript">
function toggleEnrollment(){
$(".modal-content").html($("#qr-code-modal").html());
generateQRCode(".modal-content .qr-code");
showQRCodePopup();
}
</script>
{{/zone}} {{/zone}}

@ -20,15 +20,15 @@
var modalDialog = (function () { var modalDialog = (function () {
var publicMethoads = {}; var publicMethoads = {};
publicMethoads.header = function (headerText) { publicMethoads.header = function (headerText) {
$("#modal-title-text").html(headerText); $("#basic-modal-view #modal-title-text").html(headerText);
}; };
publicMethoads.content = function (contentText) { publicMethoads.content = function (contentText) {
$("#modal-content-text").html(contentText); $("#basic-modal-view #modal-content-text").html(contentText);
}; };
publicMethoads.footer = function (footerContent) { publicMethoads.footer = function (footerContent) {
$("#modal-footer-content").html(footerContent); $("#basic-modal-view #modal-footer-content").html(footerContent);
}; };
publicMethoads.footerButtons = function (buttonList) { publicMethoads.footerButtons = function (buttonList) {
@ -37,7 +37,7 @@ var modalDialog = (function () {
footerContent = footerContent + '<div class="buttons"><a href="#" id="' + btn.id + footerContent = footerContent + '<div class="buttons"><a href="#" id="' + btn.id +
'" class="btn-operations">' + btn.text + '</a></div>'; '" class="btn-operations">' + btn.text + '</a></div>';
} }
$("#modal-footer-content").html(footerContent); $("#basic-modal-view #modal-footer-content").html(footerContent);
}; };
publicMethoads.show = function () { publicMethoads.show = function () {
@ -62,11 +62,21 @@ var modalDialog = (function () {
publicMethoads.hide = function () { publicMethoads.hide = function () {
$("#basic-modal-view").addClass('hidden'); $("#basic-modal-view").addClass('hidden');
$("#basic-modal-view").modal('hide'); $("#basic-modal-view").modal('hide');
$("#modal-title-text").html("");
$("#modal-content-text").html("");
$("#modal-footer-content").html("");
$('body').removeClass('modal-open').css('padding-right', '0px');
$('.modal-backdrop').remove(); $('.modal-backdrop').remove();
}; };
$("#basic-modal-view").on('hidden.bs.modal', function () {
$('#basic-modal-view .modal-dialog').html('<div class="modal-content"><div class="modal-header">' +
'<h3 class="pull-left modal-title"><span class="fw-stack error-msg-icon hidden">' +
'<i class="fw fw-circle-outline fw-stack-2x"></i><i class="fw fw-error fw-stack-1x"></i></span>' +
'<span class="fw-stack warning-msg-icon hidden"><i class="fw fw-circle-outline fw-stack-2x"></i>' +
'<i class="fw fw-warning fw-stack-1x"></i></span><span id="modal-title-text"></span></h3>' +
'<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>' +
'</button></div><div class="modal-body add-margin-top-2x add-margin-bottom-2x">' +
'<div id="modal-content-text"></div></div>' +
'<div class="modal-footer" id="modal-footer-content"></div></div>');
$('body').removeClass('modal-open').css('padding-right', '0px');
});
return publicMethoads; return publicMethoads;
}(modalDialog)); }(modalDialog));

@ -80,9 +80,9 @@
<!--<a href="{{@app.context}}notification-listing" title="Failures of operations on the device side will be listed here">--> <!--<a href="{{@app.context}}notification-listing" title="Failures of operations on the device side will be listed here">-->
<a data-toggle="sidebar" data-target="#right-sidebar" data-container=".page-content" <a data-toggle="sidebar" data-target="#right-sidebar" data-container=".page-content"
aria-expanded="false" rel="notifications-sidebar"> aria-expanded="false" rel="notifications-sidebar">
<span class="icon fw-stack"> <span class="icon fw-stack">
<i class="fw fw-notification fw-stack-1x"></i> <i class="fw fw-notification fw-stack-1x"></i>
</span> </span>
<span class="hidden-xs">Notifications</span> <span class="hidden-xs">Notifications</span>
<span class="badge notifications" id="notification-bubble"></span> <span class="badge notifications" id="notification-bubble"></span>
</a> </a>
@ -90,9 +90,8 @@
</ul> </ul>
{{/zone}} {{/zone}}
{{#zone "sidePanes"}} {{#zone "sidePanes"}}
<div class="sidebar-wrapper" id="right-sidebar" is-authorized="{{isAuthorizedForNotifications}}" <div class="sidebar-wrapper sidebar-wrapper-animation-fix" id="right-sidebar" is-authorized="{{isAuthorizedForNotifications}}"
data-side="right" data-width="320" data-sidebar-fixed="true" data-fixed-offset="50" data-spy="affix" data-side="right" data-width="320" data-sidebar-fixed="true" data-top="90" data-fixed-offset="90" data-offset-top="50" data-spy="affix">
data-offset-top="80">
<ul class="sidebar-messages"> <ul class="sidebar-messages">
</ul> </ul>
<div class="text-center"><a href="{{@app.context}}/notification-listing" class="btn btn-primary">Show All Notifications</a></div> <div class="text-center"><a href="{{@app.context}}/notification-listing" class="btn btn-primary">Show All Notifications</a></div>

@ -32,6 +32,7 @@ function onRequest(context) {
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var uiPermissions = userModule.getUIPermissions(); var uiPermissions = userModule.getUIPermissions();
context["permissions"] = uiPermissions; context["permissions"] = uiPermissions;
context["userMgtEnabled"] = (uiPermissions["LIST_USERS"] || uiPermissions["LIST_ROLES"]);
var links = { var links = {
"user-mgt": [], "user-mgt": [],

@ -128,15 +128,16 @@ function loadNewNotifications() {
} }
/** /**
* Toggle function for * Sidebar function
* notification listing sidebar.
* @return {Null} * @return {Null}
*/ */
$.sidebar_toggle = function (action, target, container) { $.sidebar_toggle = function(action, target, container) {
var elem = '[data-toggle=sidebar]', var elem = '[data-toggle=sidebar]',
button, button,
containerOffsetLeft, container,
containerOffsetRight, conrainerOffsetLeft,
conrainerOffsetRight,
target,
targetOffsetLeft, targetOffsetLeft,
targetOffsetRight, targetOffsetRight,
targetWidth, targetWidth,
@ -145,104 +146,177 @@ $.sidebar_toggle = function (action, target, container) {
pushType, pushType,
buttonParent; buttonParent;
/**
* Dynamically adjust the height of sidebar to fill parent
*/
function sidebarHeightAdjust(){
$('.sidebar-wrapper').each(function(){
var elemOffsetBottom = $(this).data('offset-bottom'),
scrollBottom = ($(document).height() - $(window).height()),
offesetBottom = 0,
getBottomOffset = elemOffsetBottom - (scrollBottom - ($(window).scrollTop()-elemOffsetBottom) - elemOffsetBottom);
if(getBottomOffset > 0){
offesetBottom = getBottomOffset;
}
$(this).height(($(window).height() - ($(this).offset().top - $(window).scrollTop())) - offesetBottom);
if((typeof $.fn.nanoScroller == 'function') && ($('.nano-content', this).length > 0)){
$(".nano-content").parent()[0].nanoscroller.reset();
}
});
};
var sidebar_window = { var sidebar_window = {
update: function (target, container, button) { update: function(target, container, button){
containerOffsetLeft = $(container).data('offset-left') ? $(container).data('offset-left') : 0; conrainerOffsetLeft = $(container).data('offset-left') ? $(container).data('offset-left') : 0,
containerOffsetRight = $(container).data('offset-right') ? $(container).data('offset-right') : 0; conrainerOffsetRight = $(container).data('offset-right') ? $(container).data('offset-right') : 0,
targetOffsetLeft = $(target).data('offset-left') ? $(target).data('offset-left') : 0; targetTop = $(target).data('top') ? $(target).data('top') : 0,
targetOffsetRight = $(target).data('offset-right') ? $(target).data('offset-right') : 0; targetOffsetLeft = $(target).data('offset-left') ? $(target).data('offset-left') : 0,
targetWidth = $(target).data('width'); targetOffsetRight = $(target).data('offset-right') ? $(target).data('offset-right') : 0,
targetSide = $(target).data("side"); targetWidth = $(target).data('width'),
pushType = $(container).parent().is('body') == true ? 'padding' : 'margin'; targetSide = $(target).data("side"),
pushType = $(container).parent().is('body') == true ? 'padding' : 'padding'; //TODO: Remove if works everywhere
if (button !== undefined) {
$(container).addClass('sidebar-target');
if(button !== undefined){
relationship = button.attr('rel') ? button.attr('rel') : ''; relationship = button.attr('rel') ? button.attr('rel') : '';
buttonParent = $(button).parent(); buttonParent = $(button).parent();
} }
},
show: function () { $(target).css('top', targetTop);
if ($(target).data('sidebar-fixed') == true) {
sidebarHeightAdjust();
},
show: function(){
if($(target).data('sidebar-fixed') == true) {
$(target).css('top',$(target).data('fixed-offset') + 'px');
$(target).height($(window).height() - $(target).data('fixed-offset')); $(target).height($(window).height() - $(target).data('fixed-offset'));
} }
$(target).off('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend');
$(target).trigger('show.sidebar'); $(target).trigger('show.sidebar');
if (targetWidth !== undefined) {
if(targetWidth !== undefined) {
$(target).css('width', targetWidth); $(target).css('width', targetWidth);
} }
$(target).addClass('toggled'); $(target).addClass('toggled');
if (button !== undefined) {
if (relationship !== '') { if(button !== undefined){
if(relationship !== ''){
// Removing active class from all relative buttons // Removing active class from all relative buttons
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').removeClass("active"); $(elem+'[rel='+relationship+']:not([data-handle=close])').removeClass("active");
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').attr('aria-expanded', 'false'); $(elem+'[rel='+relationship+']:not([data-handle=close])').attr('aria-expanded', 'false');
} }
// Adding active class to button // Adding active class to button
if (button.attr('data-handle') !== 'close') { if(button.attr('data-handle') !== 'close'){
button.addClass("active"); button.addClass("active");
button.attr('aria-expanded', 'true'); button.attr('aria-expanded', 'true');
} }
if (buttonParent.is('li')) {
if (relationship !== '') { if(buttonParent.is('li')) {
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active"); if(relationship !== ''){
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent(). $(elem+'[rel='+relationship+']:not([data-handle=close])').parent().removeClass("active");
attr('aria-expanded', 'false'); $(elem+'[rel='+relationship+']:not([data-handle=close])').parent().attr('aria-expanded', 'false');
} }
buttonParent.addClass("active"); buttonParent.addClass("active");
buttonParent.attr('aria-expanded', 'true'); buttonParent.attr('aria-expanded', 'true');
} }
} }
// Sidebar open function // Sidebar open function
if (targetSide == 'left') { if (targetSide == 'left'){
if ((button !== undefined) && (button.attr('data-container-divide'))) { if ($(target).attr('data-container-divide')){
$(container).css(pushType + '-' + targetSide, targetWidth + targetOffsetLeft); $(container).css(pushType+'-'+targetSide, targetWidth + targetOffsetLeft);
$(target).css(targetSide, targetOffsetLeft);
} }
$(target).css(targetSide, targetOffsetLeft); else if ($(target).attr('data-container-push')){
} else if (targetSide == 'right') { $(container).css(targetSide, Math.abs(targetWidth + targetOffsetLeft));
if ((button !== undefined) && (button.attr('data-container-divide'))) { $(target).css(targetSide, -Math.abs(targetWidth + targetOffsetLeft));
$(container).css(pushType + '-' + targetSide, targetWidth + targetOffsetRight); }
else {
$(target).css(targetSide, Math.abs(targetOffsetLeft));
}
}
else if (targetSide == 'right'){
if ($(target).attr('data-container-divide')){
$(container).css(pushType+'-'+targetSide, targetWidth + targetOffsetRight);
$(target).css(targetSide, targetOffsetRight);
}
else if ($(target).attr('data-container-push')){
$(container).css(targetSide, Math.abs(targetWidth + targetOffsetRight));
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetRight));
}
else {
$(target).css(targetSide, Math.abs(targetOffsetRight));
} }
$(target).css(targetSide, targetOffsetRight);
} }
$(target).trigger('shown.sidebar'); $(target).trigger('shown.sidebar');
}, },
hide: function(){
hide: function () {
$(target).trigger('hide.sidebar'); $(target).trigger('hide.sidebar');
$(target).removeClass('toggled'); $(target).removeClass('toggled');
if (button !== undefined) {
if (relationship !== '') { if(button !== undefined){
if(relationship !== ''){
// Removing active class from all relative buttons // Removing active class from all relative buttons
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').removeClass("active"); $(elem+'[rel='+relationship+']:not([data-handle=close])').removeClass("active");
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').attr('aria-expanded', 'false'); $(elem+'[rel='+relationship+']:not([data-handle=close])').attr('aria-expanded', 'false');
} }
// Removing active class from button // Removing active class from button
if (button.attr('data-handle') !== 'close') { if(button.attr('data-handle') !== 'close'){
button.removeClass("active"); button.removeClass("active");
button.attr('aria-expanded', 'false'); button.attr('aria-expanded', 'false');
} }
if ($(button).parent().is('li')) {
if (relationship !== '') { if($(button).parent().is('li')){
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active"); if(relationship !== ''){
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent(). $(elem+'[rel='+relationship+']:not([data-handle=close])').parent().removeClass("active");
attr('aria-expanded', 'false'); $(elem+'[rel='+relationship+']:not([data-handle=close])').parent().attr('aria-expanded', 'false');
} }
} }
} }
// Sidebar close function // Sidebar close function
if (targetSide == 'left') { if (targetSide == 'left'){
if ((button !== undefined) && (button.attr('data-container-divide'))) { if($(target).attr('data-container-divide')){
$(container).css(pushType + '-' + targetSide, targetOffsetLeft); $(container).css(pushType+'-'+targetSide, targetOffsetLeft);
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetRight));
} }
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetLeft)); else if($(target).attr('data-container-push')){
} else if (targetSide == 'right') { $(container).css(targetSide, targetOffsetLeft);
if ((button !== undefined) && (button.attr('data-container-divide'))) { $(target).css(targetSide, -Math.abs(targetWidth + targetOffsetLeft));
$(container).css(pushType + '-' + targetSide, targetOffsetRight); }
else {
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetLeft));
} }
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetRight));
} }
else if (targetSide == 'right'){
if($(target).attr('data-container-divide')){
$(container).css(pushType+'-'+targetSide, targetOffsetRight);
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetRight));
}
else if($(target).attr('data-container-push')){
$(container).css(targetSide, targetOffsetRight);
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetRight));
}
else {
$(target).css(targetSide, -Math.abs(targetWidth + targetOffsetRight));
}
}
$(target).trigger('hidden.sidebar'); $(target).trigger('hidden.sidebar');
$(target).on('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(e) {
$(container).removeClass('sidebar-target');
});
} }
}; };
if (action === 'show') { if (action === 'show') {
sidebar_window.update(target, container); sidebar_window.update(target, container);
sidebar_window.show(); sidebar_window.show();
@ -251,27 +325,52 @@ $.sidebar_toggle = function (action, target, container) {
sidebar_window.update(target, container); sidebar_window.update(target, container);
sidebar_window.hide(); sidebar_window.hide();
} }
// binding click function // binding click function
var body = 'body'; $('body').off('click', elem);
$(body).off('click', elem); $('body').on('click', elem, function(e) {
$(body).on('click', elem, function (e) {
e.preventDefault(); e.preventDefault();
button = $(this); button = $(this);
container = button.data('container');
target = button.data('target'); target = button.data('target');
container = $(target).data('container');
sidebar_window.update(target, container, button); sidebar_window.update(target, container, button);
/** /**
* Sidebar function on data container divide * Sidebar function on data container divide
* @return {Null} * @return {Null}
*/ */
if (button.attr('aria-expanded') == 'false') { if(button.attr('aria-expanded') == 'false'){
sidebar_window.show(); sidebar_window.show();
} else if (button.attr('aria-expanded') == 'true') { }
else if (button.attr('aria-expanded') == 'true') {
sidebar_window.hide(); sidebar_window.hide();
} }
}); });
$(window)
.load(sidebarHeightAdjust)
.resize(sidebarHeightAdjust)
.scroll(sidebarHeightAdjust);
}; };
var sideWrapper = $('.sidebar-wrapper');
$(document).on('affix.bs.affix','.sidebar-wrapper',function(){
sideWrapper.css('top',$('.navbar-wrapper').height());
sideWrapper.data('top',$('.navbar-wrapper').height());
sideWrapper.data('fixed-offset', $('.navbar-wrapper').height());
});
$(document).on('affix-top.bs.affix','.sidebar-wrapper',function(){
sideWrapper.css('top',$('.navbar-wrapper').height() + $('.header').height());
sideWrapper.data('top',$('.navbar-wrapper').height() + $('.header').height());
sideWrapper.data('fixed-offset', $('.navbar-wrapper').height() + $('.header').height());
});
$.fn.collapse_nav_sub = function () { $.fn.collapse_nav_sub = function () {
var navSelector = 'ul.nav'; var navSelector = 'ul.nav';
@ -324,7 +423,6 @@ $.fn.collapse_nav_sub = function () {
$(document).ready(function () { $(document).ready(function () {
loadNotificationsPanel(); loadNotificationsPanel();
$.sidebar_toggle();
$("#right-sidebar").on("click", ".new-notification", function () { $("#right-sidebar").on("click", ".new-notification", function () {
var notificationId = $(this).data("id"); var notificationId = $(this).data("id");

@ -804,7 +804,7 @@ header .dropdown[aria-expanded=true], header .dropdown:hover {
.navbar .container-fluid > .navbar-header .icon, .navbar .container-fluid > .navbar-header .icon,
.navbar .container > .navbar-collapse .icon, .navbar .container > .navbar-collapse .icon,
.navbar .container > .navbar-header .icon { .navbar .container > .navbar-header .icon {
margin-bottom: 4px; margin-bottom: 0px !important;
} }
.navbar-nav { .navbar-nav {
@ -1108,6 +1108,14 @@ header .dropdown[aria-expanded=true], header .dropdown:hover {
right: 0; right: 0;
} }
.sidebar-wrapper-animation-fix{
-webkit-transition: left 0.5s ease, right 0.5s ease !important;
-moz-transition: left 0.5s ease, right 0.5s ease !important;
-ms-transition: left 0.5s ease, right 0.5s ease !important;
-o-transition: left 0.5s ease, right 0.5s ease !important;
transition: left 0.5s ease, right 0.5s ease !important;
}
ul.sidebar-messages { ul.sidebar-messages {
padding: 0; padding: 0;
margin: 0; margin: 0;
@ -6393,6 +6401,7 @@ ul.tiles .icon {
background: #f4f4f4; background: #f4f4f4;
border:1px solid #ddd; border:1px solid #ddd;
margin-bottom:10px; margin-bottom:10px;
padding: 15px;
} }
.media .list-group-item a, .media .list-group-item a{ .media .list-group-item a, .media .list-group-item a{
background:#f4f4f4; background:#f4f4f4;
@ -6536,6 +6545,9 @@ select > option:hover {
padding-right: 5px; padding-right: 5px;
} }
.btn-operations:hover, .btn-operations:focus, .btn-operations:active {
color : #C7C7C7;
}
/** /**
* *

Loading…
Cancel
Save