diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag index 4bf153b9..75cc8b77 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag @@ -124,7 +124,12 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) { var data = {}; //XMLHTTPRequest's GET - result = get(listAllDevicesEndPoint, data, "json"); + try { + result = get(listAllDevicesEndPoint, data, "json"); + }catch(err){ + log.error("Error occured while retrieveing all devices with username: "+user.username); + result=[]; + } } else if (uriMatcher.match("/{context}/api/devices/types")) { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js new file mode 100644 index 00000000..f1f45132 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015, 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. + */ + +var policyModule; +policyModule = function () { + var log = new Log("modules/policy.js"); + + var constants = require("/modules/constants.js"); + var utility = require("/modules/utility.js").utility; + + var userManagementService = utility.getUserManagementService(); + + var publicMethods = {}; + var privateMethods = {}; + + publicMethods.getPolicies = function () { + + //TODO-This method returns includes dummy policy data + + var policies = []; + var policyObj = { + "id":1, // Identifier of the policy. + "priorityId":1, // Priority of the policies. This will be used only for simple evaluation. + "profile":{}, // Profile + "policyName":"Turn off light", // Name of the policy. + "generic":true, // If true, this should be applied to all related device. + "roles":{}, // Roles which this policy should be applied. + "ownershipType":{}, // Ownership type (COPE, BYOD, CPE) + "devices":{}, // Individual devices this policy should be applied + "users":{}, // Individual users this policy should be applied + "Compliance":{}, + "policyCriterias":{}, + "startTime":283468236, // Start time to apply the policy. + "endTime":283468236, // After this time policy will not be applied + "startDate":"", // Start date to apply the policy + "endDate":"", // After this date policy will not be applied. + "tenantId":-1234, + "profileId":1 + }; + + policies.push(policyObj); + + policyObj = { + "id":2, // Identifier of the policy. + "priorityId":1, // Priority of the policies. This will be used only for simple evaluation. + "profile":{}, // Profile + "policyName":"Turn on Buzzer", // Name of the policy. + "generic":false, // If true, this should be applied to all related device. + "roles":{}, // Roles which this policy should be applied. + "ownershipType":{}, // Ownership type (COPE, BYOD, CPE) + "devices":{}, // Individual devices this policy should be applied + "users":{}, // Individual users this policy should be applied + "Compliance":{}, + "policyCriterias":{}, + "startTime":283468236, // Start time to apply the policy. + "endTime":283468236, // After this time policy will not be applied + "startDate":"", // Start date to apply the policy + "endDate":"", // After this date policy will not be applied. + "tenantId":-1234, + "profileId":2 + }; + + policies.push(policyObj); + return policies; + }; + + return publicMethods; +}(); + + diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js index 803df504..01c9e1b5 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js @@ -310,6 +310,34 @@ userModule = function () { return permissions; }; + /** + * Get User Roles from user store. + * If "Internal/Everyone" role is required - true param needs to be passed. + * @param enableInternalEveryone boolean value true/false to enable Internal/Everyone role + */ + publicMethods.getRoles = function (enableInternalEveryone) { + var carbonModule = require("carbon"); + var carbonServer = application.get("carbonServer"); + var carbonUser = session.get(constants.USER_SESSION_KEY); + if (!carbonUser) { + log.error("User object was not found in the session"); + throw constants.ERRORS.USER_NOT_FOUND; + } + var userManager = new carbonModule.user.UserManager(carbonServer, carbonUser.tenantId); + var allRoles = userManager.allRoles(); + var filteredRoles = []; + var i; + for (i = 0; i < allRoles.length; i++) { + if (enableInternalEveryone && allRoles[i] == "Internal/everyone") { + filteredRoles.push(allRoles[i]); + } + if (allRoles[i].indexOf("Internal/") != 0) { + filteredRoles.push(allRoles[i]); + } + } + return filteredRoles; + }; + publicMethods.logout = function (successCallback) { session.invalidate(); successCallback(); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js index 89aefe7b..8955a0f0 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js @@ -20,6 +20,7 @@ var utility; utility = function () { var JavaClass = Packages.java.lang.Class; var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext; + var userManagement = Packages.org.wso2.carbon.device.mgt.iot.common.UserManagement(); var getOsgiService = function (className) { return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(JavaClass.forName(className)); @@ -32,7 +33,7 @@ utility = function () { }; publicMethods.getUserManagementService = function () { - return Packages.org.wso2.carbon.device.mgt.iot.common.UserManagement(); + return userManagement; }; publicMethods.getPolicyManagementService = function () { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs new file mode 100644 index 00000000..f8a1adc7 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs @@ -0,0 +1,9 @@ +{{authorized}} +{{layout "fluid"}} +{{#zone "title"}} + WSO2 DC | Add New Policy +{{/zone}} +{{#zone "body"}} + {{unit "appbar" link="policies" title="My Policies"}} + {{unit "policy-create"}} +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs new file mode 100644 index 00000000..cb210ed1 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs @@ -0,0 +1,21 @@ +{{authorized}} +{{layout "fluid"}} +{{#zone "title"}} + Policies +{{/zone}} +{{#zone "body"}} + {{unit "appbar" link="policies" title="My Policies"}} + {{unit "extended-search-box"}} +
+
+ +
+
+ +
+ {{unit "policy-listing"}} +
+ +
+
+{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs index 4067deba..20489738 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs @@ -45,7 +45,7 @@ {{#if permissions.ADD_USER}}
  • User Management
  • {{/if}} -
  • Policy Management
  • +
  • Policy Management
  • Dashboard
  • diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.hbs new file mode 100644 index 00000000..f62dad67 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.hbs @@ -0,0 +1,243 @@ +{{#zone "main"}} +
    +
    + + + + + +
    + +
    + +

    Add Policy

    + +
    +
    +
    1
    +
    +
    +
    +
    2
    +
    +
    +
    +
    3
    +
    +
    +
    +
    4
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    +{{/zone}} +{{#zone "bottomJs"}} + + + +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.js new file mode 100644 index 00000000..f2fb4954 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.js @@ -0,0 +1,10 @@ +function onRequest(context){ + var userModule = require("/modules/user.js").userModule; + var roles = userModule.getRoles(true); + var users = userModule.getUsers(); + var actions = ["Enforce"]; + context.roles = roles; + context.users = users; + context.actions = actions; + return context; +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.json new file mode 100644 index 00000000..f2aa29a3 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.json @@ -0,0 +1,3 @@ +{ + "predicate": "false" +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/js/policy-create.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/js/policy-create.js new file mode 100644 index 00000000..90792be7 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/js/policy-create.js @@ -0,0 +1,155 @@ +$('select.select2').select2({ + placeholder: 'Select..' +}); + +$('select.select2[multiple=multiple]').select2({ + placeholder: 'Select..', + tags: true +}); +var stepperRegistry = {}, + hiddenOperation = '.wr-hidden-operations-content > div', + advanceOperation = '.wr-advance-operations'; +function initStepper(selector){ + $(selector).click(function(){ + var nextStep = $(this).data("next"); + var currentStep = $(this).data("current"); + var isBack = $(this).data("back"); + if (!isBack){ + var action = stepperRegistry[currentStep]; + if (action){ + action(this); + } + } + if (!nextStep) { + var direct = $(this).data("direct"); + window.location.href = direct; + } + $(".itm-wiz").each(function(){ + var step = $(this).data("step"); + if (step == nextStep){ + $(this).addClass("itm-wiz-current"); + }else{ + $(this).removeClass("itm-wiz-current"); + } + }); + $(".wr-wizard").html($(".wr-steps").html()); + $("." + nextStep).removeClass("hidden"); + $("." + currentStep).addClass("hidden"); + + }); +} +function showAdvanceOperation(operation, button){ + $(button).addClass('selected'); + $(button).siblings().removeClass('selected'); + $(hiddenOperation + '[data-operation="' + operation + '"]').show(); + $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); +} + +var policy = {}; +var configuredProfiles = []; + +function savePolicy(){ + var profilePayloads = []; + for (var key in policy.profile) { + if (policy.profile.hasOwnProperty(key)) { + profilePayloads.push({ + featureCode: key, + deviceTypeId: policy.platformId, + content: policy.profile[key] + }); + } + } + var payload = { + policyName: policy.policyName, + compliance: policy.selectedAction, + ownershipType: policy.selectedOwnership, + profile: { + profileName: policy.policyName, + deviceType: { + id: policy.platformId + }, + profileFeaturesList: profilePayloads + } + }; + payload.users = []; + payload.roles = []; + if (policy.selectedUsers){ + payload.users = policy.selectedUsers; + }else if (policy.selectedUserRoles){ + payload.roles = policy.selectedUserRoles; + } + invokerUtil.post("/mdm-admin/policies", payload, function(){ + $(".policy-message").removeClass("hidden"); + $(".add-policy").addClass("hidden"); + }, function(){ + + }); +} + +$(document).ready(function(){ + initStepper(".wizard-stepper"); + $( "input[type='radio'].user-select-radio" ).change(function() { + $('.user-select').hide(); + $('#'+$(this).val()).show(); + }); + //Adds an event listener to swithc + $(advanceOperation).on("click", ".wr-input-control.switch", function(evt){ + var operation = $(this).parents(".operation-data").data("operation"); + //prevents event bubbling by figuring out what element it's being called from + if (evt.target.tagName == "INPUT") { + if(!$(this).hasClass('collapsed')){ + configuredProfiles.push(operation); + }else { + //splicing the array if operation is present + var index = jQuery.inArray( operation, configuredProfiles ); + if (index!= -1){ + configuredProfiles.splice( index, 1 ); + } + } + console.log(configuredProfiles); + } + + }); + stepperRegistry['policy-content'] = function (actionButton){ + policy.policyName = $("#policy-name-input").val(); + policy.policyDescription = $("#policy-description-input").val(); + //All data is collected. Policy can now be created. + savePolicy(); + }; + stepperRegistry['policy-criteria'] = function (actionButton){ + $( "input[type='radio'].user-select-radio").each(function(){ + if ( $(this).is(':radio')){ + if ($(this).is(":checked")){ + if($(this).val() == "userSelectField"){ + policy.selectedUsers = $("#users-input").val(); + }else if($(this).val() == "userRoleSelectField"){ + policy.selectedUserRoles = $("#user-roles-input").val(); + } + } + } + }); + policy.selectedAction = $("#action-input").find(":selected").data("action"); + policy.selectedOwnership = $("#ownership-input").val(); + + }; + stepperRegistry['policy-profile'] = function (actionButton){ + var deviceType = policy.platform; + var generatedProfile = operationModule.generateProfile(deviceType, configuredProfiles); + policy.profile = generatedProfile; + }; + stepperRegistry['policy-platform'] = function (actionButton){ + policy.platform = $(actionButton).data("platform"); + policy.platformId = $(actionButton).data("platform-id"); + + }; + $(".uu").click(function(){ + var policyName = $("#policy-name-input").val(); + var selectedProfiles = $("#profile-input").find(":selected"); + var selectedProfileId = selectedProfiles.data("id"); + var selectedUserRoles = $("#user-roles-input").val(); + var selectedUsers = $("#users-input").val(); + var selectedAction = $("#action-input").val(); + + + }); +}); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-android.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-android.hbs new file mode 100644 index 00000000..c8eb81e2 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-android.hbs @@ -0,0 +1,251 @@ +
    +
    + + + + + Security + + + + + + Restrictions + + + + + + Applications + + + + + + Wi-fi + +
    +
    + + +
    +
    + +
    +
    + +
    + +
    +
    +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + +
    + +
    + + +
    +
    +
    + + + +
    +
    + +
    + + +
    + +
    + + + +
    + +
    + +
    +
    +
    + + +
    +
    + +
    + + +
    + +
    +
    + +
    + + +
    + +
    + +
    +
    +
    + +
    + + +
    + +
    + + +
    + +
    + +
    +
    +
    + +
    + + +
    + +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + +
    + +
    +
    +
    + +
    +
    \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-ios.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-ios.hbs new file mode 100644 index 00000000..4cb006ef --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-ios.hbs @@ -0,0 +1,366 @@ +
    +
    + + + + + Wi-fi + + + + + + Applications + + + + + + Restrictions + + + + + + Mail + + + + + + Air Play + +
    +
    + + +
    +
    + +
    + +
    + +
    + +
    + +
    + + +
    + +
    +
    + + +
    +
    + + +
    + Install +
    + +
    +
    + +
    + +
    + +
    + +
    + +
    + + +
    + +
    +
    + + +
    +
    + + +
    + Install +
    +
    +
    + +
    + +
    + +
    + Uninstall +
    +
    +
    + + + +
    + + +
    + +
    + +
    + + +
    + +
    + + +
    + + + +
    + +
    + + + +
    + +
    + + + +
    + +
    + + + +
    + +
    + Configure +
    + + + +
    + + +
    + +
    + + + +
    +
    + +
    +
    + Path Prefix +
    +
    +
    + + + +
    + +
    + + + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + + + +
    +
    + +
    +
    + : +
    +
    +
    + + + +
    + +
    + + + +
    + +
    + + + +
    + +
    + +
    + + +
    +
    + + + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    + Configure +
    + + +
    + +
    + +
    + +
    + +
    AirPlay password +
    + +
    + Configure +
    + +
    +
    \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.hbs new file mode 100644 index 00000000..bf566146 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.hbs @@ -0,0 +1,201 @@ +{{#zone "main"}} +
    +
    + +
    +
    +
    +
    + +
    +
    + {{unit "operation-bar" deviceType=device.type}} +
    +
    + + + +
    +
    +
    + +
    +
    +
    Owner: {{device.owner}}
    +
    Date of Enrollment:
    {{device.enrollment}}
    + + + + + +
    +
    +
    + +
    + + +
    + +
    + {{#if device.viewModel.BatteryLevel}} +
    +
    +
    BATTERY
    +
    +
    +
    {{device.viewModel.BatteryLevel}}%
    +
    +
    +
    + {{/if}} + + {{#if device.viewModel.DeviceCapacity}} +
    +
    +
    STORAGE
    +
    +
    +
    {{device.viewModel.DeviceCapacityPercentage}}%{{device.viewModel.DeviceCapacityUsed}} GB Free
    +
    +
    +
    + {{/if}} + {{#if device.viewModel.internal_memory.FreeCapacity}} +
    +
    +
    LOCAL STORAGE
    +
    +
    +
    {{device.viewModel.internal_memory.DeviceCapacityPercentage}}%{{device.viewModel.internal_memory.FreeCapacity}} GB Free
    +
    +
    +
    + {{/if}} + {{#if device.viewModel.external_memory.FreeCapacity}} +
    +
    +
    EXTERNAL STORAGE
    +
    +
    +
    {{device.viewModel.external_memory.DeviceCapacityPercentage}}%{{device.viewModel.external_memory.FreeCapacity}} GB Free
    +
    +
    +
    + {{/if}} +
    + +
    + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    +
    + Not available yet +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +
    +
    + +{{/zone}} +{{#zone "bottomJs"}} + + +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.js new file mode 100644 index 00000000..769d3041 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.js @@ -0,0 +1,58 @@ +function onRequest(context) { + var uri = request.getRequestURI(); + var uriMatcher = new URIMatcher(String(uri)); + var isMatched = uriMatcher.match("/{context}/device/{deviceType}/{+deviceId}"); + if (isMatched) { + var matchedElements = uriMatcher.elements(); + var deviceType = matchedElements.deviceType; + var deviceId = matchedElements.deviceId; + context.deviceType = deviceType; + context.deviceId = deviceId; + var deviceModule = require("/modules/device.js").deviceModule; + var device = deviceModule.viewDevice(deviceType, deviceId); + if (device){ + var viewModel = {}; + var deviceInfo = device.properties.DEVICE_INFO; + if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0){ + deviceInfo = JSON.parse(deviceInfo); + if (device.type == "ios"){ + viewModel.imei = device.properties.IMEI; + viewModel.phoneNumber = deviceInfo.PhoneNumber; + viewModel.udid = deviceInfo.UDID; + viewModel.BatteryLevel = Math.round(deviceInfo.BatteryLevel * 100); + viewModel.DeviceCapacity = Math.round(deviceInfo.DeviceCapacity * 100) / 100; + viewModel.AvailableDeviceCapacity = Math.round(deviceInfo.AvailableDeviceCapacity * 100) / 100; + viewModel.DeviceCapacityUsed = Math.round((viewModel.DeviceCapacity + - viewModel.AvailableDeviceCapacity) * 100) / 100; + viewModel.DeviceCapacityPercentage = Math.round(viewModel.DeviceCapacityUsed + / viewModel.DeviceCapacity * 10000) /100; + }else if(device.type == "android"){ + viewModel.imei = device.properties.IMEI; + viewModel.model = device.properties.DEVICE_MODEL; + viewModel.vendor = device.properties.VENDOR; + viewModel.internal_memory = {}; + viewModel.external_memory = {}; + viewModel.location = { + latitude: device.properties.LATITUDE, + longitude: device.properties.LONGITUDE + }; + viewModel.BatteryLevel = deviceInfo.BATTERY_LEVEL; + viewModel.internal_memory.FreeCapacity = Math.round((deviceInfo.INTERNAL_TOTAL_MEMORY - + deviceInfo.INTERNAL_AVAILABLE_MEMORY) * 100) / 100; + viewModel.internal_memory.DeviceCapacityPercentage = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY + / deviceInfo.INTERNAL_TOTAL_MEMORY * 10000) / 100; + viewModel.external_memory.FreeCapacity = Math.round((deviceInfo.EXTERNAL_TOTAL_MEMORY - + deviceInfo.EXTERNAL_AVAILABLE_MEMORY) * 100) / 100; + viewModel.external_memory.DeviceCapacityPercentage = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY + /deviceInfo.EXTERNAL_TOTAL_MEMORY * 10000) /100; + } + viewModel.enrollment = device.enrollment; + device.viewModel = viewModel; + } + } + context.device = device; + } else { + response.sendError(404); + } + return context; +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.json new file mode 100644 index 00000000..3dbff381 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.json @@ -0,0 +1,3 @@ +{ + "predicate": "false" +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/public/js/policy-detail.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/public/js/policy-detail.js new file mode 100644 index 00000000..c453c889 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/public/js/policy-detail.js @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015, 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. + */ + +function formatDates(){ + $(".formatDate").each(function(){ + var timeStamp = $(this).html(); + $(this).html(new Date(parseInt(timeStamp)).toUTCString()); + }); +} + +(function () { + var deviceId = $(".device-id"); + var deviceIdentifier = deviceId.data("deviceid"); + var deviceType = deviceId.data("type"); + var payload = [deviceIdentifier]; + if (deviceType == "ios") { + var serviceUrl = "/ios/operation/deviceinfo"; + } else if (deviceType == "android") { + var serviceUrl = "/mdm-android-agent/operation/device-info"; + } + invokerUtil.post(serviceUrl, payload, + function(message){ + console.log(message); + }, function (message) { + console.log(message); + }); + $(document).ready(function(){ + loadOperationBar(deviceType); + loadMap(); + formatDates(); + }); + function loadMap(){ + var map; + function initialize() { + var mapOptions = { + zoom: 18 + }; + var lat = 6.9098591; + var long = 79.8523753; + map = new google.maps.Map(document.getElementById('device-location'), + mapOptions); + + var pos = new google.maps.LatLng(lat, + long); + var marker = new google.maps.Marker({ + position: pos, + map: map + }); + + map.setCenter(pos); + } + google.maps.event.addDomListener(window, 'load', initialize); + } +}()); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs new file mode 100644 index 00000000..4ec0213e --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs @@ -0,0 +1,80 @@ +{{#zone "main"}} +
    +
    + +
    +

    Policies

    +

    {{listPolicyStatus}}

    +
    + {{#if policies}} + {{#each policies}} + + + +
    +

    {{policyName}}

    + {{policyName}} +
    + + + + + + + + Remove + + +
    +
    + {{/each}} + {{else}} + +
    +
    +

    You don't have any Policies added at the moment.

    +

    + + + + + + Add New Policy + +

    +
    +
    + + {{/if}} +
    +
    + +
    +
    + + + +{{/zone}} +{{#zone "common-navigation"}} + +{{/zone}} +{{#zone "action-bar"}} + {{#if permissions.ADD_POLICY}} + + + + + + Add Policy + + {{/if}} +{{/zone}} +{{#zone "bottomJs"}} + +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js new file mode 100644 index 00000000..238b8130 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js @@ -0,0 +1,18 @@ +function onRequest(context) { + // var log = new Log("policy-listing"); + var policyModule = require("/modules/policy.js").policyModule; + var allPolicies = policyModule.getPolicies(); + if (!allPolicies || allPolicies.length == 0) { + context.policies = []; + context.listPolicyStatus = "Oops, Sorry, No other Policies found."; + } else { + var i, filteredPoliciesList = []; + for (i = 0; i < allPolicies.length; i++) { + filteredPoliciesList.push(allPolicies[i]); + } + context.policies = filteredPoliciesList; + context.listPolicyStatus = "Total number of Policies found : " + filteredPoliciesList.length; + } + //context.permissions = policyModule.getUIPermissions(); + return context; +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.json new file mode 100644 index 00000000..3f780100 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.json @@ -0,0 +1,5 @@ +{ + + + +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/public/js/policy-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/public/js/policy-listing.js new file mode 100644 index 00000000..c28963b2 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/public/js/policy-listing.js @@ -0,0 +1,131 @@ +/** + * Sorting function of users + * listed on User Management page in WSO2 MDM Console. + */ +$(function () { + var sortableElem = '.wr-sortable'; + $(sortableElem).sortable({ + beforeStop : function () { + var sortedIDs = $(this).sortable('toArray'); + console.log(sortedIDs); + } + }); + $(sortableElem).disableSelection(); +}); + +var modalPopup = ".wr-modalpopup"; +var modalPopupContainer = modalPopup + " .modalpopup-container"; +var modalPopupContent = modalPopup + " .modalpopup-content"; +var body = "body"; + +/* + * set popup maximum height function. + */ +function setPopupMaxHeight() { + $(modalPopupContent).css('max-height', ($(body).height() - ($(body).height()/100 * 30))); + $(modalPopupContainer).css('margin-top', (-($(modalPopupContainer).height()/2))); +} + +/* + * show popup function. + */ +function showPopup() { + $(modalPopup).show(); + setPopupMaxHeight(); +} + +/* + * hide popup function. + */ +function hidePopup() { + $(modalPopupContent).html(''); + $(modalPopup).hide(); +} + +/** + * Following click function would execute + * when a user clicks on "Invite" link + * on User Management page in WSO2 MDM Console. + */ +$("a.invite-user-link").click(function () { + var username = $(this).data("username"); + var inviteUserAPI = "/iotserver/api/users/" + username + "/invite"; + + $(modalPopupContent).html($('#invite-user-modal-content').html()); + showPopup(); + + $("a#invite-user-yes-link").click(function () { + invokerUtil.get( + inviteUserAPI, + function () { + $(modalPopupContent).html($('#invite-user-success-content').html()); + $("a#invite-user-success-link").click(function () { + hidePopup(); + }); + }, + function () { + $(modalPopupContent).html($('#invite-user-error-content').html()); + $("a#invite-user-error-link").click(function () { + hidePopup(); + }); + } + ); + }); + + $("a#invite-user-cancel-link").click(function () { + hidePopup(); + }); +}); + +/** + * Following click function would execute + * when a user clicks on "Remove" link + * on User Management page in WSO2 MDM Console. + */ +$("a.remove-user-link").click(function () { + var username = $(this).data("username"); + var removeUserAPI = "/iotserver/api/users/" + username + "/remove"; + + $(modalPopupContent).html($('#remove-user-modal-content').html()); + showPopup(); + + $("a#remove-user-yes-link").click(function () { + invokerUtil.get( + removeUserAPI, + function (data) { + if (data == 200) { + $("#" + username).addClass("hide"); + $(modalPopupContent).html($('#remove-user-200-content').html()); + $("a#remove-user-200-link").click(function () { + hidePopup(); + }); + } else if (data == 400) { + $(modalPopupContent).html($('#remove-user-400-content').html()); + $("a#remove-user-400-link").click(function () { + hidePopup(); + }); + } else if (data == 403) { + $(modalPopupContent).html($('#remove-user-403-content').html()); + $("a#remove-user-403-link").click(function () { + hidePopup(); + }); + } else if (data == 409) { + $(modalPopupContent).html($('#remove-user-409-content').html()); + $("a#remove-user-409-link").click(function () { + hidePopup(); + }); + } + }, + function () { + $(modalPopupContent).html($('#remove-user-unexpected-error-content').html()); + $("a#remove-user-unexpected-error-link").click(function () { + hidePopup(); + }); + } + ); + }); + + $("a#remove-user-cancel-link").click(function () { + hidePopup(); + }); +}); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-theme.css b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-theme.css index 21acacdc..a5864677 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-theme.css +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/custom-theme.css @@ -532,3 +532,4 @@ select.select2 { .select2-dropdown { z-index: 10000; } + diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css index 9f644953..a1a5c3aa 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css @@ -547,3 +547,52 @@ header{background-color: #2a2a2a;} .wiz-lbl { padding-top:30px; } + +/* wizard */ +.wr-wizard { + border-bottom:1px solid #f0f0f0; + padding-bottom:20px; + margin-bottom:20px; +} + +.itm-wiz-current .wiz-no { + border:1px solid #444; + color:#fff; + background:#444; +} + +.itm-wiz { + font-weight:100; + margin-top:50px; +} + +.itm-wiz div { + display:inline-block; + float:left; +} + +.wiz-no { + width:50px; + height:50px; + font-size:33px; + font-weight: 100; + border-radius: 80px; + border:1px solid #ccc; + color:#fff; + padding:0px 12px; + padding-bottom:10px; + display:inline-block; + text-align: center; + background:#ccc; + margin-right: 10px; +} + +.wiz-lbl { + width:190px; + font-size:17px; +} + +.wiz-lbl > span { + padding-top:0px; + display:inline-block; +} \ No newline at end of file