From 7af8ecc68650fe0213190d6e3046bdae2fffc8d3 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 26 Jul 2016 11:59:10 +0530 Subject: [PATCH 1/3] Added userstore for role listing --- .../impl/RoleManagementServiceImpl.java | 20 +++++++++++++------ .../device/mgt/common/DeviceIdentifier.java | 2 +- ...ApplicationManagerProviderServiceImpl.java | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index 4e788411e30..e0a832a77c0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer; import org.wso2.carbon.user.api.*; +import org.wso2.carbon.user.core.common.AbstractUserStoreManager; import org.wso2.carbon.user.mgt.UserRealmProxy; import org.wso2.carbon.user.mgt.common.UIPermissionNode; import org.wso2.carbon.user.mgt.common.UserAdminException; @@ -51,22 +52,29 @@ public class RoleManagementServiceImpl implements RoleManagementService { private static final String API_BASE_PATH = "/roles"; private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class); + private static final String PRIMARY_USER_STORE = "PRIMARY"; @GET @Override public Response getRoles( @QueryParam("filter") String filter, - @QueryParam("user-store") String userStoreName, + @QueryParam("user-store") String userStore, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { List filteredRoles; RoleList targetRoles = new RoleList(); + + //if user store is null set it to primary + if(userStore == null || "".equals(userStore)){ + userStore = PRIMARY_USER_STORE; + } + try { //Get the total role count that matches the given filter - filteredRoles = getRolesFromUserStore(filter); + filteredRoles = getRolesFromUserStore(filter, userStore); targetRoles.setCount(filteredRoles.size()); - filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter), offset, limit); + filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit); targetRoles.setList(filteredRoles); return Response.ok().entity(targetRoles).build(); @@ -343,14 +351,14 @@ public class RoleManagementServiceImpl implements RoleManagementService { } } - private List getRolesFromUserStore(String filter) throws UserStoreException { - UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); + private List getRolesFromUserStore(String filter, String userStore) throws UserStoreException { + AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager(); String[] roles; boolean filterRolesByName = (!((filter == null) || filter.isEmpty())); if (log.isDebugEnabled()) { log.debug("Getting the list of user roles"); } - roles = userStoreManager.getRoleNames(); + roles = userStoreManager.getRoleNames(userStore+"/*", -1, false, true, true); // removing all internal roles, roles created for Service-providers and application related roles. List filteredRoles = new ArrayList<>(); for (String role : roles) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 44219d31df5..3a7f39b6e6b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -48,7 +48,7 @@ public class DeviceIdentifier implements Serializable{ } public void setType(String type) { - this.type = type; + this.type = type.toLowerCase(); } public String getId() { return id; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index a33df19a415..18f61261f00 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -95,7 +95,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem //TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()" String type = null; if (deviceIds.size() > 0) { - type = deviceIds.get(0).getType(); + type = deviceIds.get(0).getType().toLowerCase(); } Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). addOperation(type, operation, deviceIds); From 3afd43e14ae7718f7f13953224c084e15e02d4a2 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 26 Jul 2016 12:24:51 +0530 Subject: [PATCH 2/3] Reverting the carbon kernel version back to 4.4.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d9afb815108..41fb7eab3db 100644 --- a/pom.xml +++ b/pom.xml @@ -1739,7 +1739,7 @@ 6.1.1 - 4.4.7 + 4.4.3 [4.4.0, 5.0.0) 1.5.4 1.3 From 1ed0481ec3f386af757f3a88ca215f571dccc711 Mon Sep 17 00:00:00 2001 From: Ace Date: Tue, 26 Jul 2016 16:59:57 +0530 Subject: [PATCH 3/3] Changing nav-bar base-unit implementation --- .../pages/cdmf.page.dashboard/dashboard.hbs | 3 +- .../cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs | 121 ++++-- .../public/js/jquery.qrcode.min.js | 47 +++ .../public/js/nav-menu.js | 378 ++++++++++++++++++ .../public/templates/notifications.hbs | 14 + 5 files changed, 531 insertions(+), 32 deletions(-) create mode 100755 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/jquery.qrcode.min.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs index 012b6df8c09..07f970ec6e1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs @@ -16,12 +16,11 @@ under the License. }} {{unit "cdmf.unit.ui.title" pageTitle="Dashboard"}} -{{unit "cdmf.unit.ui.content.title" pageHeader="Dashboard"}} {{#zone "breadcrumbs"}}
  • - + Dashboard
  • {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index 181056757fb..215a4950680 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -30,13 +30,22 @@ {{/if}} - {{#if permissions.LIST_OWN_DEVICES}} + {{#if permissions.LIST_DEVICES_ADMIN}}
  • Device Management
  • + {{else}} + {{#if permissions.LIST_OWN_DEVICES}} +
  • + + + Device Management + +
  • + {{/if}} {{/if}} {{#if permissions.LIST_GROUPS}}
  • @@ -46,35 +55,87 @@
  • {{/if}} - {{#if permissions.ADD_USER}} -
  • - - - User Management - -
  • - {{/if}} - {{#if permissions.ADD_ROLE}} -
  • - - - Role Management - -
  • - {{/if}} - {{#if permissions.ADD_POLICY}} -
  • - - - Policy Management - -
  • +
  • User Management +
      + {{#if permissions.LIST_USERS}} +
    • Users
    • + {{/if}} + + {{#if permissions.LIST_ROLES}} +
    • Roles
    • + {{/if}} +
    +
  • + {{#if permissions.LIST_POLICIES}} +
  • Policy Management
  • {{/if}} - {{#if permissions.TENANT_CONFIGURATION}} -
  • - - Platform Configurations +
  • Configuration Management + +
  • +{{/zone}} + +{{#zone "navbarCollapsableRightItems"}} + +{{/zone}} + +{{#zone "navbarBelow"}} + +{{/zone}} +{{#zone "sidePanes"}} + +{{/zone}} +{{#zone "bottomJs"}} + + {{js "js/nav-menu.js"}} + {{js "js/jquery.qrcode.min.js"}} +{{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/jquery.qrcode.min.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/jquery.qrcode.min.js new file mode 100755 index 00000000000..2a169909b24 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/jquery.qrcode.min.js @@ -0,0 +1,47 @@ +//--------------------------------------------------------------------- +// QRCode for JavaScript +// +// Copyright (c) 2009 Kazuhiko Arase +// +// URL: http://www.d-project.com/ +// +// Licensed under the MIT license: +// http://www.opensource.org/licenses/mit-license.php +// +// The word "QR Code" is registered trademark of +// DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/faqpatent-e.html +// +//--------------------------------------------------------------------- + +//--------------------------------------------------------------------- +// QR8bitByte +//--------------------------------------------------------------------- +(function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.data=a}function o(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function q(a,c){if(void 0==a.length)throw Error(a.length+"/"+c);for(var d=0;da||this.moduleCount<=a||0>c||this.moduleCount<=c)throw Error(a+","+c);return this.modules[a][c]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var a=1,a=1;40>a;a++){for(var c=p.getRSBlocks(a,this.errorCorrectLevel),d=new t,b=0,e=0;e=d;d++)if(!(-1>=a+d||this.moduleCount<=a+d))for(var b=-1;7>=b;b++)-1>=c+b||this.moduleCount<=c+b||(this.modules[a+d][c+b]= + 0<=d&&6>=d&&(0==b||6==b)||0<=b&&6>=b&&(0==d||6==d)||2<=d&&4>=d&&2<=b&&4>=b?!0:!1)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;8>d;d++){this.makeImpl(!0,d);var b=j.getLostPoint(this);if(0==d||a>b)a=b,c=d}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c=f;f++)for(var i=-2;2>=i;i++)this.modules[b+f][e+i]=-2==f||2==f||-2==i||2==i||0==f&&0==i?!0:!1}},setupTypeNumber:function(a){for(var c= + j.getBCHTypeNumber(this.typeNumber),d=0;18>d;d++){var b=!a&&1==(c>>d&1);this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;18>d;d++)b=!a&&1==(c>>d&1),this.modules[d%3+this.moduleCount-8-3][Math.floor(d/3)]=b},setupTypeInfo:function(a,c){for(var d=j.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;15>b;b++){var e=!a&&1==(d>>b&1);6>b?this.modules[b][8]=e:8>b?this.modules[b+1][8]=e:this.modules[this.moduleCount-15+b][8]=e}for(b=0;15>b;b++)e=!a&&1==(d>>b&1),8>b?this.modules[8][this.moduleCount- + b-1]=e:9>b?this.modules[8][15-b-1+1]=e:this.modules[8][15-b-1]=e;this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,i=this.moduleCount-1;0g;g++)if(null==this.modules[b][i-g]){var n=!1;f>>e&1));j.getMask(c,b,i-g)&&(n=!n);this.modules[b][i-g]=n;e--; -1==e&&(f++,e=7)}b+=d;if(0>b||this.moduleCount<=b){b-=d;d=-d;break}}}};o.PAD0=236;o.PAD1=17;o.createData=function(a,c,d){for(var c=p.getRSBlocks(a, + c),b=new t,e=0;e8*a)throw Error("code length overflow. ("+b.getLengthInBits()+">"+8*a+")");for(b.getLengthInBits()+4<=8*a&&b.put(0,4);0!=b.getLengthInBits()%8;)b.putBit(!1);for(;!(b.getLengthInBits()>=8*a);){b.put(o.PAD0,8);if(b.getLengthInBits()>=8*a)break;b.put(o.PAD1,8)}return o.createBytes(b,c)};o.createBytes=function(a,c){for(var d= + 0,b=0,e=0,f=Array(c.length),i=Array(c.length),g=0;g>>=1;return c},getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case 0:return 0==(c+d)%2;case 1:return 0==c%2;case 2:return 0==d%3;case 3:return 0==(c+d)%3;case 4:return 0==(Math.floor(c/2)+Math.floor(d/3))%2;case 5:return 0==c*d%2+c*d%3;case 6:return 0==(c*d%2+c*d%3)%2;case 7:return 0==(c*d%3+(c+d)%2)%2;default:throw Error("bad maskPattern:"+ +a);}},getErrorCorrectPolynomial:function(a){for(var c=new q([1],0),d=0;dc)switch(a){case 1:return 10;case 2:return 9;case s:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>c)switch(a){case 1:return 12;case 2:return 11;case s:return 16;case 8:return 10;default:throw Error("mode:"+a);}else if(41>c)switch(a){case 1:return 14;case 2:return 13;case s:return 16;case 8:return 12;default:throw Error("mode:"+ +a);}else throw Error("type:"+c);},getLostPoint:function(a){for(var c=a.getModuleCount(),d=0,b=0;b=g;g++)if(!(0>b+g||c<=b+g))for(var h=-1;1>=h;h++)0>e+h||c<=e+h||0==g&&0==h||i==a.isDark(b+g,e+h)&&f++;5a)throw Error("glog("+a+")");return l.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256), + LOG_TABLE:Array(256)},m=0;8>m;m++)l.EXP_TABLE[m]=1<m;m++)l.EXP_TABLE[m]=l.EXP_TABLE[m-4]^l.EXP_TABLE[m-5]^l.EXP_TABLE[m-6]^l.EXP_TABLE[m-8];for(m=0;255>m;m++)l.LOG_TABLE[l.EXP_TABLE[m]]=m;q.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var c=Array(this.getLength()+a.getLength()-1),d=0;d + this.getLength()-a.getLength())return this;for(var c=l.glog(this.get(0))-l.glog(a.get(0)),d=Array(this.getLength()),b=0;b>>7-a%8&1)},put:function(a,c){for(var d=0;d>>c-d-1&1))},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);a&&(this.buffer[c]|=128>>>this.length%8);this.length++}};"string"===typeof h&&(h={text:h});h=r.extend({},{render:"canvas",width:256,height:256,typeNumber:-1, + correctLevel:2,background:"#ffffff",foreground:"#000000"},h);return this.each(function(){var a;if("canvas"==h.render){a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();var c=document.createElement("canvas");c.width=h.width;c.height=h.height;for(var d=c.getContext("2d"),b=h.width/a.getModuleCount(),e=h.height/a.getModuleCount(),f=0;f").css("width",h.width+"px").css("height",h.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",h.background);d=h.width/a.getModuleCount();b=h.height/a.getModuleCount();for(e=0;e").css("height",b+"px").appendTo(c);for(i=0;i").css("width", + d+"px").css("background-color",a.isDark(e,i)?h.foreground:h.background).appendTo(f)}}a=c;jQuery(a).appendTo(this)})}})(jQuery); \ 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.ui.navbar.nav-menu/public/js/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js new file mode 100644 index 00000000000..0a6e68fcdaa --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -0,0 +1,378 @@ +/* + * 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 modalPopup = ".wr-modalpopup", + modalPopupContainer = modalPopup + " .modalpopup-container", + modalPopupContent = modalPopup + " .modalpopup-content"; + +var emmAdminBasePath = "/api/device-mgt/v1.0"; + +//function openCollapsedNav() { +// $(".wr-hidden-nav-toggle-btn").addClass("active"); +// $("#hiddenNav").slideToggle("slideDown", function () { +// if ($(this).css("display") == "none") { +// $(".wr-hidden-nav-toggle-btn").removeClass("active"); +// } +// }); +//} + +/* + * set popup maximum height function. + */ +function setPopupMaxHeight() { + var maxHeight = "max-height"; + var marginTop = "margin-top"; + var body = "body"; + $(modalPopupContent).css(maxHeight, ($(body).height() - ($(body).height() / 100 * 30))); + $(modalPopupContainer).css(marginTop, (-($(modalPopupContainer).height() / 2))); +} + +/* + * show popup function. + */ +function showPopup() { + $(modalPopup).show(); + setPopupMaxHeight(); +} + +/* + * hide popup function. + */ +function hidePopup() { + $(modalPopupContent).html(""); + $(modalPopupContent).removeClass("operation-data"); + $(modalPopup).hide(); +} + +/* + * QR-code generation function. + */ +function generateQRCode(qrCodeClass) { + var enrollmentURL = $("#qr-code-modal").data("enrollment-url"); + $(qrCodeClass).qrcode({ + text: enrollmentURL, + width: 200, + height: 200 + }); +} + +function toggleEnrollment() { + $(".modalpopup-content").html($("#qr-code-modal").html()); + generateQRCode(".modalpopup-content .qr-code"); + showPopup(); +} + +var updateNotificationCount = function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + var responsePayload = JSON.parse(data); + var newNotificationsCount = responsePayload.count; + if (newNotificationsCount > 0) { + $("#notification-bubble").html(newNotificationsCount); + } +// } else { +// $("#notification-bubble").html("Error"); +// } + } +}; + +function loadNotificationsPanel() { + if ("true" == $("#right-sidebar").attr("is-authorized")) { + var serviceURL = emmAdminBasePath + "/notifications?status=NEW"; + invokerUtil.get(serviceURL, updateNotificationCount, hideNotificationCount); + loadNewNotifications(); + } else { + $("#notification-bubble-wrapper").remove(); + } +} + +function hideNotificationCount(jqXHR) { + if (jqXHR.status == 404) { + // this means "no new notifications to show" + $("#notification-bubble").hide(); + } else { + $("#notification-bubble").html("Error"); + } +} + +function loadNewNotifications() { + var messageSideBar = ".sidebar-messages"; + if ($("#right-sidebar").attr("is-authorized") == "true") { + var notifications = $("#notifications"); + var currentUser = notifications.data("currentUser"); + + $.template("notification-listing", notifications.attr("src"), function (template) { + var serviceURL = emmAdminBasePath + "/notifications?status=NEW"; + + var successCallback = function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + var viewModel = {}; + var responsePayload = JSON.parse(data); + + if (responsePayload.notifications) { + viewModel.notifications = responsePayload.notifications; + if (responsePayload.count > 0) { + $(messageSideBar).html(template(viewModel)); + } else { + $(messageSideBar).html("

    No new notifications found...

    "); + } + } else { + $(messageSideBar).html("

    Unexpected error occurred while loading new notifications.

    "); + } + } + }; + var errorCallback = function (jqXHR) { + if (jqXHR.status = 500) { + $(messageSideBar).html("

    Unexpected error occurred while trying " + + "to retrieve any new notifications.

    "); + } + }; + invokerUtil.get(serviceURL, successCallback, errorCallback); + }); + } else { + $(messageSideBar).html("

    You are not authorized to view notifications

    "); + } +} + +/** + * Toggle function for + * notification listing sidebar. + * @return {Null} + */ +$.sidebar_toggle = function (action, target, container) { + var elem = '[data-toggle=sidebar]', + button, + containerOffsetLeft, + containerOffsetRight, + targetOffsetLeft, + targetOffsetRight, + targetWidth, + targetSide, + relationship, + pushType, + buttonParent; + + var sidebar_window = { + update: function (target, container, button) { + containerOffsetLeft = $(container).data('offset-left') ? $(container).data('offset-left') : 0; + containerOffsetRight = $(container).data('offset-right') ? $(container).data('offset-right') : 0; + targetOffsetLeft = $(target).data('offset-left') ? $(target).data('offset-left') : 0; + targetOffsetRight = $(target).data('offset-right') ? $(target).data('offset-right') : 0; + targetWidth = $(target).data('width'); + targetSide = $(target).data("side"); + pushType = $(container).parent().is('body') == true ? 'padding' : 'margin'; + + if (button !== undefined) { + relationship = button.attr('rel') ? button.attr('rel') : ''; + buttonParent = $(button).parent(); + } + }, + + show: function () { + if ($(target).data('sidebar-fixed') == true) { + $(target).height($(window).height() - $(target).data('fixed-offset')); + } + $(target).trigger('show.sidebar'); + if (targetWidth !== undefined) { + $(target).css('width', targetWidth); + } + $(target).addClass('toggled'); + if (button !== undefined) { + if (relationship !== '') { + // Removing active class from all relative buttons + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').removeClass("active"); + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').attr('aria-expanded', 'false'); + } + // Adding active class to button + if (button.attr('data-handle') !== 'close') { + button.addClass("active"); + button.attr('aria-expanded', 'true'); + } + if (buttonParent.is('li')) { + if (relationship !== '') { + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active"); + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent(). + attr('aria-expanded', 'false'); + } + buttonParent.addClass("active"); + buttonParent.attr('aria-expanded', 'true'); + } + } + // Sidebar open function + if (targetSide == 'left') { + if ((button !== undefined) && (button.attr('data-container-divide'))) { + $(container).css(pushType + '-' + targetSide, targetWidth + targetOffsetLeft); + } + $(target).css(targetSide, targetOffsetLeft); + } else if (targetSide == 'right') { + if ((button !== undefined) && (button.attr('data-container-divide'))) { + $(container).css(pushType + '-' + targetSide, targetWidth + targetOffsetRight); + } + $(target).css(targetSide, targetOffsetRight); + } + $(target).trigger('shown.sidebar'); + }, + + hide: function () { + $(target).trigger('hide.sidebar'); + $(target).removeClass('toggled'); + if (button !== undefined) { + if (relationship !== '') { + // Removing active class from all relative buttons + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').removeClass("active"); + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').attr('aria-expanded', 'false'); + } + // Removing active class from button + if (button.attr('data-handle') !== 'close') { + button.removeClass("active"); + button.attr('aria-expanded', 'false'); + } + if ($(button).parent().is('li')) { + if (relationship !== '') { + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active"); + $(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent(). + attr('aria-expanded', 'false'); + } + } + } + // Sidebar close function + if (targetSide == 'left') { + if ((button !== undefined) && (button.attr('data-container-divide'))) { + $(container).css(pushType + '-' + targetSide, targetOffsetLeft); + } + $(target).css(targetSide, -Math.abs(targetWidth + targetOffsetLeft)); + } else if (targetSide == 'right') { + if ((button !== undefined) && (button.attr('data-container-divide'))) { + $(container).css(pushType + '-' + targetSide, targetOffsetRight); + } + $(target).css(targetSide, -Math.abs(targetWidth + targetOffsetRight)); + } + $(target).trigger('hidden.sidebar'); + } + }; + if (action === 'show') { + sidebar_window.update(target, container); + sidebar_window.show(); + } + if (action === 'hide') { + sidebar_window.update(target, container); + sidebar_window.hide(); + } + // binding click function + var body = 'body'; + $(body).off('click', elem); + $(body).on('click', elem, function (e) { + e.preventDefault(); + button = $(this); + container = button.data('container'); + target = button.data('target'); + sidebar_window.update(target, container, button); + /** + * Sidebar function on data container divide + * @return {Null} + */ + if (button.attr('aria-expanded') == 'false') { + sidebar_window.show(); + } else if (button.attr('aria-expanded') == 'true') { + sidebar_window.hide(); + } + }); +}; + +$.fn.collapse_nav_sub = function () { + var navSelector = 'ul.nav'; + + if (!$(navSelector).hasClass('collapse-nav-sub')) { + $(navSelector + ' > li', this).each(function () { + var position = $(this).offset().left - $(this).parent().scrollLeft(); + $(this).attr('data-absolute-position', (position + 5)); + }); + + $(navSelector + ' li', this).each(function () { + if ($('ul', this).length !== 0) { + $(this).addClass('has-sub'); + } + }); + + $(navSelector + ' > li', this).each(function () { + $(this).css({ + 'left': $(this).data('absolute-position'), + 'position': 'absolute' + }); + }); + + $(navSelector + ' li.has-sub', this).on('click', function () { + var elem = $(this); + if (elem.attr('aria-expanded') !== 'true') { + elem.siblings().fadeOut(100, function () { + elem.animate({'left': '15'}, 200, function () { + $(elem).first().children('ul').fadeIn(200); + }); + }); + elem.siblings().attr('aria-expanded', 'false'); + elem.attr('aria-expanded', 'true'); + } else { + $(elem).first().children('ul').fadeOut(100, function () { + elem.animate({'left': $(elem).data('absolute-position')}, 200, function () { + elem.siblings().fadeIn(100); + }); + }); + elem.siblings().attr('aria-expanded', 'false'); + elem.attr('aria-expanded', 'false'); + } + }); + + $(navSelector + ' > li.has-sub ul', this).on('click', function (e) { + e.stopPropagation(); + }); + $(navSelector).addClass('collapse-nav-sub'); + } +}; + +$(document).ready(function () { + loadNotificationsPanel(); + $.sidebar_toggle(); + + $("#right-sidebar").on("click", ".new-notification", function () { + var notificationId = $(this).data("id"); + var redirectUrl = $(this).data("url"); + var markAsReadNotificationsAPI = "/mdm-admin/notifications/" + notificationId + "/CHECKED"; + var messageSideBar = ".sidebar-messages"; + + invokerUtil.put( + markAsReadNotificationsAPI, + null, + function (data) { + data = JSON.parse(data); + if (data.statusCode == responseCodes["ACCEPTED"]) { + location.href = redirectUrl; + } + }, function () { + var content = "
  • Warning

    " + + "

    Unexpected error occurred while loading notification. Please refresh the page and" + + " try again

  • "; + $(messageSideBar).html(content); + } + ); + }); + + if (typeof $.fn.collapse == 'function') { + $('.navbar-collapse.tiles').on('shown.bs.collapse', function () { + $(this).collapse_nav_sub(); + }); + } +}); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs new file mode 100644 index 00000000000..30cf5fb41fb --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs @@ -0,0 +1,14 @@ +{{#each notifications}} +
  • +

    + + + Device Type : {{deviceIdentifier.type}} + +

    +

    {{description}}

    +
  • +{{/each}} \ No newline at end of file