diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java index c0c768eeb2..e7ef0c0e6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper; import javax.validation.constraints.Size; import java.util.List; @@ -75,6 +76,10 @@ public class PolicyWrapper { required = true) private List users; + @ApiModelProperty(name = "deviceGroups", value = "Lists out the groups on whose devices the policy is enforced", + required = true) + private List deviceGroups; + public Profile getProfile() { return profile; } @@ -147,4 +152,12 @@ public class PolicyWrapper { this.users = users; } + public List getDeviceGroups() { + return deviceGroups; + } + + public void setDeviceGroups(List deviceGroups) { + this.deviceGroups = deviceGroups; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 3934ceedf1..16e7a8eb06 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -122,6 +122,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { policy.setRoles(policyWrapper.getRoles()); policy.setUsers(policyWrapper.getUsers()); policy.setCompliance(policyWrapper.getCompliance()); + policy.setDeviceGroups(policyWrapper.getDeviceGroups()); //TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here. List devices = new ArrayList(); List deviceIdentifiers = policyWrapper.getDeviceIdentifiers(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js index 5862f6bc8e..fefd73bd0b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js @@ -79,4 +79,30 @@ var groupModule = {}; ); }; + groupModule.getGroups = function () { + var permissions = userModule.getUIPermissions(); + if (permissions.LIST_ALL_GROUPS) { + endPoint = deviceServiceEndpoint + "/admin/groups"; + } else if (permissions.LIST_GROUPS) { + endPoint = deviceServiceEndpoint + "/groups"; + } else { + log.error("Access denied for user: " + carbonUser.username); + return -1; + } + return serviceInvokers.XMLHttp.get( + endPoint, function (responsePayload) { + var data = JSON.parse(responsePayload.responseText); + if(data) { + return data.deviceGroups; + } else { + return []; + } + }, + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + }(groupModule)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs index 4c5280f154..0738a93225 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs @@ -34,6 +34,7 @@
  • + Policies @@ -41,18 +42,24 @@ {{/zone}} {{#zone "navbarActions"}} - {{#if managePermitted}} -
  • - - - - - - Add Policy - -
  • + {{#if permissions.ADD_ADMIN_POLICY}} {{#equal noPolicy false}}
  • + + + + + + + Add New Policy + +
  • + {{/equal}} + {{/if}} + {{#if permissions.CHANGE_POLICY_PRIORITY}} + {{#equal noPolicy false}} +
  • + @@ -75,44 +82,37 @@ {{/zone}} {{#zone "content"}} + {{#equal isUpdated true}} + + {{/equal}} {{#equal noPolicy true}} {{/equal}} {{#equal noPolicy false}} - {{#equal isUpdated true}} - - {{/equal}}
    Loading policies . . .
    - @@ -141,10 +141,9 @@ - - - + - + - - - + + + {{/each}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js index 33a4088306..515a002f94 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js @@ -6,12 +6,12 @@ * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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 + * "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. */ @@ -37,27 +37,23 @@ function onRequest(context) { var policyCount = policyListToView.length; if (policyCount == 0) { page["policyListingStatusMsg"] = "No policy is available to be displayed."; - page["saveNewPrioritiesButtonEnabled"] = false; page["noPolicy"] = true; - } else if (policyCount == 1) { - page["saveNewPrioritiesButtonEnabled"] = false; - page["noPolicy"] = false; - page["isUpdated"] = response["updated"]; } else { - page["saveNewPrioritiesButtonEnabled"] = true; page["noPolicy"] = false; page["isUpdated"] = response["updated"]; } } else { // here, response["status"] == "error" - page["policyListToView"] = []; - page["policyListingStatusMsg"] = "An unexpected error occurred @ backend. Please try again later."; - page["saveNewPrioritiesButtonEnabled"] = false; + page["policyListingStatusMsg"] = "An unexpected error occurred. Please try again later."; page["noPolicy"] = true; } - if (userModule.isAuthorized("/permission/admin/device-mgt/policies/manage")) { - page.managePermitted = true; + if (userModule.isAuthorized("/permission/admin/device-mgt/policies/remove")) { + page["removePermitted"] = true; + } + if (userModule.isAuthorized("/permission/admin/device-mgt/policies/update")) { + page["editPermitted"] = true; } + page.permissions = userModule.getUIPermissions(); return page; -} +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js index e70c127c20..8e31e39ecc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/public/js/policy-list.js @@ -1,30 +1,30 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015-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 + * 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 + * "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. */ /* sorting function */ var sortUpdateBtn = "#sortUpdateBtn"; -var sortedIDs; -var dataTableSelection = '.DTTT_selected'; +// var sortedIDs; +// var dataTableSelection = ".DTTT_selected"; var settings = { "sorting": false }; $('#policy-grid').datatables_extended(settings); -$(".icon .text").res_text(0.2); +// $(".icon .text").res_text(0.2); var saveNewPrioritiesButton = "#save-new-priorities-button"; var saveNewPrioritiesButtonEnabled = Boolean($(saveNewPrioritiesButton).data("enabled")); @@ -41,25 +41,6 @@ function InitiateViewOption() { $(location).attr('href', $(this).data("url")); } -var addSortableIndexNumbers = function () { - $(".wr-sortable .list-group-item").not(".ui-sortable-placeholder").each(function (i) { - $(".wr-sort-index", this).html(i + 1); - }); -}; - -var sortElements = function () { - addSortableIndexNumbers(); - var sortableElem = ".wr-sortable"; - $(sortableElem).sortable({ - beforeStop: function () { - sortedIDs = $(this).sortable("toArray"); - addSortableIndexNumbers(); - $(sortUpdateBtn).prop("disabled", false); - } - }); - $(sortableElem).disableSelection(); -}; - /** * Modal related stuff are as follows. */ @@ -129,31 +110,29 @@ function getSelectedPolicies() { } $(document).ready(function () { - sortElements(); - $("#loading-content").remove(); - var policyRoles = $("#policy-roles").text(); - var policyUsers = $("#policy-users").text(); + /** + * ******************************************** + * Click functions related to Policy Listing + * ******************************************** + */ - if (!policyRoles) { - $("#policy-roles").hide(); - } - if (!policyUsers) { - $("#policy-users").hide(); - } + // [1] logic for running apply-changes-for-devices use-case - if ($("#policy-listing-status-msg").text()) { - $("#policy-listing-status").removeClass("hidden"); - } + var applyChangesButtonId = "#appbar-btn-apply-changes"; - // Click functions related to Policy Listing - var isUpdated = $('#is-updated').val(); + var isUpdated = $("#is-updated").val(); if (!isUpdated) { - $('#appbar-btn-apply-changes').addClass('hidden'); + // if no updated policies found, hide button from app bar + $(applyChangesButtonId).addClass("hidden"); + } else { + // if updated policies found, show button from app bar + $(applyChangesButtonId).removeClass("hidden"); } - $("#appbar-btn-apply-changes").click(function () { - var applyPolicyChangesAPI = "/devicemgt_admin/policies/apply-changes"; + // click-event function for applyChangesButton + $(applyChangesButtonId).click(function () { + var serviceURL = "/api/device-mgt/v1.0/policies/apply-changes"; modalDialog.header('Do you really want to apply changes to all policies?'); modalDialog.footer(''); @@ -161,20 +140,23 @@ $(document).ready(function () { $("a#change-policy-yes-link").click(function () { invokerUtil.put( - applyPolicyChangesAPI, + serviceURL, null, // on success - function () { - modalDialog.header('Done. Changes applied successfully.'); - modalDialog.footer(''); - $("a#change-policy-success-link").click(function () { - modalDialog.hide(); - location.reload(); - }); + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + modalDialog.header('Done. Changes applied successfully.'); + modalDialog.footer(''); + $("a#change-policy-success-link").click(function () { + modalDialog.hide(); + location.reload(); + }); + } }, // on error - function () { + function (jqXHR) { + console.log(stringify(jqXHR.data)); modalDialog.header('An unexpected error occurred. Please try again later.'); modalDialog.footer(''); @@ -191,61 +173,26 @@ $(document).ready(function () { }); }); - $(sortUpdateBtn).click(function () { - $(sortUpdateBtn).prop("disabled", true); - - var newPolicyPriorityList = []; - var policy; - var i; - for (i = 0; i < sortedIDs.length; i++) { - policy = {}; - policy.id = parseInt(sortedIDs[i]); - policy.priority = i + 1; - newPolicyPriorityList.push(policy); - } - - var updatePolicyAPI = "/devicemgt_admin/policies/priorities"; - invokerUtil.put( - updatePolicyAPI, - newPolicyPriorityList, - function () { - modalDialog.header('Done. New Policy priorities were successfully updated.'); - modalDialog.footer('Ok' + - ''); - modalDialog.show(); - $("a#save-policy-priorities-success-link").click(function () { - modalDialog.hide(); - }); - }, - function () { - modalDialog.header('An unexpected error occurred. Please try again later.'); - modalDialog.content(html("Message From Server : " + data["statusText"])); - modalDialog.footer(''); - modalDialog.showAsError(); - $("a#save-policy-priorities-error-link").click(function () { - modalDialog.hide(); - }); - } - ); - - }); + // [2] logic for un-publishing a selected set of Active, Active/Updated policies $(".policy-unpublish-link").click(function () { var policyList = getSelectedPolicies(); var statusList = getSelectedPolicyStates(); - if (($.inArray('Inactive/Updated', statusList) > -1) || ($.inArray('Inactive', statusList) > -1)) { - modalDialog.header('Operation cannot be performed !'); - modalDialog.content('You cannot select already inactive policies. Please deselect inactive policies and ' + - 'try again.'); - modalDialog.footer(''); + if (($.inArray("Inactive/Updated", statusList) > -1) || ($.inArray("Inactive", statusList) > -1)) { + // if policies found in Inactive or Inactive/Updated states with in the selection, + // pop-up an error saying + // "You cannot select already inactive policies. Please deselect inactive policies and try again." + modalDialog.header('Action cannot be performed !'); + modalDialog.content('You cannot select already inactive policies to be unpublished. Please deselect ' + + 'inactive policies and try again.'); + modalDialog.footer('
    Ok' + + '
    '); modalDialog.showAsAWarning(); } else { - var serviceURL = "/devicemgt_admin/policies/inactivate"; - if (policyList == 0) { - modalDialog.header('Operation cannot be performed !'); - modalDialog.content('Please select a policy or a list of policies to unpublish.'); + var serviceURL = "/api/device-mgt/v1.0/policies/deactivate-policy"; + if (policyList.length == 0) { + modalDialog.header('Action cannot be performed !'); + modalDialog.content('Please select a policy or a list of policies to un-publish.'); modalDialog.footer(''); modalDialog.showAsAWarning(); @@ -257,22 +204,26 @@ $(document).ready(function () { modalDialog.show(); } + // on-click function for policy un-publishing "yes" button $("a#unpublish-policy-yes-link").click(function () { - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success - function () { - modalDialog.header('Done. Selected policy was successfully unpublished.'); - modalDialog.footer(''); - $("a#unpublish-policy-success-link").click(function () { - modalDialog.hide(); - location.reload(); - }); + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + modalDialog.header('Done. Selected policy was successfully unpublished.'); + modalDialog.footer(''); + $("a#unpublish-policy-success-link").click(function () { + modalDialog.hide(); + location.reload(); + }); + } }, // on error - function () { + function (jqXHR) { + console.log(stringify(jqXHR.data)); modalDialog.header('An unexpected error occurred. Please try again later.'); modalDialog.footer(''); @@ -284,30 +235,35 @@ $(document).ready(function () { ); }); + // on-click function for policy un-publishing "cancel" button $("a#unpublish-policy-cancel-link").click(function () { modalDialog.hide(); }); } }); + // [3] logic for publishing a selected set of Inactive, Inactive/Updated policies $(".policy-publish-link").click(function () { var policyList = getSelectedPolicies(); var statusList = getSelectedPolicyStates(); - if (($.inArray('Active/Updated', statusList) > -1) || ($.inArray('Active', statusList) > -1)) { - modalDialog.header('Operation cannot be performed !'); + if (($.inArray("Active/Updated", statusList) > -1) || ($.inArray("Active", statusList) > -1)) { + // if policies found in Active or Active/Updated states with in the selection, + // pop-up an error saying + // "You cannot select already active policies. Please deselect active policies and try again." + modalDialog.header('Action cannot be performed !'); modalDialog.content('You cannot select already active policies. Please deselect active policies and try ' + 'again.'); modalDialog.footer(''); modalDialog.showAsAWarning(); } else { - var serviceURL = "/devicemgt_admin/policies/activate"; - if (policyList == 0) { - modalDialog.header('Operation cannot be performed !'); + var serviceURL = "/api/device-mgt/v1.0/policies/activate-policy"; + if (policyList.length == 0) { + modalDialog.header('Action cannot be performed !'); modalDialog.content('Please select a policy or a list of policies to publish.'); - modalDialog.footer(''); + modalDialog.footer(''); modalDialog.showAsAWarning(); } else { modalDialog.header('Do you really want to publish the selected policy(s)?'); @@ -316,23 +272,26 @@ $(document).ready(function () { 'class="btn-operations btn-default">No'); modalDialog.show(); } - + // on-click function for policy removing "yes" button $("a#publish-policy-yes-link").click(function () { - invokerUtil.put( + invokerUtil.post( serviceURL, policyList, // on success - function () { - modalDialog.header('Done. Selected policy was successfully published.'); - modalDialog.footer(''); - $("a#publish-policy-success-link").click(function () { - modalDialog.hide(); - location.reload(); - }); + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + modalDialog.header('Done. Selected policy was successfully published.'); + modalDialog.footer(''); + $("a#publish-policy-success-link").click(function () { + modalDialog.hide(); + location.reload(); + }); + } }, // on error - function () { + function (jqXHR) { + console.log(stringify(jqXHR.data)); modalDialog.header('An unexpected error occurred. Please try again later.'); modalDialog.footer(''); @@ -344,66 +303,64 @@ $(document).ready(function () { ); }); + // on-click function for policy removing "cancel" button $("a#publish-policy-cancel-link").click(function () { modalDialog.hide(); }); } }); + // [4] logic for removing a selected set of policies + $(".policy-remove-link").click(function () { var policyList = getSelectedPolicies(); - var deletePolicyAPI = "/devicemgt_admin/policies/bulk-remove"; - if (policyList == 0) { - modalDialog.header('Operation cannot be performed !'); - modalDialog.content('Please select a policy or a list of policies to remove.'); + var statusList = getSelectedPolicyStates(); + if (($.inArray("Active/Updated", statusList) > -1) || ($.inArray("Active", statusList) > -1)) { + // if policies found in Active or Active/Updated states with in the selection, + // pop-up an error saying + // "You cannot remove already active policies. Please deselect active policies and try again." + modalDialog.header('Action cannot be performed !'); + modalDialog.content('You cannot select already active policies. Please deselect active policies and try ' + + 'again.'); modalDialog.footer(''); modalDialog.showAsAWarning(); } else { - modalDialog.header('Do you really want to remove the selected policy(s)?'); - modalDialog.footer(''); - modalDialog.show(); - } + var serviceURL = "/api/device-mgt/v1.0/policies/remove-policy"; + if (policyList.length == 0) { + modalDialog.header('Action cannot be performed !'); + modalDialog.content('Please select a policy or a list of policies to remove.'); + modalDialog.footer(''); + modalDialog.showAsAWarning(); + } else { + modalDialog.header('Do you really want to remove the selected policy(s)?'); + modalDialog.footer(''); + modalDialog.show(); + } - $("a#remove-policy-yes-link").click(function () { - invokerUtil.post( - deletePolicyAPI, - policyList, - // on success - function (data) { - data = JSON.parse(data); - if (data.errorMessage) { - modalDialog.header('Cannot Remove Policies.'); - modalDialog.footer(''); - modalDialog.showAsError(); - $("a#remove-policy-error-devices").click(function () { - modalDialog.hide(); - }); - } else { - modalDialog.header('Done. Selected policy was successfully removed.'); - modalDialog.footer(''); - $("a#remove-policy-success-link").click(function () { - var thisTable = $(".DTTT_selected").closest('.dataTables_wrapper').find('.dataTable').dataTable(); - thisTable.api().rows('.DTTT_selected').remove().draw(false); - modalDialog.hide(); - }); - } - }, - // on error - function (data) { - if (JSON.parse(data.responseText).errorMessage) { - modalDialog.header('Cannot Remove Policies.'); - modalDialog.footer(''); - modalDialog.showAsError(); - $("a#remove-policy-error-devices").click(function () { - modalDialog.hide(); - }); - } else { + // on-click function for policy removing "yes" button + $("a#remove-policy-yes-link").click(function () { + invokerUtil.post( + serviceURL, + policyList, + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + modalDialog.header('Done. Selected policy was successfully removed.'); + modalDialog.footer(''); + $("a#remove-policy-success-link").click(function () { + modalDialog.hide(); + location.reload(); + }); + } + }, + // on error + function (jqXHR) { + console.log(stringify(jqXHR.data)); modalDialog.header('An unexpected error occurred. Please try again later.'); modalDialog.footer(''); @@ -412,15 +369,19 @@ $(document).ready(function () { modalDialog.hide(); }); } - } - ); - }); + ); + }); - $("a#remove-policy-cancel-link").click(function () { - modalDialog.hide(); - }); + // on-click function for policy removing "cancel" button + $("a#remove-policy-cancel-link").click(function () { + modalDialog.hide(); + }); + } }); + $("#loading-content").remove(); + if ($("#policy-listing-status-msg").text()) { + $("#policy-listing-status").removeClass("hidden"); + } $("#policy-grid").removeClass("hidden"); - $(".icon .text").res_text(0.2); -}); +}); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json index 13574a2cb4..5322b6ff2b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.create.wizard/wizard.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.0", "uri": "/policy/add/{deviceType}", - "layout": "cdmf.layout.default" + "layout": "cdmf.layout.default" } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.hbs new file mode 100644 index 0000000000..20db2036a4 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.hbs @@ -0,0 +1,14 @@ +{{#zone "topCss"}} + {{css "css/codemirror.css"}} +{{/zone}} +
    +
    + +
    +
    +
    +{{#zone "bottomJs"}} + {{js "js/codemirror.js"}} + {{js "js/sql.js"}} + {{js "js/editor.js"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.json new file mode 100644 index 0000000000..b88788f78b --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/policy-wizard.json @@ -0,0 +1,3 @@ +{ + "version" : "1.0.0" +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/css/codemirror.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/css/codemirror.css similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/css/codemirror.css rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/css/codemirror.css diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/codemirror.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/codemirror.js similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/codemirror.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/codemirror.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js new file mode 100644 index 0000000000..aca1bf0a7c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js @@ -0,0 +1,37 @@ +/* + * 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. + */ + +window.queryEditor = CodeMirror.fromTextArea(document.getElementById('policy-definition-input'), { + mode: MIME_TYPE_SIDDHI_QL, + indentWithTabs: true, + smartIndent: true, + lineNumbers: true, + matchBrackets: true, + autofocus: true, + extraKeys: { + "Shift-2": function (cm) { + insertStr(cm, cm.getCursor(), '@'); + CodeMirror.showHint(cm, getAnnotationHints); + }, + "Ctrl-Space": "autocomplete" + } +}); + +var validatePolicyProfile = function () { + return true; +}; \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/sql.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/sql.js similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.wizard/public/js/sql.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/sql.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js index e64704b078..4e99b801b9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.handlebars/public/js/utils.js @@ -33,12 +33,26 @@ callback(template); } }; + + $.isResourceExists = function (location, callback) { + $.ajax({ + url: location, + type: 'HEAD', + success: function () { + callback(true); + }, + error: function () { + callback(false); + } + }); + }; + $.registerPartial = function (name, location, callback) { - $.get(location, function (data) { - Handlebars.registerPartial( name, data); - console.log("Partial " + name + " has been registered"); - callback(); - }); + $.get(location, function (data) { + Handlebars.registerPartial(name, data); + console.log("Partial " + name + " has been registered"); + callback(); + }); }; })(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs index 6ca4a63285..32e124a9a4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs @@ -1,74 +1,315 @@ -{{! - 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. -}} {{#zone "content"}} {{#if isAuthorized}} +
    -
    + + + +