From 352643a4218f2a1566c1feb720b531702153d439 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 11 Aug 2016 15:31:28 +0530 Subject: [PATCH 1/2] Changing deactivate-policy api method to PUT --- .../device/mgt/jaxrs/service/api/PolicyManagementService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index da0931e10fe..1ede29f3e87 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -374,7 +374,7 @@ public interface PolicyManagementService { required = true) List policyIds); - @POST + @PUT @Path("/deactivate-policy") @ApiOperation( consumes = MediaType.APPLICATION_JSON, From 390d929e706d505a0bd2a37a60d1a29738eb75a2 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 11 Aug 2016 15:49:45 +0530 Subject: [PATCH 2/2] Adding policy priority UI --- .../cdmf.page.policy.priority/priority.hbs | 9 +- .../cdmf.page.policy.priority/priority.json | 2 +- .../cdmf.unit.policy.priority/priority.hbs | 200 ++++++++---------- .../cdmf.unit.policy.priority/priority.js | 17 +- .../public/js/policy-priority.js | 78 ++++--- .../public/js/sortable-list.js | 4 +- 6 files changed, 156 insertions(+), 154 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs index 6295e4b87dc..7b1a0775fe6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.hbs @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. }} -{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}} +{{unit "cdmf.unit.ui.title" pageTitle="Policy Management | Policy Priorities"}} {{#zone "breadcrumbs"}}
  • @@ -24,10 +24,17 @@
  • + Policies
  • +
  • + + + Priorities + +
  • {{/zone}} {{#zone "content"}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json index 96ec4c8d857..b8be6d8bbb8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policy.priority/priority.json @@ -1,5 +1,5 @@ { "version": "1.0.0", - "uri": "/policy/priority", + "uri": "/policy/priority", "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.policy.priority/priority.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs index 5a7fea7f8ae..f4c6ff77540 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.hbs @@ -15,20 +15,19 @@ specific language governing permissions and limitations under the License. }} +
     Policy List by priority order
    -
    -
    -
    - {{policyListingStatusMsg}} - -
    - {{#each policyListToView}} - +
    +
    + {{policyListingStatusMsg}} +
    + {{#each policyListToView}} +
    @@ -40,15 +39,7 @@ - {{#equal platform "android"}} - - {{/equal}} - {{#equal platform "windows"}} - - {{/equal}} - {{#equal platform "ios"}} - - {{/equal}} +

    {{name}}

    @@ -62,19 +53,20 @@ Ownership Type : {{ownershipType}}
    - {{#if roles}} + {{#equal roles "None"}}
    - Assigned Role(s) : {{roles}} + Assigned User(s) : {{users}}
    - {{else}} + {{/equal}} + {{#equal users "None"}}
    - Assigned User(s) : {{users}} + Assigned Role(s) : {{roles}}
    - {{/if}} + {{/equal}}
    Compliance Type : {{compliance}} @@ -84,120 +76,112 @@
    - {{/each}} -
    - {{#equal noPolicy false}} -
    - - + {{/each}}
    - {{/equal}} + {{#equal noPolicy false}} +
    + + +
    + {{/equal}} +
    -
    -
    -
    -
    -
    -

    Do you really want to apply changes to all policies?

    - -
    - - Yes - - - No - +
    +
    +
    +
    +

    Do you really want to apply changes to all policies?

    + +
    -
    -
    -
    -
    -
    -

    Done. Changes applied successfully.

    - -
    - - Ok - +
    +
    +
    +
    +

    Done. Changes applied successfully.

    + +
    -
    -
    -
    -
    -
    -

    An unexpected error occurred. Please try again later.

    - -
    - - Ok - +
    +
    +
    +
    +

    An unexpected error occurred. Please try again later.

    + +
    -
    -
    -
    -
    -
    -

    An unexpected error occurred. Please try again later.

    - -
    - - Ok - +
    +
    +
    +
    +

    An unexpected error occurred. Please try again later.

    + +
    -
    -
    -
    -
    -
    -

    Done. New Policy priorities were successfully updated.

    - -
    - - Ok - +
    +
    +
    +
    +

    Done. New Policy priorities were successfully updated.

    + +
    -
    -
    -
    -
    -
    -

    An unexpected error occurred. Please try again later.

    -

    - -
    - - Ok - +
    +
    +
    +
    +

    An unexpected error occurred. Please try again later.

    +
    diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js index 2ba2155ac20..a6afb10f6bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js @@ -1,17 +1,17 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. */ @@ -27,8 +27,9 @@ function onRequest(context) { return options.fn(this); } }); - var policyModule = require("/app/modules/business-controllers/group.js")["groupModule"]; + var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"]; var response = policyModule.getAllPolicies(); + if (response["status"] == "success") { var policyListToView = response["content"]; context["policyListToView"] = policyListToView; @@ -38,7 +39,7 @@ function onRequest(context) { context["saveNewPrioritiesButtonEnabled"] = false; context["noPolicy"] = true; } else if (policyCount == 1) { - context["policyListingStatusMsg"] = "Add more policies to set up a priority order."; + context["policyListingStatusMsg"] = "Two or more policies should be available to set up a priority order."; context["saveNewPrioritiesButtonEnabled"] = false; context["noPolicy"] = false; } else { @@ -47,9 +48,11 @@ function onRequest(context) { context["noPolicy"] = false; } } else { + // here, response["status"] == "error" context["policyListToView"] = []; - context["policyListingStatusMsg"] = response["content"]; + context["policyListingStatusMsg"] = "Error in retrieving policies. Please try reloading the page."; context["saveNewPrioritiesButtonEnabled"] = false; } + return context; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js index f2ccc3b9d15..f6b5514d7e8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/policy-priority.js @@ -1,17 +1,17 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. */ @@ -78,58 +78,66 @@ $(document).ready(function () { newPolicyPriorityList.push(policy); } - var updatePolicyAPI = "/devicemgt_admin/policies/priorities"; + var updatePolicyAPI = "/api/device-mgt/v1.0/policies/priorities"; invokerUtil.put( updatePolicyAPI, newPolicyPriorityList, - function () { - $(modalPopupContent).html($('#save-policy-priorities-success-content').html()); - showPopup(); - $("a#save-policy-priorities-success-link").click(function () { - hidePopup(); - }); + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(modalPopupContent).html($('#save-policy-priorities-success-content').html()); + showPopup(); + $("a#save-policy-priorities-success-link").click(function () { + hidePopup(); + }); + } }, - function () { - $("#save-policy-priorities-error-content").find(".message-from-server").html( - "Message From Server : " + data["statusText"]); - $(modalPopupContent).html($('#save-policy-priorities-error-content').html()); - showPopup(); - $("a#save-policy-priorities-error-link").click(function () { - hidePopup(); - }); + // on error + function (jqXHR) { + if (jqXHR.status == 400 || jqXHR.status == 500) { + $(modalPopupContent).html($("#save-policy-priorities-error-content").html()); + showPopup(); + $("a#save-policy-priorities-error-link").click(function () { + hidePopup(); + }); + } } ); }); $(applyChangesBtn).click(function () { - var applyPolicyChangesAPI = "/devicemgt_admin/policies/apply-changes"; - $(modalPopupContent).html($('#change-policy-modal-content').html()); + var applyPolicyChangesAPI = "/api/device-mgt/v1.0/policies/apply-changes"; + $(modalPopupContent).html($("#apply-changes-modal-content").html()); showPopup(); - $("a#change-policy-yes-link").click(function () { + $("a#apply-changes-yes-link").click(function () { invokerUtil.put( applyPolicyChangesAPI, null, // on success - function () { - $(modalPopupContent).html($('#change-policy-success-content').html()); - showPopup(); - $("a#change-policy-success-link").click(function () { - hidePopup(); - }); + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(modalPopupContent).html($("#apply-changes-success-content").html()); + showPopup(); + $("a#apply-changes-success-link").click(function () { + hidePopup(); + }); + } }, // on error - function () { - $(modalPopupContent).html($('#change-policy-error-content').html()); - showPopup(); - $("a#change-policy-error-link").click(function () { - hidePopup(); - }); + function (jqXHR) { + if (jqXHR.status == 500) { + $(modalPopupContent).html($("#apply-changes-error-content").html()); + showPopup(); + $("a#apply-changes-error-link").click(function () { + hidePopup(); + }); + } } ); }); - $("a#change-policy-cancel-link").click(function () { + $("a#apply-changes-cancel-link").click(function () { hidePopup(); }); }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js index c4f78b1bc11..c436e2ac56d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/public/js/sortable-list.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 @@ -47,7 +47,7 @@ var sortableListFunction = (function () { } /** - * on input text field focus autocomplete bind function + * on input text field focus auto-complete bind function */ $(sortableElem).on('focus', '.wr-sort-index input.index', function () { currentElemId = $(this).val();